From 85004c48799ce03a3f57ea97a9cf18e78b037cdf Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Wed, 6 Jan 2021 20:09:15 +0100 Subject: [PATCH] Fix the logger option not being applied to the event object --- CHANGELOG.md | 1 + src/Client.php | 4 ++++ tests/ClientTest.php | 45 ++++++++++++++++++++++---------------------- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf99830746..90136affcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - Fix unwanted call to the `before_send` callback with transaction events, use `traces_sampler` instead to filter transactions (#1158) +- Fix the `logger` option not being applied to the event object (#1165) ## 3.1.1 (2020-12-07) diff --git a/src/Client.php b/src/Client.php index 51606745ba..35081c4af7 100644 --- a/src/Client.php +++ b/src/Client.php @@ -232,6 +232,10 @@ private function prepareEvent(Event $event, ?EventHint $hint = null, ?Scope $sco $event->setTags($this->options->getTags()); $event->setEnvironment($this->options->getEnvironment()); + if (null === $event->getLogger()) { + $event->setLogger($this->options->getLogger()); + } + $isTransaction = EventType::transaction() === $event->getType(); $sampleRate = $this->options->getSampleRate(); diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 3c2b219b83..112c4cb266 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -454,29 +454,6 @@ public function testFlush(): void $this->assertTrue($promise->wait()); } - private function createTransportFactory(TransportInterface $transport): TransportFactoryInterface - { - return new class($transport) implements TransportFactoryInterface { - /** - * @var TransportInterface - */ - private $transport; - - public function __construct(TransportInterface $transport) - { - $this->transport = $transport; - } - - public function create(Options $options): TransportInterface - { - return $this->transport; - } - }; - } - - /** - * @backupGlobals - */ public function testBuildEventWithDefaultValues(): void { $options = new Options(); @@ -484,6 +461,7 @@ public function testBuildEventWithDefaultValues(): void $options->setRelease('testRelease'); $options->setTags(['test' => 'tag']); $options->setEnvironment('testEnvironment'); + $options->setLogger('app.logger'); /** @var TransportInterface&MockObject $transport */ $transport = $this->createMock(TransportInterface::class); @@ -496,6 +474,7 @@ public function testBuildEventWithDefaultValues(): void $this->assertSame($options->getRelease(), $event->getRelease()); $this->assertSame($options->getTags(), $event->getTags()); $this->assertSame($options->getEnvironment(), $event->getEnvironment()); + $this->assertSame($options->getLogger(), $event->getLogger()); $this->assertNull($event->getStacktrace()); return true; @@ -642,4 +621,24 @@ public function testBuildWithStacktrace(): void $client->captureEvent(Event::createEvent()); } + + private function createTransportFactory(TransportInterface $transport): TransportFactoryInterface + { + return new class($transport) implements TransportFactoryInterface { + /** + * @var TransportInterface + */ + private $transport; + + public function __construct(TransportInterface $transport) + { + $this->transport = $transport; + } + + public function create(Options $options): TransportInterface + { + return $this->transport; + } + }; + } }