Skip to content

Commit

Permalink
customizeContent
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Apr 21, 2021
1 parent 023eac4 commit a85bb62
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,11 @@ public Context startSpan(
onConnectionAndRequest(spanBuilder, connection, request);

Context context = withServerSpan(parentContext, spanBuilder.startSpan());
context = customizeContext(context, request);
attachServerContext(context, storage);

return context;
}

/** Override in subclass to customize context that is returned by {@code startSpan}. */
protected Context customizeContext(Context context, REQUEST request) {
return context;
}

/**
* Convenience method. Delegates to {@link #end(Context, Object, long)}, passing {@code timestamp}
* value of {@code -1}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ public static Jetty11HttpServerTracer tracer() {
}

public Context startServerSpan(HttpServletRequest request) {
return startSpan(request, "HTTP " + request.getMethod(), false);
}

@Override
protected Context customizeContext(Context context, HttpServletRequest request) {
context = super.customizeContext(context, request);
Context context = startSpan(request, "HTTP " + request.getMethod(), false);
return AppServerBridge.init(context, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ public static Jetty8HttpServerTracer tracer() {
}

public Context startServerSpan(HttpServletRequest request) {
return startSpan(request, "HTTP " + request.getMethod(), false);
}

@Override
protected Context customizeContext(Context context, HttpServletRequest request) {
context = super.customizeContext(context, request);
Context context = startSpan(request, "HTTP " + request.getMethod(), false);
return AppServerBridge.init(context, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,14 @@ public Context startSpan(REQUEST request, String spanName, boolean servlet) {
accessor.setRequestAttribute(request, "trace_id", spanContext.getTraceId());
accessor.setRequestAttribute(request, "span_id", spanContext.getSpanId());

// add context for tracking whether servlet instrumentation has updated the server span name
if (servlet) {
// server span name shouldn't be updated when server span was created from a call to Servlet
// (if created from a call to Filter then name may be updated from updateContext)
ServerSpanNaming.setUpdatedServerSpanName(SERVLET);
context = ServerSpanNaming.init(context, SERVLET);
} else {
context = ServerSpanNaming.init(context, CONTAINER);
}
return addServletContextPath(context, request);
}

@Override
protected Context customizeContext(Context context, REQUEST request) {
// add context for tracking whether servlet instrumentation has updated the server span name
context = ServerSpanNaming.init(context, CONTAINER);
// add context for current request's context path
return addServletContextPath(context, request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ public abstract class TomcatTracer extends HttpServerTracer<Request, Response, R
private static final Logger log = LoggerFactory.getLogger(TomcatTracer.class);

public Context startServerSpan(Request request) {
return startSpan(request, request, request, "HTTP " + request.method().toString());
}

@Override
protected Context customizeContext(Context context, Request request) {
Context context = startSpan(request, request, request, "HTTP " + request.method().toString());
context = ServerSpanNaming.init(context, CONTAINER);
return AppServerBridge.init(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,8 @@ protected String getInstrumentationName() {
}

public Context startServerSpan(HttpServerExchange exchange) {
return startSpan(
exchange, exchange, exchange, "HTTP " + exchange.getRequestMethod().toString());
}

@Override
protected Context customizeContext(Context context, HttpServerExchange exchange) {
Context context =
startSpan(exchange, exchange, exchange, "HTTP " + exchange.getRequestMethod().toString());
context = ServerSpanNaming.init(context, CONTAINER);
// span is ended when counter reaches 0, we start from 2 which accounts for the
// handler that started the span and exchange completion listener
Expand Down

0 comments on commit a85bb62

Please sign in to comment.