From 70d1e3a0cbc9219dc559c76bd319cf8f20697c14 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 3 Sep 2021 18:17:08 +0200 Subject: [PATCH] outpost: fix spans being sent without parent context Signed-off-by: Jens Langhammer --- internal/outpost/ak/api.go | 2 +- internal/outpost/ak/tracing.go | 8 +++++--- internal/outpost/flow.go | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/outpost/ak/api.go b/internal/outpost/ak/api.go index b6616ef2e..b690e1cba 100644 --- a/internal/outpost/ak/api.go +++ b/internal/outpost/ak/api.go @@ -47,7 +47,7 @@ func NewAPIController(akURL url.URL, token string) *APIController { config.Host = akURL.Host config.Scheme = akURL.Scheme config.HTTPClient = &http.Client{ - Transport: NewTracingTransport(GetTLSTransport()), + Transport: NewTracingTransport(context.TODO(), GetTLSTransport()), } config.AddDefaultHeader("Authorization", fmt.Sprintf("Bearer %s", token)) diff --git a/internal/outpost/ak/tracing.go b/internal/outpost/ak/tracing.go index 54e0871e1..dd3bf40d6 100644 --- a/internal/outpost/ak/tracing.go +++ b/internal/outpost/ak/tracing.go @@ -1,6 +1,7 @@ package ak import ( + "context" "net/http" "github.com/getsentry/sentry-go" @@ -8,14 +9,15 @@ import ( type tracingTransport struct { inner http.RoundTripper + ctx context.Context } -func NewTracingTransport(inner http.RoundTripper) *tracingTransport { - return &tracingTransport{inner} +func NewTracingTransport(ctx context.Context, inner http.RoundTripper) *tracingTransport { + return &tracingTransport{inner, ctx} } func (tt *tracingTransport) RoundTrip(r *http.Request) (*http.Response, error) { - span := sentry.StartSpan(r.Context(), "authentik.go.http_request") + span := sentry.StartSpan(tt.ctx, "authentik.go.http_request") span.SetTag("url", r.URL.String()) span.SetTag("method", r.Method) defer span.Finish() diff --git a/internal/outpost/flow.go b/internal/outpost/flow.go index 2bc444751..832e4fd51 100644 --- a/internal/outpost/flow.go +++ b/internal/outpost/flow.go @@ -61,7 +61,7 @@ func NewFlowExecutor(ctx context.Context, flowSlug string, refConfig *api.Config config.UserAgent = constants.OutpostUserAgent() config.HTTPClient = &http.Client{ Jar: jar, - Transport: ak.NewTracingTransport(ak.GetTLSTransport()), + Transport: ak.NewTracingTransport(ctx, ak.GetTLSTransport()), } apiClient := api.NewAPIClient(config) return &FlowExecutor{