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
  • Loading branch information
ste93cry committed Jul 4, 2020
1 parent 8544f70 commit cb06986
Show file tree
Hide file tree
Showing 27 changed files with 167 additions and 117 deletions.
1 change: 1 addition & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ branches:
- master
- develop
- /^release\/.+$/
- 3.x

environment:
matrix:
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ branches:
- master
- develop
- /^release\/.+$/
- 3.x

php:
- 7.1
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- 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)

- Fix HTTP client connection timeouts not being applied if an HTTP proxy is specified (#1033)
Expand Down
15 changes: 15 additions & 0 deletions UPGRADE-3.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Upgrade from 2.x to 3.0

- The signature of the `captureMessage()` global function changed to return an instance of the `Sentry\EventId` class instead of a `string`
- The signature of the `captureException()` global function changed to return an instance of the `Sentry\EventId` class instead of a `string`
- The signature of the `captureEvent()` global function changed to return an instance of the `Sentry\EventId` class instead of a `string`
- The signature of the `captureLastError()` global function changed to return an instance of the `Sentry\EventId` class instead of a `string`
- The signature of the `ClientInterface::captureMessage()` method changed to return an instance of the `Sentry\EventId` class instead of a `string`
- The signature of the `ClientInterface::captureException()` method changed to return an instance of the `Sentry\EventId` class instead of a `string`
- The signature of the `ClientInterface::captureEvent()` method changed to return an instance of the `Sentry\EventId` class instead of a `string`
- The signature of the `ClientInterface::captureLastError()` method changed to return an instance of the `Sentry\EventId` class instead of a `string`
- The signature of the `HubInterface::captureMessage()` method changed to return an instance of the `Sentry\EventId` class instead of a `string`
- The signature of the `HubInterface::captureException()` method changed to return an instance of the `Sentry\EventId` class instead of a `string`
- The signature of the `HubInterface::captureEvent()` method changed to return an instance of the `Sentry\EventId` class instead of a `string`
- The signature of the `HubInterface::captureLastError()` method 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(array $payload, ?Scope $scope = null): ?string
public function captureEvent(array $payload, ?Scope $scope = null): ?EventId
{
$event = $this->prepareEvent($payload, $scope);

Expand All @@ -127,7 +127,7 @@ public function captureEvent(array $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> $payload The data of the event being captured
* @param Scope|null $scope An optional scope keeping the state
*/
public function captureEvent(array $payload, ?Scope $scope = null): ?string;
public function captureEvent(array $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 @@ -168,18 +168,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\SentrySdk;
use Sentry\Severity;
Expand All @@ -21,7 +22,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 @@ -47,7 +48,7 @@ public function getClient(): ?ClientInterface
/**
* {@inheritdoc}
*/
public function getLastEventId(): ?string
public function getLastEventId(): ?EventId
{
return $this->lastEventId;
}
Expand Down Expand Up @@ -110,7 +111,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 @@ -124,7 +125,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 @@ -138,7 +139,7 @@ public function captureException(\Throwable $exception): ?string
/**
* {@inheritdoc}
*/
public function captureEvent(array $payload): ?string
public function captureEvent(array $payload): ?EventId
{
$client = $this->getClient();

Expand All @@ -152,7 +153,7 @@ public function captureEvent(array $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 @@ -52,7 +53,7 @@ public function getClient(): ?ClientInterface
/**
* {@inheritdoc}
*/
public function getLastEventId(): ?string
public function getLastEventId(): ?EventId
{
return SentrySdk::getCurrentHub()->getLastEventId();
}
Expand Down Expand Up @@ -100,31 +101,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(array $payload): ?string
public function captureEvent(array $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 @@ -6,6 +6,7 @@

use Sentry\Breadcrumb;
use Sentry\ClientInterface;
use Sentry\EventId;
use Sentry\Integration\IntegrationInterface;
use Sentry\Severity;

Expand All @@ -24,7 +25,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 @@ -71,26 +72,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 array<string, mixed> $payload The data of the event being captured
*/
public function captureEvent(array $payload): ?string;
public function captureEvent(array $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/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 @@ -142,7 +143,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 cb06986

Please sign in to comment.