/** * Idempotently sets correlation properties to hex representation of trace identifiers in this * context. */ void maybeReplaceTraceContext( TraceContext currentSpan, String previousTraceId, @Nullable String previousParentId, String previousSpanId ) { String traceId = currentSpan.traceIdString(); if (!traceId.equals(previousTraceId)) put("traceId", currentSpan.traceIdString()); String parentId = currentSpan.parentIdString(); if (parentId == null) { remove("parentId"); } else { boolean sameParentId = parentId.equals(previousParentId); if (!sameParentId) put("parentId", parentId); } String spanId = currentSpan.spanIdString(); if (!spanId.equals(previousSpanId)) put("spanId", spanId); }
String traceIdString = currentSpan.traceIdString(); MDC.put("traceId", traceIdString); MDC.put(LEGACY_TRACE_ID_NAME, traceIdString);
String traceIdString = currentSpan.traceIdString(); MDC.put("traceId", traceIdString); MDC.put(LEGACY_TRACE_ID_NAME, traceIdString);
@Test public void makesChildOfCurrentSpan() throws Exception { Tracer tracer = httpTracing.tracing().tracer(); server.enqueue(new MockResponse()); ScopedSpan parent = tracer.startScopedSpan("test"); try { get(client, "/foo"); } finally { parent.finish(); } RecordedRequest request = server.takeRequest(); assertThat(request.getHeader("x-b3-traceId")) .isEqualTo(parent.context().traceIdString()); assertThat(request.getHeader("x-b3-parentspanid")) .isEqualTo(parent.context().spanIdString()); assertThat(Arrays.asList(takeSpan(), takeSpan())) .extracting(Span::kind) .containsOnly(null, Span.Kind.CLIENT); }
@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; }
@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"); } } }
RecordedRequest request = server.takeRequest(); assertThat(request.getHeader("x-b3-traceId")) .isEqualTo(parent.context().traceIdString()); assertThat(request.getHeader("x-b3-parentspanid")) .isEqualTo(parent.context().spanIdString());
@Override public Message postProcessMessage(final Message message) { MessageProperties messageProperties = message.getMessageProperties(); String correlationId = messageProperties.getCorrelationId(); if (correlationId == null) { correlationId = (tracer!=null && tracer.currentSpan()!=null)? tracer.currentSpan().context().traceIdString():UUID.randomUUID().toString(); messageProperties.setCorrelationId(correlationId); } messageProperties.getHeaders().put("correlation-id", correlationId); return message; }
/** * Idempotently sets correlation properties to hex representation of trace identifiers in this * context. */ void maybeReplaceTraceContext( TraceContext currentSpan, String previousTraceId, @Nullable String previousParentId, String previousSpanId ) { String traceId = currentSpan.traceIdString(); if (!traceId.equals(previousTraceId)) put("traceId", currentSpan.traceIdString()); String parentId = currentSpan.parentIdString(); if (parentId == null) { remove("parentId"); } else { boolean sameParentId = parentId.equals(previousParentId); if (!sameParentId) put("parentId", parentId); } String spanId = currentSpan.spanIdString(); if (!spanId.equals(previousSpanId)) put("spanId", spanId); }
private void serverResponse(Tracing brave, String serviceName, Exchange exchange) { Span span = null; ZipkinState state = exchange.getProperty(ZipkinState.KEY, ZipkinState.class); if (state != null) { // only process if it was a zipkin server event span = state.popServerSpan(); } if (span != null) { ZipkinServerResponseAdapter parser = new ZipkinServerResponseAdapter(this, exchange); parser.onResponse(exchange, span.customizer()); span.finish(); TraceContext context = span.context(); String traceId = "" + context.traceIdString(); String spanId = "" + context.spanId(); String parentId = context.parentId() != null ? "" + context.parentId() : null; if (camelContext.isUseMDCLogging()) { MDC.put("traceId", traceId); MDC.put("spanId", spanId); MDC.put("parentId", parentId); } if (LOG.isDebugEnabled()) { if (parentId != null) { LOG.debug(String.format("serverResponse[service=%s, traceId=%20s, spanId=%20s, parentId=%20s]", serviceName, traceId, spanId, parentId)); } else { LOG.debug(String.format("serverResponse[service=%s, traceId=%20s, spanId=%20s]", serviceName, traceId, spanId)); } } } }
private void clientResponse(Tracing brave, String serviceName, ExchangeSentEvent event) { Span span = null; ZipkinState state = event.getExchange().getProperty(ZipkinState.KEY, ZipkinState.class); if (state != null) { // only process if it was a zipkin client event span = state.popClientSpan(); } if (span != null) { ZipkinClientResponseAdaptor parser = new ZipkinClientResponseAdaptor(this, event.getEndpoint()); parser.onResponse(event.getExchange(), span.customizer()); span.finish(); TraceContext context = span.context(); String traceId = "" + context.traceIdString(); String spanId = "" + context.spanId(); String parentId = context.parentId() != null ? "" + context.parentId() : null; if (camelContext.isUseMDCLogging()) { MDC.put("traceId", traceId); MDC.put("spanId", spanId); MDC.put("parentId", parentId); } if (LOG.isDebugEnabled()) { if (parentId != null) { LOG.debug(String.format("clientResponse[service=%s, traceId=%20s, spanId=%20s, parentId=%20s]", serviceName, traceId, spanId, parentId)); } else { LOG.debug(String.format("clientResponse[service=%s, traceId=%20s, spanId=%20s]", serviceName, traceId, spanId)); } } } }
String traceIdString = currentSpan.traceIdString(); MDC.put("traceId", traceIdString); MDC.put(LEGACY_TRACE_ID_NAME, traceIdString);
String traceIdString = currentSpan.traceIdString(); MDC.put("traceId", traceIdString); MDC.put(LEGACY_TRACE_ID_NAME, traceIdString);
@Test public void makesChildOfCurrentSpan() throws Exception { Tracer tracer = httpTracing.tracing().tracer(); server.enqueue(new MockResponse()); ScopedSpan parent = tracer.startScopedSpan("test"); try { get(client, "/foo"); } finally { parent.finish(); } RecordedRequest request = server.takeRequest(); assertThat(request.getHeader("x-b3-traceId")) .isEqualTo(parent.context().traceIdString()); assertThat(request.getHeader("x-b3-parentspanid")) .isEqualTo(parent.context().spanIdString()); assertThat(Arrays.asList(takeSpan(), takeSpan())) .extracting(Span::kind) .containsOnly(null, Span.Kind.CLIENT); }
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())); }
String traceId = "" + context.traceIdString(); String spanId = "" + context.spanId(); String parentId = context.parentId() != null ? "" + context.parentId() : null;
@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; }
String traceId = "" + context.traceIdString(); String spanId = "" + context.spanId(); String parentId = context.parentId() != null ? "" + context.parentId() : null;
RecordedRequest request = server.takeRequest(); assertThat(request.getHeader("x-b3-traceId")) .isEqualTo(parent.context().traceIdString()); assertThat(request.getHeader("x-b3-parentspanid")) .isEqualTo(parent.context().spanIdString());
@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"); } } }