-
-
Notifications
You must be signed in to change notification settings - Fork 27
refactor(sentry): use Context API for transaction storage #1055
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
|
|
||
| namespace FriendsOfHyperf\Sentry; | ||
|
|
||
| use Hyperf\Context\Context; | ||
| use Sentry\Breadcrumb; | ||
| use Sentry\Event; | ||
| use Sentry\Integration\IntegrationInterface; | ||
|
|
@@ -28,7 +29,7 @@ | |
|
|
||
| class Integration implements IntegrationInterface | ||
| { | ||
| private static ?string $transaction = null; | ||
| public const TRANSACTION = 'sentry.integration.transaction'; | ||
|
|
||
| public function setupOnce(): void | ||
| { | ||
|
|
@@ -47,13 +48,15 @@ public function setupOnce(): void | |
|
|
||
| if (defined('\Swow\Extension::VERSION')) { | ||
| $event->setContext('swow', [ | ||
| /* @phpstan-ignore-next-line */ | ||
| 'version' => \Swow\Extension::VERSION, | ||
| 'version' => \Swow\Extension::VERSION, // @phpstan-ignore-line | ||
| ]); | ||
| } | ||
|
|
||
| if (empty($event->getTransaction())) { | ||
| $event->setTransaction($self->getTransaction()); | ||
| if ( | ||
| empty($event->getTransaction()) | ||
| && $transaction = $self->getTransaction() | ||
| ) { | ||
| $event->setTransaction($transaction); | ||
| } | ||
|
|
||
| return $event; | ||
|
|
@@ -90,12 +93,12 @@ public static function configureScope(callable $callback): void | |
|
|
||
| public static function getTransaction(): ?string | ||
| { | ||
| return self::$transaction; | ||
| return Context::get(self::TRANSACTION); | ||
| } | ||
|
|
||
| public static function setTransaction(?string $transaction): void | ||
| { | ||
| self::$transaction = $transaction; | ||
| Context::set(self::TRANSACTION, $transaction); | ||
| } | ||
|
Comment on lines
94
to
102
|
||
|
|
||
| /** | ||
|
|
||
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.
The constant naming doesn't follow the established pattern in the codebase. Looking at the
SentryContextclass, all context key constants use a prefix likeCTX_(e.g.,CTX_CRON_CHECKIN_ID,CTX_CARRIER). For consistency, this constant should be namedCTX_TRANSACTIONinstead ofTRANSACTION, and the value should follow the pattern'sentry.ctx.transaction'instead of'sentry.integration.transaction'.