38 lines
692 B
Go
38 lines
692 B
Go
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)
|
|
}
|