From 3dd70426d003207742029d95b695024440fba3e0 Mon Sep 17 00:00:00 2001 From: Thomas Hipp Date: Mon, 2 Dec 2024 09:27:38 +0100 Subject: [PATCH] tracing: Continue trace if it exists --- maintenance/tracing/tracing.go | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/maintenance/tracing/tracing.go b/maintenance/tracing/tracing.go index ae1f90b3..f7c1c4b4 100755 --- a/maintenance/tracing/tracing.go +++ b/maintenance/tracing/tracing.go @@ -39,18 +39,25 @@ func (h *traceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ctx = sentry.SetHubOnContext(ctx, hub) } - options := []sentry.SpanOption{ - sentry.ContinueFromRequest(r), - sentry.WithOpName("http.server"), - sentry.WithTransactionSource(sentry.SourceURL), - sentry.WithSpanOrigin(sentry.SpanOriginStdLib), - } + var transaction *sentry.Span + + transaction = sentry.TransactionFromContext(ctx) + if transaction != nil { + transaction = transaction.StartChild("http.server", sentry.WithDescription(getHTTPSpanName(r))) + } else { + options := []sentry.SpanOption{ + sentry.ContinueFromRequest(r), + sentry.WithOpName("http.server"), + sentry.WithTransactionSource(sentry.SourceURL), + sentry.WithSpanOrigin(sentry.SpanOriginStdLib), + } - transaction := sentry.StartTransaction(ctx, - getHTTPSpanName(r), - options..., - ) - transaction.SetData("http.request.method", r.Method) + transaction = sentry.StartTransaction(ctx, + getHTTPSpanName(r), + options..., + ) + transaction.SetData("http.request.method", r.Method) + } ww := mutil.WrapWriter(w)