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{