RealKey(TraceContext context, ReferenceQueue<TraceContext> queue) { super(context, queue); hashCode = context.hashCode(); traceIdHigh = context.traceIdHigh(); traceId = context.traceId(); localRootId = context.localRootId(); spanId = context.spanId(); sampled = Boolean.TRUE.equals(context.sampled()); }
void noticesDifferentSpanId(Scope scope) { TraceContext differentSpanId = context.toBuilder().spanId(context.spanId() + 1L).build(); try (Scope scope2 = currentTraceContext.maybeScope(differentSpanId)) { assertThat(scope2).isNotEqualTo(Scope.NOOP); assertThat(currentTraceContext.get()) .isEqualTo(differentSpanId); verifyImplicitContext(differentSpanId); } finally { scope.close(); } }
/** Resolves hash code collisions */ @Override public boolean equals(Object other) { RealKey that = (RealKey) other; TraceContext thatContext = that.get(); if (thatContext == null) return false; return (traceIdHigh == thatContext.traceIdHigh()) && (traceId == thatContext.traceId()) && (spanId == thatContext.spanId()) && shared == thatContext.shared(); } }
void set(TraceContext context) { set(context.traceIdHigh(), context.traceId(), context.spanId(), context.shared()); }
/** Trace contexts are equal only on trace ID and span ID. try to get the parent's clock */ @Nullable TickClock getClockFromParent(TraceContext context) { long parentId = context.parentIdAsLong(); // NOTE: we still look for lookup key even on root span, as a client span can be root, and a // server can share the same ID. Essentially, a shared span is similar to a child. PendingSpan parent = null; if (context.shared() || parentId != 0L) { long spanId = parentId != 0L ? parentId : context.spanId(); parent = delegate.get(InternalPropagation.instance.newTraceContext( 0, context.traceIdHigh(), context.traceId(), 0, 0, spanId, Collections.emptyList() )); } return parent != null ? parent.clock : null; }
static byte[] toBytes(TraceContext traceContext) { checkNotNull(traceContext, "traceContext"); byte[] bytes = new byte[FORMAT_LENGTH]; bytes[0] = VERSION; bytes[1] = TRACE_ID_FIELD_ID; writeLong(bytes, 2, traceContext.traceIdHigh()); writeLong(bytes, 10, traceContext.traceId()); bytes[18] = SPAN_ID_FIELD_ID; writeLong(bytes, 19, traceContext.spanId()); bytes[27] = TRACE_OPTION_FIELD_ID; if (traceContext.sampled() != null && traceContext.sampled()) { bytes[28] = 1; } return bytes; }
replace("parentId", parentId); replace(LEGACY_PARENT_ID_NAME, parentId); String spanId = HexCodec.toLowerHex(currentSpan.spanId()); MDC.put("spanId", spanId); MDC.put(LEGACY_SPAN_ID_NAME, spanId);
public final TraceContext decorate(TraceContext context) { long traceId = context.traceId(), spanId = context.spanId(); Class<E> type = type();
replace("parentId", parentId); replace(LEGACY_PARENT_ID_NAME, parentId); String spanId = HexCodec.toLowerHex(currentSpan.spanId()); MDC.put("spanId", spanId); MDC.put(LEGACY_SPAN_ID_NAME, spanId);
/** * Called by methods which can accept externally supplied parent trace contexts: Ex. {@link * #newChild(TraceContext)} and {@link #startScopedSpanWithParent(String, TraceContext)}. This * implies the {@link TraceContext#localRootId()} could be zero, if the context was manually * created. */ TraceContext nextContext(TraceContext parent) { return nextContext( InternalPropagation.instance.flags(parent), parent.traceIdHigh(), parent.traceId(), parent.localRootId(), parent.spanId(), parent.extra() ); }
static int writeB3SingleFormat(TraceContext context, long parentId, char[] result) { int pos = 0; long traceIdHigh = context.traceIdHigh(); if (traceIdHigh != 0L) { writeHexLong(result, pos, traceIdHigh); pos += 16; } writeHexLong(result, pos, context.traceId()); pos += 16; result[pos++] = '-'; writeHexLong(result, pos, context.spanId()); pos += 16; Boolean sampled = context.sampled(); if (sampled != null) { result[pos++] = '-'; result[pos++] = context.debug() ? 'd' : sampled ? '1' : '0'; } if (parentId != 0L) { result[pos++] = '-'; writeHexLong(result, pos, parentId); pos += 16; } return pos; }
traceId = implicitParent.traceId(); localRootId = implicitParent.localRootId(); spanId = implicitParent.spanId(); extra = concatImmutableLists(extra, implicitParent.extra()); } else {
RealKey(TraceContext context, ReferenceQueue<TraceContext> queue) { super(context, queue); hashCode = context.hashCode(); traceIdHigh = context.traceIdHigh(); traceId = context.traceId(); localRootId = context.localRootId(); spanId = context.spanId(); sampled = Boolean.TRUE.equals(context.sampled()); }
void noticesDifferentSpanId(Scope scope) { TraceContext differentSpanId = context.toBuilder().spanId(context.spanId() + 1L).build(); try (Scope scope2 = currentTraceContext.maybeScope(differentSpanId)) { assertThat(scope2).isNotEqualTo(Scope.NOOP); assertThat(currentTraceContext.get()) .isEqualTo(differentSpanId); verifyImplicitContext(differentSpanId); } finally { scope.close(); } }
/** Resolves hash code collisions */ @Override public boolean equals(Object other) { RealKey that = (RealKey) other; TraceContext thatContext = that.get(); if (thatContext == null) return false; return (traceIdHigh == thatContext.traceIdHigh()) && (traceId == thatContext.traceId()) && (spanId == thatContext.spanId()) && shared == thatContext.shared(); } }
void set(TraceContext context) { set(context.traceIdHigh(), context.traceId(), context.spanId(), context.shared()); }
public void propagationTraceInfo(HttpUriRequest request, Span span) { TraceContext currentSpan = span.context(); request.addHeader("X-B3-TraceId",currentSpan.traceIdString()); request.addHeader("X-B3-SpanId", HexCodec.toLowerHex(currentSpan.spanId())); if(currentSpan.parentId() != null) { request.addHeader("X-B3-ParentSpanId", HexCodec.toLowerHex(currentSpan.parentId())); } request.addHeader("X-B3-Sampled",String.valueOf(currentSpan.sampled())); }
static SpanId toSpanId(TraceContext context) { return SpanId.builder() .traceIdHigh(context.traceIdHigh()) .traceId(context.traceId()) .parentId(context.parentId()) .spanId(context.spanId()) .debug(context.debug()) .sampled(context.sampled()).build(); } }
Tracing.Builder tracingBuilder(Sampler sampler) { return Tracing.newBuilder() .spanReporter( s -> { // make sure the context was cleared prior to finish.. no leaks! TraceContext current = httpTracing.tracing().currentTraceContext().get(); if (current != null) { Assert.assertNotEquals(current.spanId(), s.id()); } spans.add(s); }) .currentTraceContext(currentTraceContext) .sampler(sampler); }