-
-
Notifications
You must be signed in to change notification settings - Fork 462
ref(client): replace nullable client with NoOpClient #1957
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
Litarnus
wants to merge
5
commits into
5.x
Choose a base branch
from
not-null-client
base: 5.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0d55157
ref(client): replace nullable client with NullClient
Litarnus 0659fc2
return null for checkin when using NullClient
Litarnus f607182
rename NullClient -> NoOpClient
Litarnus 677ea95
make NoOpClient lazy
Litarnus 006230d
fix
Litarnus 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
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
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
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,95 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Sentry; | ||
|
|
||
| use Sentry\Integration\IntegrationInterface; | ||
| use Sentry\Serializer\RepresentationSerializer; | ||
| use Sentry\State\Scope; | ||
| use Sentry\Transport\Result; | ||
| use Sentry\Transport\ResultStatus; | ||
|
|
||
| /** | ||
| * This client does not perform any operations, it acts as an interface compatible layer in order to | ||
| * simply workflows where previously the client was null. | ||
| * It also holds options which helps with situations where no options were available if the client was set to `null`. | ||
| */ | ||
| class NoOpClient implements ClientInterface | ||
| { | ||
| /** | ||
| * @var array<string, mixed> | ||
| */ | ||
| private $options; | ||
|
|
||
| /** | ||
| * @var Options | ||
| */ | ||
| private $sentryOptions; | ||
|
|
||
| /** | ||
| * @var StacktraceBuilder|null | ||
| */ | ||
| private $stacktraceBuilder; | ||
|
|
||
| /** | ||
| * @param array<string, mixed> $options | ||
| */ | ||
| public function __construct(array $options = []) | ||
| { | ||
| $this->options = $options; | ||
| } | ||
|
|
||
| public function getOptions(): Options | ||
| { | ||
| if ($this->sentryOptions === null) { | ||
| $this->sentryOptions = new Options($this->options); | ||
| } | ||
|
|
||
| return $this->sentryOptions; | ||
| } | ||
|
|
||
| public function getCspReportUrl(): ?string | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| public function captureMessage(string $message, ?Severity $level = null, ?Scope $scope = null, ?EventHint $hint = null): ?EventId | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| public function captureException(\Throwable $exception, ?Scope $scope = null, ?EventHint $hint = null): ?EventId | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| public function captureLastError(?Scope $scope = null, ?EventHint $hint = null): ?EventId | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| public function captureEvent(Event $event, ?EventHint $hint = null, ?Scope $scope = null): ?EventId | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| public function getIntegration(string $className): ?IntegrationInterface | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| public function flush(?int $timeout = null): Result | ||
| { | ||
| return new Result(ResultStatus::skipped()); | ||
| } | ||
|
|
||
| public function getStacktraceBuilder(): StacktraceBuilder | ||
| { | ||
| if ($this->stacktraceBuilder === null) { | ||
| $this->stacktraceBuilder = new StacktraceBuilder($this->getOptions(), new RepresentationSerializer($this->getOptions())); | ||
| } | ||
|
|
||
| return $this->stacktraceBuilder; | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ | |
|
|
||
| namespace Sentry\State; | ||
|
|
||
| use Psr\Log\NullLogger; | ||
| use Sentry\Attachment\Attachment; | ||
| use Sentry\Breadcrumb; | ||
| use Sentry\CheckIn; | ||
|
|
@@ -15,6 +14,7 @@ | |
| use Sentry\EventId; | ||
| use Sentry\Integration\IntegrationInterface; | ||
| use Sentry\MonitorConfig; | ||
| use Sentry\NoOpClient; | ||
| use Sentry\Severity; | ||
| use Sentry\Tracing\SamplingContext; | ||
| use Sentry\Tracing\Span; | ||
|
|
@@ -39,18 +39,18 @@ class Hub implements HubInterface | |
| /** | ||
| * Hub constructor. | ||
| * | ||
| * @param ClientInterface|null $client The client bound to the hub | ||
| * @param Scope|null $scope The scope bound to the hub | ||
| * @param ClientInterface $client The client bound to the hub | ||
| * @param Scope|null $scope The scope bound to the hub | ||
| */ | ||
| public function __construct(?ClientInterface $client = null, ?Scope $scope = null) | ||
| public function __construct(ClientInterface $client, ?Scope $scope = null) | ||
| { | ||
| $this->stack[] = new Layer($client, $scope ?? new Scope()); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function getClient(): ?ClientInterface | ||
| public function getClient(): ClientInterface | ||
| { | ||
| return $this->getStackTop()->getClient(); | ||
| } | ||
|
|
@@ -123,55 +123,31 @@ public function bindClient(ClientInterface $client): void | |
| */ | ||
| public function captureMessage(string $message, ?Severity $level = null, ?EventHint $hint = null): ?EventId | ||
| { | ||
| $client = $this->getClient(); | ||
|
|
||
| if ($client !== null) { | ||
| return $this->lastEventId = $client->captureMessage($message, $level, $this->getScope(), $hint); | ||
| } | ||
|
|
||
| return null; | ||
| return $this->lastEventId = $this->getClient()->captureMessage($message, $level, $this->getScope(), $hint); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function captureException(\Throwable $exception, ?EventHint $hint = null): ?EventId | ||
| { | ||
| $client = $this->getClient(); | ||
|
|
||
| if ($client !== null) { | ||
| return $this->lastEventId = $client->captureException($exception, $this->getScope(), $hint); | ||
| } | ||
|
|
||
| return null; | ||
| return $this->lastEventId = $this->getClient()->captureException($exception, $this->getScope(), $hint); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function captureEvent(Event $event, ?EventHint $hint = null): ?EventId | ||
| { | ||
| $client = $this->getClient(); | ||
|
|
||
| if ($client !== null) { | ||
| return $this->lastEventId = $client->captureEvent($event, $hint, $this->getScope()); | ||
| } | ||
|
|
||
| return null; | ||
| return $this->lastEventId = $this->getClient()->captureEvent($event, $hint, $this->getScope()); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function captureLastError(?EventHint $hint = null): ?EventId | ||
| { | ||
| $client = $this->getClient(); | ||
|
|
||
| if ($client !== null) { | ||
| return $this->lastEventId = $client->captureLastError($this->getScope(), $hint); | ||
| } | ||
|
|
||
| return null; | ||
| return $this->lastEventId = $this->getClient()->captureLastError($this->getScope(), $hint); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -183,7 +159,7 @@ public function captureCheckIn(string $slug, CheckInStatus $status, $duration = | |
| { | ||
| $client = $this->getClient(); | ||
|
|
||
| if ($client === null) { | ||
| if ($client instanceof NoOpClient) { | ||
| return null; | ||
| } | ||
|
|
||
|
|
@@ -211,7 +187,8 @@ public function addBreadcrumb(Breadcrumb $breadcrumb): bool | |
| { | ||
| $client = $this->getClient(); | ||
|
|
||
| if ($client === null) { | ||
| // No point in storing breadcrumbs if the client will never send them | ||
|
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: NullClient misreports success on captureCheckInThe |
||
| if ($client instanceof NoOpClient) { | ||
| return false; | ||
| } | ||
|
|
||
|
|
@@ -234,9 +211,8 @@ public function addBreadcrumb(Breadcrumb $breadcrumb): bool | |
|
|
||
| public function addAttachment(Attachment $attachment): bool | ||
| { | ||
| $client = $this->getClient(); | ||
|
|
||
| if ($client === null) { | ||
| // No point in storing attachments if the client will never send them | ||
| if ($this->getClient() instanceof NoOpClient) { | ||
| return false; | ||
| } | ||
|
|
||
|
|
@@ -250,13 +226,7 @@ public function addAttachment(Attachment $attachment): bool | |
| */ | ||
| public function getIntegration(string $className): ?IntegrationInterface | ||
| { | ||
| $client = $this->getClient(); | ||
|
|
||
| if ($client !== null) { | ||
| return $client->getIntegration($className); | ||
| } | ||
|
|
||
| return null; | ||
| return $this->getClient()->getIntegration($className); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -267,11 +237,10 @@ public function getIntegration(string $className): ?IntegrationInterface | |
| public function startTransaction(TransactionContext $context, array $customSamplingContext = []): Transaction | ||
| { | ||
| $transaction = new Transaction($context, $this); | ||
| $client = $this->getClient(); | ||
| $options = $client !== null ? $client->getOptions() : null; | ||
| $logger = $options !== null ? $options->getLoggerOrNullLogger() : new NullLogger(); | ||
| $options = $this->getClient()->getOptions(); | ||
| $logger = $options->getLoggerOrNullLogger(); | ||
|
|
||
| if ($options === null || !$options->isTracingEnabled()) { | ||
| if (!$options->isTracingEnabled()) { | ||
| $transaction->setSampled(false); | ||
|
|
||
| $logger->warning(\sprintf('Transaction [%s] was started but tracing is not enabled.', (string) $transaction->getTraceId()), ['context' => $context]); | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.