OpenTelemetry Support
Using OpenTelemetry with Sentry Performance.
You can configure your OpenTelemetry SDK to send traces and spans to Sentry.
OpenTelemetry integration was added in sentry-go
version 0.18.0, and works only for Go >= 1.18.
The Sentry Go OpenTelemetry integration requires go.opentelemetry.io/otel
(and its submodules), version 1.11.0
or higher.
Install the otel
module in addition to the main SDK:
go get github.com/getsentry/sentry-go \
github.com/getsentry/sentry-go/otel
You need to register the Sentry-provided SpanProcessor and Propagator as shown below:
import (
"go.opentelemetry.io/otel"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"github.com/getsentry/sentry-go"
"github.com/getsentry/sentry-go/otel"
// ...
)
sentry.Init(sentry.ClientOptions{
Dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
EnableTracing: true,
TracesSampleRate: 1.0,
Debug: true,
})
tp := sdktrace.NewTracerProvider(
sdktrace.WithSpanProcessor(sentryotel.NewSentrySpanProcessor()),
)
otel.SetTracerProvider(tp)
otel.SetTextMapPropagator(sentryotel.NewSentryPropagator())
Now, all spans produced by OpenTelemetry will also be captured and sent to Sentry.
If you want the errors and messages the SDK produces (for example, via CaptureException
or CaptureMessage
) to be linked to transactions in the UI, a couple of extra steps are required. Most importantly, the current OpenTelemetry-enhanced context has to be passed as part of EventHint
to client.Capture*
methods:
hub := sentry.CurrentHub()
//// or:
// hub := sentry.GetHubFromContext(ctx)
client, scope := hub.Client(), hub.Scope()
client.CaptureException(
errors.New("new error"),
&sentry.EventHint{Context: ctx},
scope,
)
Events captured with the high-level sentry.CaptureException
or sentry.CaptureMessage
functions are NOT linked to transactions or spans at the moment. This will be improved in future releases.
With Sentry’s OpenTelemetry SDK, an OpenTelemetry Span
becomes a Sentry Transaction
or Span
. The first Span
sent through the Sentry SpanProcessor
is a Transaction
, and any child Span
gets attached to the first Transaction
upon checking the parent Span
context. This is true for the OpenTelemetry root Span
and any top level Span
in the system. For example, a request sent from frontend to backend will create an OpenTelemetry root Span
with a corresponding Sentry Transaction
. The backend request will create a new Sentry Transaction
for the OpenTelemetry Span
. The Sentry Transaction
and Span
are linked as a trace for navigation and error tracking purposes.
If you need more fine grained control over Sentry, take a look at the Configuration page. In case you'd like to filter out transactions before sending them to Sentry (to get rid of health checks, for example), you may find the Filtering page helpful.
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").