feat(scope): remove Hub from Transaction#2122
Conversation
| } | ||
|
|
||
| $samplingContext = DynamicSamplingContext::fromTransaction($this->transaction, $this->hub); | ||
| $samplingContext = DynamicSamplingContext::fromTransaction($this->transaction, SentrySdk::getClient()); |
There was a problem hiding this comment.
Bug: getDynamicSamplingContext now uses SentrySdk::getClient(), which may return NoOpClient if a custom hub is used without updating the global client, breaking trace propagation.
Severity: HIGH
Suggested Fix
To build the Dynamic Sampling Context, use the client from the current hub instead of the one from SentrySdk::getClient(). This ensures the correct client configuration is used, especially in multi-hub scenarios where the global client may not be the one associated with the current transaction.
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/Tracing/Transaction.php#L93
Potential issue: The function `getDynamicSamplingContext()` was changed to use
`SentrySdk::getClient()` instead of the hub's client. `SentrySdk::getClient()` resolves
the client from the isolation or global scope, not the current hub. In scenarios where a
custom hub is set via `SentrySdk::setCurrentHub()` without also updating the global
client (e.g., in multi-tenant apps), `SentrySdk::getClient()` will return a
`NoOpClient`. This results in an incomplete Dynamic Sampling Context (DSC) missing
`public_key`, `release`, and `environment`, which breaks trace propagation between
services.
Did we get this right? 👍 / 👎 to inform future reviews.
5c69016 to
2e630c8
Compare
db6e223 to
14d6804
Compare
2e630c8 to
012018d
Compare
14d6804 to
0352e56
Compare
012018d to
3b8b293
Compare
0352e56 to
3a5d496
Compare
3b8b293 to
c316d3e
Compare
3a5d496 to
0f25f5f
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0f25f5f. Configure here.
| } | ||
|
|
||
| $samplingContext = DynamicSamplingContext::fromTransaction($this->transaction, $this->hub); | ||
| $samplingContext = DynamicSamplingContext::fromTransaction($this->transaction, SentrySdk::getClient()); |
There was a problem hiding this comment.
Wrong client for sampling context
Medium Severity
getDynamicSamplingContext() and initProfiler() now resolve options via SentrySdk::getClient(), which reads the isolation/global scope, while finish() still sends through \Sentry\captureEvent() on the current hub’s client. When the real client is only on the hub (e.g. bindClient() or setCurrentHub(new Hub($client)) without updating scope clients), DSC and profiler use NoOpClient options but the transaction event is captured with the hub client—missing or wrong public_key, release, and related baggage fields.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 0f25f5f. Configure here.


This PR removes the
Hubfrom the transaction and instead replaces it withClientInterfacein some instances.