@Override public String toString() { return "SpanId{spanId=" + toLowerBase16() + "}"; }
@Test public void toLowerBase16() { assertThat(SpanId.INVALID.toLowerBase16()).isEqualTo("0000000000000000"); assertThat(first.toLowerBase16()).isEqualTo("0000000000000061"); assertThat(second.toLowerBase16()).isEqualTo("ff00000000000041"); }
@Override public <C /*>>> extends @NonNull Object*/> void inject( SpanContext spanContext, C carrier, Setter<C> setter) { checkNotNull(spanContext, "spanContext"); checkNotNull(setter, "setter"); checkNotNull(carrier, "carrier"); setter.put(carrier, X_B3_TRACE_ID, spanContext.getTraceId().toLowerBase16()); setter.put(carrier, X_B3_SPAN_ID, spanContext.getSpanId().toLowerBase16()); if (spanContext.getTraceOptions().isSampled()) { setter.put(carrier, X_B3_SAMPLED, SAMPLED_VALUE); } }
@Override public <C /*>>> extends @NonNull Object*/> void inject( SpanContext spanContext, C carrier, Setter<C> setter) { checkNotNull(spanContext, "spanContext"); checkNotNull(setter, "setter"); checkNotNull(carrier, "carrier"); setter.put(carrier, X_B3_TRACE_ID, spanContext.getTraceId().toLowerBase16()); setter.put(carrier, X_B3_SPAN_ID, spanContext.getSpanId().toLowerBase16()); if (spanContext.getTraceOptions().isSampled()) { setter.put(carrier, X_B3_SAMPLED, SAMPLED_VALUE); } }
private static void addTracingData( String tracePrefix, SpanContext span, LogEntry.Builder builder) { builder.setTrace(formatTraceId(tracePrefix, span.getTraceId())); builder.setSpanId(span.getSpanId().toLowerBase16()); builder.setTraceSampled(span.getTraceOptions().isSampled()); }
/** * Puts a {@link SpanContext} into the attachments of the given {@link MeasureMap}. * * <p>{@link TraceId} and {@link SpanId} of the {@link SpanContext} will be encoded in base 16 * lower case encoding. * * @param measureMap the {@code MeasureMap} * @param spanContext the {@code SpanContext} to be put as attachments. * @since 0.16 */ public static void putSpanContextAttachments(MeasureMap measureMap, SpanContext spanContext) { checkNotNull(measureMap, "measureMap"); checkNotNull(spanContext, "spanContext"); measureMap.putAttachment(ATTACHMENT_KEY_TRACE_ID, spanContext.getTraceId().toLowerBase16()); measureMap.putAttachment(ATTACHMENT_KEY_SPAN_ID, spanContext.getSpanId().toLowerBase16()); }
@Test public void putSpanContext() { FakeMeasureMap measureMap = new FakeMeasureMap(); ExemplarUtils.putSpanContextAttachments(measureMap, SPAN_CONTEXT); assertThat(measureMap.attachments) .containsExactly( ATTACHMENT_KEY_TRACE_ID, TRACE_ID.toLowerBase16(), ATTACHMENT_KEY_SPAN_ID, SPAN_ID.toLowerBase16()); }
private static void assertSpanEquals( Span span, org.springframework.cloud.sleuth.Span sleuthSpan) { assertThat(Long.parseLong(span.getContext().getTraceId().toLowerBase16().substring(0, 16), 16)) .isEqualTo(sleuthSpan.getTraceIdHigh()); assertThat(Long.parseLong(span.getContext().getTraceId().toLowerBase16().substring(16, 32), 16)) .isEqualTo(sleuthSpan.getTraceId()); assertThat(Long.parseLong(span.getContext().getSpanId().toLowerBase16(), 16)) .isEqualTo(sleuthSpan.getSpanId()); assertThat(span.getContext().getTraceOptions().isSampled()) .isEqualTo(sleuthSpan.isExportable()); } }
private static final void assertSpanEquals(io.opencensus.trace.Span span, Span sleuthSpan) { assertThat(span.getContext().isValid()).isTrue(); assertThat(Long.parseLong(span.getContext().getTraceId().toLowerBase16().substring(0, 16), 16)) .isEqualTo(sleuthSpan.getTraceIdHigh()); assertThat(Long.parseLong(span.getContext().getTraceId().toLowerBase16().substring(16, 32), 16)) .isEqualTo(sleuthSpan.getTraceId()); assertThat(Long.parseLong(span.getContext().getSpanId().toLowerBase16(), 16)) .isEqualTo(sleuthSpan.getSpanId()); assertThat(span.getContext().getTraceOptions().isSampled()) .isEqualTo(sleuthSpan.isExportable()); } }
private static Link toLinkProto(io.opencensus.trace.Link link) { checkNotNull(link); return Link.newBuilder() .setTraceId(link.getTraceId().toLowerBase16()) .setSpanId(link.getSpanId().toLowerBase16()) .setType(toLinkTypeProto(link.getType())) .setAttributes(toAttributesBuilderProto(link.getAttributes(), 0)) .build(); }
private static Link toLinkProto(io.opencensus.trace.Link link) { checkNotNull(link); return Link.newBuilder() .setTraceId(link.getTraceId().toLowerBase16()) .setSpanId(link.getSpanId().toLowerBase16()) .setType(toLinkTypeProto(link.getType())) .setAttributes(toAttributesBuilderProto(link.getAttributes(), 0)) .build(); }
static StringMap getContextAndTracingData() { SpanContext spanContext = getCurrentSpanContext(); ReadOnlyThreadContextMap context = ThreadContext.getThreadContextMap(); SortedArrayStringMap stringMap; if (context == null) { stringMap = new SortedArrayStringMap(ThreadContext.getImmutableContext()); } else { StringMap contextData = context.getReadOnlyContextData(); stringMap = new SortedArrayStringMap(contextData.size() + 3); stringMap.putAll(contextData); } // TODO(sebright): Move the calls to TraceId.toLowerBase16() and SpanId.toLowerBase16() out of // the critical path by wrapping the trace and span IDs in objects that call toLowerBase16() in // their toString() methods, after there is a fix for // https://github.com/census-instrumentation/opencensus-java/issues/1436. stringMap.putValue( OpenCensusTraceContextDataInjector.TRACE_ID_CONTEXT_KEY, spanContext.getTraceId().toLowerBase16()); stringMap.putValue( OpenCensusTraceContextDataInjector.SPAN_ID_CONTEXT_KEY, spanContext.getSpanId().toLowerBase16()); stringMap.putValue( OpenCensusTraceContextDataInjector.TRACE_SAMPLED_CONTEXT_KEY, spanContext.getTraceOptions().isSampled() ? "true" : "false"); return stringMap; }
Span.newBuilder() .traceId(context.getTraceId().toLowerBase16()) .id(context.getSpanId().toLowerBase16()) .kind(toSpanKind(spanData)) .name(spanData.getName()) spanBuilder.parentId(spanData.getParentSpanId().toLowerBase16());
Map<String, AttributeValue> fixedAttributes) { SpanContext context = spanData.getContext(); final String spanIdHex = context.getSpanId().toLowerBase16(); SpanName spanName = SpanName.newBuilder() spanBuilder.setParentSpanId(spanData.getParentSpanId().toLowerBase16());
Map<String, AttributeValue> fixedAttributes) { SpanContext context = spanData.getContext(); final String spanIdHex = context.getSpanId().toLowerBase16(); SpanName spanName = SpanName.newBuilder() spanBuilder.setParentSpanId(spanData.getParentSpanId().toLowerBase16());