Search in sources :

Example 1 with SpanContext

use of io.opentracing.SpanContext in project jaeger-client-java by jaegertracing.

the class ServerFilter method filter.

@Override
public void filter(ContainerRequestContext containerRequestContext) throws IOException {
    // TODO: Add a @DisableTracing annotation and use the resourceInfo to check if it's applied
    try {
        Tracer.SpanBuilder builder = tracer.buildSpan(getOperationName(containerRequestContext)).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).withTag(Tags.PEER_HOSTNAME.getKey(), containerRequestContext.getUriInfo().getBaseUri().getHost()).withTag(Tags.HTTP_URL.getKey(), containerRequestContext.getUriInfo().getAbsolutePath().toString());
        // TODO(oibe) make X_UBER_SOURCE configurable for open source projects
        MultivaluedMap<String, String> headers = containerRequestContext.getHeaders();
        if (headers.containsKey(com.uber.jaeger.Constants.X_UBER_SOURCE)) {
            builder = builder.withTag(Tags.PEER_SERVICE.getKey(), headers.getFirst(com.uber.jaeger.Constants.X_UBER_SOURCE));
        }
        ServerRequestCarrier carrier = new ServerRequestCarrier(containerRequestContext);
        SpanContext spanContext = tracer.extract(Format.Builtin.HTTP_HEADERS, carrier);
        if (spanContext != null) {
            builder = builder.asChildOf(spanContext);
        }
        builder.startActive(true);
    } catch (Exception e) {
        log.error("Server Filter Request:", e);
    }
}
Also used : SpanContext(io.opentracing.SpanContext) Tracer(io.opentracing.Tracer) IOException(java.io.IOException)

Example 2 with SpanContext

use of io.opentracing.SpanContext in project opentracing-java by opentracing.

the class GlobalTracerTest method testDelegation_inject.

@Test
public void testDelegation_inject() {
    Tracer mockTracer = mock(Tracer.class);
    SpanContext mockContext = mock(SpanContext.class);
    Format<Object> mockFormat = mock(Format.class);
    Object mockCarrier = mock(Object.class);
    GlobalTracer.register(mockTracer);
    GlobalTracer.get().inject(mockContext, mockFormat, mockCarrier);
    verify(mockTracer).inject(eq(mockContext), eq(mockFormat), eq(mockCarrier));
    verifyNoMoreInteractions(mockTracer, mockContext, mockFormat, mockCarrier);
}
Also used : SpanContext(io.opentracing.SpanContext) Tracer(io.opentracing.Tracer) Test(org.junit.Test)

Example 3 with SpanContext

use of io.opentracing.SpanContext in project batfish by batfish.

the class WorkItemTest method testNullActiveSpan.

@Test
public void testNullActiveSpan() {
    _workItem.setSourceSpan(null, _mockTracer);
    SpanContext sourceSpanContext = _workItem.getSourceSpan(_mockTracer);
    assertThat(sourceSpanContext, nullValue());
    try (ActiveSpan childSpan = _mockTracer.buildSpan("test dangling child").addReference(References.FOLLOWS_FROM, sourceSpanContext).startActive()) {
        assertThat(childSpan, notNullValue());
        assertThat(childSpan, instanceOf(ThreadLocalActiveSpan.class));
    }
}
Also used : SpanContext(io.opentracing.SpanContext) ThreadLocalActiveSpan(io.opentracing.util.ThreadLocalActiveSpan) ActiveSpan(io.opentracing.ActiveSpan) NoopActiveSpan(io.opentracing.NoopActiveSpanSource.NoopActiveSpan) ThreadLocalActiveSpan(io.opentracing.util.ThreadLocalActiveSpan) Test(org.junit.Test)

Example 4 with SpanContext

use of io.opentracing.SpanContext in project batfish by batfish.

the class WorkItemTest method testNullActiveSpanNoop.

@Test
public void testNullActiveSpanNoop() {
    _workItem.setSourceSpan(null, _noopTracer);
    SpanContext sourceSpanContext = _workItem.getSourceSpan(_noopTracer);
    try (ActiveSpan childSpan = _noopTracer.buildSpan("test dangling child").addReference(References.FOLLOWS_FROM, sourceSpanContext).startActive()) {
        assertThat(childSpan, notNullValue());
        assertThat(childSpan, instanceOf(NoopActiveSpan.class));
    }
}
Also used : SpanContext(io.opentracing.SpanContext) ThreadLocalActiveSpan(io.opentracing.util.ThreadLocalActiveSpan) ActiveSpan(io.opentracing.ActiveSpan) NoopActiveSpan(io.opentracing.NoopActiveSpanSource.NoopActiveSpan) NoopActiveSpan(io.opentracing.NoopActiveSpanSource.NoopActiveSpan) Test(org.junit.Test)

Example 5 with SpanContext

use of io.opentracing.SpanContext in project batfish by batfish.

the class WorkItemTest method testExtractOnlyNoop.

@Test
public void testExtractOnlyNoop() {
    SpanContext sourceSpanContext = _workItem.getSourceSpan(_noopTracer);
    try (ActiveSpan childSpan = _noopTracer.buildSpan("test dangling child").addReference(References.FOLLOWS_FROM, sourceSpanContext).startActive()) {
        assertThat(childSpan, notNullValue());
        assertThat(childSpan, instanceOf(NoopActiveSpan.class));
    }
}
Also used : SpanContext(io.opentracing.SpanContext) ThreadLocalActiveSpan(io.opentracing.util.ThreadLocalActiveSpan) ActiveSpan(io.opentracing.ActiveSpan) NoopActiveSpan(io.opentracing.NoopActiveSpanSource.NoopActiveSpan) NoopActiveSpan(io.opentracing.NoopActiveSpanSource.NoopActiveSpan) Test(org.junit.Test)

Aggregations

SpanContext (io.opentracing.SpanContext)118 Span (io.opentracing.Span)81 Future (io.vertx.core.Future)70 Tracer (io.opentracing.Tracer)60 Objects (java.util.Objects)57 HttpURLConnection (java.net.HttpURLConnection)56 JsonObject (io.vertx.core.json.JsonObject)55 TracingHelper (org.eclipse.hono.tracing.TracingHelper)55 Logger (org.slf4j.Logger)54 LoggerFactory (org.slf4j.LoggerFactory)54 List (java.util.List)51 Promise (io.vertx.core.Promise)45 Optional (java.util.Optional)45 Map (java.util.Map)40 ClientErrorException (org.eclipse.hono.client.ClientErrorException)39 MessageHelper (org.eclipse.hono.util.MessageHelper)33 UUID (java.util.UUID)31 Collectors (java.util.stream.Collectors)31 HashMap (java.util.HashMap)25 Vertx (io.vertx.core.Vertx)24