Search in sources :

Example 1 with TextMapExtractAdapter

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

the class BraveTracerTest method extractTraceContextTextMap.

@Test
public void extractTraceContextTextMap() throws Exception {
    Map<String, String> map = new LinkedHashMap<>();
    map.put("X-B3-TraceId", "0000000000000001");
    map.put("X-B3-SpanId", "0000000000000002");
    map.put("X-B3-Sampled", "1");
    BraveSpanContext openTracingContext = (BraveSpanContext) opentracing.extract(Format.Builtin.TEXT_MAP, new TextMapExtractAdapter(map));
    assertThat(openTracingContext.unwrap()).isEqualTo(TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(true).build());
}
Also used : TextMapExtractAdapter(io.opentracing.propagation.TextMapExtractAdapter) BraveSpanContext(brave.opentracing.BraveSpanContext) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with TextMapExtractAdapter

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

the class BraveTracerTest method extractTraceContext.

@Test
public void extractTraceContext() throws Exception {
    Map<String, String> map = new LinkedHashMap<>();
    map.put("X-B3-TraceId", "0000000000000001");
    map.put("X-B3-SpanId", "0000000000000002");
    map.put("X-B3-Sampled", "1");
    BraveSpanContext openTracingContext = (BraveSpanContext) opentracing.extract(Format.Builtin.HTTP_HEADERS, new TextMapExtractAdapter(map));
    assertThat(openTracingContext.unwrap()).isEqualTo(TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(true).build());
}
Also used : TextMapExtractAdapter(io.opentracing.propagation.TextMapExtractAdapter) BraveSpanContext(brave.opentracing.BraveSpanContext) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with TextMapExtractAdapter

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

the class BraveTracerTest method extractBaggage.

@Test
public void extractBaggage() throws Exception {
    Map<String, String> map = new LinkedHashMap<>();
    map.put("X-B3-TraceId", "0000000000000001");
    map.put("X-B3-SpanId", "0000000000000002");
    map.put("X-B3-Sampled", "1");
    map.put("baggage-country-code", "FO");
    BraveSpanContext openTracingContext = opentracing.extract(Format.Builtin.HTTP_HEADERS, new TextMapExtractAdapter(map));
    assertThat(openTracingContext.baggageItems()).containsExactly(entry("country-code", "FO"));
}
Also used : TextMapExtractAdapter(io.opentracing.propagation.TextMapExtractAdapter) BraveSpanContext(brave.opentracing.BraveSpanContext) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with TextMapExtractAdapter

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

the class BraveTracerTest method extractTraceContextCaseInsensitive.

@Test
public void extractTraceContextCaseInsensitive() throws Exception {
    Map<String, String> map = new LinkedHashMap<>();
    map.put("X-B3-TraceId", "0000000000000001");
    map.put("x-b3-spanid", "0000000000000002");
    map.put("x-b3-SaMpLeD", "1");
    map.put("other", "1");
    BraveSpanContext openTracingContext = (BraveSpanContext) opentracing.extract(Format.Builtin.HTTP_HEADERS, new TextMapExtractAdapter(map));
    assertThat(openTracingContext.unwrap()).isEqualTo(TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(true).build());
}
Also used : TextMapExtractAdapter(io.opentracing.propagation.TextMapExtractAdapter) BraveSpanContext(brave.opentracing.BraveSpanContext) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with TextMapExtractAdapter

use of io.opentracing.propagation.TextMapExtractAdapter 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

TextMapExtractAdapter (io.opentracing.propagation.TextMapExtractAdapter)8 Test (org.junit.Test)6 BraveSpanContext (brave.opentracing.BraveSpanContext)4 LinkedHashMap (java.util.LinkedHashMap)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 HashMap (java.util.HashMap)3 SpanContext (io.opentracing.SpanContext)2 TextMap (io.opentracing.propagation.TextMap)2 TextMapInjectAdapter (io.opentracing.propagation.TextMapInjectAdapter)2 Span (com.uber.jaeger.Span)1 SpanContext (com.uber.jaeger.SpanContext)1 InMemoryReporter (com.uber.jaeger.reporters.InMemoryReporter)1 ConstSampler (com.uber.jaeger.samplers.ConstSampler)1 Span (io.opentracing.Span)1 SpanBuilder (io.opentracing.Tracer.SpanBuilder)1 Map (java.util.Map)1 SpanWrapper (org.apache.synapse.aspects.flow.statistics.opentracing.models.SpanWrapper)1 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)1