Skip to content

Commit

Permalink
maintenance/tracing: Don't overwrite context in traceLogHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
monstermunchkin committed Nov 28, 2024
1 parent 603c5ba commit 6775de6
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions maintenance/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,21 @@ type traceLogHandler struct {
// Trace the service function handler execution
func (h *traceLogHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
span := sentry.TransactionFromContext(r.Context())
defer span.Finish()

ctx := span.Context()

span.SetData("req_id", log.RequestIDFromContext(ctx))
span.SetData("path", r.URL.Path)
span.SetData("method", r.Method)
if span != nil {
span.SetData("req_id", log.RequestIDFromContext(r.Context()))
span.SetData("path", r.URL.Path)
span.SetData("method", r.Method)
}

ww := mutil.WrapWriter(w)

h.next.ServeHTTP(ww, r.WithContext(ctx))
span.SetData("bytes", ww.BytesWritten())
span.SetData("status_code", ww.Status())
h.next.ServeHTTP(ww, r)

if span != nil {
span.SetData("bytes", ww.BytesWritten())
span.SetData("status_code", ww.Status())
}
}

// TraceLogHandler generates a tracing handler that adds logging data to existing handler.
Expand Down

0 comments on commit 6775de6

Please sign in to comment.