outpost: add tracing for http client

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-07-23 17:37:06 +02:00
parent d16c24fd53
commit aca3a5c458
3 changed files with 25 additions and 2 deletions

View File

@ -44,7 +44,7 @@ func NewAPIController(akURL url.URL, token string) *APIController {
config.Host = akURL.Host config.Host = akURL.Host
config.Scheme = akURL.Scheme config.Scheme = akURL.Scheme
config.HTTPClient = &http.Client{ config.HTTPClient = &http.Client{
Transport: GetTLSTransport(), Transport: NewTracingTransport(GetTLSTransport()),
} }
config.AddDefaultHeader("Authorization", fmt.Sprintf("Bearer %s", token)) config.AddDefaultHeader("Authorization", fmt.Sprintf("Bearer %s", token))

View File

@ -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()))
}

View File

@ -61,7 +61,7 @@ func NewFlowExecutor(ctx context.Context, flowSlug string, refConfig *api.Config
config.UserAgent = constants.OutpostUserAgent() config.UserAgent = constants.OutpostUserAgent()
config.HTTPClient = &http.Client{ config.HTTPClient = &http.Client{
Jar: jar, Jar: jar,
Transport: ak.GetTLSTransport(), Transport: ak.NewTracingTransport(ak.GetTLSTransport()),
} }
apiClient := api.NewAPIClient(config) apiClient := api.NewAPIClient(config)
return &FlowExecutor{ return &FlowExecutor{