Search in sources :

Example 11 with SpanContext

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

the class BaggageSetterTest method testUnsampledSpan.

@Test
public void testUnsampledSpan() {
    tracer = new Tracer.Builder("SamplerTest", reporter, new ConstSampler(false)).withMetrics(metrics).build();
    span = (Span) tracer.buildSpan("some-operation").startManual();
    when(mgr.getRestriction(SERVICE, KEY)).thenReturn(Restriction.of(true, 5));
    final String value = "value";
    SpanContext ctx = setter.setBaggage(span, KEY, value);
    assertEquals(value, ctx.getBaggageItem(KEY));
    // No logs should be written if the span is not sampled
    assertNull(span.getLogs());
}
Also used : SpanContext(com.uber.jaeger.SpanContext) Tracer(com.uber.jaeger.Tracer) ConstSampler(com.uber.jaeger.samplers.ConstSampler) Test(org.junit.Test)

Example 12 with SpanContext

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

the class B3TextMapCodecResiliencyTest method shouldFallbackWhenMaliciousInput.

@Test
@UseDataProvider("maliciousInputs")
public void shouldFallbackWhenMaliciousInput(String headerName, String maliciousInput) {
    TextMap maliciousCarrier = validHeaders();
    maliciousCarrier.put(headerName, maliciousInput);
    // when
    SpanContext extract = sut.extract(maliciousCarrier);
    // then
    assertNull(extract);
}
Also used : SpanContext(com.uber.jaeger.SpanContext) TextMap(io.opentracing.propagation.TextMap) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 13 with SpanContext

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

the class B3TextMapCodecTest method testInject.

@Test
public void testInject() throws Exception {
    DelegatingTextMap textMap = new DelegatingTextMap();
    b3Codec.inject(new SpanContext(1, 1, 1, SAMPLED), textMap);
    assertTrue(textMap.containsKey(TRACE_ID_NAME));
    assertTrue(textMap.containsKey(SPAN_ID_NAME));
}
Also used : SpanContext(com.uber.jaeger.SpanContext) Test(org.junit.Test)

Example 14 with SpanContext

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

the class B3TextMapCodecTest method downgrades128BitTraceIdToLower64Bits.

@Test
public void downgrades128BitTraceIdToLower64Bits() throws Exception {
    String hex128Bits = "463ac35c9f6413ad48485a3953bb6124";
    String lower64Bits = "48485a3953bb6124";
    DelegatingTextMap textMap = new DelegatingTextMap();
    textMap.put(TRACE_ID_NAME, hex128Bits);
    textMap.put(SPAN_ID_NAME, lower64Bits);
    textMap.put(PARENT_SPAN_ID_NAME, "0");
    textMap.put(SAMPLED_NAME, "1");
    textMap.put(FLAGS_NAME, "1");
    SpanContext context = b3Codec.extract(textMap);
    assertNotNull(HexCodec.lowerHexToUnsignedLong(lower64Bits));
    assertEquals(HexCodec.lowerHexToUnsignedLong(lower64Bits).longValue(), context.getTraceId());
    assertEquals(HexCodec.lowerHexToUnsignedLong(lower64Bits).longValue(), context.getSpanId());
    assertEquals(0, context.getParentId());
    assertEquals(SAMPLED_FLAG | DEBUG_FLAG, context.getFlags());
}
Also used : SpanContext(com.uber.jaeger.SpanContext) Test(org.junit.Test)

Example 15 with SpanContext

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

the class JaegerThriftSpanConverterTest method testConvertSpanTwoReferencesChildOf.

@Test
public void testConvertSpanTwoReferencesChildOf() {
    Span parent = tracer.buildSpan("foo").startManual();
    Span parent2 = tracer.buildSpan("foo").startManual();
    Span child = tracer.buildSpan("foo").asChildOf(parent).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.CHILD_OF), 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