diff options
author | Alan Pearce | 2025-01-19 01:19:15 +0100 |
---|---|---|
committer | Alan Pearce | 2025-01-19 01:19:15 +0100 |
commit | eece88d32b1b613aba7ec2f11bcfeb10163616b1 (patch) | |
tree | faee549b469409514bf43bd7657b4ae585888f2d | |
parent | c7be08473e423ead4896aaa2b3355a08c4559145 (diff) | |
download | searchix-eece88d32b1b613aba7ec2f11bcfeb10163616b1.tar.lz searchix-eece88d32b1b613aba7ec2f11bcfeb10163616b1.tar.zst searchix-eece88d32b1b613aba7ec2f11bcfeb10163616b1.zip |
fix(sentry): report correct HTTP path in traces
-rw-r--r-- | internal/sentryhttp/http.go | 29 | ||||
-rw-r--r-- | internal/server/mux.go | 17 |
2 files changed, 35 insertions, 11 deletions
diff --git a/internal/sentryhttp/http.go b/internal/sentryhttp/http.go new file mode 100644 index 0000000..7897b81 --- /dev/null +++ b/internal/sentryhttp/http.go @@ -0,0 +1,29 @@ +package sentryhttp + +import ( + "net/http" + + sentryhttp "github.com/getsentry/sentry-go/http" +) + +type ServeMux struct { + sentryHandler *sentryhttp.Handler + *http.ServeMux +} + +func NewServeMux() *ServeMux { + return &ServeMux{ + sentryHandler: sentryhttp.New(sentryhttp.Options{ + Repanic: true, + }), + ServeMux: http.NewServeMux(), + } +} + +func (sm *ServeMux) Handle(pattern string, handler http.Handler) { + sm.ServeMux.Handle(pattern, sm.sentryHandler.Handle(handler)) +} + +func (sm *ServeMux) HandleFunc(pattern string, handler http.HandlerFunc) { + sm.ServeMux.HandleFunc(pattern, sm.sentryHandler.HandleFunc(handler)) +} diff --git a/internal/server/mux.go b/internal/server/mux.go index 16f9226..0403470 100644 --- a/internal/server/mux.go +++ b/internal/server/mux.go @@ -17,9 +17,9 @@ import ( search "go.alanpearce.eu/searchix/internal/index" "go.alanpearce.eu/searchix/internal/opensearch" "go.alanpearce.eu/searchix/internal/pagination" + "go.alanpearce.eu/searchix/internal/sentryhttp" "go.alanpearce.eu/x/log" - sentryhttp "github.com/getsentry/sentry-go/http" "github.com/osdevisnot/sorvor/pkg/livereload" "github.com/pkg/errors" ) @@ -65,15 +65,12 @@ func NewMux( if index == nil { return nil, errors.New("index is nil") } - sentryHandler := sentryhttp.New(sentryhttp.Options{ - Repanic: true, - }) sortSources(cfg.Importer.Sources) errorHandler := createErrorHandler(cfg, log) top := http.NewServeMux() - mux := http.NewServeMux() + mux := sentryhttp.NewServeMux() mux.HandleFunc("/{$}", func(w http.ResponseWriter, r *http.Request) { indexData := components.TemplateData{ ExtraHeadHTML: cfg.Web.ExtraHeadHTML, @@ -389,12 +386,10 @@ func NewMux( top.Handle("/", AddHeadersMiddleware( - sentryHandler.Handle( - wrapHandlerWithLogging(mux, wrappedHandlerOptions{ - defaultHostname: cfg.Web.BaseURL.Hostname(), - logger: log, - }), - ), + wrapHandlerWithLogging(mux, wrappedHandlerOptions{ + defaultHostname: cfg.Web.BaseURL.Hostname(), + logger: log, + }), cfg, ), ) |