mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
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.
35 lines
776 B
Go
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()))
|
|
})
|
|
}
|