Name Sentry transactions after the route they matched (closes #185)
check / check (push) Waiting to run

sentryhttp names each transaction after the concrete path, which the
BeforeSendTransaction hook has to withhold, so with tracing on the
transactions would fall into one Sentry group per method, such as
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. A path that matches nothing at the top level keeps the
withheld name; one that matches no route inside a route group, or
that the group's middleware turns away, is named after the group's
pattern, such as GET /pages/*. Tracing stays off.

Model: opus-5-5
This commit was merged in pull request #516.
This commit is contained in:
2026-10-13 05:47:26 +02:00
parent 957de7f99f
commit f86ab6321d
5 changed files with 194 additions and 21 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)
}
}