Skip to content

[OTLP] Generate Sentry issues based on OTel span exception events #5097

Closed

Description

@gregoiredx

Problem Statement

Currently, the OpenTelemetry SentrySpanProcessor does not interpret span events at all.

This means that when a span has an exception event attached, there's no issue visible in Sentry when using INSTRUMENTER.OTEL and the OTel Python SDK.

When using the OTel API to record and exception using trace.get_current_span().record_exception(error), it has no effect on Sentry issues, while one would expect it to do something equivalent to sentry_sdk.capture_exception(error).

Solution Brainstorm

In the docs, there's already an idea of what could be done, at least in TypeScript, see https://develop.sentry.dev/sdk/telemetry/traces/opentelemetry/#step-7-define-generatesentryerrorsfromotelspan

In OpenTelemetry, spans can have exception events. These have a stacktrace, message, and type. We want to convert these to Sentry errors and attach them to the trace.

function generateSentryErrorsFromOtelSpan(otelSpan) {
  otelSpan.events.forEach(event => {
    // Only convert exception events to Sentry errors.
    if (event.name !=== 'exception') {
      return;
    }
    const attributes = event.attributes;
    const message = attributes[SemanticAttributes.EXCEPTION_MESSAGE];
    const syntheticError = new Error(message);
    syntheticError.stack = attributes[SemanticAttributes.EXCEPTION_STACKTRACE];
    syntheticError.name = attributes[SemanticAttributes.EXCEPTION_TYPE];
    Sentry.captureException(syntheticError, {
      contexts: {
        otel: {
          attributes: otelSpan.attributes,
          resource: otelSpan.resource.attributes,
        },
        trace: {
          trace_id: otelSpan.spanContext().traceId,
          span_id: otelSpan.spanContext().spanId,
          parent_span_id: otelSpan.parentSpanId,
        },
      },
    });
  });
}

But it's not that easy to transpose in Python since sentry_sdk.capture_exception(error) relies a lot on having an actual exception instance which we don't have in SentrySpanProcessor.on_end(otel_span) where we could generate Sentry issues from OTel span events (we do have the exception type, message, and stacktrace, though).

Activity

  1. linear commented on Nov 12, 2025

    @linear
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Nov 12, 2025
  3. sl0thentr0py commented on Nov 12, 2025

    @sl0thentr0py
    Member

    @gregoiredx thanks for the issue.
    We're actually in the process of rolling out first-class OTLP support - #4877
    and we will encourage users to move away from the SpanProcessor once it's released.

    As part of that new OTLPIntegration, we could indeed make sure that we intercept errors reported via trace.get_current_span().record_exception(error) and make sure they are trace connected. Will let you know once it's all ready!

  4. self-assigned this
    on Nov 12, 2025
  5. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Nov 12, 2025
  6. changed the title [-]Generate Sentry issues based on OTel span exception events[/-] [+][OTLP] Generate Sentry issues based on OTel span exception events[/+] on Nov 12, 2025
  7. gregoiredx commented on Nov 13, 2025

    @gregoiredx
    Author

    @sl0thentr0py thanks for your rapid answer, yes please let me know when OTLPIntegration is released!

    On a close subject, I tested the Sentry OTLP endpoint and it looks like similarly it's not taking into account exception events to create issues. It looks to me like it should.
    WDYT? Should I create an issue elsewhere?

  8. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Nov 13, 2025
  9. sl0thentr0py commented on Nov 13, 2025

    @sl0thentr0py
    Member

    by itself it will not, correct. But we will make it very easy to integrate Sentry into an existing otel setup with an extra integration in the Sentry SDK that you just have to turn on.

    This issue is sufficient for tracking that feature!

  10. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Nov 13, 2025
  11. kerenkhatiwada commented on Dec 10, 2025

    @kerenkhatiwada

    Hey team, any update on this issue? Have another user running onto this here.

  12. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Dec 10, 2025
  13. sl0thentr0py commented on Dec 11, 2025

    @sl0thentr0py
    Member

    next week!

  14. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Dec 11, 2025
  15. added a commit that references this issue on Dec 15, 2025
    00787dd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions