From cf943e23d6f28b3c596abeae106de8f9b4b5e9c3 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Wed, 9 Oct 2024 19:32:19 +0200 Subject: [PATCH 1/4] Merge and move Symfony Monolog docs --- docs/platforms/php/guides/symfony/index.mdx | 23 ++----------------- .../guides/symfony/integrations/monolog.mdx | 6 ++++- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/docs/platforms/php/guides/symfony/index.mdx b/docs/platforms/php/guides/symfony/index.mdx index f712d372373ad..f7dc760bd5240 100644 --- a/docs/platforms/php/guides/symfony/index.mdx +++ b/docs/platforms/php/guides/symfony/index.mdx @@ -17,11 +17,12 @@ Install the `sentry/sentry-symfony` bundle: composer require sentry/sentry-symfony ``` +If you are using [Monolog](https://github.com/Seldaek/monolog) to report events instead of the typical error listener approach, you need this [additional configuration](integrations/monolog/) to log the errors correctly. + ## Configure Add your DSN to your `.env` file: - ```plain {filename:.env} ###> sentry/sentry-symfony ### SENTRY_DSN="___PUBLIC_DSN___" @@ -32,26 +33,6 @@ SENTRY_DSN="___PUBLIC_DSN___" In order to receive stack trace arguments in your errors, make sure to set `zend.exception_ignore_args: Off` in your php.ini -### Monolog Integration - -If you are using [Monolog](https://github.com/Seldaek/monolog) to report events instead of the typical error listener approach, you need this additional configuration to log the errors correctly: - -{/* */} -```yaml {filename:config/packages/sentry.yaml} -sentry: - register_error_listener: false # Disables the ErrorListener to avoid duplicated log in sentry - register_error_handler: false # Disables the ErrorListener, ExceptionListener and FatalErrorListener integrations of the base PHP SDK - -monolog: - handlers: - sentry: - type: sentry - level: !php/const Monolog\Logger::ERROR - hub_id: Sentry\State\HubInterface - fill_extra_context: true # Enables sending monolog context to Sentry - process_psr_3_messages: false # Disables the resolution of PSR-3 placeholders in reported messages -``` - ## Verify To test that both logger error and exception are correctly sent to sentry.io, you can create the following controller: diff --git a/docs/platforms/php/guides/symfony/integrations/monolog.mdx b/docs/platforms/php/guides/symfony/integrations/monolog.mdx index c6e25c034ed31..eb0d63ee27f22 100644 --- a/docs/platforms/php/guides/symfony/integrations/monolog.mdx +++ b/docs/platforms/php/guides/symfony/integrations/monolog.mdx @@ -6,7 +6,11 @@ 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 +```yaml {filename:config/packages/sentry.yaml} +sentry: + register_error_listener: false # Disables the ErrorListener to avoid duplicated log in sentry + register_error_handler: false # Disables the ErrorListener, ExceptionListener and FatalErrorListener integrations of the base PHP SDK + services: # Configure the breadcrumb handler as a service Sentry\Monolog\BreadcrumbHandler: From 11891de53e0f93d5ccd9c0cab64757302369fdf1 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Wed, 9 Oct 2024 19:32:40 +0200 Subject: [PATCH 2/4] Update Laravel log channels note --- docs/platforms/php/guides/laravel/index.mdx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/platforms/php/guides/laravel/index.mdx b/docs/platforms/php/guides/laravel/index.mdx index a5f7498446daa..ddc6aa04da449 100644 --- a/docs/platforms/php/guides/laravel/index.mdx +++ b/docs/platforms/php/guides/laravel/index.mdx @@ -41,23 +41,22 @@ return Application::configure(basePath: dirname(__DIR__)) }) ->withExceptions(function (Exceptions $exceptions) { Integration::handles($exceptions); - })->create(); + }) + ->create(); ``` -Alternatively, you can configure Sentry in your [Laravel Log Channel](usage/#log-channels), allowing you to log `info` and `debug` as well. +Alternatively, you can configure Sentry as a [Laravel Log Channel](usage/#log-channels). ## Configure Configure the Sentry DSN with this command: - ```shell php artisan sentry:publish --dsn=___PUBLIC_DSN___ ``` It creates the config file (`config/sentry.php`) and adds the `DSN` to your `.env` file. - ```shell {filename:.env} SENTRY_LARAVEL_DSN=___PUBLIC_DSN___ ``` From 1ceb8d313d97aba08d3e15ec261a7021c48fa87b Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Wed, 9 Oct 2024 19:42:45 +0200 Subject: [PATCH 3/4] Fix missing options --- docs/platforms/php/guides/symfony/integrations/monolog.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/platforms/php/guides/symfony/integrations/monolog.mdx b/docs/platforms/php/guides/symfony/integrations/monolog.mdx index eb0d63ee27f22..2fb59d15ff7e5 100644 --- a/docs/platforms/php/guides/symfony/integrations/monolog.mdx +++ b/docs/platforms/php/guides/symfony/integrations/monolog.mdx @@ -30,4 +30,6 @@ monolog: type: sentry level: !php/const Monolog\Logger::ERROR # Configures the level of messages to capture as events hub_id: Sentry\State\HubInterface + fill_extra_context: true # Enables sending monolog context to Sentry + process_psr_3_messages: false # Disables the resolution of PSR-3 placeholders in reported messages ``` From 54f83ec150d877b814927bb7eec5ab015bfb8531 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Wed, 9 Oct 2024 19:44:05 +0200 Subject: [PATCH 4/4] Mark breadcrumb handler as optional --- docs/platforms/php/guides/symfony/integrations/monolog.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/platforms/php/guides/symfony/integrations/monolog.mdx b/docs/platforms/php/guides/symfony/integrations/monolog.mdx index 2fb59d15ff7e5..9168f7fb71a03 100644 --- a/docs/platforms/php/guides/symfony/integrations/monolog.mdx +++ b/docs/platforms/php/guides/symfony/integrations/monolog.mdx @@ -12,7 +12,7 @@ sentry: register_error_handler: false # Disables the ErrorListener, ExceptionListener and FatalErrorListener integrations of the base PHP SDK services: - # Configure the breadcrumb handler as a service + # (Optionally) Configure the breadcrumb handler as a service (needed for the breadcrumb Monolog handler) Sentry\Monolog\BreadcrumbHandler: arguments: - '@Sentry\State\HubInterface' @@ -20,7 +20,7 @@ services: monolog: handlers: - # Register the breadcrumb handler as a Monolog handler + # (Optionally) Register the breadcrumb handler as a Monolog handler sentry_breadcrumbs: type: service name: sentry_breadcrumbs