From d65ed14479a23420fb470ef1f7af7627e0a486f5 Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Mon, 1 Sep 2025 23:57:19 +0200 Subject: [PATCH 1/5] wip --- .../php/common/integrations/monolog.mdx | 57 ++++++++++++++++++- docs/platforms/php/common/logs/index.mdx | 4 ++ platform-includes/logs/integrations/php.mdx | 4 ++ platform-includes/logs/requirements/php.mdx | 6 ++ platform-includes/logs/setup/php.mdx | 28 +++++++++ 5 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 platform-includes/logs/integrations/php.mdx diff --git a/docs/platforms/php/common/integrations/monolog.mdx b/docs/platforms/php/common/integrations/monolog.mdx index 78209b823427e..2a64debc40242 100644 --- a/docs/platforms/php/common/integrations/monolog.mdx +++ b/docs/platforms/php/common/integrations/monolog.mdx @@ -1,11 +1,64 @@ --- title: Monolog -description: "Learn how to enable Sentry's PHP SDK to capture Monolog events." +description: "Learn how to enable Sentry's PHP SDK to capture Monolog events and logs." --- -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. +When using [Monolog](https://github.com/Seldaek/monolog) you can configure handlers to capture Monolog messages in several ways: + +- **Logs Handler** - Send structured logs to Sentry for search and analysis +- **Event Handler** - Capture messages as error events in Sentry +- **Breadcrumb Handler** - Record messages as breadcrumbs attached to future events + 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. +## Logs + + +Available in SDK version 4.12.0 and above. + + +To send structured logs to Sentry, use the `\Sentry\Monolog\LogsHandler`. This handler sends log entries to Sentry's structured logs feature, where they can be searched, filtered, and analyzed. + +```php + '___PUBLIC_DSN___', + 'enable_logs' => true, // Required for logs to be sent to Sentry +]); + +// Create a Monolog channel with a logs handler +$log = new Logger('app'); +$log->pushHandler(new \Sentry\Monolog\LogsHandler( + hub: \Sentry\SentrySdk::getCurrentHub(), + level: Level::Info, // Minimum level to send to Sentry logs +)); + +// Send logs to Sentry +$log->info('User logged in', [ + 'user_id' => 12345, + 'email' => 'user@example.com', + 'login_method' => 'password', +]); + +$log->warning('API rate limit approaching', [ + 'endpoint' => '/api/users', + 'requests_remaining' => 10, + 'window_seconds' => 60, +]); + +// Flush to ensure logs are sent +\Sentry\logger()->flush(); +``` + +The context array passed to Monolog methods becomes searchable attributes in the Sentry logs interface. + +## Events + ```php +## Integrations + + + ## Options diff --git a/platform-includes/logs/integrations/php.mdx b/platform-includes/logs/integrations/php.mdx new file mode 100644 index 0000000000000..84807a4b247a7 --- /dev/null +++ b/platform-includes/logs/integrations/php.mdx @@ -0,0 +1,4 @@ +Available integrations: +- [Monolog](/platforms/php/integrations/monolog/#logs) + +If there's an integration you would like to see, open a [new issue on GitHub](https://github.com/getsentry/sentry-php/issues/new/choose). diff --git a/platform-includes/logs/requirements/php.mdx b/platform-includes/logs/requirements/php.mdx index 204c1536d79be..0697d4fe8d1ea 100644 --- a/platform-includes/logs/requirements/php.mdx +++ b/platform-includes/logs/requirements/php.mdx @@ -1 +1,7 @@ Logs for PHP are supported in Sentry PHP SDK version `4.12.0` and above. + +## Monolog Integration + +To use logs with Monolog, you'll need: +- Sentry PHP SDK version `4.12.0` and above +- Monolog version `^2.0` or `^3.0` diff --git a/platform-includes/logs/setup/php.mdx b/platform-includes/logs/setup/php.mdx index c6c5ef7d93fa5..b909fdef27b81 100644 --- a/platform-includes/logs/setup/php.mdx +++ b/platform-includes/logs/setup/php.mdx @@ -10,3 +10,31 @@ To enable logging, you need to initialize the SDK with the `enable_logs` option // Somewhere at the end of your execution, you should flush the logger to send pending logs to Sentry. \Sentry\logger()->flush(); ``` + +## Using with Monolog + +If you're already using [Monolog](https://github.com/Seldaek/monolog), you can use the `\Sentry\Monolog\LogsHandler` to send logs directly through your existing logging setup: + +```php +use Monolog\Level; +use Monolog\Logger; + +\Sentry\init([ + 'dsn' => '___PUBLIC_DSN___', + 'enable_logs' => true, +]); + +$log = new Logger('app'); +$log->pushHandler(new \Sentry\Monolog\LogsHandler( + hub: \Sentry\SentrySdk::getCurrentHub(), + level: Level::Info, +)); + +// Your existing Monolog usage will now send logs to Sentry +$log->info('Application started'); + +// Don't forget to flush +\Sentry\logger()->flush(); +``` + +For more details, see the [Monolog integration documentation](/platforms/php/integrations/monolog/#logs). From 574d143580b0fd1457179e10aad1cbd09c0991f3 Mon Sep 17 00:00:00 2001 From: Martin Linzmayer Date: Tue, 14 Oct 2025 11:05:53 +0200 Subject: [PATCH 2/5] cleanup text --- .../php/common/integrations/monolog.mdx | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/docs/platforms/php/common/integrations/monolog.mdx b/docs/platforms/php/common/integrations/monolog.mdx index 2a64debc40242..2033db5fb76a0 100644 --- a/docs/platforms/php/common/integrations/monolog.mdx +++ b/docs/platforms/php/common/integrations/monolog.mdx @@ -5,7 +5,7 @@ description: "Learn how to enable Sentry's PHP SDK to capture Monolog events and When using [Monolog](https://github.com/Seldaek/monolog) you can configure handlers to capture Monolog messages in several ways: -- **Logs Handler** - Send structured logs to Sentry for search and analysis +- **Logs Handler** - Send structured logs to Sentry - **Event Handler** - Capture messages as error events in Sentry - **Breadcrumb Handler** - Record messages as breadcrumbs attached to future events @@ -17,47 +17,42 @@ The breadcrumb handler will not send anything to Sentry directly, it only record Available in SDK version 4.12.0 and above. -To send structured logs to Sentry, use the `\Sentry\Monolog\LogsHandler`. This handler sends log entries to Sentry's structured logs feature, where they can be searched, filtered, and analyzed. +To send structured logs to Sentry, use the `\Sentry\Monolog\LogsHandler`. ```php '___PUBLIC_DSN___', - 'enable_logs' => true, // Required for logs to be sent to Sentry + 'enable_logs' => true, // Enable Sentry logging ]); // Create a Monolog channel with a logs handler -$log = new Logger('app'); -$log->pushHandler(new \Sentry\Monolog\LogsHandler( - hub: \Sentry\SentrySdk::getCurrentHub(), - level: Level::Info, // Minimum level to send to Sentry logs +$logger = new Logger('sentry_logs'); +$logger->pushHandler(new \Sentry\Monolog\LogsHandler( + LogLevel::info(), // Minimum level to send logs )); // Send logs to Sentry -$log->info('User logged in', [ +$logger->info('User logged in', [ 'user_id' => 12345, 'email' => 'user@example.com', 'login_method' => 'password', ]); -$log->warning('API rate limit approaching', [ +$logger->warning('API rate limit approaching', [ 'endpoint' => '/api/users', 'requests_remaining' => 10, 'window_seconds' => 60, ]); - -// Flush to ensure logs are sent -\Sentry\logger()->flush(); ``` The context array passed to Monolog methods becomes searchable attributes in the Sentry logs interface. -## Events +## Events & Breadcrumbs ```php Date: Tue, 11 Nov 2025 09:43:16 +0100 Subject: [PATCH 3/5] cleanup --- platform-includes/logs/requirements/php.mdx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/platform-includes/logs/requirements/php.mdx b/platform-includes/logs/requirements/php.mdx index 0697d4fe8d1ea..204c1536d79be 100644 --- a/platform-includes/logs/requirements/php.mdx +++ b/platform-includes/logs/requirements/php.mdx @@ -1,7 +1 @@ Logs for PHP are supported in Sentry PHP SDK version `4.12.0` and above. - -## Monolog Integration - -To use logs with Monolog, you'll need: -- Sentry PHP SDK version `4.12.0` and above -- Monolog version `^2.0` or `^3.0` From 133af1075c6db395b26fd8e4235e65b1d631ca14 Mon Sep 17 00:00:00 2001 From: Martin Linzmayer Date: Tue, 18 Nov 2025 16:14:12 +0100 Subject: [PATCH 4/5] add alert how to enable logs --- docs/platforms/php/common/integrations/monolog.mdx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/platforms/php/common/integrations/monolog.mdx b/docs/platforms/php/common/integrations/monolog.mdx index 054d2283a5591..d53b333041e18 100644 --- a/docs/platforms/php/common/integrations/monolog.mdx +++ b/docs/platforms/php/common/integrations/monolog.mdx @@ -3,6 +3,12 @@ title: Monolog description: "Learn how to enable Sentry's PHP SDK to capture Monolog events and logs." --- + + + Enable the Sentry Logs feature with `\Sentry\init(['enabled_logs' => true])` to unlock Sentry's full logging power. With Sentry Logs, you can search, filter, and analyze logs from across your entire application in one place. + + + When using [Monolog](https://github.com/Seldaek/monolog) you can configure handlers to capture Monolog messages in several ways: - **Logs Handler** - Send structured logs to Sentry From 819ddd10b7cfa9a99bbde7aa092a64b62a6b32a4 Mon Sep 17 00:00:00 2001 From: Martin Linzmayer Date: Tue, 18 Nov 2025 16:15:52 +0100 Subject: [PATCH 5/5] typo --- docs/platforms/php/common/integrations/monolog.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/php/common/integrations/monolog.mdx b/docs/platforms/php/common/integrations/monolog.mdx index d53b333041e18..07a15d6917a20 100644 --- a/docs/platforms/php/common/integrations/monolog.mdx +++ b/docs/platforms/php/common/integrations/monolog.mdx @@ -5,7 +5,7 @@ description: "Learn how to enable Sentry's PHP SDK to capture Monolog events and - Enable the Sentry Logs feature with `\Sentry\init(['enabled_logs' => true])` to unlock Sentry's full logging power. With Sentry Logs, you can search, filter, and analyze logs from across your entire application in one place. + Enable the Sentry Logs feature with `\Sentry\init(['enable_logs' => true])` to unlock Sentry's full logging power. With Sentry Logs, you can search, filter, and analyze logs from across your entire application in one place.