Search in sources :

Example 21 with SpanContext

use of com.uber.jaeger.SpanContext 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)

Example 22 with SpanContext

use of com.uber.jaeger.SpanContext 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;
    SpanContext ctx = setter.setBaggage(span, KEY, value);
    assertBaggageLogs(span, KEY, null, false, false, false);
    assertNull(ctx.getBaggageItem(KEY));
}
Also used : SpanContext(com.uber.jaeger.SpanContext) Test(org.junit.Test)

Example 23 with SpanContext

use of com.uber.jaeger.SpanContext 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";
    SpanContext ctx = setter.setBaggage(span, KEY, value);
    assertBaggageLogs(span, KEY, value, false, false, true);
    assertNull(ctx.getBaggageItem(KEY));
    assertEquals(1, metricsFactory.getCounter("jaeger:baggage_updates", "result=err"));
}
Also used : SpanContext(com.uber.jaeger.SpanContext) Test(org.junit.Test)

Example 24 with SpanContext

use of com.uber.jaeger.SpanContext in project jaeger-client-java by jaegertracing.

the class BaggageSetterTest method testTruncatedBaggage.

@Test
public void testTruncatedBaggage() {
    when(mgr.getRestriction(SERVICE, KEY)).thenReturn(Restriction.of(true, 5));
    final String value = "0123456789";
    final String expected = "01234";
    SpanContext ctx = setter.setBaggage(span, KEY, value);
    assertBaggageLogs(span, KEY, expected, true, false, false);
    assertEquals(expected, ctx.getBaggageItem(KEY));
    assertEquals(1, metricsFactory.getCounter("jaeger:baggage_truncations", ""));
    assertEquals(1, metricsFactory.getCounter("jaeger:baggage_updates", "result=ok"));
}
Also used : SpanContext(com.uber.jaeger.SpanContext) Test(org.junit.Test)

Example 25 with SpanContext

use of com.uber.jaeger.SpanContext in project jaeger-client-java by jaegertracing.

the class JaegerThriftSpanConverterTest method testConvertSpanMixedReferences.

@Test
public void testConvertSpanMixedReferences() {
    Span parent = tracer.buildSpan("foo").startManual();
    Span parent2 = tracer.buildSpan("foo").startManual();
    Span child = tracer.buildSpan("foo").addReference(References.FOLLOWS_FROM, parent.context()).asChildOf(parent2).startManual();
    com.uber.jaeger.thriftjava.Span span = JaegerThriftSpanConverter.convertSpan((com.uber.jaeger.Span) child);
    assertEquals(0, span.getParentSpanId());
    assertEquals(2, span.getReferences().size());
    assertEquals(buildReference((SpanContext) parent.context(), References.FOLLOWS_FROM), span.getReferences().get(0));
    assertEquals(buildReference((SpanContext) parent2.context(), References.CHILD_OF), span.getReferences().get(1));
}
Also used : SpanContext(com.uber.jaeger.SpanContext) Span(io.opentracing.Span) Test(org.junit.Test)

Aggregations

SpanContext (com.uber.jaeger.SpanContext)29 Test (org.junit.Test)25 TextMap (io.opentracing.propagation.TextMap)6 Response (javax.ws.rs.core.Response)6 Span (com.uber.jaeger.Span)5 TraceData (com.github.kristofa.brave.TraceData)3 HashMap (java.util.HashMap)3 SpanId (com.github.kristofa.brave.SpanId)2 Tracer (com.uber.jaeger.Tracer)2 Span (io.opentracing.Span)2 List (java.util.List)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 Endpoint (com.twitter.zipkin.thriftjava.Endpoint)1 ObservedSpan (com.uber.jaeger.crossdock.api.ObservedSpan)1 ConstSampler (com.uber.jaeger.samplers.ConstSampler)1 SpanRef (com.uber.jaeger.thriftjava.SpanRef)1 TextMapExtractAdapter (io.opentracing.propagation.TextMapExtractAdapter)1 TextMapInjectAdapter (io.opentracing.propagation.TextMapInjectAdapter)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1