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);
}
}
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);
}
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));
}
}
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));
}
}
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));
}
}
Aggregations