diff --git a/docs/platforms/php/common/integrations/monolog.mdx b/docs/platforms/php/common/integrations/monolog.mdx new file mode 100644 index 0000000000000..78209b823427e --- /dev/null +++ b/docs/platforms/php/common/integrations/monolog.mdx @@ -0,0 +1,43 @@ +--- +title: Monolog +description: "Learn how to enable Sentry's PHP SDK to capture Monolog events." +--- + +When using [Monolog](https://github.com/Seldaek/monolog) you can configure a [breadcrumb](../../enriching-events/breadcrumbs/) handler to capture Monolog messages as breadcrumbs and a handler that captures messages as events in Sentry. +The breadcrumb handler will not send anything to Sentry directly, it only records breadcrumbs that will be attached to any event or exception sent to Sentry. + +```php + '___PUBLIC_DSN___' +]); + +// Create a Monolog channel with a breadcrumb handler and a Sentry handler +$log = new Logger('sentry'); +$log->pushHandler(new \Sentry\Monolog\BreadcrumbHandler( + hub: \Sentry\SentrySdk::getCurrentHub(), + level: Level::Info, // Take note of the level here, messages with that level or higher will be attached to future Sentry events as breadcrumbs +)); +$log->pushHandler(new \Sentry\Monolog\Handler( + hub: \Sentry\SentrySdk::getCurrentHub(), + level: Level::Error, // Take note of the level here, messages with that level or higher will be sent to Sentry + bubble: true, + fillExtraContext: false, // Will add a `monolog.context` & `monolog.extra`, key to the event with the Monolog `context` & `extra` values +)); + +// Log an error: +$log->error('Something bad happened'); + +// To log an exception you can use the following code: +try { + throw new RuntimeException('Some exception'); +} catch (RuntimeException $exception) { + $log->error('Some exception happened', ['exception' => $exception]); +} +``` diff --git a/docs/platforms/php/guides/symfony/integrations/monolog.mdx b/docs/platforms/php/guides/symfony/integrations/monolog.mdx new file mode 100644 index 0000000000000..c6e25c034ed31 --- /dev/null +++ b/docs/platforms/php/guides/symfony/integrations/monolog.mdx @@ -0,0 +1,29 @@ +--- +title: Monolog +description: "Learn how to enable Sentry's Symfony SDK to capture Monolog events." +--- + +When using [Monolog](https://github.com/Seldaek/monolog) you can configure a [breadcrumb](../../enriching-events/breadcrumbs/) handler to capture Monolog messages as breadcrumbs and a handler that captures messages as events in Sentry. +The breadcrumb handler will not send anything to Sentry directly, it only records breadcrumbs that will be attached to any event or exception sent to Sentry. + +```yaml +services: + # Configure the breadcrumb handler as a service + Sentry\Monolog\BreadcrumbHandler: + arguments: + - '@Sentry\State\HubInterface' + - !php/const Monolog\Logger::INFO # Configures the level of messages to capture as breadcrumbs + +monolog: + handlers: + # Register the breadcrumb handler as a Monolog handler + sentry_breadcrumbs: + type: service + name: sentry_breadcrumbs + id: Sentry\Monolog\BreadcrumbHandler + # Register the handler as a Monolog handler to capture messages as events + sentry: + type: sentry + level: !php/const Monolog\Logger::ERROR # Configures the level of messages to capture as events + hub_id: Sentry\State\HubInterface +```