Search in sources :

Example 1 with BraveSpanContext

use of brave.opentracing.BraveSpanContext 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 BraveSpanContext

use of brave.opentracing.BraveSpanContext 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 BraveSpanContext

use of brave.opentracing.BraveSpanContext 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 BraveSpanContext

use of brave.opentracing.BraveSpanContext 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)

Aggregations

BraveSpanContext (brave.opentracing.BraveSpanContext)4 TextMapExtractAdapter (io.opentracing.propagation.TextMapExtractAdapter)4 LinkedHashMap (java.util.LinkedHashMap)4 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4