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 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 jaeger-client-java by jaegertracing.
the class AdhocHeadersTest method traceWithAdhocBaggage.
private void traceWithAdhocBaggage(Map<String, String> headers) {
headers.put("jaeger-baggage", "k1=v1, k2 = v2");
JaegerSpanContext parent = tracer.extract(Format.Builtin.HTTP_HEADERS, new TextMapAdapter(headers));
JaegerSpan span = tracer.buildSpan("test").asChildOf(parent).start();
assertTrue(span.context().isSampled());
assertEquals("must have baggage", "v1", span.getBaggageItem("k1"));
assertEquals("must have baggage", "v2", span.getBaggageItem("k2"));
}
use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.
the class ThriftSpanConverterTest method testRpcChildSpanHasTheSameId.
@Test
public void testRpcChildSpanHasTheSameId() {
String expectedOperation = "parent";
JaegerSpan client = tracer.buildSpan(expectedOperation).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start();
Map<String, String> map = new HashMap<>();
TextMap carrier = new TextMapAdapter(map);
tracer.inject(client.context(), Format.Builtin.TEXT_MAP, carrier);
JaegerSpanContext ctx = tracer.extract(Format.Builtin.TEXT_MAP, carrier);
JaegerSpanContext clientCtx = client.context();
assertEquals(clientCtx.getSpanId(), ctx.getSpanId());
JaegerSpan server = tracer.buildSpan("child").withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).asChildOf(ctx).start();
JaegerSpanContext serverCtx = server.context();
assertEquals("client and server must have the same span ID", clientCtx.getSpanId(), serverCtx.getSpanId());
}
Aggregations