-
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Sentry BreadcrumbHandler support
- Loading branch information
Showing
3 changed files
with
92 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -371,12 +371,10 @@ public function testRavenHandlerWhenAClientIsSpecified() | |
|
||
public function testSentryHandlerWhenConfigurationIsWrong() | ||
{ | ||
try { | ||
$this->getContainer([['handlers' => ['sentry' => ['type' => 'sentry']]]]); | ||
$this->fail(); | ||
} catch (InvalidConfigurationException $e) { | ||
$this->assertStringContainsString('DSN', $e->getMessage()); | ||
} | ||
$this->expectException(InvalidConfigurationException::class); | ||
$this->expectExceptionMessage('The DSN has to be specified to use Sentry\'s handler'); | ||
|
||
$this->getContainer([['handlers' => ['sentry' => ['type' => 'sentry']]]]); | ||
} | ||
|
||
public function testSentryHandlerWhenADSNIsSpecified() | ||
|
@@ -426,7 +424,10 @@ public function testSentryHandlerWhenADSNAndAClientAreSpecified() | |
$this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', [new Reference('monolog.handler.sentry')]); | ||
|
||
$handler = $container->getDefinition('monolog.handler.sentry'); | ||
$this->assertDICConstructorArguments($handler->getArguments()[0], [new Reference('sentry.client')]); | ||
$this->assertDICConstructorArguments($handler, [new Reference('monolog.handler.sentry.hub'), 'DEBUG', true, false]); | ||
|
||
$hub = $container->getDefinition($handler->getArguments()[0]); | ||
$this->assertDICConstructorArguments($hub, [new Reference('sentry.client')]); | ||
} | ||
|
||
public function testSentryHandlerWhenAClientIsSpecified() | ||
|
@@ -452,7 +453,10 @@ public function testSentryHandlerWhenAClientIsSpecified() | |
$this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', [new Reference('monolog.handler.sentry')]); | ||
|
||
$handler = $container->getDefinition('monolog.handler.sentry'); | ||
$this->assertDICConstructorArguments($handler->getArguments()[0], [new Reference('sentry.client')]); | ||
$this->assertDICConstructorArguments($handler, [new Reference('monolog.handler.sentry.hub'), 'DEBUG', true, false]); | ||
|
||
$hub = $container->getDefinition($handler->getArguments()[0]); | ||
$this->assertDICConstructorArguments($hub, [new Reference('sentry.client')]); | ||
} | ||
|
||
public function testSentryHandlerWhenAHubIsSpecified() | ||
|
@@ -501,6 +505,51 @@ public function testSentryHandlerWhenAHubAndAClientAreSpecified() | |
); | ||
} | ||
|
||
public function testSentryBreadcrumbHandlerWhenConfigurationIsWrong() | ||
{ | ||
$this->expectException(InvalidConfigurationException::class); | ||
$this->expectExceptionMessage('The sentry_handler has to be specified to use a Sentry BreadcrumbHandler'); | ||
|
||
$this->getContainer([['handlers' => ['sentry_breadcrumb' => ['type' => 'sentry_breadcrumb']]]]); | ||
} | ||
|
||
/** | ||
* @testWith [{"dsn": "http://a:[email protected]:9000/1"}, "monolog.handler.sentry.hub"] | ||
* [{"hub_id": "sentry.hub"}, "sentry.hub"] | ||
*/ | ||
public function testSentryBreadcrumbHandlerWhenConfigurationIsOk(array $config, string $hubId) | ||
{ | ||
$container = $this->getContainer( | ||
[ | ||
[ | ||
'handlers' => [ | ||
'sentry_breadcrumb' => ['type' => 'sentry_breadcrumb', 'sentry_handler' => 'sentry'], | ||
'sentry' => ['type' => 'sentry'] + $config, | ||
], | ||
], | ||
], | ||
[ | ||
'sentry.hub' => new Definition(\Sentry\State\HubInterface::class), | ||
] | ||
); | ||
|
||
$this->assertTrue($container->hasDefinition('monolog.logger')); | ||
$this->assertTrue($container->hasDefinition('monolog.handler.sentry')); | ||
$this->assertTrue($container->hasDefinition('monolog.handler.sentry_breadcrumb')); | ||
|
||
$logger = $container->getDefinition('monolog.logger'); | ||
$this->assertDICDefinitionMethodCallAt(0, $logger, 'useMicrosecondTimestamps', ['%monolog.use_microseconds%']); | ||
$this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', [new Reference('monolog.handler.sentry')]); | ||
$this->assertDICDefinitionMethodCallAt(2, $logger, 'pushHandler', [new Reference('monolog.handler.sentry_breadcrumb')]); | ||
|
||
$handler = $container->getDefinition('monolog.handler.sentry_breadcrumb'); | ||
$this->assertDICDefinitionClass($handler, 'Sentry\Monolog\BreadcrumbHandler'); | ||
$this->assertDICConstructorArguments($handler, [new Reference($hubId), 'DEBUG', true]); | ||
|
||
$sentry = $container->getDefinition('monolog.handler.sentry'); | ||
$this->assertSame((string) $sentry->getArgument(0), (string) $handler->getArgument(0)); | ||
} | ||
|
||
public function testLogglyHandler() | ||
{ | ||
$token = '026308d8-2b63-4225-8fe9-e01294b6e472'; | ||
|