Skip to content

Commit c8e48bf

Browse files
committed
ref: remove old sentry logs to error handler documentation
1 parent aea04dc commit c8e48bf

File tree

6 files changed

+54
-178
lines changed

6 files changed

+54
-178
lines changed
Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
---
22
title: Monolog
3-
description: "Learn how to enable Sentry's PHP SDK to capture Monolog events and logs."
3+
description: "Learn how to use Monolog with Sentry's PHP SDK."
44
---
55

66
<Alert level="info" title="Sentry Logs">
77

8-
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.
8+
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.
99

1010
</Alert>
1111

12-
When using [Monolog](https://github.com/Seldaek/monolog) you can configure handlers to capture Monolog messages in several ways:
12+
When using [Monolog](https://github.com/Seldaek/monolog), you can configure handlers to capture Monolog messages in Sentry. The examples below show common patterns for sending structured logs and recording breadcrumbs:
1313

1414
- **Logs Handler** - Send structured logs to Sentry
15-
- **Event Handler** - Capture messages as error events in Sentry
1615
- **Breadcrumb Handler** - Record messages as breadcrumbs attached to future events
1716

18-
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.
17+
The breadcrumb handler does not send anything to Sentry directly. It records breadcrumbs that are attached to a later event or exception.
1918

2019
## Logs
2120

22-
<Alert level="info">
23-
Available in SDK version 4.12.0 and above.
24-
</Alert>
21+
<Alert level="info">Available in SDK version 4.12.0 and above.</Alert>
2522

2623
To send structured logs to Sentry, use the `\Sentry\Monolog\LogsHandler`.
2724

@@ -58,55 +55,30 @@ $logger->warning('API rate limit approaching', [
5855

5956
The context array passed to Monolog methods becomes searchable attributes in the Sentry logs interface.
6057

61-
## Events & Breadcrumbs
58+
## Breadcrumbs
59+
60+
Use the breadcrumb handler when you want Monolog messages attached to future Sentry events for extra context.
6261

6362
```php
6463
<?php
6564

6665
use Monolog\Level;
6766
use Monolog\Logger;
68-
use Monolog\Handler\StreamHandler;
6967

70-
// Setup the Sentry SDK, this can also be done elsewhere in your application
68+
// Set up the Sentry SDK, this can also be done elsewhere in your application
7169
\Sentry\init([
72-
'dsn' => '___PUBLIC_DSN___'
70+
'dsn' => '___PUBLIC_DSN___',
7371
]);
7472

75-
// Create a Monolog channel with a breadcrumb handler and a Sentry handler
73+
// Create a Monolog channel with a breadcrumb handler
7674
$log = new Logger('sentry');
7775
$log->pushHandler(new \Sentry\Monolog\BreadcrumbHandler(
7876
hub: \Sentry\SentrySdk::getCurrentHub(),
79-
level: Level::Info, // Take note of the level here, messages with that level or higher will be attached to future Sentry events as breadcrumbs
80-
));
81-
$log->pushHandler(new \Sentry\Monolog\Handler(
82-
hub: \Sentry\SentrySdk::getCurrentHub(),
83-
level: Level::Error, // Take note of the level here, messages with that level or higher will be sent to Sentry
84-
bubble: true,
85-
fillExtraContext: false, // Will add a `monolog.context` & `monolog.extra`, key to the event with the Monolog `context` & `extra` values
77+
level: Level::Info, // Messages with this level or higher will be attached to future Sentry events as breadcrumbs
8678
));
8779

88-
// Log an error:
89-
$log->error('Something bad happened');
90-
91-
// To log an exception you can use the following code:
92-
try {
93-
throw new RuntimeException('Some exception');
94-
} catch (RuntimeException $exception) {
95-
$log->error('Some exception happened', ['exception' => $exception]);
96-
}
97-
```
98-
99-
## Support With Sentry Logs
100-
101-
Monolog logs can also be captured as <PlatformLink to="/logs/">Sentry Logs</PlatformLink> for better searchability and querying.
102-
103-
To enable this, set `enable_logs` to `true` when initializing the SDK:
104-
105-
```php
106-
\Sentry\init([
107-
'dsn' => '___PUBLIC_DSN___',
108-
'enable_logs' => true,
80+
$log->info('Starting checkout flow');
81+
$log->warning('API rate limit approaching', [
82+
'endpoint' => '/api/users',
10983
]);
11084
```
111-
112-
You can control which log levels are sent to Sentry Logs by configuring the Monolog handler's minimum level.

docs/platforms/php/guides/laravel/index.mdx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ og_image: /og-images/platforms-php-guides-laravel.png
1010

1111
## Prerequisites
1212

13-
* You need a [Sentry account](https://sentry.io/signup/) and project
14-
* Your Laravel application needs to run on PHP 7.2 or later
15-
* Your Laravel version needs to be 11.x or higher
16-
* Read one of these guides if you use an [older version](/platforms/php/guides/laravel/other-versions/) or need [Lumen-specific instructions](/platforms/php/guides/laravel/other-versions/lumen/)
13+
- You need a [Sentry account](https://sentry.io/signup/) and project
14+
- Your Laravel application needs to run on PHP 7.2 or later
15+
- Your Laravel version needs to be 11.x or higher
16+
- Read one of these guides if you use an [older version](/platforms/php/guides/laravel/other-versions/) or need [Lumen-specific instructions](/platforms/php/guides/laravel/other-versions/lumen/)
1717

1818
## Install
1919

@@ -48,7 +48,7 @@ return Application::configure(basePath: dirname(__DIR__))
4848
->create();
4949
```
5050

51-
Alternatively, you can configure Sentry as a [Laravel Log Channel](usage/#log-channels).
51+
If you also want to send structured logs to Sentry, see the [Logs guide](logs/).
5252

5353
## Configure
5454

@@ -65,7 +65,8 @@ SENTRY_LARAVEL_DSN=___PUBLIC_DSN___
6565
```
6666

6767
<Alert level="warning">
68-
In order to receive stack trace arguments in your errors, make sure to set `zend.exception_ignore_args: Off` in your php.ini
68+
In order to receive stack trace arguments in your errors, make sure to set
69+
`zend.exception_ignore_args: Off` in your php.ini
6970
</Alert>
7071

7172
## Verify

docs/platforms/php/guides/laravel/other-versions/laravel8-10.mdx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,25 @@ public function register(): void
3030
}
3131
```
3232

33-
<Alert>
34-
35-
Alternatively, you can configure Sentry in your [Laravel Log Channel](/platforms/php/guides/laravel/usage/#log-channels), allowing you to log `info` and `debug` as well.
36-
37-
</Alert>
33+
If you also want to send structured logs to Sentry, see the [Logs guide](/platforms/php/guides/laravel/logs/).
3834

3935
## Configure
4036

4137
Configure the Sentry DSN with this command:
4238

43-
4439
```shell
4540
php artisan sentry:publish --dsn=___PUBLIC_DSN___
4641
```
4742

4843
It creates the config file (`config/sentry.php`) and adds the `DSN` to your `.env` file.
4944

50-
5145
```shell {filename:.env}
5246
SENTRY_LARAVEL_DSN=___PUBLIC_DSN___
5347
```
5448

5549
<Alert level="warning">
56-
In order to receive stack trace arguments in your errors, make sure to set `zend.exception_ignore_args: Off` in your php.ini
50+
In order to receive stack trace arguments in your errors, make sure to set
51+
`zend.exception_ignore_args: Off` in your php.ini
5752
</Alert>
5853

5954
## Verify

docs/platforms/php/guides/laravel/usage/index.mdx

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -89,50 +89,6 @@ class SentryContext
8989
}
9090
```
9191

92-
### Log Channels
93-
94-
<Alert title="Note">
95-
96-
If you're using log channels to log your exceptions and are also logging exceptions to Sentry in your exception handler, exceptions might show up in Sentry twice.
97-
98-
</Alert>
99-
100-
To configure Sentry as a log channel, add the following config to the `channels` section in `config/logging.php`.
101-
If this file does not exist, run `php artisan config:publish logging` to publish it.
102-
103-
```php {filename:config/logging.php}
104-
'channels' => [
105-
// ...
106-
'sentry' => [
107-
'driver' => 'sentry',
108-
],
109-
],
110-
```
111-
112-
After you configured the Sentry log channel, you can configure your app to both log to a log file and to Sentry by modifying the log stack:
113-
114-
```bash {filename:.env}
115-
# ...
116-
LOG_CHANNEL=stack
117-
LOG_STACK=single,sentry
118-
# ...
119-
```
120-
121-
Optionally, you can set the [logging level](https://laravel.com/docs/8.x/logging#log-levels) and if events should bubble on the driver:
122-
123-
```php {filename:config/logging.php}
124-
'channels' => [
125-
// ...
126-
'sentry' => [
127-
'driver' => 'sentry',
128-
// The minimum logging level at which this handler will be triggered
129-
// Available levels: debug, info, notice, warning, error, critical, alert, emergency
130-
'level' => env('LOG_LEVEL', 'error'),
131-
'bubble' => true, // Whether the messages that are handled can bubble up the stack or not
132-
],
133-
],
134-
```
135-
13692
### Queue Jobs
13793

13894
When you have defined a `failed` method on your job class ([documentation](https://laravel.com/docs/8.x/queues#cleaning-up-after-failed-jobs)), that failed method acts as if your job runs inside a `try {} catch (\Exception $e) {}`. This will prevent reporting exception, causing the job to have failed to be reported to Sentry.
@@ -157,32 +113,6 @@ public function failed(\Exception $exception)
157113
}
158114
```
159115

160-
#### Naming Your Log Channels
161-
162-
To filter on multiple log channels inside Sentry, you can add the `name` attribute to the log channel.
163-
It will show up in Sentry as the `logger` tag, which is filterable.
164-
165-
For example:
166-
167-
```php {filename:config/logging.php}
168-
'channels' => [
169-
'my_stacked_channel' => [
170-
'driver' => 'stack',
171-
'channels' => ['single', 'sentry'],
172-
'name' => 'my-channel'
173-
],
174-
//...
175-
],
176-
```
177-
178-
As a result, you can log errors to your channel:
179-
180-
```php
181-
\Log::channel('my_stacked_channel')->error('My error');
182-
```
183-
184-
And Sentry's `logger` tag now has the channel's `name`. You can filter on the "my-channel" value.
185-
186116
### Resolve Name Conflicts
187117

188118
If you have other packages also named Sentry, you'll need to create your own service provider extending ours so we can prevent naming conflicts.

docs/platforms/php/guides/symfony/index.mdx

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ description: "Symfony is a set of reusable PHP components and a PHP framework to
66

77
## Prerequisites
88

9-
* You need a [Sentry account](https://sentry.io/signup/) and project
10-
* Your Symfony application needs to run on PHP 7.2 or later
9+
- You need a [Sentry account](https://sentry.io/signup/) and project
10+
- Your Symfony application needs to run on PHP 7.2 or later
1111

1212
## Install
1313

@@ -17,7 +17,7 @@ Install the `sentry/sentry-symfony` bundle:
1717
composer require sentry/sentry-symfony
1818
```
1919

20-
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.
20+
If you're already using [Monolog](https://github.com/Seldaek/monolog), see the [Monolog integration docs](integrations/monolog/) for Monolog-related configuration.
2121

2222
## Configure
2323

@@ -32,41 +32,33 @@ SENTRY_DSN="___PUBLIC_DSN___"
3232
When using Symfony Flex, the Sentry bundle is configured to be enabled in the `prod` environment only by default. You can change this behaviour in your `config/packages/sentry.yaml` and `config/bundles.php` files.
3333

3434
<Alert level="warning">
35-
In order to receive stack trace arguments in your errors, make sure to set `zend.exception_ignore_args: Off` in your php.ini
35+
In order to receive stack trace arguments in your errors, make sure to set
36+
`zend.exception_ignore_args: Off` in your php.ini
3637
</Alert>
3738

3839
## Verify
3940

40-
To test that both logger error and exception are correctly sent to sentry.io, you can create the following controller:
41+
To test that Sentry is capturing unhandled exceptions, you can create the following controller:
4142

4243
```php
4344
<?php
4445

4546
namespace App\Controller;
4647

47-
use Psr\Log\LoggerInterface;
4848
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
4949
use Symfony\Component\Routing\Attribute\Route;
5050

5151
class SentryTestController extends AbstractController
5252
{
53-
public function __construct(private LoggerInterface $logger)
54-
{
55-
}
56-
5753
#[Route('/_sentry-test', name: 'sentry_test')]
58-
public function testLog()
54+
public function testException()
5955
{
60-
// the following code will test if monolog integration logs to sentry
61-
$this->logger->error('My custom logged error.', ['some' => 'Context Data']);
62-
63-
// the following code will test if an uncaught exception logs to sentry
6456
throw new \RuntimeException('Example exception.');
6557
}
6658
}
6759
```
6860

69-
After you visit the `/_sentry-test` page, you can view and resolve the recorded error by logging into [sentry.io](https://sentry.io) and opening your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.
61+
After you visit the `/_sentry-test` page, you can view and resolve the recorded error by logging into [sentry.io](https://sentry.io) and opening your project.
7062

7163
## Next Steps
7264

0 commit comments

Comments
 (0)