diff --git a/.gitignore b/.gitignore index b1249ba55..ac8bbb468 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ TODO.md # IDE system files .idea .vscode + +/go.work* \ No newline at end of file diff --git a/client.go b/client.go index 0e14658af..bdbfedde0 100644 --- a/client.go +++ b/client.go @@ -133,6 +133,9 @@ type ClientOptions struct { TracesSampleRate float64 // Used to customize the sampling of traces, overrides TracesSampleRate. TracesSampler TracesSampler + // Which instrumentation to use for tracing. Either "sentry" or "otel" are supported. + // Setting this to "otel" will ignore TracesSampleRate and TracesSampler and assume sampling is performed by otel. + TracesInstrumenter string // The sample rate for profiling traces in the range [0.0, 1.0]. // This is relative to TracesSampleRate - it is a ratio of profiled traces out of all sampled traces. ProfilesSampleRate float64 @@ -301,6 +304,19 @@ func NewClient(options ClientOptions) (*Client, error) { options.MaxSpans = defaultMaxSpans } + switch options.TracesInstrumenter { + case "": + options.TracesInstrumenter = "sentry" + case "sentry": + // noop + case "otel": + // sampling is performed by the OpenTelemetry SDK + options.TracesSampleRate = 1.0 + options.TracesSampler = nil + default: + return nil, fmt.Errorf("invalid value for TracesInstrumenter (supported are 'sentry' and 'otel'): %q", options.TracesInstrumenter) + } + // SENTRYGODEBUG is a comma-separated list of key=value pairs (similar // to GODEBUG). It is not a supported feature: recognized debug options // may change any time. diff --git a/gin/sentrygin.go b/gin/sentrygin.go index 387699109..cae1256cc 100644 --- a/gin/sentrygin.go +++ b/gin/sentrygin.go @@ -79,16 +79,18 @@ func (h *handler) handle(c *gin.Context) { sentry.WithTransactionSource(transactionSource), } - transaction := sentry.StartTransaction(ctx, - fmt.Sprintf("%s %s", c.Request.Method, transactionName), - options..., - ) - defer func() { - transaction.Status = sentry.HTTPtoSpanStatus(c.Writer.Status()) - transaction.Finish() - }() - - c.Request = c.Request.WithContext(transaction.Context()) + if hub.Client().Options().TracesInstrumenter == "sentry" { + transaction := sentry.StartTransaction(ctx, + fmt.Sprintf("%s %s", c.Request.Method, transactionName), + options..., + ) + defer func() { + transaction.Status = sentry.HTTPtoSpanStatus(c.Writer.Status()) + transaction.Finish() + }() + c.Request = c.Request.WithContext(transaction.Context()) + } + hub.Scope().SetRequest(c.Request) c.Set(valuesKey, hub) defer h.recoverWithSentry(hub, c.Request) diff --git a/http/sentryhttp.go b/http/sentryhttp.go index 2fb5a9f90..55820b32e 100644 --- a/http/sentryhttp.go +++ b/http/sentryhttp.go @@ -99,17 +99,20 @@ func (h *Handler) handle(handler http.Handler) http.HandlerFunc { sentry.ContinueFromRequest(r), sentry.WithTransactionSource(sentry.SourceURL), } - // We don't mind getting an existing transaction back so we don't need to - // check if it is. - transaction := sentry.StartTransaction(ctx, - fmt.Sprintf("%s %s", r.Method, r.URL.Path), - options..., - ) - defer transaction.Finish() - // TODO(tracing): if the next handler.ServeHTTP panics, store - // information on the transaction accordingly (status, tag, - // level?, ...). - r = r.WithContext(transaction.Context()) + + if hub.Client().Options().TracesInstrumenter == "sentry" { + // We don't mind getting an existing transaction back so we don't need to + // check if it is. + transaction := sentry.StartTransaction(ctx, + fmt.Sprintf("%s %s", r.Method, r.URL.Path), + options..., + ) + defer transaction.Finish() + // TODO(tracing): if the next handler.ServeHTTP panics, store + // information on the transaction accordingly (status, tag, + // level?, ...). + r = r.WithContext(transaction.Context()) + } hub.Scope().SetRequest(r) defer h.recoverWithSentry(hub, r) // TODO(tracing): use custom response writer to intercept