Search in sources :

Example 46 with JaegerSpanContext

use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.

the class TraceContextCodecTest method testInject.

@Test
public void testInject() {
    Map<String, String> carrier = new HashMap<>();
    TextMapAdapter textMap = new TextMapAdapter(carrier);
    long traceIdLow = 1;
    long spanId = 2;
    long parentId = 3;
    long traceIdHigh = HexCodec.hexToUnsignedLong("c281c27976c85681", 0, 16);
    JaegerSpanContext spanContext = new JaegerSpanContext(traceIdHigh, traceIdLow, spanId, parentId, (byte) 0);
    traceContextCodec.inject(spanContext, textMap);
    String expectedTraceContextHeader = "00-c281c27976c856810000000000000001-0000000000000002-00";
    assertEquals(1, carrier.size());
    assertNotNull(carrier.get(TRACE_PARENT));
    assertEquals(expectedTraceContextHeader, carrier.get(TRACE_PARENT));
}
Also used : HashMap(java.util.HashMap) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 47 with JaegerSpanContext

use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.

the class TraceContextCodecTest method testDebugIdWithTraceHeader.

@Test
public void testDebugIdWithTraceHeader() {
    Map<String, String> extractCarrier = new HashMap<>();
    TextMapAdapter textMap = new TextMapAdapter(extractCarrier);
    textMap.put(TRACE_PARENT, EXAMPLE_TRACE_PARENT);
    textMap.put(Constants.DEBUG_ID_HEADER_KEY, EXAMPLE_DEBUG_ID);
    JaegerSpanContext spanContext = traceContextCodec.extract(textMap);
    JaegerTracer tracer = new JaegerTracer.Builder("service").withReporter(new InMemoryReporter()).build();
    assertEquals("0000000000000001", spanContext.getTraceId());
    JaegerSpan child = tracer.buildSpan("span").asChildOf(spanContext).start();
    assertFalse(child.context().isDebug());
    child.finish();
    tracer.close();
}
Also used : InMemoryReporter(io.jaegertracing.internal.reporters.InMemoryReporter) HashMap(java.util.HashMap) JaegerSpan(io.jaegertracing.internal.JaegerSpan) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Test(org.junit.Test)

Example 48 with JaegerSpanContext

use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.

the class TraceContextCodecTest method testExtractWithCapitalizedTraceHeaders.

@Test
public void testExtractWithCapitalizedTraceHeaders() {
    Map<String, String> extractCarrier = new HashMap<>();
    TextMapAdapter textMap = new TextMapAdapter(extractCarrier);
    textMap.put("Traceparent", EXAMPLE_TRACE_PARENT);
    textMap.put("Tracestate", "whatever");
    JaegerSpanContext spanContext = traceContextCodec.extract(textMap);
    assertEquals("0000000000000001:0000000000000002:0:0", spanContext.toString());
    assertEquals("whatever", spanContext.getTraceState());
}
Also used : HashMap(java.util.HashMap) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 49 with JaegerSpanContext

use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.

the class BaggageSetterTest method testInvalidBaggage.

@Test
public void testInvalidBaggage() {
    when(mgr.getRestriction(SERVICE, KEY)).thenReturn(Restriction.of(false, 0));
    final String value = "value";
    JaegerSpanContext ctx = setter.setBaggage(jaegerSpan, KEY, value);
    assertBaggageLogs(jaegerSpan, KEY, value, false, false, true);
    assertNull(ctx.getBaggageItem(KEY));
    assertEquals(1, metricsFactory.getCounter("jaeger_tracer_baggage_updates", "result=err"));
}
Also used : JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 50 with JaegerSpanContext

use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.

the class BaggageSetterTest method testBaggageNullValueTolerated.

@Test
public void testBaggageNullValueTolerated() {
    when(mgr.getRestriction(SERVICE, KEY)).thenReturn(Restriction.of(true, 5));
    final String value = null;
    JaegerSpanContext ctx = setter.setBaggage(jaegerSpan, KEY, value);
    assertBaggageLogs(jaegerSpan, KEY, null, false, false, false);
    assertNull(ctx.getBaggageItem(KEY));
}
Also used : JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Aggregations

JaegerSpanContext (io.jaegertracing.internal.JaegerSpanContext)68 Test (org.junit.Test)59 HashMap (java.util.HashMap)20 TextMapAdapter (io.opentracing.propagation.TextMapAdapter)19 JaegerSpan (io.jaegertracing.internal.JaegerSpan)10 JaegerTracer (io.jaegertracing.internal.JaegerTracer)8 Response (javax.ws.rs.core.Response)7 TextMap (io.opentracing.propagation.TextMap)6 CodecConfiguration (io.jaegertracing.Configuration.CodecConfiguration)4 ReporterConfiguration (io.jaegertracing.Configuration.ReporterConfiguration)4 SamplerConfiguration (io.jaegertracing.Configuration.SamplerConfiguration)4 SenderConfiguration (io.jaegertracing.Configuration.SenderConfiguration)4 List (java.util.List)3 ObservedSpan (io.jaegertracing.crossdock.api.ObservedSpan)2 TestBinaryCarrier (io.jaegertracing.internal.propagation.TestBinaryCarrier)2 InMemoryReporter (io.jaegertracing.internal.reporters.InMemoryReporter)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 Endpoint (com.twitter.zipkin.thriftjava.Endpoint)1