diff --git a/maintenance/tracing/tracing.go b/maintenance/tracing/tracing.go index 9796514d..c0c2f6f9 100755 --- a/maintenance/tracing/tracing.go +++ b/maintenance/tracing/tracing.go @@ -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.