feat: add sentry spans to evaluate proxy performances
Cadoles/bouncer/pipeline/head This commit looks good
Details
Cadoles/bouncer/pipeline/head This commit looks good
Details
This commit is contained in:
parent
867e7c549f
commit
590505e17a
|
@ -8,6 +8,7 @@ import (
|
|||
"forge.cadoles.com/Cadoles/go-proxy"
|
||||
"forge.cadoles.com/Cadoles/go-proxy/wildcard"
|
||||
"forge.cadoles.com/cadoles/bouncer/internal/cache"
|
||||
bouncersentry "forge.cadoles.com/cadoles/bouncer/internal/sentry"
|
||||
"forge.cadoles.com/cadoles/bouncer/internal/store"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
@ -257,6 +258,7 @@ func (d *Director) Middleware() proxy.Middleware {
|
|||
}
|
||||
|
||||
handler := createMiddlewareChain(next, httpMiddlewares)
|
||||
handler = bouncersentry.SpanHandler(handler, "director.proxy")
|
||||
|
||||
handler.ServeHTTP(w, r)
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
|
||||
bouncersentry "forge.cadoles.com/cadoles/bouncer/internal/sentry"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
|
@ -189,7 +191,7 @@ func (s *Server) run(parentCtx context.Context, addrs chan net.Addr, errs chan e
|
|||
proxy.WithDefaultHandler(http.HandlerFunc(s.handleDefault)),
|
||||
)
|
||||
|
||||
r.Handle("/*", handler)
|
||||
r.Handle("/*", bouncersentry.SpanHandler(handler, "http.proxy"))
|
||||
})
|
||||
|
||||
if err := http.Serve(listener, router); err != nil && !errors.Is(err, net.ErrClosed) {
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package sentry
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
)
|
||||
|
||||
func SpanHandler(handler http.Handler, name string) http.Handler {
|
||||
fn := 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)
|
||||
}
|
||||
|
||||
options := []sentry.SpanOption{
|
||||
sentry.WithOpName(name),
|
||||
sentry.ContinueFromRequest(r),
|
||||
sentry.WithTransactionSource(sentry.SourceURL),
|
||||
}
|
||||
|
||||
span := sentry.StartSpan(ctx,
|
||||
name,
|
||||
options...,
|
||||
)
|
||||
defer span.Finish()
|
||||
|
||||
r = r.WithContext(span.Context())
|
||||
|
||||
handler.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
return http.HandlerFunc(fn)
|
||||
}
|
Loading…
Reference in New Issue