Name Sentry transactions after the route they matched (closes #185)
check / check (push) Successful in 14m13s

sentryhttp names each transaction after the concrete path, which the
BeforeSendTransaction hook has to withhold, so with tracing on every
transaction would land in one Sentry group, POST /(redacted). A
middleware installed beside every sentryhttp handler now renames the
transaction to the method and chi route pattern once the request is
routed, and sets its source to route. The hook keeps a route-sourced
name and withholds every other name as before, so a request that
matched no route still reads POST /(redacted). Tracing stays off.

Model: opus-5-5
This commit is contained in:
2026-10-12 23:46:21 +00:00
parent 9199544999
commit 96d8e7c1aa
5 changed files with 179 additions and 17 deletions
+7 -2
View File
@@ -90,8 +90,8 @@ func (s *Server) setupGlobalMiddleware() {
// recoverPanics installs on r the recoverer, answering a panic with
// page (a plain 500 when page is nil), and inside it the Sentry error
// reporting (if SENTRY_DSN is set). Repanic is true so panics still
// bubble up to the recoverer.
// reporting and transaction naming (if SENTRY_DSN is set). Repanic is
// true so panics still bubble up to the recoverer.
//
// Each admin page route group installs its own, with the error page,
// as its first middleware. A panic there is logged, reported and
@@ -105,6 +105,11 @@ func (s *Server) recoverPanics(r chi.Router, page http.Handler) {
Repanic: true,
})
r.Use(sentryHandler.Handle)
// Installed with every sentryhttp handler rather than once
// globally: in an admin page route group, the group's own
// handler finishes the transaction as the group returns, so
// a rename further out would come too late.
r.Use(nameSentryTransaction)
}
}