-
-
Notifications
You must be signed in to change notification settings - Fork 471
feat(scope): dont use hub for capturing events anymore #2132
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
Open
+782
−114
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Sentry\State; | ||
|
|
||
| use Sentry\Breadcrumb; | ||
| use Sentry\ClientInterface; | ||
| use Sentry\NoOpClient; | ||
|
|
||
| /** | ||
| * @internal | ||
| */ | ||
| final class BreadcrumbRecorder | ||
| { | ||
| private function __construct() | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Records the breadcrumb on the given scope if the client configuration allows it. | ||
| */ | ||
| public static function record(ClientInterface $client, Scope $scope, Breadcrumb $breadcrumb): bool | ||
| { | ||
| if ($client instanceof NoOpClient) { | ||
| return false; | ||
| } | ||
|
|
||
| $options = $client->getOptions(); | ||
| $maxBreadcrumbs = $options->getMaxBreadcrumbs(); | ||
|
|
||
| if ($maxBreadcrumbs <= 0) { | ||
| return false; | ||
| } | ||
|
|
||
| $breadcrumb = ($options->getBeforeBreadcrumbCallback())($breadcrumb); | ||
|
|
||
| if ($breadcrumb !== null) { | ||
| $scope->addBreadcrumb($breadcrumb, $maxBreadcrumbs); | ||
| } | ||
|
|
||
| return $breadcrumb !== null; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Sentry\State; | ||
|
|
||
| use Sentry\CheckIn; | ||
| use Sentry\CheckInStatus; | ||
| use Sentry\ClientInterface; | ||
| use Sentry\Event; | ||
| use Sentry\EventHint; | ||
| use Sentry\EventId; | ||
| use Sentry\MonitorConfig; | ||
| use Sentry\NoOpClient; | ||
| use Sentry\SentrySdk; | ||
| use Sentry\Severity; | ||
|
|
||
| /** | ||
| * @internal | ||
| */ | ||
| final class EventCapturer | ||
| { | ||
| private function __construct() | ||
| { | ||
| } | ||
|
|
||
| public static function captureMessage(string $message, ?Severity $level = null, ?EventHint $hint = null): ?EventId | ||
| { | ||
| return self::capture(static function (ClientInterface $client, Scope $captureScope) use ($message, $level, $hint): ?EventId { | ||
| return $client->captureMessage($message, $level, $captureScope, $hint); | ||
| }); | ||
| } | ||
|
|
||
| public static function captureException(\Throwable $exception, ?EventHint $hint = null): ?EventId | ||
| { | ||
| return self::capture(static function (ClientInterface $client, Scope $captureScope) use ($exception, $hint): ?EventId { | ||
| return $client->captureException($exception, $captureScope, $hint); | ||
| }); | ||
| } | ||
|
|
||
| public static function captureEvent(Event $event, ?EventHint $hint = null): ?EventId | ||
| { | ||
| return self::capture(static function (ClientInterface $client, Scope $captureScope) use ($event, $hint): ?EventId { | ||
| return $client->captureEvent($event, $hint, $captureScope); | ||
| }); | ||
| } | ||
|
|
||
| public static function captureLastError(?EventHint $hint = null): ?EventId | ||
| { | ||
| return self::capture(static function (ClientInterface $client, Scope $captureScope) use ($hint): ?EventId { | ||
| return $client->captureLastError($captureScope, $hint); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * @param int|float|null $duration | ||
| */ | ||
| public static function captureCheckIn(string $slug, CheckInStatus $status, $duration = null, ?MonitorConfig $monitorConfig = null, ?string $checkInId = null): ?string | ||
| { | ||
| $isolationScope = SentrySdk::getIsolationScope(); | ||
| $client = SentrySdk::getClient($isolationScope); | ||
|
|
||
| if ($client instanceof NoOpClient) { | ||
| return null; | ||
| } | ||
|
|
||
| $options = $client->getOptions(); | ||
| $event = Event::createCheckIn(); | ||
| $checkIn = new CheckIn( | ||
| $slug, | ||
| $status, | ||
| $checkInId, | ||
| $options->getRelease(), | ||
| $options->getEnvironment(), | ||
| $duration, | ||
| $monitorConfig | ||
| ); | ||
| $event->setCheckIn($checkIn); | ||
|
|
||
| self::captureWithScope($client, $isolationScope, static function (ClientInterface $client, Scope $captureScope) use ($event): ?EventId { | ||
| return $client->captureEvent($event, null, $captureScope); | ||
| }); | ||
|
|
||
| return $checkIn->getId(); | ||
| } | ||
|
|
||
| /** | ||
| * @param callable(ClientInterface, Scope): ?EventId $capture | ||
| */ | ||
| private static function capture(callable $capture): ?EventId | ||
| { | ||
| $isolationScope = SentrySdk::getIsolationScope(); | ||
|
|
||
| return self::captureWithScope(SentrySdk::getClient($isolationScope), $isolationScope, $capture); | ||
| } | ||
|
|
||
| /** | ||
| * @param callable(ClientInterface, Scope): ?EventId $capture | ||
| */ | ||
| private static function captureWithScope(ClientInterface $client, Scope $isolationScope, callable $capture): ?EventId | ||
| { | ||
| $eventId = $capture($client, Scope::mergeScopes(SentrySdk::getGlobalScope(), $isolationScope)); | ||
| $isolationScope->setLastEventId($eventId); | ||
|
|
||
| return $eventId; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Capturer is awkward in my head maybe EventRecorder is a nice fit. But highly subjective so feel free to leave as is!
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.
Yeah that makes more sense, we have
BreadcrumbRecorderandSpanRecorderso that would fit