From ec953c7ea06b3d801c004baf360d21e6ec365e38 Mon Sep 17 00:00:00 2001 From: Thomas Hipp Date: Wed, 27 Nov 2024 10:29:23 +0100 Subject: [PATCH 1/6] pkg/routine: Fix spans --- pkg/routine/instance.go | 11 +++++------ pkg/routine/routine.go | 13 ++++++------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/pkg/routine/instance.go b/pkg/routine/instance.go index c076b1dcf..01c6911f4 100755 --- a/pkg/routine/instance.go +++ b/pkg/routine/instance.go @@ -58,11 +58,6 @@ func (r *routineThatKeepsRunningOneInstance) Run(ctx context.Context) { // until it returns. Return the backoff duration after which another single run // should be performed. func (r *routineThatKeepsRunningOneInstance) singleRun(ctx context.Context) time.Duration { - span := sentry.StartSpan(ctx, "function", sentry.WithDescription(fmt.Sprintf("Routine %s", r.Name))) - defer span.Finish() - - ctx = span.Context() - l := redis.NewLock("routine:lock:"+r.Name, redis.SetTTL(r.lockTTL)) lockCtx, cancel, err := l.AcquireAndKeepUp(ctx) if err != nil { @@ -74,7 +69,11 @@ func (r *routineThatKeepsRunningOneInstance) singleRun(ctx context.Context) time routinePanicked := true func() { defer errors.HandleWithCtx(ctx, fmt.Sprintf("routine %d", r.num)) // handle panics - r.Routine(lockCtx) + + span := sentry.StartSpan(lockCtx, "function", sentry.WithDescription(fmt.Sprintf("routine %d", r.num))) + defer span.Finish() + + r.Routine(span.Context()) routinePanicked = false }() if routinePanicked { diff --git a/pkg/routine/routine.go b/pkg/routine/routine.go index f6d242303..7cbbdc35b 100755 --- a/pkg/routine/routine.go +++ b/pkg/routine/routine.go @@ -13,7 +13,6 @@ import ( "syscall" "github.com/getsentry/sentry-go" - "github.com/pace/bricks/maintenance/errors" "github.com/pace/bricks/maintenance/log" pkgcontext "github.com/pace/bricks/pkg/context" @@ -94,16 +93,12 @@ func Run(parentCtx context.Context, routine func(context.Context)) (cancel conte // add routine number to context and logger num := atomic.AddInt64(&ctr, 1) - span := sentry.StartTransaction(ctx, fmt.Sprintf("Routine %d", num), sentry.WithOpName("function")) - defer span.Finish() - - ctx = span.Context() - ctx = context.WithValue(ctx, ctxNumKey{}, num) logger := log.Ctx(ctx).With().Int64("routine", num).Logger() ctx = logger.WithContext(ctx) // get cancel function ctx, cancel = context.WithCancel(ctx) + // register context to be cancelled when the program is shut down contextsMx.Lock() contexts[num] = cancel @@ -120,7 +115,11 @@ func Run(parentCtx context.Context, routine func(context.Context)) (cancel conte go func() { defer errors.HandleWithCtx(ctx, fmt.Sprintf("routine %d", num)) // handle panics defer cancel() - routine(ctx) + + span := sentry.StartSpan(ctx, "function", sentry.WithDescription(fmt.Sprintf("routine %d", num))) + defer span.Finish() + + routine(span.Context()) }() return } From 2251924b0eba5e8e1f1b571d15a84d70f737c5fc Mon Sep 17 00:00:00 2001 From: Thomas Hipp Date: Wed, 27 Nov 2024 14:17:08 +0100 Subject: [PATCH 2/6] Don't overwrite request --- http/oauth2/oauth2.go | 1 - http/transport/tracing_round_tripper.go | 3 +-- maintenance/tracing/tracing.go | 8 +++----- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/http/oauth2/oauth2.go b/http/oauth2/oauth2.go index 6079207d4..68c0f3a18 100644 --- a/http/oauth2/oauth2.go +++ b/http/oauth2/oauth2.go @@ -67,7 +67,6 @@ func introspectRequest(r *http.Request, w http.ResponseWriter, tokenIntro TokenI defer span.Finish() ctx := span.Context() - r = r.WithContext(ctx) tok := security.GetBearerTokenFromHeader(r.Header.Get(oAuth2Header)) if tok == "" { diff --git a/http/transport/tracing_round_tripper.go b/http/transport/tracing_round_tripper.go index f8e684bc0..def73d2f1 100755 --- a/http/transport/tracing_round_tripper.go +++ b/http/transport/tracing_round_tripper.go @@ -46,9 +46,8 @@ func (l *TracingRoundTripper) RoundTrip(req *http.Request) (*http.Response, erro defer span.Finish() ctx = span.Context() - req = req.WithContext(ctx) - resp, err := l.Transport().RoundTrip(req) + resp, err := l.Transport().RoundTrip(req.WithContext(ctx)) attempt := attemptFromCtx(ctx) if attempt > 0 { diff --git a/maintenance/tracing/tracing.go b/maintenance/tracing/tracing.go index 9fd7d04f4..9796514db 100755 --- a/maintenance/tracing/tracing.go +++ b/maintenance/tracing/tracing.go @@ -76,12 +76,10 @@ type traceLogHandler struct { // Trace the service function handler execution func (h *traceLogHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() - - span := sentry.TransactionFromContext(ctx) + span := sentry.TransactionFromContext(r.Context()) defer span.Finish() - r = r.WithContext(span.Context()) + ctx := span.Context() span.SetData("req_id", log.RequestIDFromContext(ctx)) span.SetData("path", r.URL.Path) @@ -89,7 +87,7 @@ func (h *traceLogHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ww := mutil.WrapWriter(w) - h.next.ServeHTTP(ww, r) + h.next.ServeHTTP(ww, r.WithContext(ctx)) span.SetData("bytes", ww.BytesWritten()) span.SetData("status_code", ww.Status()) } From b1eb2ec59f58195fbd12236c3de9e185d03f65e3 Mon Sep 17 00:00:00 2001 From: Thomas Hipp Date: Wed, 27 Nov 2024 14:24:09 +0100 Subject: [PATCH 3/6] pkg/context: Fix context transfer --- pkg/context/transfer.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/context/transfer.go b/pkg/context/transfer.go index 5be96a455..1ba6b9135 100755 --- a/pkg/context/transfer.go +++ b/pkg/context/transfer.go @@ -19,7 +19,8 @@ import ( // new context with all these objects. func Transfer(in context.Context) context.Context { // transfer logger, log.Sink, authentication and error info - out := log.Ctx(in).WithContext(context.Background()) + out := TransferTracingContext(in, context.Background()) + out = log.Ctx(in).WithContext(out) out = log.SinkContextTransfer(in, out) out = oauth2.ContextTransfer(in, out) out = errors.ContextTransfer(in, out) @@ -27,7 +28,6 @@ func Transfer(in context.Context) context.Context { out = redact.ContextTransfer(in, out) out = utm.ContextTransfer(in, out) out = hlog.ContextTransfer(in, out) - out = TransferTracingContext(in, out) out = locale.ContextTransfer(in, out) out = TransferExternalDependencyContext(in, out) @@ -36,10 +36,11 @@ func Transfer(in context.Context) context.Context { func TransferTracingContext(in, out context.Context) context.Context { span := sentry.SpanFromContext(in) - if span != nil { - out = span.Context() + if span == nil { + return out } - return out + + return span.Context() } func TransferExternalDependencyContext(in, out context.Context) context.Context { From b7380cecf1022d4d424c00a4bbabd5a95c60578b Mon Sep 17 00:00:00 2001 From: Thomas Hipp Date: Wed, 27 Nov 2024 14:58:19 +0100 Subject: [PATCH 4/6] Cleanup generated code --- http/jsonapi/generator/generate_handler.go | 12 +- .../internal/articles/open-api_test.go | 8 +- .../internal/fueling/open-api_test.go | 8 +- .../generator/internal/pay/open-api_test.go | 22 +-- .../generator/internal/poi/open-api_test.go | 177 +++++++----------- .../internal/securitytest/open-api_test.go | 5 +- tools/testserver/simple/open-api.go | 2 +- 7 files changed, 101 insertions(+), 133 deletions(-) diff --git a/http/jsonapi/generator/generate_handler.go b/http/jsonapi/generator/generate_handler.go index 6eb58c57c..4182fdb07 100644 --- a/http/jsonapi/generator/generate_handler.go +++ b/http/jsonapi/generator/generate_handler.go @@ -597,9 +597,16 @@ func (g *Generator) buildHandler(method string, op *openapi3.Operation, pattern g.Add(auth) // set tracing context + + ctxStmt := jen.Id("r").Dot("Context").Call() + + if auth != nil { + ctxStmt = jen.Id("ctx") + } + g.Line().Comment("Trace the service function handler execution") g.Id("span").Op(":=").Qual(pkgSentry, "StartSpan").Call( - jen.Id("r").Dot("Context").Call(), jen.Lit("http.server"), jen.Qual(pkgSentry, "WithDescription").Call(jen.Lit(handler))) + ctxStmt, jen.Lit("http.server"), jen.Qual(pkgSentry, "WithDescription").Call(jen.Lit(handler))) g.Defer().Id("span").Dot("Finish").Call() g.Line().Empty() @@ -626,7 +633,7 @@ func (g *Generator) buildHandler(method string, op *openapi3.Operation, pattern // request g.Id("request").Op(":=").Id(route.requestType). - Block(jen.Id("Request").Op(":").Id("r").Dot("WithContext").Call(jen.Id("ctx")).Op(",")) + Block(jen.Id("Request").Op(":").Id("r").Op(",")) // vars in case parameters are given g.Line().Comment("Scan and validate incoming request parameters") @@ -773,7 +780,6 @@ func generateAuthorization(op *openapi3.Operation, secSchemes map[string]*openap return nil, err } - r.Line().Id("r").Op("=").Id("r.WithContext").Call(jen.Id("ctx")) return r, nil } diff --git a/http/jsonapi/generator/internal/articles/open-api_test.go b/http/jsonapi/generator/internal/articles/open-api_test.go index 0a067b65d..686872335 100644 --- a/http/jsonapi/generator/internal/articles/open-api_test.go +++ b/http/jsonapi/generator/internal/articles/open-api_test.go @@ -76,7 +76,7 @@ func GetArticleCommentsHandler(service GetArticleCommentsHandlerService) http.Ha ResponseWriter: metrics.NewMetric("articles", "/api/articles/{uuid}/relationships/comments", w, r), } request := GetArticleCommentsRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -134,7 +134,7 @@ func UpdateArticleCommentsHandler(service UpdateArticleCommentsHandlerService) h ResponseWriter: metrics.NewMetric("articles", "/api/articles/{uuid}/relationships/comments", w, r), } request := UpdateArticleCommentsRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -200,7 +200,7 @@ func UpdateArticleInlineTypeHandler(service UpdateArticleInlineTypeHandlerServic ResponseWriter: metrics.NewMetric("articles", "/api/articles/{uuid}/relationships/inline", w, r), } request := UpdateArticleInlineTypeRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -261,7 +261,7 @@ func UpdateArticleInlineRefHandler(service UpdateArticleInlineRefHandlerService) ResponseWriter: metrics.NewMetric("articles", "/api/articles/{uuid}/relationships/inlineref", w, r), } request := UpdateArticleInlineRefRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters diff --git a/http/jsonapi/generator/internal/fueling/open-api_test.go b/http/jsonapi/generator/internal/fueling/open-api_test.go index c7a6e8d4b..568e5224a 100644 --- a/http/jsonapi/generator/internal/fueling/open-api_test.go +++ b/http/jsonapi/generator/internal/fueling/open-api_test.go @@ -143,7 +143,7 @@ func ProcessPaymentHandler(service ProcessPaymentHandlerService) http.Handler { ResponseWriter: metrics.NewMetric("fueling", "/gas-station/{gasStationId}/payment", w, r), } request := ProcessPaymentRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -204,7 +204,7 @@ func ApproachingAtTheForecourtHandler(service ApproachingAtTheForecourtHandlerSe ResponseWriter: metrics.NewMetric("fueling", "/gas-stations/{gasStationId}/approaching", w, r), } request := ApproachingAtTheForecourtRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -269,7 +269,7 @@ func GetPumpHandler(service GetPumpHandlerService) http.Handler { ResponseWriter: metrics.NewMetric("fueling", "/gas-stations/{gasStationId}/pumps/{pumpId}", w, r), } request := GetPumpRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -332,7 +332,7 @@ func WaitOnPumpStatusChangeHandler(service WaitOnPumpStatusChangeHandlerService) ResponseWriter: metrics.NewMetric("fueling", "/gas-stations/{gasStationId}/pumps/{pumpId}/wait-for-status-change", w, r), } request := WaitOnPumpStatusChangeRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters diff --git a/http/jsonapi/generator/internal/pay/open-api_test.go b/http/jsonapi/generator/internal/pay/open-api_test.go index 35f3299a3..8bf869462 100644 --- a/http/jsonapi/generator/internal/pay/open-api_test.go +++ b/http/jsonapi/generator/internal/pay/open-api_test.go @@ -173,7 +173,7 @@ func GetPaymentMethodsHandler(service GetPaymentMethodsHandlerService, authBacke ResponseWriter: metrics.NewMetric("pay", "/beta/payment-methods", w, r), } request := GetPaymentMethodsRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -231,10 +231,9 @@ func CreatePaymentMethodSEPAHandler(service CreatePaymentMethodSEPAHandlerServic http.Error(w, "Authorization Error", http.StatusUnauthorized) return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("CreatePaymentMethodSEPAHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("CreatePaymentMethodSEPAHandler")) defer span.Finish() ctx = span.Context() @@ -245,7 +244,7 @@ func CreatePaymentMethodSEPAHandler(service CreatePaymentMethodSEPAHandlerServic ResponseWriter: metrics.NewMetric("pay", "/beta/payment-methods/sepa-direct-debit", w, r), } request := CreatePaymentMethodSEPARequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -303,10 +302,9 @@ func DeletePaymentMethodHandler(service DeletePaymentMethodHandlerService, authB http.Error(w, "Authorization Error", http.StatusUnauthorized) return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("DeletePaymentMethodHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("DeletePaymentMethodHandler")) defer span.Finish() ctx = span.Context() @@ -317,7 +315,7 @@ func DeletePaymentMethodHandler(service DeletePaymentMethodHandlerService, authB ResponseWriter: metrics.NewMetric("pay", "/beta/payment-methods/{paymentMethodId}", w, r), } request := DeletePaymentMethodRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -375,7 +373,7 @@ func AuthorizePaymentMethodHandler(service AuthorizePaymentMethodHandlerService, ResponseWriter: metrics.NewMetric("pay", "/beta/payment-methods/{paymentMethodId}/authorize", w, r), } request := AuthorizePaymentMethodRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -436,7 +434,7 @@ func DeletePaymentTokenHandler(service DeletePaymentTokenHandlerService, authBac ResponseWriter: metrics.NewMetric("pay", "/beta/payment-methods/{paymentMethodId}/paymentTokens/{paymentTokenId}", w, r), } request := DeletePaymentTokenRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -499,7 +497,7 @@ func GetPaymentMethodsIncludingCreditCheckHandler(service GetPaymentMethodsInclu ResponseWriter: metrics.NewMetric("pay", "/beta/payment-methods?include=creditCheck", w, r), } request := GetPaymentMethodsIncludingCreditCheckRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -555,7 +553,7 @@ func GetPaymentMethodsIncludingPaymentTokenHandler(service GetPaymentMethodsIncl ResponseWriter: metrics.NewMetric("pay", "/beta/payment-methods?include=paymentToken", w, r), } request := GetPaymentMethodsIncludingPaymentTokenRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -611,7 +609,7 @@ func ProcessPaymentHandler(service ProcessPaymentHandlerService, authBackend Aut ResponseWriter: metrics.NewMetric("pay", "/beta/transaction/{pathDecimal}", w, r), } request := ProcessPaymentRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters diff --git a/http/jsonapi/generator/internal/poi/open-api_test.go b/http/jsonapi/generator/internal/poi/open-api_test.go index 9379dfece..0ee675e0b 100644 --- a/http/jsonapi/generator/internal/poi/open-api_test.go +++ b/http/jsonapi/generator/internal/poi/open-api_test.go @@ -433,10 +433,9 @@ func DeduplicatePoiHandler(service DeduplicatePoiHandlerService, authBackend Aut if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("DeduplicatePoiHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("DeduplicatePoiHandler")) defer span.Finish() ctx = span.Context() @@ -447,7 +446,7 @@ func DeduplicatePoiHandler(service DeduplicatePoiHandlerService, authBackend Aut ResponseWriter: metrics.NewMetric("poi", "/beta/admin/poi/dedupe", w, r), } request := DeduplicatePoiRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -491,10 +490,9 @@ func MovePoiAtPositionHandler(service MovePoiAtPositionHandlerService, authBacke if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("MovePoiAtPositionHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("MovePoiAtPositionHandler")) defer span.Finish() ctx = span.Context() @@ -505,7 +503,7 @@ func MovePoiAtPositionHandler(service MovePoiAtPositionHandlerService, authBacke ResponseWriter: metrics.NewMetric("poi", "/beta/admin/poi/move", w, r), } request := MovePoiAtPositionRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -549,10 +547,9 @@ func GetAppsHandler(service GetAppsHandlerService, authBackend AuthorizationBack if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetAppsHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("GetAppsHandler")) defer span.Finish() ctx = span.Context() @@ -563,7 +560,7 @@ func GetAppsHandler(service GetAppsHandlerService, authBackend AuthorizationBack ResponseWriter: metrics.NewMetric("poi", "/beta/apps", w, r), } request := GetAppsRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -627,10 +624,9 @@ func CreateAppHandler(service CreateAppHandlerService, authBackend Authorization if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("CreateAppHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("CreateAppHandler")) defer span.Finish() ctx = span.Context() @@ -641,7 +637,7 @@ func CreateAppHandler(service CreateAppHandlerService, authBackend Authorization ResponseWriter: metrics.NewMetric("poi", "/beta/apps", w, r), } request := CreateAppRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -685,10 +681,9 @@ func CheckForPaceAppHandler(service CheckForPaceAppHandlerService, authBackend A if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("CheckForPaceAppHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("CheckForPaceAppHandler")) defer span.Finish() ctx = span.Context() @@ -699,7 +694,7 @@ func CheckForPaceAppHandler(service CheckForPaceAppHandlerService, authBackend A ResponseWriter: metrics.NewMetric("poi", "/beta/apps/query", w, r), } request := CheckForPaceAppRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -755,10 +750,9 @@ func DeleteAppHandler(service DeleteAppHandlerService, authBackend Authorization if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("DeleteAppHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("DeleteAppHandler")) defer span.Finish() ctx = span.Context() @@ -769,7 +763,7 @@ func DeleteAppHandler(service DeleteAppHandlerService, authBackend Authorization ResponseWriter: metrics.NewMetric("poi", "/beta/apps/{appID}", w, r), } request := DeleteAppRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -819,10 +813,9 @@ func GetAppHandler(service GetAppHandlerService, authBackend AuthorizationBacken if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetAppHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("GetAppHandler")) defer span.Finish() ctx = span.Context() @@ -833,7 +826,7 @@ func GetAppHandler(service GetAppHandlerService, authBackend AuthorizationBacken ResponseWriter: metrics.NewMetric("poi", "/beta/apps/{appID}", w, r), } request := GetAppRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -883,10 +876,9 @@ func UpdateAppHandler(service UpdateAppHandlerService, authBackend Authorization if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("UpdateAppHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("UpdateAppHandler")) defer span.Finish() ctx = span.Context() @@ -897,7 +889,7 @@ func UpdateAppHandler(service UpdateAppHandlerService, authBackend Authorization ResponseWriter: metrics.NewMetric("poi", "/beta/apps/{appID}", w, r), } request := UpdateAppRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -950,10 +942,9 @@ func GetAppPOIsRelationshipsHandler(service GetAppPOIsRelationshipsHandlerServic if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetAppPOIsRelationshipsHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("GetAppPOIsRelationshipsHandler")) defer span.Finish() ctx = span.Context() @@ -964,7 +955,7 @@ func GetAppPOIsRelationshipsHandler(service GetAppPOIsRelationshipsHandlerServic ResponseWriter: metrics.NewMetric("poi", "/beta/apps/{appID}/relationships/pois", w, r), } request := GetAppPOIsRelationshipsRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -1014,10 +1005,9 @@ func UpdateAppPOIsRelationshipsHandler(service UpdateAppPOIsRelationshipsHandler if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("UpdateAppPOIsRelationshipsHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("UpdateAppPOIsRelationshipsHandler")) defer span.Finish() ctx = span.Context() @@ -1028,7 +1018,7 @@ func UpdateAppPOIsRelationshipsHandler(service UpdateAppPOIsRelationshipsHandler ResponseWriter: metrics.NewMetric("poi", "/beta/apps/{appID}/relationships/pois", w, r), } request := UpdateAppPOIsRelationshipsRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -1081,10 +1071,9 @@ func GetDuplicatesKMLHandler(service GetDuplicatesKMLHandlerService, authBackend if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetDuplicatesKMLHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("GetDuplicatesKMLHandler")) defer span.Finish() ctx = span.Context() @@ -1095,7 +1084,7 @@ func GetDuplicatesKMLHandler(service GetDuplicatesKMLHandlerService, authBackend ResponseWriter: metrics.NewMetric("poi", "/beta/datadumps/duplicatemap/{countryCode}", w, r), } request := GetDuplicatesKMLRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -1145,10 +1134,9 @@ func GetPoisDumpHandler(service GetPoisDumpHandlerService, authBackend Authoriza if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetPoisDumpHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("GetPoisDumpHandler")) defer span.Finish() ctx = span.Context() @@ -1159,7 +1147,7 @@ func GetPoisDumpHandler(service GetPoisDumpHandlerService, authBackend Authoriza ResponseWriter: metrics.NewMetric("poi", "/beta/datadumps/pois", w, r), } request := GetPoisDumpRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -1207,10 +1195,9 @@ func DeleteGasStationReferenceStatusHandler(service DeleteGasStationReferenceSta if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("DeleteGasStationReferenceStatusHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("DeleteGasStationReferenceStatusHandler")) defer span.Finish() ctx = span.Context() @@ -1221,7 +1208,7 @@ func DeleteGasStationReferenceStatusHandler(service DeleteGasStationReferenceSta ResponseWriter: metrics.NewMetric("poi", "/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}", w, r), } request := DeleteGasStationReferenceStatusRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -1276,10 +1263,9 @@ func PutGasStationReferenceStatusHandler(service PutGasStationReferenceStatusHan if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("PutGasStationReferenceStatusHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("PutGasStationReferenceStatusHandler")) defer span.Finish() ctx = span.Context() @@ -1290,7 +1276,7 @@ func PutGasStationReferenceStatusHandler(service PutGasStationReferenceStatusHan ResponseWriter: metrics.NewMetric("poi", "/beta/delivery/gas-stations/{gasStationId}/reference-status/{reference}", w, r), } request := PutGasStationReferenceStatusRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -1348,10 +1334,9 @@ func GetEventsHandler(service GetEventsHandlerService, authBackend Authorization if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetEventsHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("GetEventsHandler")) defer span.Finish() ctx = span.Context() @@ -1362,7 +1347,7 @@ func GetEventsHandler(service GetEventsHandlerService, authBackend Authorization ResponseWriter: metrics.NewMetric("poi", "/beta/events", w, r), } request := GetEventsRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -1422,10 +1407,9 @@ func GetGasStationsHandler(service GetGasStationsHandlerService, authBackend Aut if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetGasStationsHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("GetGasStationsHandler")) defer span.Finish() ctx = span.Context() @@ -1436,7 +1420,7 @@ func GetGasStationsHandler(service GetGasStationsHandlerService, authBackend Aut ResponseWriter: metrics.NewMetric("poi", "/beta/gas-stations", w, r), } request := GetGasStationsRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -1520,10 +1504,9 @@ func GetGasStationHandler(service GetGasStationHandlerService, authBackend Autho if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetGasStationHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("GetGasStationHandler")) defer span.Finish() ctx = span.Context() @@ -1534,7 +1517,7 @@ func GetGasStationHandler(service GetGasStationHandlerService, authBackend Autho ResponseWriter: metrics.NewMetric("poi", "/beta/gas-stations/{id}", w, r), } request := GetGasStationRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -1588,10 +1571,9 @@ func GetPriceHistoryHandler(service GetPriceHistoryHandlerService, authBackend A if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetPriceHistoryHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("GetPriceHistoryHandler")) defer span.Finish() ctx = span.Context() @@ -1602,7 +1584,7 @@ func GetPriceHistoryHandler(service GetPriceHistoryHandlerService, authBackend A ResponseWriter: metrics.NewMetric("poi", "/beta/gas-stations/{id}/fuel-price-histories/{fuel_type}", w, r), } request := GetPriceHistoryRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -1669,10 +1651,9 @@ func GetGasStationFuelTypeNameMappingHandler(service GetGasStationFuelTypeNameMa if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetGasStationFuelTypeNameMappingHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("GetGasStationFuelTypeNameMappingHandler")) defer span.Finish() ctx = span.Context() @@ -1683,7 +1664,7 @@ func GetGasStationFuelTypeNameMappingHandler(service GetGasStationFuelTypeNameMa ResponseWriter: metrics.NewMetric("poi", "/beta/gas-stations/{id}/fueltype", w, r), } request := GetGasStationFuelTypeNameMappingRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -1737,10 +1718,9 @@ func GetMetadataFiltersHandler(service GetMetadataFiltersHandlerService, authBac if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetMetadataFiltersHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("GetMetadataFiltersHandler")) defer span.Finish() ctx = span.Context() @@ -1751,7 +1731,7 @@ func GetMetadataFiltersHandler(service GetMetadataFiltersHandlerService, authBac ResponseWriter: metrics.NewMetric("poi", "/beta/meta", w, r), } request := GetMetadataFiltersRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -1803,10 +1783,9 @@ func GetPoisHandler(service GetPoisHandlerService, authBackend AuthorizationBack if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetPoisHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("GetPoisHandler")) defer span.Finish() ctx = span.Context() @@ -1817,7 +1796,7 @@ func GetPoisHandler(service GetPoisHandlerService, authBackend AuthorizationBack ResponseWriter: metrics.NewMetric("poi", "/beta/pois", w, r), } request := GetPoisRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -1877,10 +1856,9 @@ func GetPoiHandler(service GetPoiHandlerService, authBackend AuthorizationBacken if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetPoiHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("GetPoiHandler")) defer span.Finish() ctx = span.Context() @@ -1891,7 +1869,7 @@ func GetPoiHandler(service GetPoiHandlerService, authBackend AuthorizationBacken ResponseWriter: metrics.NewMetric("poi", "/beta/pois/{poiId}", w, r), } request := GetPoiRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -1941,10 +1919,9 @@ func ChangePoiHandler(service ChangePoiHandlerService, authBackend Authorization if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("ChangePoiHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("ChangePoiHandler")) defer span.Finish() ctx = span.Context() @@ -1955,7 +1932,7 @@ func ChangePoiHandler(service ChangePoiHandlerService, authBackend Authorization ResponseWriter: metrics.NewMetric("poi", "/beta/pois/{poiId}", w, r), } request := ChangePoiRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -2008,10 +1985,9 @@ func GetPoliciesHandler(service GetPoliciesHandlerService, authBackend Authoriza if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetPoliciesHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("GetPoliciesHandler")) defer span.Finish() ctx = span.Context() @@ -2022,7 +1998,7 @@ func GetPoliciesHandler(service GetPoliciesHandlerService, authBackend Authoriza ResponseWriter: metrics.NewMetric("poi", "/beta/policies", w, r), } request := GetPoliciesRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -2086,10 +2062,9 @@ func CreatePolicyHandler(service CreatePolicyHandlerService, authBackend Authori if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("CreatePolicyHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("CreatePolicyHandler")) defer span.Finish() ctx = span.Context() @@ -2100,7 +2075,7 @@ func CreatePolicyHandler(service CreatePolicyHandlerService, authBackend Authori ResponseWriter: metrics.NewMetric("poi", "/beta/policies", w, r), } request := CreatePolicyRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -2144,10 +2119,9 @@ func GetPolicyHandler(service GetPolicyHandlerService, authBackend Authorization if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetPolicyHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("GetPolicyHandler")) defer span.Finish() ctx = span.Context() @@ -2158,7 +2132,7 @@ func GetPolicyHandler(service GetPolicyHandlerService, authBackend Authorization ResponseWriter: metrics.NewMetric("poi", "/beta/policies/{policyId}", w, r), } request := GetPolicyRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -2216,7 +2190,7 @@ func GetRegionalPricesHandler(service GetRegionalPricesHandlerService, authBacke ResponseWriter: metrics.NewMetric("poi", "/beta/prices/regional", w, r), } request := GetRegionalPricesRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -2268,10 +2242,9 @@ func GetSourcesHandler(service GetSourcesHandlerService, authBackend Authorizati if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetSourcesHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("GetSourcesHandler")) defer span.Finish() ctx = span.Context() @@ -2282,7 +2255,7 @@ func GetSourcesHandler(service GetSourcesHandlerService, authBackend Authorizati ResponseWriter: metrics.NewMetric("poi", "/beta/sources", w, r), } request := GetSourcesRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -2342,10 +2315,9 @@ func CreateSourceHandler(service CreateSourceHandlerService, authBackend Authori if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("CreateSourceHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("CreateSourceHandler")) defer span.Finish() ctx = span.Context() @@ -2356,7 +2328,7 @@ func CreateSourceHandler(service CreateSourceHandlerService, authBackend Authori ResponseWriter: metrics.NewMetric("poi", "/beta/sources", w, r), } request := CreateSourceRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -2400,10 +2372,9 @@ func DeleteSourceHandler(service DeleteSourceHandlerService, authBackend Authori if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("DeleteSourceHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("DeleteSourceHandler")) defer span.Finish() ctx = span.Context() @@ -2414,7 +2385,7 @@ func DeleteSourceHandler(service DeleteSourceHandlerService, authBackend Authori ResponseWriter: metrics.NewMetric("poi", "/beta/sources/{sourceId}", w, r), } request := DeleteSourceRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -2464,10 +2435,9 @@ func GetSourceHandler(service GetSourceHandlerService, authBackend Authorization if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetSourceHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("GetSourceHandler")) defer span.Finish() ctx = span.Context() @@ -2478,7 +2448,7 @@ func GetSourceHandler(service GetSourceHandlerService, authBackend Authorization ResponseWriter: metrics.NewMetric("poi", "/beta/sources/{sourceId}", w, r), } request := GetSourceRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -2528,10 +2498,9 @@ func UpdateSourceHandler(service UpdateSourceHandlerService, authBackend Authori if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("UpdateSourceHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("UpdateSourceHandler")) defer span.Finish() ctx = span.Context() @@ -2542,7 +2511,7 @@ func UpdateSourceHandler(service UpdateSourceHandlerService, authBackend Authori ResponseWriter: metrics.NewMetric("poi", "/beta/sources/{sourceId}", w, r), } request := UpdateSourceRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -2595,10 +2564,9 @@ func GetSubscriptionsHandler(service GetSubscriptionsHandlerService, authBackend if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetSubscriptionsHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("GetSubscriptionsHandler")) defer span.Finish() ctx = span.Context() @@ -2609,7 +2577,7 @@ func GetSubscriptionsHandler(service GetSubscriptionsHandlerService, authBackend ResponseWriter: metrics.NewMetric("poi", "/beta/subscriptions", w, r), } request := GetSubscriptionsRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -2653,10 +2621,9 @@ func DeleteSubscriptionHandler(service DeleteSubscriptionHandlerService, authBac if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("DeleteSubscriptionHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("DeleteSubscriptionHandler")) defer span.Finish() ctx = span.Context() @@ -2667,7 +2634,7 @@ func DeleteSubscriptionHandler(service DeleteSubscriptionHandlerService, authBac ResponseWriter: metrics.NewMetric("poi", "/beta/subscriptions/{id}", w, r), } request := DeleteSubscriptionRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -2705,10 +2672,9 @@ func StoreSubscriptionHandler(service StoreSubscriptionHandlerService, authBacke if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("StoreSubscriptionHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("StoreSubscriptionHandler")) defer span.Finish() ctx = span.Context() @@ -2719,7 +2685,7 @@ func StoreSubscriptionHandler(service StoreSubscriptionHandlerService, authBacke ResponseWriter: metrics.NewMetric("poi", "/beta/subscriptions/{id}", w, r), } request := StoreSubscriptionRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters @@ -2763,10 +2729,9 @@ func GetTilesHandler(service GetTilesHandlerService, authBackend AuthorizationBa if !ok { return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetTilesHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("GetTilesHandler")) defer span.Finish() ctx = span.Context() @@ -2777,7 +2742,7 @@ func GetTilesHandler(service GetTilesHandlerService, authBackend AuthorizationBa ResponseWriter: metrics.NewMetric("poi", "/v1/tiles/query", w, r), } request := GetTilesRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters diff --git a/http/jsonapi/generator/internal/securitytest/open-api_test.go b/http/jsonapi/generator/internal/securitytest/open-api_test.go index d3302b6ee..e8157fc08 100644 --- a/http/jsonapi/generator/internal/securitytest/open-api_test.go +++ b/http/jsonapi/generator/internal/securitytest/open-api_test.go @@ -64,10 +64,9 @@ func GetTestHandler(service GetTestHandlerService, authBackend AuthorizationBack http.Error(w, "Authorization Error", http.StatusUnauthorized) return } - r = r.WithContext(ctx) // Trace the service function handler execution - span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetTestHandler")) + span := sentry.StartSpan(ctx, "http.server", sentry.WithDescription("GetTestHandler")) defer span.Finish() ctx = span.Context() @@ -78,7 +77,7 @@ func GetTestHandler(service GetTestHandlerService, authBackend AuthorizationBack ResponseWriter: metrics.NewMetric("securitytest", "/beta/test", w, r), } request := GetTestRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters diff --git a/tools/testserver/simple/open-api.go b/tools/testserver/simple/open-api.go index 93522d3fd..e9db7d885 100644 --- a/tools/testserver/simple/open-api.go +++ b/tools/testserver/simple/open-api.go @@ -32,7 +32,7 @@ func GetTestHandler(service GetTestHandlerService) http.Handler { ResponseWriter: metrics.NewMetric("simple", "/beta/test", w, r), } request := GetTestRequest{ - Request: r.WithContext(ctx), + Request: r, } // Scan and validate incoming request parameters From 603c5baa6f4e125ba72bac613b73623c8ddc3375 Mon Sep 17 00:00:00 2001 From: Thomas Hipp Date: Wed, 27 Nov 2024 21:45:00 +0100 Subject: [PATCH 5/6] pkg/context: Add deprecation notice --- pkg/context/transfer.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/context/transfer.go b/pkg/context/transfer.go index 1ba6b9135..d33e3332c 100755 --- a/pkg/context/transfer.go +++ b/pkg/context/transfer.go @@ -17,6 +17,7 @@ import ( // Transfer takes the logger, log.Sink, authentication, request and // error info from the given context and returns a complete // new context with all these objects. +// Deprecated: Use context.WithoutCancel instead. func Transfer(in context.Context) context.Context { // transfer logger, log.Sink, authentication and error info out := TransferTracingContext(in, context.Background()) From 6775de62d284d9f2152f39989f1eb50750f728e7 Mon Sep 17 00:00:00 2001 From: Thomas Hipp Date: Thu, 28 Nov 2024 10:42:41 +0100 Subject: [PATCH 6/6] maintenance/tracing: Don't overwrite context in traceLogHandler --- maintenance/tracing/tracing.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/maintenance/tracing/tracing.go b/maintenance/tracing/tracing.go index 9796514db..c0c2f6f91 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.