Skip to content

Commit 6775de6

Browse files
maintenance/tracing: Don't overwrite context in traceLogHandler
1 parent 603c5ba commit 6775de6

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

maintenance/tracing/tracing.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,21 @@ type traceLogHandler struct {
7777
// Trace the service function handler execution
7878
func (h *traceLogHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
7979
span := sentry.TransactionFromContext(r.Context())
80-
defer span.Finish()
81-
82-
ctx := span.Context()
8380

84-
span.SetData("req_id", log.RequestIDFromContext(ctx))
85-
span.SetData("path", r.URL.Path)
86-
span.SetData("method", r.Method)
81+
if span != nil {
82+
span.SetData("req_id", log.RequestIDFromContext(r.Context()))
83+
span.SetData("path", r.URL.Path)
84+
span.SetData("method", r.Method)
85+
}
8786

8887
ww := mutil.WrapWriter(w)
8988

90-
h.next.ServeHTTP(ww, r.WithContext(ctx))
91-
span.SetData("bytes", ww.BytesWritten())
92-
span.SetData("status_code", ww.Status())
89+
h.next.ServeHTTP(ww, r)
90+
91+
if span != nil {
92+
span.SetData("bytes", ww.BytesWritten())
93+
span.SetData("status_code", ww.Status())
94+
}
9395
}
9496

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

0 commit comments

Comments
 (0)