OpenTelemetry Usage

Using OpenTelemetry with Sentry.

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 have the OpenTelemetry SDK in you classpath, you can also instrument your code manually using the OpenTelemetry API as documented in the OpenTelemetry docs.

A manually created span for HTTP requests needs to declare its SpanKind as well as the HttpAttributes.HTTP_REQUEST_METHOD attribute, so that Sentry can correctly process these:

Copied
Span span = tracer.spanBuilder("myspan")
  .setAttribute(HTTP_REQUEST_METHOD, "GET")
  .setSpanKind(SpanKind.SERVER)
  .startSpan();

By default OpenTelemetry does not capture any HTTP headers. This, however, can be configured using system properties or environment variables as per OpenTelemetry's configuration documentation here. Each variable is a comma-separated list of HTTP header names that should be captured.

  • OTEL_INSTRUMENTATION_HTTP_CLIENT_CAPTURE_REQUEST_HEADERS
  • OTEL_INSTRUMENTATION_HTTP_CLIENT_CAPTURE_RESPONSE_HEADERS

  • OTEL_INSTRUMENTATION_HTTP_SERVER_CAPTURE_REQUEST_HEADERS
  • OTEL_INSTRUMENTATION_HTTP_SERVER_CAPTURE_RESPONSE_HEADERS

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.

Was this helpful?
Help improve this content
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").