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