From aca3a5c458069d6bbdf137f074952f7b4238fb88 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 23 Jul 2021 17:37:06 +0200 Subject: [PATCH] outpost: add tracing for http client Signed-off-by: Jens Langhammer --- internal/outpost/ak/api.go | 2 +- internal/outpost/ak/tracing.go | 23 +++++++++++++++++++++++ internal/outpost/flow.go | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 internal/outpost/ak/tracing.go diff --git a/internal/outpost/ak/api.go b/internal/outpost/ak/api.go index 79465eadc..26a02b16c 100644 --- a/internal/outpost/ak/api.go +++ b/internal/outpost/ak/api.go @@ -44,7 +44,7 @@ func NewAPIController(akURL url.URL, token string) *APIController { config.Host = akURL.Host config.Scheme = akURL.Scheme config.HTTPClient = &http.Client{ - Transport: GetTLSTransport(), + Transport: NewTracingTransport(GetTLSTransport()), } config.AddDefaultHeader("Authorization", fmt.Sprintf("Bearer %s", token)) diff --git a/internal/outpost/ak/tracing.go b/internal/outpost/ak/tracing.go new file mode 100644 index 000000000..54e0871e1 --- /dev/null +++ b/internal/outpost/ak/tracing.go @@ -0,0 +1,23 @@ +package ak + +import ( + "net/http" + + "github.com/getsentry/sentry-go" +) + +type tracingTransport struct { + inner http.RoundTripper +} + +func NewTracingTransport(inner http.RoundTripper) *tracingTransport { + return &tracingTransport{inner} +} + +func (tt *tracingTransport) RoundTrip(r *http.Request) (*http.Response, error) { + span := sentry.StartSpan(r.Context(), "authentik.go.http_request") + span.SetTag("url", r.URL.String()) + span.SetTag("method", r.Method) + defer span.Finish() + return tt.inner.RoundTrip(r.WithContext(span.Context())) +} diff --git a/internal/outpost/flow.go b/internal/outpost/flow.go index 0ffbdabf6..dbcd47bb1 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.GetTLSTransport(), + Transport: ak.NewTracingTransport(ak.GetTLSTransport()), } apiClient := api.NewAPIClient(config) return &FlowExecutor{