Skip to content

Commit

Permalink
Add Sentry Hub instance in DI container to resolve event context issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dedpikhto authored and jderusse committed Mar 21, 2021
1 parent 888b54b commit 8a77eb9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions DependencyInjection/MonologExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
5 changes: 5 additions & 0 deletions Tests/DependencyInjection/MonologExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,18 @@ 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%']);
$this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', [new Reference('monolog.handler.sentry')]);

$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()
Expand Down

0 comments on commit 8a77eb9

Please sign in to comment.