-
-
Notifications
You must be signed in to change notification settings - Fork 471
feat(scope): remove Hub from Transaction #2122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,18 +9,12 @@ | |
| use Sentry\Options; | ||
| use Sentry\Profiling\Profiler; | ||
| use Sentry\SentrySdk; | ||
| use Sentry\State\HubInterface; | ||
|
|
||
| /** | ||
| * This class stores all the information about a Transaction. | ||
| */ | ||
| final class Transaction extends Span | ||
| { | ||
| /** | ||
| * @var HubInterface The hub instance | ||
| */ | ||
| private $hub; | ||
|
|
||
| /** | ||
| * @var string Name of the transaction | ||
| */ | ||
|
|
@@ -45,15 +39,13 @@ final class Transaction extends Span | |
| * Span constructor. | ||
| * | ||
| * @param TransactionContext $context The context to create the transaction with | ||
| * @param HubInterface|null $hub Instance of a hub to flush the transaction | ||
| * | ||
| * @internal | ||
| */ | ||
| public function __construct(TransactionContext $context, ?HubInterface $hub = null) | ||
| public function __construct(TransactionContext $context) | ||
| { | ||
| parent::__construct($context); | ||
|
|
||
| $this->hub = $hub ?? SentrySdk::getCurrentHub(); | ||
| $this->name = $context->getName(); | ||
| $this->metadata = $context->getMetadata(); | ||
| $this->transaction = $this; | ||
|
|
@@ -98,7 +90,7 @@ public function getDynamicSamplingContext(): DynamicSamplingContext | |
| return $this->metadata->getDynamicSamplingContext(); | ||
| } | ||
|
|
||
| $samplingContext = DynamicSamplingContext::fromTransaction($this->transaction, $this->hub); | ||
| $samplingContext = DynamicSamplingContext::fromTransaction($this->transaction, SentrySdk::getClient()); | ||
|
cursor[bot] marked this conversation as resolved.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Suggested FixTo build the Dynamic Sampling Context, use the client from the current hub instead of the one from Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong client for sampling contextMedium Severity
Additional Locations (1)Reviewed by Cursor Bugbot for commit 0f25f5f. Configure here. |
||
| $this->getMetadata()->setDynamicSamplingContext($samplingContext); | ||
|
|
||
| return $samplingContext; | ||
|
|
@@ -123,7 +115,7 @@ public function initSpanRecorder(int $maxSpans = 1000): self | |
| public function initProfiler(?Options $options = null): Profiler | ||
| { | ||
| if ($this->profiler === null) { | ||
| $this->profiler = new Profiler($options ?? $this->hub->getClient()->getOptions()); | ||
| $this->profiler = new Profiler($options ?? SentrySdk::getClient()->getOptions()); | ||
| } | ||
|
|
||
| return $this->profiler; | ||
|
|
@@ -188,6 +180,6 @@ public function finish(?float $endTimestamp = null): ?EventId | |
| } | ||
| } | ||
|
|
||
| return $this->hub->captureEvent($event); | ||
| return \Sentry\captureEvent($event); | ||
| } | ||
| } | ||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it now make sense that this transaction is able to "switch clients" I feel like the AI comments try to point this out with a lot of words but that seems odd that if the global client changes for whatever reason a transaction will be finished on it where it wasn't started. Client or scope. Maybe it should get the scope instead of the hub and hold a ref to it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True that's a good point, I will update the signature to allow a (isolation) Scope