use of io.opentracing.propagation.TextMapAdapter in project brave by openzipkin.
the class OpenTracingAdapterTest method injectRemoteSpanTraceContext.
@Test
public void injectRemoteSpanTraceContext() {
BraveSpan openTracingSpan = opentracing.buildSpan("encode").withTag("lc", "codec").withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_PRODUCER).withStartTimestamp(1L).start();
Map<String, String> map = new LinkedHashMap<>();
TextMapAdapter request = new TextMapAdapter(map);
opentracing.inject(openTracingSpan.context(), Format.Builtin.HTTP_HEADERS, request);
assertThat(map).containsOnlyKeys("b3");
openTracingSpan.unwrap().abandon();
}
use of io.opentracing.propagation.TextMapAdapter in project brave by openzipkin.
the class OpenTracingAdapterTest method injectTraceContext.
@Test
public void injectTraceContext() {
TraceContext context = TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(true).build();
Map<String, String> map = new LinkedHashMap<>();
TextMapAdapter request = new TextMapAdapter(map);
opentracing.inject(new BraveSpanContext(context), Format.Builtin.HTTP_HEADERS, request);
assertThat(map).containsExactly(entry("X-B3-TraceId", "0000000000000001"), entry("X-B3-SpanId", "0000000000000002"), entry("X-B3-Sampled", "1"));
}
use of io.opentracing.propagation.TextMapAdapter in project cxf by apache.
the class AbstractOpenTracingProvider method startTraceSpan.
protected TraceScopeHolder<TraceScope> startTraceSpan(final Map<String, List<String>> requestHeaders, URI uri, String method) {
SpanContext parent = tracer.extract(Builtin.HTTP_HEADERS, new TextMapAdapter(requestHeaders.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, this::getFirstValueOrEmpty))));
final Span activeSpan;
final Scope scope;
if (parent == null) {
activeSpan = tracer.buildSpan(buildSpanDescription(uri.getPath(), method)).start();
scope = tracer.scopeManager().activate(activeSpan);
} else {
activeSpan = tracer.buildSpan(buildSpanDescription(uri.getPath(), method)).asChildOf(parent).start();
scope = tracer.scopeManager().activate(activeSpan);
}
// Set additional tags
activeSpan.setTag(Tags.HTTP_METHOD.getKey(), method);
activeSpan.setTag(Tags.HTTP_URL.getKey(), uri.toString());
// If the service resource is using asynchronous processing mode, the trace
// scope will be closed in another thread and as such should be detached.
Span span = null;
if (isAsyncResponse()) {
// Do not modify the current context span
span = activeSpan;
propagateContinuationSpan(span);
scope.close();
}
return new TraceScopeHolder<TraceScope>(new TraceScope(activeSpan, scope), span != null);
}
use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.
the class TraceContextCodecTest method testNoTraceHeader.
@Test
public void testNoTraceHeader() {
TextMapAdapter textMap = new TextMapAdapter(new HashMap<>());
JaegerSpanContext spanContext = traceContextCodec.extract(textMap);
assertNull(spanContext);
verifyWarningNotPresent();
}
use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.
the class TraceContextCodecTest method testInvalidTraceId.
@Test
public void testInvalidTraceId() {
TextMapAdapter textMap = new TextMapAdapter(new HashMap<>());
textMap.put(TRACE_PARENT, "00-00000000000000000000000000000000-0000000000000002-00");
JaegerSpanContext spanContext = traceContextCodec.extract(textMap);
assertNull(spanContext);
verifyWarningPresent();
}
Aggregations