feat: add sentry spans to evaluate proxy performances
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
This commit is contained in:
37
internal/sentry/sentry.go
Normal file
37
internal/sentry/sentry.go
Normal file
@ -0,0 +1,37 @@
|
||||
package sentry
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
)
|
||||
|
||||
func SpanHandler(handler http.Handler, name string) http.Handler {
|
||||
fn := func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
||||
hub := sentry.GetHubFromContext(ctx)
|
||||
if hub == nil {
|
||||
hub = sentry.CurrentHub().Clone()
|
||||
ctx = sentry.SetHubOnContext(ctx, hub)
|
||||
}
|
||||
|
||||
options := []sentry.SpanOption{
|
||||
sentry.WithOpName(name),
|
||||
sentry.ContinueFromRequest(r),
|
||||
sentry.WithTransactionSource(sentry.SourceURL),
|
||||
}
|
||||
|
||||
span := sentry.StartSpan(ctx,
|
||||
name,
|
||||
options...,
|
||||
)
|
||||
defer span.Finish()
|
||||
|
||||
r = r.WithContext(span.Context())
|
||||
|
||||
handler.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
return http.HandlerFunc(fn)
|
||||
}
|
Reference in New Issue
Block a user