mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
infra(tracing): Fix span naming order-of-operations bug (#90025)
This commit is contained in:
parent
8f99d58aaf
commit
7ac757afcb
@ -87,10 +87,6 @@ func RequestTracing(tracer tracing.Tracer) web.Middleware {
|
||||
|
||||
// generic span name for requests where there's no route operation name
|
||||
spanName := fmt.Sprintf("HTTP %s <unknown>", req.Method)
|
||||
// TODO: do not depend on web.Context from the future
|
||||
if routeOperation, exists := RouteOperationName(web.FromContext(req.Context()).Req); exists {
|
||||
spanName = fmt.Sprintf("HTTP %s %s", req.Method, routeOperation)
|
||||
}
|
||||
|
||||
ctx, span := tracer.Start(ctx, spanName, trace.WithAttributes(
|
||||
semconv.HTTPURLKey.String(req.RequestURI),
|
||||
@ -105,6 +101,13 @@ func RequestTracing(tracer tracing.Tracer) web.Middleware {
|
||||
|
||||
next.ServeHTTP(rw, req)
|
||||
|
||||
// Reset the span name after the request has been processed, as
|
||||
// the route operation may have been injected by middleware.
|
||||
// TODO: do not depend on web.Context from the future
|
||||
if routeOperation, exists := RouteOperationName(web.FromContext(req.Context()).Req); exists {
|
||||
span.SetName(fmt.Sprintf("HTTP %s %s", req.Method, routeOperation))
|
||||
}
|
||||
|
||||
status := rw.Status()
|
||||
|
||||
span.SetAttributes(semconv.HTTPStatusCode(status))
|
||||
|
Loading…
Reference in New Issue
Block a user