Search in sources :

Example 1 with Span

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

the class SpanCreationRequestInterceptor method process.

@Override
public void process(HttpRequest httpRequest, HttpContext httpContext) throws HttpException, IOException {
    try {
        Span currentActiveSpan = tracer.activeSpan();
        Tracer.SpanBuilder clientSpanBuilder = tracer.buildSpan(getOperationName(httpRequest));
        if (currentActiveSpan != null) {
            clientSpanBuilder.asChildOf(currentActiveSpan);
        }
        Span clientSpan = clientSpanBuilder.start();
        RequestLine requestLine = httpRequest.getRequestLine();
        Tags.SPAN_KIND.set(clientSpan, Tags.SPAN_KIND_CLIENT);
        Tags.HTTP_URL.set(clientSpan, requestLine.getUri());
        if (httpContext instanceof HttpClientContext) {
            HttpHost host = ((HttpClientContext) httpContext).getTargetHost();
            Tags.PEER_HOSTNAME.set(clientSpan, host.getHostName());
            Tags.PEER_PORT.set(clientSpan, host.getPort());
        }
        onSpanStarted(clientSpan, httpRequest, httpContext);
        httpContext.setAttribute(Constants.CURRENT_SPAN_CONTEXT_KEY, clientSpan);
    } catch (Exception e) {
        log.error("Could not start client tracing span.", e);
    }
}
Also used : RequestLine(org.apache.http.RequestLine) Tracer(io.opentracing.Tracer) HttpHost(org.apache.http.HttpHost) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) Span(io.opentracing.Span) HttpException(org.apache.http.HttpException) IOException(java.io.IOException)

Example 2 with Span

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

the class ScopeManagerTraceContext method pop.

/**
 * Deactivates the current active span and returns it. If there is no active span returns null.
 */
@Override
public Span pop() {
    Scope scope = scopeManager.active();
    if (scope == null) {
        return null;
    }
    Span span = scope.span();
    scope.close();
    return span;
}
Also used : Scope(io.opentracing.Scope) Span(io.opentracing.Span)

Example 3 with Span

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

the class ScopeManagerTraceContextTest method getCurrentSpan.

@Test
public void getCurrentSpan() throws Exception {
    traceContext.push(span);
    Span actual = traceContext.getCurrentSpan();
    Assert.assertEquals(span, actual);
}
Also used : Span(io.opentracing.Span) Test(org.junit.Test)

Example 4 with Span

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

the class ClientSpanCreationFilter method filter.

@Override
public void filter(ClientRequestContext clientRequestContext) throws IOException {
    Span currentActiveSpan = tracer.activeSpan();
    Tracer.SpanBuilder clientSpanBuilder = tracer.buildSpan(clientRequestContext.getMethod());
    if (currentActiveSpan != null) {
        clientSpanBuilder.asChildOf(currentActiveSpan);
    }
    Span clientSpan = clientSpanBuilder.start();
    // we assume there are no more spans created for this RPC request, therefore we do not need
    // to make the span active in the thread. Instead we store it in the clientRequestContext,
    // from where the resporse filter can retrieve it and finish the span.
    clientRequestContext.setProperty(Constants.CURRENT_SPAN_CONTEXT_KEY, clientSpan);
    Tags.SPAN_KIND.set(clientSpan, Tags.SPAN_KIND_CLIENT);
    Tags.HTTP_URL.set(clientSpan, clientRequestContext.getUri().toString());
    Tags.PEER_HOSTNAME.set(clientSpan, clientRequestContext.getUri().getHost());
}
Also used : Tracer(io.opentracing.Tracer) Span(io.opentracing.Span)

Example 5 with Span

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

the class ClientSpanInjectionFilter method filter.

@Override
public void filter(ClientRequestContext clientRequestContext, ClientResponseContext clientResponseContext) throws IOException {
    try {
        Span clientSpan = (io.opentracing.Span) clientRequestContext.getProperty(Constants.CURRENT_SPAN_CONTEXT_KEY);
        if (clientSpan != null) {
            Tags.HTTP_STATUS.set(clientSpan, clientResponseContext.getStatus());
            clientSpan.finish();
        }
    } catch (Exception e) {
        log.error("Client Span Injection Filter Response:", e);
    }
}
Also used : Span(io.opentracing.Span) IOException(java.io.IOException)

Aggregations

Span (io.opentracing.Span)368 Future (io.vertx.core.Future)182 HttpURLConnection (java.net.HttpURLConnection)174 Tracer (io.opentracing.Tracer)123 JsonObject (io.vertx.core.json.JsonObject)119 ClientErrorException (org.eclipse.hono.client.ClientErrorException)117 Map (java.util.Map)115 SpanContext (io.opentracing.SpanContext)114 Objects (java.util.Objects)109 List (java.util.List)104 TracingHelper (org.eclipse.hono.tracing.TracingHelper)104 Optional (java.util.Optional)102 Promise (io.vertx.core.Promise)98 Test (org.junit.jupiter.api.Test)96 MessageHelper (org.eclipse.hono.util.MessageHelper)89 Vertx (io.vertx.core.Vertx)84 Constants (org.eclipse.hono.util.Constants)82 ServerErrorException (org.eclipse.hono.client.ServerErrorException)80 Truth.assertThat (com.google.common.truth.Truth.assertThat)79 Mockito.mock (org.mockito.Mockito.mock)79