Skip to content

Commit

Permalink
Cleanup the deprecated returning of an event ID as a string instead o…
Browse files Browse the repository at this point in the history
…f as a value object (#1036)
  • Loading branch information
ste93cry committed Jul 6, 2020
1 parent ce982cc commit 2e329d5
Show file tree
Hide file tree
Showing 27 changed files with 159 additions and 121 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [BC BREAK] Remove the deprecated code that made the `Hub` class a singleton (#1038)
- [BC BREAK] Remove deprecated code that permitted to register the error, fatal error and exception handlers at once (#1037)
- [BC BREAK] Change the default value for the `error_types` option from `E_ALL` to the value get from `error_reporting()` (#1037)
- [BC BREAK] Remove deprecated code to return the event ID as a `string` rather than an object instance from the transport, the client and the hub (#1036)

### 2.4.1 (2020-07-03)

Expand Down
4 changes: 4 additions & 0 deletions UPGRADE-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
- The signature of the `FatalErrorListenerIntegration::__construct()` method changed to not accept any parameter
- The `ErrorListenerIntegration` integration does not get called anymore when a fatal error occurs
- The default value of the `error_types` option changed to the value get from `error_reporting()`
- The signature of the `capture*()` global functions changed to return an instance of the `Sentry\EventId` class instead of a `string`
- The signature of the `ClientInterface::capture*()` methods changed to return an instance of the `Sentry\EventId` class instead of a `string`
- The signature of the `HubInterface::capture*e()` methods changed to return an instance of the `Sentry\EventId` class instead of a `string`
- The signature of the `Event::getId()` method changed to return an instance of the `Sentry\EventId` class instead of a `string`
8 changes: 4 additions & 4 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function getOptions(): Options
/**
* {@inheritdoc}
*/
public function captureMessage(string $message, ?Severity $level = null, ?Scope $scope = null): ?string
public function captureMessage(string $message, ?Severity $level = null, ?Scope $scope = null): ?EventId
{
$payload = [
'message' => $message,
Expand All @@ -101,7 +101,7 @@ public function captureMessage(string $message, ?Severity $level = null, ?Scope
/**
* {@inheritdoc}
*/
public function captureException(\Throwable $exception, ?Scope $scope = null): ?string
public function captureException(\Throwable $exception, ?Scope $scope = null): ?EventId
{
if (!isset($this->integrations[IgnoreErrorsIntegration::class]) && $this->options->isExcludedException($exception, false)) {
return null;
Expand All @@ -113,7 +113,7 @@ public function captureException(\Throwable $exception, ?Scope $scope = null): ?
/**
* {@inheritdoc}
*/
public function captureEvent($payload, ?Scope $scope = null): ?string
public function captureEvent($payload, ?Scope $scope = null): ?EventId
{
$event = $this->prepareEvent($payload, $scope);

Expand All @@ -127,7 +127,7 @@ public function captureEvent($payload, ?Scope $scope = null): ?string
/**
* {@inheritdoc}
*/
public function captureLastError(?Scope $scope = null): ?string
public function captureLastError(?Scope $scope = null): ?EventId
{
$error = error_get_last();

Expand Down
8 changes: 4 additions & 4 deletions src/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,30 @@ public function getOptions(): Options;
* @param Severity $level The level of the message to be sent
* @param Scope|null $scope An optional scope keeping the state
*/
public function captureMessage(string $message, ?Severity $level = null, ?Scope $scope = null): ?string;
public function captureMessage(string $message, ?Severity $level = null, ?Scope $scope = null): ?EventId;

/**
* Logs an exception.
*
* @param \Throwable $exception The exception object
* @param Scope|null $scope An optional scope keeping the state
*/
public function captureException(\Throwable $exception, ?Scope $scope = null): ?string;
public function captureException(\Throwable $exception, ?Scope $scope = null): ?EventId;

/**
* Logs the most recent error (obtained with {@link error_get_last}).
*
* @param Scope|null $scope An optional scope keeping the state
*/
public function captureLastError(?Scope $scope = null): ?string;
public function captureLastError(?Scope $scope = null): ?EventId;

/**
* Captures a new event using the provided data.
*
* @param array<string, mixed>|Event $payload The data of the event being captured
* @param Scope|null $scope An optional scope keeping the state
*/
public function captureEvent($payload, ?Scope $scope = null): ?string;
public function captureEvent($payload, ?Scope $scope = null): ?EventId;

/**
* Returns the integration instance if it is installed on the client.
Expand Down
12 changes: 2 additions & 10 deletions src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,10 @@ public function __construct(?EventId $eventId = null)
}

/**
* Gets the UUID of this event.
*
* @return string|EventId
* Gets the ID of this event.
*/
public function getId(bool $returnAsString = true)
public function getId(): EventId
{
if ($returnAsString) {
@trigger_error(sprintf('Calling the method %s() and expecting it to return a string is deprecated since version 2.4 and will stop working in 3.0.', __METHOD__), E_USER_DEPRECATED);

return (string) $this->id;
}

return $this->id;
}

Expand Down
13 changes: 7 additions & 6 deletions src/State/Hub.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Sentry\Breadcrumb;
use Sentry\ClientInterface;
use Sentry\EventId;
use Sentry\Integration\IntegrationInterface;
use Sentry\Severity;
use Sentry\Tracing\Transaction;
Expand All @@ -22,7 +23,7 @@ final class Hub implements HubInterface
private $stack = [];

/**
* @var string|null The ID of the last captured event
* @var EventId|null The ID of the last captured event
*/
private $lastEventId;

Expand All @@ -48,7 +49,7 @@ public function getClient(): ?ClientInterface
/**
* {@inheritdoc}
*/
public function getLastEventId(): ?string
public function getLastEventId(): ?EventId
{
return $this->lastEventId;
}
Expand Down Expand Up @@ -111,7 +112,7 @@ public function bindClient(ClientInterface $client): void
/**
* {@inheritdoc}
*/
public function captureMessage(string $message, ?Severity $level = null): ?string
public function captureMessage(string $message, ?Severity $level = null): ?EventId
{
$client = $this->getClient();

Expand All @@ -125,7 +126,7 @@ public function captureMessage(string $message, ?Severity $level = null): ?strin
/**
* {@inheritdoc}
*/
public function captureException(\Throwable $exception): ?string
public function captureException(\Throwable $exception): ?EventId
{
$client = $this->getClient();

Expand All @@ -139,7 +140,7 @@ public function captureException(\Throwable $exception): ?string
/**
* {@inheritdoc}
*/
public function captureEvent($payload): ?string
public function captureEvent($payload): ?EventId
{
$client = $this->getClient();

Expand All @@ -153,7 +154,7 @@ public function captureEvent($payload): ?string
/**
* {@inheritdoc}
*/
public function captureLastError(): ?string
public function captureLastError(): ?EventId
{
$client = $this->getClient();

Expand Down
11 changes: 6 additions & 5 deletions src/State/HubAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Sentry\Breadcrumb;
use Sentry\ClientInterface;
use Sentry\EventId;
use Sentry\Integration\IntegrationInterface;
use Sentry\SentrySdk;
use Sentry\Severity;
Expand Down Expand Up @@ -54,7 +55,7 @@ public function getClient(): ?ClientInterface
/**
* {@inheritdoc}
*/
public function getLastEventId(): ?string
public function getLastEventId(): ?EventId
{
return SentrySdk::getCurrentHub()->getLastEventId();
}
Expand Down Expand Up @@ -102,31 +103,31 @@ public function bindClient(ClientInterface $client): void
/**
* {@inheritdoc}
*/
public function captureMessage(string $message, ?Severity $level = null): ?string
public function captureMessage(string $message, ?Severity $level = null): ?EventId
{
return SentrySdk::getCurrentHub()->captureMessage($message, $level);
}

/**
* {@inheritdoc}
*/
public function captureException(\Throwable $exception): ?string
public function captureException(\Throwable $exception): ?EventId
{
return SentrySdk::getCurrentHub()->captureException($exception);
}

/**
* {@inheritdoc}
*/
public function captureEvent($payload): ?string
public function captureEvent($payload): ?EventId
{
return SentrySdk::getCurrentHub()->captureEvent($payload);
}

/**
* {@inheritdoc}
*/
public function captureLastError(): ?string
public function captureLastError(): ?EventId
{
return SentrySdk::getCurrentHub()->captureLastError();
}
Expand Down
11 changes: 6 additions & 5 deletions src/State/HubInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Sentry\Breadcrumb;
use Sentry\ClientInterface;
use Sentry\Event;
use Sentry\EventId;
use Sentry\Integration\IntegrationInterface;
use Sentry\Severity;
use Sentry\Tracing\Transaction;
Expand All @@ -27,7 +28,7 @@ public function getClient(): ?ClientInterface;
/**
* Gets the ID of the last captured event.
*/
public function getLastEventId(): ?string;
public function getLastEventId(): ?EventId;

/**
* Creates a new scope to store context information that will be layered on
Expand Down Expand Up @@ -74,26 +75,26 @@ public function bindClient(ClientInterface $client): void;
* @param string $message The message
* @param Severity $level The severity level of the message
*/
public function captureMessage(string $message, ?Severity $level = null): ?string;
public function captureMessage(string $message, ?Severity $level = null): ?EventId;

/**
* Captures an exception event and sends it to Sentry.
*
* @param \Throwable $exception The exception
*/
public function captureException(\Throwable $exception): ?string;
public function captureException(\Throwable $exception): ?EventId;

/**
* Captures a new event using the provided data.
*
* @param Event|array<string, mixed> $payload The data of the event being captured
*/
public function captureEvent($payload): ?string;
public function captureEvent($payload): ?EventId;

/**
* Captures an event that logs the last occurred error.
*/
public function captureLastError(): ?string;
public function captureLastError(): ?EventId;

/**
* Records a new breadcrumb which will be attached to future events. They
Expand Down
5 changes: 3 additions & 2 deletions src/Tracing/Span.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Sentry\Context\Context;
use Sentry\Context\TagsContext;
use Sentry\EventId;

/**
* This class stores all the information about a Span.
Expand Down Expand Up @@ -112,9 +113,9 @@ public function __construct(?SpanContext $context = null)
*
* @param float|null $endTimestamp Takes an endTimestamp if the end should not be the time when you call this function
*
* @return string|null Finish for a span always returns null
* @return EventId|null Finish for a span always returns null
*/
public function finish($endTimestamp = null): ?string
public function finish($endTimestamp = null): ?EventId
{
$this->endTimestamp = $endTimestamp ?? microtime(true);

Expand Down
5 changes: 3 additions & 2 deletions src/Tracing/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Sentry\Tracing;

use Sentry\Event;
use Sentry\EventId;
use Sentry\Severity;
use Sentry\State\HubInterface;

Expand Down Expand Up @@ -74,9 +75,9 @@ public function initSpanRecorder(): void
/**
* {@inheritdoc}
*
* @return string|null Finish for a transaction returns the eventId or null in case we didn't send it
* @return EventId|null Finish for a transaction returns the eventId or null in case we didn't send it
*/
public function finish($endTimestamp = null): ?string
public function finish($endTimestamp = null): ?EventId
{
if (null !== $this->endTimestamp) {
// Transaction was already finished once and we don't want to re-flush it
Expand Down
5 changes: 3 additions & 2 deletions src/Transport/HttpTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Psr\Log\NullLogger;
use Sentry\Dsn;
use Sentry\Event;
use Sentry\EventId;
use Sentry\Options;
use Sentry\Util\JSON;

Expand Down Expand Up @@ -109,7 +110,7 @@ public function __destruct()
/**
* {@inheritdoc}
*/
public function send(Event $event): ?string
public function send(Event $event): ?EventId
{
$dsn = $this->options->getDsn(false);

Expand Down Expand Up @@ -151,7 +152,7 @@ public function send(Event $event): ?string
}
}

return (string) $event->getId(false);
return $event->getId();
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Transport/NullTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Sentry\Transport;

use Sentry\Event;
use Sentry\EventId;

/**
* This transport fakes the sending of events by just ignoring them.
Expand All @@ -18,8 +19,8 @@ class NullTransport implements TransportInterface
/**
* {@inheritdoc}
*/
public function send(Event $event): ?string
public function send(Event $event): ?EventId
{
return (string) $event->getId(false);
return $event->getId();
}
}
5 changes: 3 additions & 2 deletions src/Transport/SpoolTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Sentry\Transport;

use Sentry\Event;
use Sentry\EventId;
use Sentry\Spool\SpoolInterface;

/**
Expand Down Expand Up @@ -40,10 +41,10 @@ public function getSpool(): SpoolInterface
/**
* {@inheritdoc}
*/
public function send(Event $event): ?string
public function send(Event $event): ?EventId
{
if ($this->spool->queueEvent($event)) {
return (string) $event->getId(false);
return $event->getId();
}

return null;
Expand Down
5 changes: 3 additions & 2 deletions src/Transport/TransportInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Sentry\Transport;

use Sentry\Event;
use Sentry\EventId;

/**
* This interface must be implemented by all classes willing to provide a way
Expand All @@ -19,7 +20,7 @@ interface TransportInterface
*
* @param Event $event The event
*
* @return string|null Returns the ID of the event or `null` if it failed to be sent
* @return EventId|null Returns the ID of the event or `null` if it failed to be sent
*/
public function send(Event $event): ?string;
public function send(Event $event): ?EventId;
}

0 comments on commit 2e329d5

Please sign in to comment.