diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f844b0516..30e4c60902 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Deprecate the `logger` option (#1167) - Pass the event hint from the `capture*()` methods down to the `before_send` callback (#1138) - Deprecate the `tags` option, see the [docs](https://docs.sentry.io/platforms/php/guides/laravel/enriching-events/tags/) for other ways to set tags (#1174) +- Make sure the `environment` field is set to `production` if it has not been overridden explicitly (#1116) ## 3.1.5 (2021-02-18) diff --git a/src/Client.php b/src/Client.php index f40e68fecf..87ceca46b9 100644 --- a/src/Client.php +++ b/src/Client.php @@ -242,7 +242,7 @@ private function prepareEvent(Event $event, ?EventHint $hint = null, ?Scope $sco } if (null === $event->getEnvironment()) { - $event->setEnvironment($this->options->getEnvironment()); + $event->setEnvironment($this->options->getEnvironment() ?? Event::DEFAULT_ENVIRONMENT); } if (null === $event->getLogger()) { diff --git a/src/Event.php b/src/Event.php index 60bf4ae8e5..6f0e582d4d 100644 --- a/src/Event.php +++ b/src/Event.php @@ -16,6 +16,8 @@ */ final class Event { + public const DEFAULT_ENVIRONMENT = 'production'; + /** * @var EventId The ID */ diff --git a/src/Options.php b/src/Options.php index 43c1963fe7..8b5c5bd17f 100644 --- a/src/Options.php +++ b/src/Options.php @@ -311,7 +311,7 @@ public function getRelease(): ?string /** * Sets the release tag to be passed with every event sent to Sentry. * - * @param string $release The release + * @param string|null $release The release */ public function setRelease(?string $release): void { diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 461f2aad93..304167725e 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -14,7 +14,6 @@ use Sentry\ClientBuilder; use Sentry\Event; use Sentry\EventHint; -use Sentry\EventId; use Sentry\ExceptionMechanism; use Sentry\Frame; use Sentry\Integration\IntegrationInterface; @@ -204,7 +203,9 @@ public function captureExceptionWithEventHintDataProvider(): \Generator */ public function testCaptureEvent(array $options, Event $event, Event $expectedEvent): void { - $this->expectDeprecation('The option "tags" is deprecated since version 3.2 and will be removed in 4.0. Either set the tags on the scope or on the event.'); + if (isset($options['tags'])) { + $this->expectDeprecation('The option "tags" is deprecated since version 3.2 and will be removed in 4.0. Either set the tags on the scope or on the event.'); + } $transport = $this->createMock(TransportInterface::class); $transport->expects($this->once()) @@ -224,8 +225,7 @@ public function testCaptureEvent(array $options, Event $event, Event $expectedEv public function captureEventDataProvider(): \Generator { - $eventId = EventId::generate(); - $event = Event::createEvent($eventId); + $event = Event::createEvent(); yield 'Options set && no event properties set => use options' => [ [ @@ -238,7 +238,7 @@ public function captureEventDataProvider(): \Generator $event, ]; - $event = Event::createEvent($eventId); + $event = Event::createEvent(); $event->setServerName('foo.example.com'); $event->setRelease('721e41770371db95eee98ca2707686226b993eda'); $event->setEnvironment('production'); @@ -254,6 +254,14 @@ public function captureEventDataProvider(): \Generator $event, $event, ]; + + $event = Event::createEvent(); + + yield 'Environment option set to null && no event property set => fallback to default value' => [ + ['environment' => null], + $event, + $event, + ]; } public function testCaptureEventWithEventHint(): void