Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions docs/platforms/php/common/logs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<Alert title="Looking for Symfony?">

Let us know what you would like to see on GitHub: [Symfony Logs](https://github.com/getsentry/sentry-symfony/issues/925).

</Alert>

## Requirements

<PlatformContent includePath="logs/requirements" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions docs/product/explore/logs/getting-started/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ To set up Sentry Logs, use the links below for supported SDKs. After it's been s
### PHP

- <LinkWithPlatformIcon platform="php" label="PHP" url="/platforms/php/logs/" />
- <LinkWithPlatformIcon
platform="php.symfony"
label="Symfony"
url="/platforms/php/guides/symfony/logs/"
/>
- <LinkWithPlatformIcon
platform="php.laravel"
label="Laravel"
Expand Down Expand Up @@ -281,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"
/>
- <LinkWithPlatformIcon
platform="php.symfony"
label="Symfony"
url="https://github.com/getsentry/sentry-symfony/issues/925"
/>
- <LinkWithPlatformIcon
platform="unity"
label="Unity"
Expand Down
11 changes: 11 additions & 0 deletions platform-includes/logs/default-attributes/php.symfony.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
The Symfony SDK automatically sets several default attributes on all log entries to provide context and improve debugging:

<Include name="logs/default-attributes/core" />

<Include name="logs/default-attributes/message-template" />

<Include name="logs/default-attributes/server" />

<Include name="logs/default-attributes/user" />

<Include name="logs/default-attributes/integration" />
45 changes: 45 additions & 0 deletions platform-includes/logs/options/php.symfony.mdx
Original file line number Diff line number Diff line change
@@ -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}
<?php

namespace App\Service;

class Sentry
{
public function getBeforeSendLog(): callable
{
return function (\Sentry\Logs\Log $log): ?\Sentry\Logs\Log {
if ($log->getLevel() === \Sentry\Logs\LogLevel::info()) {
// Filter out all info logs
return null;
}

return $log;
};
}
}
```

<Alert>

Learn more in [Callables in Symfony Options](/platforms/php/guides/symfony/configuration/symfony-options/#callables).

</Alert>

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.
1 change: 1 addition & 0 deletions platform-includes/logs/requirements/php.symfony.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Logs for Symfony are supported in Sentry Symfony SDK version `5.4.0` and above.
26 changes: 26 additions & 0 deletions platform-includes/logs/setup/php.symfony.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
To configure Sentry logging, you need to add the Monolog handler to your configuration:

```yaml {filename: config/packages/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
```
17 changes: 17 additions & 0 deletions platform-includes/logs/usage/php.symfony.mdx
Original file line number Diff line number Diff line change
@@ -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,
]);
```
Loading