feat: add sentry spans to evaluate proxy performances
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good

This commit is contained in:
2024-09-27 10:46:18 +02:00
parent 867e7c549f
commit 590505e17a
3 changed files with 42 additions and 1 deletions

37
internal/sentry/sentry.go Normal file
View 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)
}