Search in sources :

Example 6 with Scope

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

the class PropagationTest method testActiveSpanNotAutoFinishOnClose.

@Test
public void testActiveSpanNotAutoFinishOnClose() {
    InMemoryReporter reporter = new InMemoryReporter();
    Tracer tracer = new Tracer.Builder("test", reporter, new ConstSampler(true)).build();
    Scope scope = tracer.buildSpan("parent").startActive(false);
    Span span = (Span) scope.span();
    scope.close();
    assertTrue(reporter.getSpans().isEmpty());
    span.finish();
    assertEquals(1, reporter.getSpans().size());
}
Also used : InMemoryReporter(com.uber.jaeger.reporters.InMemoryReporter) Scope(io.opentracing.Scope) ConstSampler(com.uber.jaeger.samplers.ConstSampler) Test(org.junit.Test)

Example 7 with Scope

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

the class PropagationTest method testActiveSpanAutoReference.

@Test
public void testActiveSpanAutoReference() {
    InMemoryReporter reporter = new InMemoryReporter();
    Tracer tracer = new Tracer.Builder("test", reporter, new ConstSampler(true)).build();
    try (Scope parent = tracer.buildSpan("parent").startActive(true)) {
        tracer.buildSpan("child").startActive(true).close();
    }
    assertEquals(2, reporter.getSpans().size());
    Span childSpan = reporter.getSpans().get(0);
    Span parentSpan = reporter.getSpans().get(1);
    assertEquals("child", childSpan.getOperationName());
    assertEquals(1, childSpan.getReferences().size());
    assertEquals("parent", parentSpan.getOperationName());
    assertTrue(parentSpan.getReferences().isEmpty());
    assertEquals(References.CHILD_OF, childSpan.getReferences().get(0).getType());
    assertEquals(parentSpan.context(), childSpan.getReferences().get(0).getSpanContext());
    assertEquals(parentSpan.context().getTraceId(), childSpan.context().getTraceId());
    assertEquals(parentSpan.context().getSpanId(), childSpan.context().getParentId());
}
Also used : InMemoryReporter(com.uber.jaeger.reporters.InMemoryReporter) Scope(io.opentracing.Scope) ConstSampler(com.uber.jaeger.samplers.ConstSampler) Test(org.junit.Test)

Example 8 with Scope

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

the class TracingRequestInterceptor method process.

@Override
public void process(HttpRequest httpRequest, HttpContext httpContext) throws HttpException, IOException {
    try {
        spanCreationInterceptor.process(httpRequest, httpContext);
        Scope currentScope = tracer.scopeManager().active();
        if (currentScope != null) {
            onSpanStarted(currentScope.span(), httpRequest, httpContext);
        } else {
            log.warn("Current scope is null; possibly failed to start client tracing span.");
        }
        spanInjectionInterceptor.process(httpRequest, httpContext);
    } catch (Exception e) {
        log.error("Could not start client tracing span.", e);
    }
}
Also used : Scope(io.opentracing.Scope) HttpException(org.apache.http.HttpException) IOException(java.io.IOException)

Aggregations

Scope (io.opentracing.Scope)8 InMemoryReporter (com.uber.jaeger.reporters.InMemoryReporter)5 ConstSampler (com.uber.jaeger.samplers.ConstSampler)5 Test (org.junit.Test)5 IOException (java.io.IOException)2 ScopeManager (io.opentracing.ScopeManager)1 Span (io.opentracing.Span)1 HttpException (org.apache.http.HttpException)1