Skip to content

feat(otel): add OTLP integration#2030

Open
Litarnus wants to merge 4 commits intomasterfrom
otlp-integration
Open

feat(otel): add OTLP integration#2030
Litarnus wants to merge 4 commits intomasterfrom
otlp-integration

Conversation

@Litarnus
Copy link
Contributor

Adds OTLP support by providing an Integration.

It use it, it's necessary to add the integration in the init call:

  Sentry\init([
      'dsn' => '___PUBLIC_DSN___',
      'integrations' => [
          new Sentry\Integration\OTLPIntegration(),
      ],
  ]);

Using sentry tracing with OTLP tracing is not supported. If sentry tracing is enabled, the integration will not be registered

@Litarnus Litarnus marked this pull request as ready for review March 19, 2026 19:50
Comment on lines +97 to +100
/**
* @var callable|null
*/
private static $externalPropagationContextCallback;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The OTLPIntegration registers a callback in a static property, Scope::$externalPropagationContextCallback, which is not cleared on re-initialization, causing state leakage in tests or long-running applications.
Severity: MEDIUM

Suggested Fix

Implement an automatic cleanup mechanism for the static Scope::$externalPropagationContextCallback property. This could be done within SentrySdk::init() to clear the callback before setting up a new client. Alternatively, provide a way for integrations to register cleanup hooks that are executed upon re-initialization. At a minimum, the clearExternalPropagationContext() method should be called in the test suite's tearDown to ensure test isolation.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/State/Scope.php#L97-L100

Potential issue: The `OTLPIntegration` registers a callback in the static property
`Scope::$externalPropagationContextCallback`. This property is not automatically cleared
when a new Sentry client is initialized via `SentrySdk::init()`. This leads to state
leakage, where the callback from a previous initialization persists. In long-running
applications (e.g., using RoadRunner or Swoole) or complex test suites, this can cause
unpredictable behavior. Although the callback is hub-aware and may return `null` if the
integration is missing on the current hub, the persistent global state violates
isolation principles and poses a risk in multi-tenant or multi-context scenarios.

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant