Search in sources :

Example 1 with TextMapInjectAdapter

use of io.opentracing.propagation.TextMapInjectAdapter in project brave by openzipkin.

the class OpenTracingAdapterTest method injectTraceContext.

@Test
public void injectTraceContext() throws Exception {
    TraceContext context = TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(true).build();
    Map<String, String> map = new LinkedHashMap<>();
    TextMapInjectAdapter carrier = new TextMapInjectAdapter(map);
    opentracing.inject(BraveSpanContext.wrap(context), Format.Builtin.HTTP_HEADERS, carrier);
    assertThat(map).containsExactly(entry("X-B3-TraceId", "0000000000000001"), entry("X-B3-SpanId", "0000000000000002"), entry("X-B3-Sampled", "1"));
}
Also used : TextMapInjectAdapter(io.opentracing.propagation.TextMapInjectAdapter) TraceContext(brave.propagation.TraceContext) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 2 with TextMapInjectAdapter

use of io.opentracing.propagation.TextMapInjectAdapter in project spring-cloud-sleuth by spring-cloud.

the class BraveTracerTest method injectTraceContext_baggage.

@Test
public void injectTraceContext_baggage() throws Exception {
    BraveSpan span = opentracing.buildSpan("foo").start();
    span.setBaggageItem("country-code", "FO");
    Map<String, String> map = new LinkedHashMap<>();
    TextMapInjectAdapter carrier = new TextMapInjectAdapter(map);
    opentracing.inject(span.context(), Format.Builtin.HTTP_HEADERS, carrier);
    assertThat(map).containsEntry("baggage-country-code", "FO");
}
Also used : BraveSpan(brave.opentracing.BraveSpan) TextMapInjectAdapter(io.opentracing.propagation.TextMapInjectAdapter) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with TextMapInjectAdapter

use of io.opentracing.propagation.TextMapInjectAdapter in project opentracing-java by opentracing.

the class Client method send.

public void send() throws InterruptedException {
    Message message = new Message();
    try (Scope scope = tracer.buildSpan("send").withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).withTag(Tags.COMPONENT.getKey(), "example-client").startActive(true)) {
        tracer.inject(scope.span().context(), Builtin.TEXT_MAP, new TextMapInjectAdapter(message));
        queue.put(message);
    }
}
Also used : Scope(io.opentracing.Scope) TextMapInjectAdapter(io.opentracing.propagation.TextMapInjectAdapter)

Example 4 with TextMapInjectAdapter

use of io.opentracing.propagation.TextMapInjectAdapter in project opentracing-java by opentracing.

the class MockTracerTest method testDefaultConstructor.

@Test
public void testDefaultConstructor() {
    MockTracer mockTracer = new MockTracer();
    Scope scope = mockTracer.buildSpan("foo").startActive(true);
    assertEquals(scope, mockTracer.scopeManager().active());
    Map<String, String> propag = new HashMap<>();
    mockTracer.inject(scope.span().context(), Format.Builtin.TEXT_MAP, new TextMapInjectAdapter(propag));
    assertFalse(propag.isEmpty());
}
Also used : Scope(io.opentracing.Scope) HashMap(java.util.HashMap) TextMapInjectAdapter(io.opentracing.propagation.TextMapInjectAdapter) Test(org.junit.Test)

Example 5 with TextMapInjectAdapter

use of io.opentracing.propagation.TextMapInjectAdapter in project jaeger-client-java by jaegertracing.

the class ThriftSpanConverterTest method testRpcChildSpanHasTheSameId.

@Test
public void testRpcChildSpanHasTheSameId() {
    String expectedOperation = "parent";
    Span client = (Span) tracer.buildSpan(expectedOperation).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).startManual();
    Map<String, String> map = new HashMap<>();
    TextMap carrier = new TextMapInjectAdapter(map);
    tracer.inject(client.context(), Format.Builtin.TEXT_MAP, carrier);
    carrier = new TextMapExtractAdapter(map);
    SpanContext ctx = (SpanContext) tracer.extract(Format.Builtin.TEXT_MAP, carrier);
    assertEquals(client.context().getSpanId(), ctx.getSpanId());
    Span server = (Span) tracer.buildSpan("child").withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).asChildOf(ctx).startManual();
    assertEquals("client and server must have the same span ID", client.context().getSpanId(), server.context().getSpanId());
}
Also used : TextMapExtractAdapter(io.opentracing.propagation.TextMapExtractAdapter) SpanContext(com.uber.jaeger.SpanContext) HashMap(java.util.HashMap) TextMapInjectAdapter(io.opentracing.propagation.TextMapInjectAdapter) TextMap(io.opentracing.propagation.TextMap) Span(com.uber.jaeger.Span) Test(org.junit.Test)

Aggregations

TextMapInjectAdapter (io.opentracing.propagation.TextMapInjectAdapter)5 Test (org.junit.Test)4 Scope (io.opentracing.Scope)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 BraveSpan (brave.opentracing.BraveSpan)1 TraceContext (brave.propagation.TraceContext)1 Span (com.uber.jaeger.Span)1 SpanContext (com.uber.jaeger.SpanContext)1 TextMap (io.opentracing.propagation.TextMap)1 TextMapExtractAdapter (io.opentracing.propagation.TextMapExtractAdapter)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1