@Override public boolean isSampled(Span span) { // TODO replace with Span#unwrap once https://github.com/opentracing/opentracing-java/pull/211 is merged if (span instanceof SpanWrapper) { span = ((SpanWrapper) span).getDelegate(); } if (span instanceof BraveSpan) { final BraveSpan braveSpan = (BraveSpan) span; return braveSpan.unwrap().context().sampled(); } return false; }
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; }
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()); }
@Override public void inject(TraceContext traceContext, C carrier) { setter.put(carrier, propagation.traceIdKey, traceContext.traceIdString()); setter.put(carrier, propagation.spanIdKey, traceContext.spanIdString()); String parentId = traceContext.parentIdString(); if (parentId != null) { setter.put(carrier, propagation.parentSpanIdKey, parentId); } if (traceContext.debug()) { setter.put(carrier, propagation.debugKey, "1"); } else if (traceContext.sampled() != null) { setter.put(carrier, propagation.sampledKey, traceContext.sampled() ? "1" : "0"); } } }
MDC.put("spanId", spanId); MDC.put(LEGACY_SPAN_ID_NAME, spanId); String sampled = String.valueOf(currentSpan.sampled()); MDC.put("spanExportable", sampled); MDC.put(LEGACY_EXPORTABLE_NAME, sampled);
MDC.put("spanId", spanId); MDC.put(LEGACY_SPAN_ID_NAME, spanId); String sampled = String.valueOf(currentSpan.sampled()); MDC.put("spanExportable", sampled); MDC.put(LEGACY_EXPORTABLE_NAME, sampled);
@Override public boolean handle(TraceContext context, MutableSpan span) { if (!Boolean.TRUE.equals(context.sampled())) return true; Span.Builder builderWithContextData = Span.newBuilder() .traceId(context.traceIdString()) .parentId(context.parentIdString()) .id(context.spanIdString()); if (context.debug()) builderWithContextData.debug(true); converter.convert(span, builderWithContextData); spanReporter.report(builderWithContextData.build()); return true; }
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; }
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; }
writeHexLong(result, 48, traceContext.spanId()); System.arraycopy(SAMPLED, 0, result, 64, 9); Boolean sampled = traceContext.sampled();
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()); }
@Override public void inject(TraceContext traceContext, C carrier) { setter.put(carrier, propagation.traceIdKey, traceContext.traceIdString()); setter.put(carrier, propagation.spanIdKey, traceContext.spanIdString()); String parentId = traceContext.parentIdString(); if (parentId != null) { setter.put(carrier, propagation.parentSpanIdKey, parentId); } if (traceContext.debug()) { setter.put(carrier, propagation.debugKey, "1"); } else if (traceContext.sampled() != null) { setter.put(carrier, propagation.sampledKey, traceContext.sampled() ? "1" : "0"); } } }
MDC.put("spanId", spanId); MDC.put(LEGACY_SPAN_ID_NAME, spanId); String sampled = String.valueOf(currentSpan.sampled()); MDC.put("spanExportable", sampled); MDC.put(LEGACY_EXPORTABLE_NAME, sampled);
MDC.put("spanId", spanId); MDC.put(LEGACY_SPAN_ID_NAME, spanId); String sampled = String.valueOf(currentSpan.sampled()); MDC.put("spanExportable", sampled); MDC.put(LEGACY_EXPORTABLE_NAME, sampled);
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())); }
@Override public boolean handle(TraceContext context, MutableSpan span) { if (!Boolean.TRUE.equals(context.sampled())) return true; Span.Builder builderWithContextData = Span.newBuilder() .traceId(context.traceIdString()) .parentId(context.parentIdString()) .id(context.spanIdString()); if (context.debug()) builderWithContextData.debug(true); converter.convert(span, builderWithContextData); spanReporter.report(builderWithContextData.build()); return true; }
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; }
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(); } }