Conversation
| /** | ||
| * @var callable|null | ||
| */ | ||
| private static $externalPropagationContextCallback; |
There was a problem hiding this comment.
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.
Adds OTLP support by providing an Integration.
It use it, it's necessary to add the integration in the init call:
Using sentry tracing with OTLP tracing is not supported. If sentry tracing is enabled, the integration will not be registered