c21c1757de
* core: bump github.com/getsentry/sentry-go from 0.15.0 to 0.16.0 Bumps [github.com/getsentry/sentry-go](https://github.com/getsentry/sentry-go) from 0.15.0 to 0.16.0. - [Release notes](https://github.com/getsentry/sentry-go/releases) - [Changelog](https://github.com/getsentry/sentry-go/blob/master/CHANGELOG.md) - [Commits](https://github.com/getsentry/sentry-go/compare/v0.15.0...v0.16.0) --- updated-dependencies: - dependency-name: github.com/getsentry/sentry-go dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * update custom tracer Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jens Langhammer <jens.langhammer@beryju.org>
35 lines
899 B
Go
35 lines
899 B
Go
package sentry
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/getsentry/sentry-go"
|
|
)
|
|
|
|
type contextSentryNoSample struct{}
|
|
|
|
func SentryNoSample(handler func(rw http.ResponseWriter, r *http.Request)) func(http.ResponseWriter, *http.Request) {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
ctx := context.WithValue(r.Context(), contextSentryNoSample{}, true)
|
|
handler(w, r.WithContext(ctx))
|
|
}
|
|
}
|
|
|
|
func SentryNoSampleMiddleware(h http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
|
ctx := context.WithValue(r.Context(), contextSentryNoSample{}, true)
|
|
h.ServeHTTP(rw, r.WithContext(ctx))
|
|
})
|
|
}
|
|
|
|
func SamplerFunc(defaultRate float64) sentry.TracesSampler {
|
|
return func(ctx sentry.SamplingContext) float64 {
|
|
data, ok := ctx.Span.Context().Value(contextSentryNoSample{}).(bool)
|
|
if data && ok {
|
|
return 0
|
|
}
|
|
return defaultRate
|
|
}
|
|
}
|