Skip to content

Commit

Permalink
Merge pull request #260 from laci9/operation-name-fix
Browse files Browse the repository at this point in the history
added request uri as the operation name of the spam
  • Loading branch information
SimonEismann authored Dec 11, 2023
2 parents 58c49d4 + ea273c7 commit 442abd9
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static Scope extractCurrentSpan(HttpServletRequest request) {
for (String headerName : Collections.list(request.getHeaderNames())) {
headers.put(headerName, request.getHeader(headerName));
}
return buildSpanFromHeaders(headers);
return buildSpanFromHeaders(headers, request.getRequestURI());
}

/**
Expand All @@ -89,22 +89,23 @@ public static Scope extractCurrentSpan(HttpHeaders httpHeaders) {
for (String headerName : httpHeaders.getRequestHeaders().keySet()) {
headers.put(headerName, httpHeaders.getRequestHeader(headerName).get(0));
}
return buildSpanFromHeaders(headers);
return buildSpanFromHeaders(headers, "op");
}

/**
* Helper method to extract and build the active span out of Map containing the
* processed headers.
*
* @param headers is the Map of the processed headers
* @param operationName is the operation name of the span (can be either URL or URI)
* @return Scope containing the extracted span marked as active. Can be used
* with try-with-resource construct
*/
private static Scope buildSpanFromHeaders(Map<String, String> headers) {
Tracer.SpanBuilder spanBuilder = GlobalTracer.get().buildSpan("op");
private static Scope buildSpanFromHeaders(Map<String, String> headers, String operationName) {
Tracer.SpanBuilder spanBuilder = GlobalTracer.get().buildSpan(operationName);
try {
SpanContext parentSpanCtx = GlobalTracer.get().extract(Format.Builtin.HTTP_HEADERS,
new TextMapExtractAdapter(headers));
new TextMapExtractAdapter(headers));
if (parentSpanCtx != null) {
spanBuilder = spanBuilder.asChildOf(parentSpanCtx);
}
Expand Down

0 comments on commit 442abd9

Please sign in to comment.