From 8a77eb9792cc71ced6de40420b45961bd95ac802 Mon Sep 17 00:00:00 2001 From: Dmitriy Ivanchuk Date: Fri, 5 Mar 2021 21:23:19 +0300 Subject: [PATCH] Add Sentry Hub instance in DI container to resolve event context issue --- DependencyInjection/MonologExtension.php | 1 + Tests/DependencyInjection/MonologExtensionTest.php | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/DependencyInjection/MonologExtension.php b/DependencyInjection/MonologExtension.php index 3ad15948..d927ab01 100644 --- a/DependencyInjection/MonologExtension.php +++ b/DependencyInjection/MonologExtension.php @@ -757,6 +757,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler 'Sentry\\State\\Hub', [new Reference($clientId)] ); + $container->setDefinition(sprintf('monolog.handler.%s.hub', $name), $hub); // can't set the hub to the current hub, getting into a recursion otherwise... //$hub->addMethodCall('setCurrent', array($hub)); diff --git a/Tests/DependencyInjection/MonologExtensionTest.php b/Tests/DependencyInjection/MonologExtensionTest.php index 7846ebd4..573523da 100644 --- a/Tests/DependencyInjection/MonologExtensionTest.php +++ b/Tests/DependencyInjection/MonologExtensionTest.php @@ -393,6 +393,7 @@ public function testSentryHandlerWhenADSNIsSpecified() ]]]]); $this->assertTrue($container->hasDefinition('monolog.logger')); $this->assertTrue($container->hasDefinition('monolog.handler.sentry')); + $this->assertTrue($container->hasDefinition('monolog.handler.sentry.hub')); $logger = $container->getDefinition('monolog.logger'); $this->assertDICDefinitionMethodCallAt(0, $logger, 'useMicrosecondTimestamps', ['%monolog.use_microseconds%']); @@ -400,6 +401,10 @@ public function testSentryHandlerWhenADSNIsSpecified() $handler = $container->getDefinition('monolog.handler.sentry'); $this->assertDICDefinitionClass($handler, 'Sentry\Monolog\Handler'); + + $hub = $container->getDefinition('monolog.handler.sentry.hub'); + $this->assertDICDefinitionClass($hub, 'Sentry\State\Hub'); + $this->assertDICConstructorArguments($hub, [new Reference('monolog.sentry.client.'.sha1($dsn))]); } public function testSentryHandlerWhenADSNAndAClientAreSpecified()