Skip to content

Commit 8a77eb9

Browse files
dedpikhtojderusse
authored andcommitted
Add Sentry Hub instance in DI container to resolve event context issue
1 parent 888b54b commit 8a77eb9

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

DependencyInjection/MonologExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
757757
'Sentry\\State\\Hub',
758758
[new Reference($clientId)]
759759
);
760+
$container->setDefinition(sprintf('monolog.handler.%s.hub', $name), $hub);
760761

761762
// can't set the hub to the current hub, getting into a recursion otherwise...
762763
//$hub->addMethodCall('setCurrent', array($hub));

Tests/DependencyInjection/MonologExtensionTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,18 @@ public function testSentryHandlerWhenADSNIsSpecified()
393393
]]]]);
394394
$this->assertTrue($container->hasDefinition('monolog.logger'));
395395
$this->assertTrue($container->hasDefinition('monolog.handler.sentry'));
396+
$this->assertTrue($container->hasDefinition('monolog.handler.sentry.hub'));
396397

397398
$logger = $container->getDefinition('monolog.logger');
398399
$this->assertDICDefinitionMethodCallAt(0, $logger, 'useMicrosecondTimestamps', ['%monolog.use_microseconds%']);
399400
$this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', [new Reference('monolog.handler.sentry')]);
400401

401402
$handler = $container->getDefinition('monolog.handler.sentry');
402403
$this->assertDICDefinitionClass($handler, 'Sentry\Monolog\Handler');
404+
405+
$hub = $container->getDefinition('monolog.handler.sentry.hub');
406+
$this->assertDICDefinitionClass($hub, 'Sentry\State\Hub');
407+
$this->assertDICConstructorArguments($hub, [new Reference('monolog.sentry.client.'.sha1($dsn))]);
403408
}
404409

405410
public function testSentryHandlerWhenADSNAndAClientAreSpecified()

0 commit comments

Comments
 (0)