rentease/internal/server/tracing.go
Ruidy 973a15c55b
feat(deps): migrate from Echo to Chi, update Stripe/Sentry
Switch web framework from Echo to Chi, removing Echo-related
dependencies
and adding chi and cors. Update Stripe to v83.1.0 and Sentry to v0.36.2.
Remove unused and indirect dependencies for a cleaner go.mod/go.sum.
2025-11-02 16:17:18 +01:00

35 lines
776 B
Go

package server
import (
"fmt"
"net/http"
"github.com/getsentry/sentry-go"
)
func SentryTracingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(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)
r = r.WithContext(ctx)
}
options := []sentry.SpanOption{
sentry.WithOpName("http.server"),
sentry.ContinueFromRequest(r),
sentry.WithTransactionSource(sentry.SourceURL),
}
transaction := sentry.StartTransaction(
ctx,
fmt.Sprintf("%s %s", r.Method, r.URL.Path),
options...,
)
defer transaction.Finish()
next.ServeHTTP(w, r.WithContext(transaction.Context()))
})
}