From 70408d2515b4d34d37097dd4861cd24da112e6ec Mon Sep 17 00:00:00 2001 From: Martin Linzmayer Date: Mon, 1 Sep 2025 18:12:41 +0200 Subject: [PATCH 1/7] feat(logs): add documentation for symfony logging --- .../logs/default-attributes/php.symfony.mdx | 11 +++++ .../logs/options/php.symfony.mdx | 45 +++++++++++++++++++ .../logs/requirements/php.symfony.mdx | 1 + platform-includes/logs/setup/php.symfony.mdx | 26 +++++++++++ platform-includes/logs/usage/php.symfony.mdx | 17 +++++++ 5 files changed, 100 insertions(+) create mode 100644 platform-includes/logs/default-attributes/php.symfony.mdx create mode 100644 platform-includes/logs/options/php.symfony.mdx create mode 100644 platform-includes/logs/requirements/php.symfony.mdx create mode 100644 platform-includes/logs/setup/php.symfony.mdx create mode 100644 platform-includes/logs/usage/php.symfony.mdx diff --git a/platform-includes/logs/default-attributes/php.symfony.mdx b/platform-includes/logs/default-attributes/php.symfony.mdx new file mode 100644 index 00000000000000..fbff5a7e66e947 --- /dev/null +++ b/platform-includes/logs/default-attributes/php.symfony.mdx @@ -0,0 +1,11 @@ +The Symfony SDK automatically sets several default attributes on all log entries to provide context and improve debugging: + + + + + + + + + + diff --git a/platform-includes/logs/options/php.symfony.mdx b/platform-includes/logs/options/php.symfony.mdx new file mode 100644 index 00000000000000..2d00e586450b69 --- /dev/null +++ b/platform-includes/logs/options/php.symfony.mdx @@ -0,0 +1,45 @@ +#### before_send_log + +To filter logs, or update them before they are sent to Sentry, you can use the `before_send_log` option. + +```yaml {filename:config/packages/sentry.yaml} +sentry: + options: + before_send_log: "sentry.callback.before_send_log" + +services: + sentry.callback.before_send_log: + class: 'App\Service\Sentry' + factory: ['@App\Service\Sentry', 'getBeforeSendLog'] +``` + +The service needed for the `before_send_log` option can be implemented as follows: + +```php {filename:src/Service/Sentry.php} +getLevel() === \Sentry\Logs\LogLevel::info()) { + // Filter out all info logs + return null; + } + + return $log; + }; + } +} +``` + + + + Learn more in [Callables in Symfony Options](/platforms/php/guides/symfony/configuration/symfony-options/#callables). + + + +The `before_send_log` function receives a log object, and should return the log object if you want it to be sent to Sentry, or `null` if you want to discard it. diff --git a/platform-includes/logs/requirements/php.symfony.mdx b/platform-includes/logs/requirements/php.symfony.mdx new file mode 100644 index 00000000000000..f9bf232b3b502b --- /dev/null +++ b/platform-includes/logs/requirements/php.symfony.mdx @@ -0,0 +1 @@ +Logs for Symfony are supported in Sentry Symfony SDK version `5.4` and above. diff --git a/platform-includes/logs/setup/php.symfony.mdx b/platform-includes/logs/setup/php.symfony.mdx new file mode 100644 index 00000000000000..70e0b76f43b347 --- /dev/null +++ b/platform-includes/logs/setup/php.symfony.mdx @@ -0,0 +1,26 @@ +To configure Sentry logging, you need to add the Monolog handler to your configuration: + +```yaml {filename: monolog.yaml} +monolog: + handlers: + sentry_logs: + type: service + id: Sentry\SentryBundle\Monolog\LogsHandler +``` + +Configure the service and choose a minimum log level: + +```yaml {filename: config/packages/sentry.yaml} +services: + Sentry\SentryBundle\Monolog\LogsHandler: + arguments: + - !php/const Monolog\Logger::INFO +``` + +Enable the logs option: + +```yaml {filename: config/packages/sentry.yaml} +sentry: + options: + enable_logs: true +``` diff --git a/platform-includes/logs/usage/php.symfony.mdx b/platform-includes/logs/usage/php.symfony.mdx new file mode 100644 index 00000000000000..b31ee3f5acb9f6 --- /dev/null +++ b/platform-includes/logs/usage/php.symfony.mdx @@ -0,0 +1,17 @@ +Once you have configured the Sentry log handler, you can use your regular `LoggerInterface`. It will send logs to Sentry: + +```php +$this->logger->info("This is an info message"); +$this->logger->warning('User {id} failed to login.', ['id' => $user->id]); +$this->logger->error("This is an error message"); +``` + +You can pass additional attributes directly to the logging functions. These properties will be sent to Sentry, and can be searched from within the Logs UI, and even added to the Logs views as a dedicated column. + +```php +$this->logger->error('Something went wrong', [ + 'user_id' => $userId, + 'action' => 'update_profile', + 'additional_data' => $data, +]); +``` From 3c293eb8a011817990b83d1bf02fc8310c177074 Mon Sep 17 00:00:00 2001 From: Martin Linzmayer Date: Mon, 1 Sep 2025 18:25:43 +0200 Subject: [PATCH 2/7] update file path --- platform-includes/logs/setup/php.symfony.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform-includes/logs/setup/php.symfony.mdx b/platform-includes/logs/setup/php.symfony.mdx index 70e0b76f43b347..fbcb13a02812e4 100644 --- a/platform-includes/logs/setup/php.symfony.mdx +++ b/platform-includes/logs/setup/php.symfony.mdx @@ -1,6 +1,6 @@ To configure Sentry logging, you need to add the Monolog handler to your configuration: -```yaml {filename: monolog.yaml} +```yaml {filename: config/packages/monolog.yaml} monolog: handlers: sentry_logs: From 173f69f0ef199b3263bb0ed5e2b95d04b8010710 Mon Sep 17 00:00:00 2001 From: Martin Linzmayer Date: Wed, 3 Sep 2025 09:31:05 +0200 Subject: [PATCH 3/7] add symfony to getting started page --- docs/product/explore/logs/getting-started/index.mdx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/product/explore/logs/getting-started/index.mdx b/docs/product/explore/logs/getting-started/index.mdx index 15a6aaa0b334e9..f6f53a80201422 100644 --- a/docs/product/explore/logs/getting-started/index.mdx +++ b/docs/product/explore/logs/getting-started/index.mdx @@ -215,6 +215,11 @@ To set up Sentry Logs, use the links below for supported SDKs. After it's been s ### PHP - +- - Date: Wed, 3 Sep 2025 09:31:53 +0200 Subject: [PATCH 4/7] Update platform-includes/logs/requirements/php.symfony.mdx Co-authored-by: Abhijeet Prasad --- platform-includes/logs/requirements/php.symfony.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform-includes/logs/requirements/php.symfony.mdx b/platform-includes/logs/requirements/php.symfony.mdx index f9bf232b3b502b..7cf6177fb8c30f 100644 --- a/platform-includes/logs/requirements/php.symfony.mdx +++ b/platform-includes/logs/requirements/php.symfony.mdx @@ -1 +1 @@ -Logs for Symfony are supported in Sentry Symfony SDK version `5.4` and above. +Logs for Symfony are supported in Sentry Symfony SDK version `5.4.0` and above. From 71bd51a0f4fd19e0e7fdccc81308ee009df0b6a1 Mon Sep 17 00:00:00 2001 From: Martin Linzmayer Date: Fri, 5 Sep 2025 15:31:59 +0200 Subject: [PATCH 5/7] add options --- .../php/guides/symfony/configuration/symfony-options.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/platforms/php/guides/symfony/configuration/symfony-options.mdx b/docs/platforms/php/guides/symfony/configuration/symfony-options.mdx index 1a6c86d061953e..439c9abefc474d 100644 --- a/docs/platforms/php/guides/symfony/configuration/symfony-options.mdx +++ b/docs/platforms/php/guides/symfony/configuration/symfony-options.mdx @@ -37,6 +37,8 @@ sentry: - "Symfony\\Component\\HttpKernel\\Exception\\BadRequestHttpException" ignore_transactions: - "GET /health" + enable_logs: true + before_send_log: "sentry.callback.before_send_log" before_send: "sentry.callback.before_send" before_send_transaction: "sentry.callback.before_send_transaction" trace_propagation_targets: From c07f6adce505b13cb2f3f19485a97eb568e83f86 Mon Sep 17 00:00:00 2001 From: Martin Linzmayer Date: Fri, 5 Sep 2025 16:03:41 +0200 Subject: [PATCH 6/7] remove symfony from upcoming SDKs --- docs/product/explore/logs/getting-started/index.mdx | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docs/product/explore/logs/getting-started/index.mdx b/docs/product/explore/logs/getting-started/index.mdx index f6f53a80201422..a157756bd0d9b7 100644 --- a/docs/product/explore/logs/getting-started/index.mdx +++ b/docs/product/explore/logs/getting-started/index.mdx @@ -286,11 +286,6 @@ We're actively working on adding Log functionality to additional SDKs. Check out label="Elixir" url="https://github.com/getsentry/sentry-elixir/issues/886" /> -- - Date: Mon, 8 Sep 2025 08:35:39 +0200 Subject: [PATCH 7/7] remove link to PR --- docs/platforms/php/common/logs/index.mdx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/docs/platforms/php/common/logs/index.mdx b/docs/platforms/php/common/logs/index.mdx index 9f784b60008525..48a454e33fc110 100644 --- a/docs/platforms/php/common/logs/index.mdx +++ b/docs/platforms/php/common/logs/index.mdx @@ -7,12 +7,6 @@ sidebar_order: 5600 With Sentry Structured Logs, you can send text-based log information from your applications to Sentry. Once in Sentry, these logs can be viewed alongside relevant errors, searched by text-string, or searched using their individual attributes. - - -Let us know what you would like to see on GitHub: [Symfony Logs](https://github.com/getsentry/sentry-symfony/issues/925). - - - ## Requirements