2021-07-23 15:37:06 +00:00
|
|
|
package ak
|
|
|
|
|
|
|
|
import (
|
2021-09-03 16:17:08 +00:00
|
|
|
"context"
|
2021-07-23 15:37:06 +00:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/getsentry/sentry-go"
|
2021-09-08 18:04:56 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2021-07-23 15:37:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type tracingTransport struct {
|
|
|
|
inner http.RoundTripper
|
2021-09-03 16:17:08 +00:00
|
|
|
ctx context.Context
|
2021-07-23 15:37:06 +00:00
|
|
|
}
|
|
|
|
|
2021-09-03 16:17:08 +00:00
|
|
|
func NewTracingTransport(ctx context.Context, inner http.RoundTripper) *tracingTransport {
|
|
|
|
return &tracingTransport{inner, ctx}
|
2021-07-23 15:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (tt *tracingTransport) RoundTrip(r *http.Request) (*http.Response, error) {
|
2021-09-03 16:17:08 +00:00
|
|
|
span := sentry.StartSpan(tt.ctx, "authentik.go.http_request")
|
2021-07-23 15:37:06 +00:00
|
|
|
span.SetTag("url", r.URL.String())
|
|
|
|
span.SetTag("method", r.Method)
|
|
|
|
defer span.Finish()
|
2021-09-08 18:04:56 +00:00
|
|
|
res, err := tt.inner.RoundTrip(r.WithContext(span.Context()))
|
|
|
|
log.WithFields(log.Fields{
|
|
|
|
"url": r.URL.String(),
|
|
|
|
"method": r.Method,
|
|
|
|
}).Trace("http request")
|
|
|
|
return res, err
|
2021-07-23 15:37:06 +00:00
|
|
|
}
|