Search in sources :

Example 51 with JaegerSpanContext

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

the class TraceBehaviorResourceTest method testStartTraceHttp.

@Test
public void testStartTraceHttp() throws Exception {
    Span root = server.getTracer().buildSpan("root").start();
    String expectedTraceId = ((JaegerSpanContext) root.context()).getTraceId();
    String expectedBaggage = "baggage-example";
    try (Scope scope = server.getTracer().activateSpan(root)) {
        Downstream downstream = new Downstream(SERVICE_NAME, "127.0.0.1", String.valueOf(port), Constants.TRANSPORT_HTTP, "server", null);
        StartTraceRequest startTraceRequest = new StartTraceRequest("server-role", expectedSampled, expectedBaggage, downstream);
        Response resp = JerseyServer.client.target(String.format("http://%s/start_trace", hostPort)).request(MediaType.APPLICATION_JSON).post(Entity.json(startTraceRequest));
        TraceResponse traceResponse = resp.readEntity(TraceResponse.class);
        assertNotNull(traceResponse.getDownstream());
        validateTraceResponse(traceResponse, expectedTraceId, expectedBaggage, 1);
    }
}
Also used : StartTraceRequest(io.jaegertracing.crossdock.api.StartTraceRequest) TraceResponse(io.jaegertracing.crossdock.api.TraceResponse) Response(javax.ws.rs.core.Response) Scope(io.opentracing.Scope) ObservedSpan(io.jaegertracing.crossdock.api.ObservedSpan) Span(io.opentracing.Span) Downstream(io.jaegertracing.crossdock.api.Downstream) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) TraceResponse(io.jaegertracing.crossdock.api.TraceResponse) Test(org.junit.Test)

Example 52 with JaegerSpanContext

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

the class TraceContextCodecTest method support128BitTraceIdExtraction.

@Test
public void support128BitTraceIdExtraction() {
    String hex128Bits = "463ac35c9f6413ad48485a3953bb6124";
    String parentSpan = "d1595c6ec91668af";
    String tracecontext = String.format("00-%s-%s-01", hex128Bits, parentSpan);
    TextMapAdapter textMap = new TextMapAdapter(new HashMap<>());
    textMap.put(TRACE_PARENT, tracecontext);
    JaegerSpanContext context = traceContextCodec.extract(textMap);
    assertNotNull(HexCodec.lowerHexToUnsignedLong(parentSpan));
    assertEquals(HexCodec.lowerHexToUnsignedLong(hex128Bits).longValue(), context.getTraceIdLow());
    assertEquals(HexCodec.higherHexToUnsignedLong(hex128Bits).longValue(), context.getTraceIdHigh());
    assertEquals(HexCodec.lowerHexToUnsignedLong(parentSpan).longValue(), context.getSpanId());
    assertTrue(context.isSampled());
}
Also used : TextMapAdapter(io.opentracing.propagation.TextMapAdapter) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 53 with JaegerSpanContext

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

the class TraceContextCodecTest method testTraceStatePropagation.

@Test
public void testTraceStatePropagation() {
    Map<String, String> extractCarrier = new HashMap<>();
    TextMapAdapter textMap = new TextMapAdapter(extractCarrier);
    textMap.put(TRACE_PARENT, EXAMPLE_TRACE_PARENT);
    textMap.put(TRACE_STATE, "whatever");
    JaegerSpanContext spanContext = traceContextCodec.extract(textMap);
    Map<String, String> injectCarrier = new HashMap<>();
    traceContextCodec.inject(spanContext, new TextMapAdapter(injectCarrier));
    assertEquals(extractCarrier, injectCarrier);
}
Also used : HashMap(java.util.HashMap) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 54 with JaegerSpanContext

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

the class B3TextMapCodecTest method support128BitTraceIdExtraction.

@Test
public void support128BitTraceIdExtraction() {
    String hex128Bits = "463ac35c9f6413ad48485a3953bb6124";
    String lower64Bits = "48485a3953bb6124";
    DelegatingTextMap textMap = new DelegatingTextMap();
    textMap.put(B3TextMapCodec.TRACE_ID_NAME, hex128Bits);
    textMap.put(B3TextMapCodec.SPAN_ID_NAME, lower64Bits);
    textMap.put(B3TextMapCodec.PARENT_SPAN_ID_NAME, "0");
    textMap.put(B3TextMapCodec.SAMPLED_NAME, "1");
    textMap.put(B3TextMapCodec.FLAGS_NAME, "1");
    textMap.put(B3TextMapCodec.BAGGAGE_PREFIX + "foo", "bar");
    textMap.put("random-foo", "bar");
    JaegerSpanContext context = b3Codec.extract(textMap);
    assertNotNull(HexCodec.lowerHexToUnsignedLong(lower64Bits));
    assertEquals(HexCodec.lowerHexToUnsignedLong(hex128Bits).longValue(), context.getTraceIdLow());
    assertEquals(HexCodec.higherHexToUnsignedLong(hex128Bits).longValue(), context.getTraceIdHigh());
    assertEquals(HexCodec.lowerHexToUnsignedLong(lower64Bits).longValue(), context.getSpanId());
    assertEquals(0, context.getParentId());
    assertEquals(B3TextMapCodec.SAMPLED_FLAG | B3TextMapCodec.DEBUG_FLAG, context.getFlags());
    assertEquals(1, ((Set<Entry<String, String>>) context.baggageItems()).size());
    assertEquals("bar", context.getBaggageItem("foo"));
}
Also used : Entry(java.util.Map.Entry) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 55 with JaegerSpanContext

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

the class B3TextMapCodecTest method testDefault.

@Test
public void testDefault() {
    B3TextMapCodec b3Codec = new B3TextMapCodec.Builder().build();
    DelegatingTextMap entries = new DelegatingTextMap();
    long traceIdLow = 1;
    long spanId = 2;
    long parentId = 3;
    JaegerSpanContext spanContext = new JaegerSpanContext(0L, traceIdLow, spanId, parentId, (byte) 0).withBaggageItem("foo", "bar");
    b3Codec.inject(spanContext, entries);
    assertEquals(5, entries.delegate.size());
    assertNotNull(entries.delegate.get(B3TextMapCodec.TRACE_ID_NAME));
    assertNotNull(entries.delegate.get(B3TextMapCodec.SPAN_ID_NAME));
    assertNotNull(entries.delegate.get(B3TextMapCodec.PARENT_SPAN_ID_NAME));
    assertNotNull(entries.delegate.get(B3TextMapCodec.SAMPLED_NAME));
    assertEquals("bar", entries.delegate.get("baggage-foo"));
}
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