Skip to content
Permalink
Browse files
s/span/scope/ for server too and we finally pass tcks
  • Loading branch information
rmannibucau committed May 20, 2018
1 parent 56830cf commit 1fb36417111bd0fdb8ce34cf4d9f8a8439dddb7b
Showing 3 changed files with 14 additions and 9 deletions.
@@ -16,6 +16,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.Tracer;
import io.opentracing.tag.Tags;
@@ -36,8 +37,9 @@ public void doFilter(final ServletRequest request, final ServletResponse respons
try {
chain.doFilter(request, response);
} catch (final Exception ex) {
ofNullable(request.getAttribute(OpenTracingFilter.class.getName())).map(Span.class::cast).ifPresent(span -> {
ofNullable(request.getAttribute(OpenTracingFilter.class.getName())).map(Scope.class::cast).ifPresent(scope -> {
final int status = HttpServletResponse.class.cast(response).getStatus();
final Span span = scope.span();
Tags.HTTP_STATUS.set(span, status == HttpServletResponse.SC_OK ? HttpServletResponse.SC_INTERNAL_SERVER_ERROR : status);
Tags.ERROR.set(span, true);
span.log(new HashMap<String, Object>() {
@@ -50,13 +52,13 @@ public void doFilter(final ServletRequest request, final ServletResponse respons
});
throw ex;
} finally {
ofNullable(request.getAttribute(OpenTracingFilter.class.getName())).map(Span.class::cast).ifPresent(span -> {
ofNullable(request.getAttribute(OpenTracingFilter.class.getName())).map(Scope.class::cast).ifPresent(scope -> {
if (request.isAsyncStarted()) {
request.getAsyncContext().addListener(new AsyncListener() {

@Override
public void onComplete(final AsyncEvent event) {
span.finish();
scope.close();
}

@Override
@@ -75,7 +77,7 @@ public void onStartAsync(final AsyncEvent event) {
}
});
} else {
span.finish();
scope.close();
}
});
}
@@ -24,6 +24,7 @@
import org.apache.geronimo.microprofile.opentracing.impl.HeaderTextMap;
import org.apache.geronimo.microprofile.opentracing.microprofile.client.OpenTracingClientRequestFilter;

import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.Tracer;
import io.opentracing.propagation.Format;
@@ -55,13 +56,15 @@ public void filter(final ContainerRequestContext context) {
.orElseGet(() -> tracer.extract(Format.Builtin.HTTP_HEADERS, new HeaderTextMap<>(context.getHeaders()))))
.ifPresent(builder::asChildOf);

final Span span = builder.startActive(true).span();
final Scope scope = builder.startActive(true);
final Span span = scope.span();

if (!"true".equalsIgnoreCase(
String.valueOf(context.getProperty("org.apache.geronimo.microprofile.opentracing.server.skipDefaultSpanTags")))) {
Tags.HTTP_METHOD.set(span, context.getMethod());
Tags.HTTP_URL.set(span, context.getUriInfo().getRequestUri().toASCIIString());
}

context.setProperty(OpenTracingFilter.class.getName(), span);
context.setProperty(OpenTracingFilter.class.getName(), scope);
}
}
@@ -24,15 +24,15 @@
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;

import io.opentracing.Span;
import io.opentracing.Scope;
import io.opentracing.tag.Tags;

@Priority(Priorities.HEADER_DECORATOR)
public class OpenTracingServerResponseFilter implements ContainerResponseFilter {

@Override
public void filter(final ContainerRequestContext req, final ContainerResponseContext resp) {
ofNullable(req.getProperty(OpenTracingFilter.class.getName())).map(Span.class::cast)
.ifPresent(span -> Tags.HTTP_STATUS.set(span, resp.getStatus()));
ofNullable(req.getProperty(OpenTracingFilter.class.getName())).map(Scope.class::cast)
.ifPresent(scope -> Tags.HTTP_STATUS.set(scope.span(), resp.getStatus()));
}
}

0 comments on commit 1fb3641

Please sign in to comment.