Skip to content

feat(scopes): use TransactionSampler#2120

Open
Litarnus wants to merge 1 commit into
transaction-samplerfrom
use-transaction-sampler
Open

feat(scopes): use TransactionSampler#2120
Litarnus wants to merge 1 commit into
transaction-samplerfrom
use-transaction-sampler

Conversation

@Litarnus

Copy link
Copy Markdown
Contributor

No description provided.

@Litarnus Litarnus force-pushed the transaction-sampler branch from 0ab8198 to 99d01dc Compare June 15, 2026 13:19
@Litarnus Litarnus force-pushed the use-transaction-sampler branch from d4ded95 to 5c69016 Compare June 15, 2026 13:20
@Litarnus Litarnus marked this pull request as ready for review June 22, 2026 14:38
Comment thread src/Tracing/TransactionSampler.php
public static function startTransaction(Options $options, TransactionContext $context, array $customSamplingContext = []): Transaction
{
$logger = $this->options->getLoggerOrNullLogger();
$transaction = new Transaction($context);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The Transaction constructor now defaults to the global hub instead of using the specific hub instance on which startTransaction() was called, affecting multi-hub scenarios.
Severity: MEDIUM

Suggested Fix

The TransactionSampler::startTransaction method should be updated to accept the HubInterface instance as a parameter. This hub instance should then be passed explicitly to the Transaction constructor, restoring the previous behavior and ensuring the transaction is associated with the correct hub on which it was started.

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/TransactionSampler.php#L25

Potential issue: The refactoring of `TransactionSampler::startTransaction` to a static
method removed the passing of the `HubInterface` instance to the `Transaction`
constructor. Consequently, the constructor now defaults to using the global hub via
`SentrySdk::getCurrentHub()`. In scenarios where multiple hubs are instantiated and
used, calling `startTransaction()` on a specific, non-global hub will cause the
resulting transaction to be incorrectly associated with the global hub. This leads to
the transaction event being captured by the wrong hub and its Dynamic Sampling Context
(DSC) being populated from the wrong client's options, breaking the API contract for
multi-hub usage.

Also affects:

  • src/State/Hub.php:239~239

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

@Litarnus Litarnus force-pushed the transaction-sampler branch from 99d01dc to 346a63d Compare June 22, 2026 22:12
@Litarnus Litarnus force-pushed the use-transaction-sampler branch from 5c69016 to 2e630c8 Compare June 22, 2026 22:12
Comment thread src/Tracing/TransactionSampler.php
@Litarnus Litarnus force-pushed the transaction-sampler branch from 346a63d to 0878a69 Compare June 22, 2026 22:46
@Litarnus Litarnus force-pushed the use-transaction-sampler branch from 2e630c8 to 012018d Compare June 22, 2026 22:46
Comment thread src/Tracing/TransactionSampler.php
@Litarnus Litarnus force-pushed the transaction-sampler branch from 0878a69 to 472a3ab Compare June 22, 2026 22:54
@Litarnus Litarnus force-pushed the use-transaction-sampler branch from 012018d to 3b8b293 Compare June 22, 2026 22:54

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3b8b293. Configure here.

Comment thread src/Tracing/TransactionSampler.php
@Litarnus Litarnus force-pushed the transaction-sampler branch from 472a3ab to 7de1710 Compare June 24, 2026 11:14
@Litarnus Litarnus force-pushed the use-transaction-sampler branch from 3b8b293 to c316d3e Compare June 24, 2026 11:14
public static function startTransaction(Options $options, TransactionContext $context, array $customSamplingContext = []): Transaction
{
$logger = $this->options->getLoggerOrNullLogger();
$transaction = new Transaction($context);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: In multi-hub scenarios, transactions are incorrectly associated with the global hub instead of the hub that created them, causing events to be sent to the wrong project.
Severity: HIGH

Suggested Fix

The static TransactionSampler::startTransaction method should be modified to accept the calling HubInterface instance as an argument. This hub instance must then be passed to the Transaction constructor, like new Transaction($context, $hub), to ensure the transaction is correctly associated with the hub that initiated its creation.

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/TransactionSampler.php#L25

Potential issue: The refactoring of `Hub::startTransaction` to use the static
`TransactionSampler::startTransaction` method has introduced a regression. The call to
`new Transaction($context)` inside the sampler no longer receives the calling hub
instance. As a result, the `Transaction` constructor defaults to using the global hub
via `SentrySdk::getCurrentHub()`. In a multi-hub scenario, if a transaction is started
on a non-current hub, subsequent operations like `finish()` will be executed against the
wrong hub, causing events to be captured by the wrong client and sent to the incorrect
DSN.

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