*: add versioned user agent to sentry
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
29
internal/utils/web/http_tracing.go
Normal file
29
internal/utils/web/http_tracing.go
Normal file
@ -0,0 +1,29 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
)
|
||||
|
||||
type tracingTransport struct {
|
||||
inner http.RoundTripper
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
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(tt.ctx, "authentik.go.http_request")
|
||||
r.Header.Set("sentry-trace", span.ToSentryTrace())
|
||||
span.Description = fmt.Sprintf("%s %s", r.Method, r.URL.String())
|
||||
span.SetTag("url", r.URL.String())
|
||||
span.SetTag("method", r.Method)
|
||||
defer span.Finish()
|
||||
res, err := tt.inner.RoundTrip(r.WithContext(span.Context()))
|
||||
return res, err
|
||||
}
|
Reference in New Issue
Block a user