Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Classes/Command/SentryCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testCommand(string $mode = self::TEST_MODE_THROW): void

private function captureMessage(): void
{
$eventId = $this->sentryClient->captureMessage(
$captureResult = $this->sentryClient->captureMessage(
'Flownative Sentry Plugin Test',
Severity::debug(),
[
Expand All @@ -86,7 +86,11 @@ private function captureMessage(): void
);

$this->outputLine();
$this->outputLine('<success>An informational message was sent to Sentry</success> Event ID: #%s', [$eventId]);
if ($captureResult->suceess) {
$this->outputLine('<success>An informational message was sent to Sentry</success> Event ID: #%s', [$captureResult->eventId]);
} else {
$this->outputLine('<error>Sending an informational message to Sentry failed</error>: %s', [$captureResult->message]);
}
$this->outputLine();
}

Expand Down
36 changes: 13 additions & 23 deletions Classes/SentryClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,38 +222,28 @@ public function captureThrowable(Throwable $throwable, array $extraData = [], ar
);
}

public function captureMessage(string $message, Severity $severity, array $extraData = [], array $tags = []): ?EventId
public function captureMessage(string $message, Severity $severity, array $extraData = [], array $tags = []): CaptureResult
{
if (empty($this->dsn)) {
if ($this->logger) {
$this->logger->warning('Sentry: Failed capturing message, because no Sentry DSN was set. Please check your settings.');
}
return null;
}

if (preg_match('/Sentry: [0-9a-f]{32}/', $message) === 1) {
return null;
return new CaptureResult(
false,
'Failed capturing message, because no Sentry DSN was set. Please check your settings.',
''
);
}

$this->setTags();
$this->configureScope($extraData, $tags);
$eventHint = EventHint::fromArray([
'stacktrace' => $this->prepareStacktrace()
]);
$this->setTags();
$sentryEventId = \Sentry\captureMessage($message, $severity, $eventHint);

if ($this->logger) {
$this->logger->log(
(string)$severity,
sprintf(
'%s (Sentry: %s)',
$message,
$sentryEventId
)
);
}
$sentryEventId = SentrySdk::getCurrentHub()->captureMessage($message, $severity, $eventHint);

return $sentryEventId;
return new CaptureResult(
true,
$message,
(string)$sentryEventId
);
}

private function configureScope(array $extraData, array $tags): void
Expand Down