Skip to content

Symfony SDK 5.0.0 #9634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 9, 2024
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
2 changes: 1 addition & 1 deletion docs/platforms/php/common/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Learn more about [DSN utilization](/product/sentry-basics/dsn-explainer/#dsn-uti

</ConfigKey>

<ConfigKey name="logger" supported={["php", "php.laravel"]} notSupported={["php.symfony"]}>
<ConfigKey name="logger">

If enabled, the SDK prints out debug information about if something went wrong while sending events.
It isn't recommended to use this in production.
Expand Down
90 changes: 42 additions & 48 deletions docs/platforms/php/guides/symfony/configuration/symfony-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,58 @@ All configuration for Symfony is done in `config/packages/sentry.yaml`.
sentry:
dsn: "___PUBLIC_DSN___"
register_error_listener: true
register_error_handler: true
options:
attach_stacktrace: true
before_breadcrumb: "sentry.callback.before_breadcrumb"
before_send: "sentry.callback.before_send"
capture_silenced_errors: false
context_lines: 5
default_integrations: true
enable_compression: true
environment: "%kernel.environment%"
error_types: "E_ALL & ~E_NOTICE"
http_proxy: "10.0.0.12:3456"
in_app_exclude:
- "%kernel.build_dir%"
- "%kernel.cache_dir%"
- "%kernel.project_dir%/vendor"
integrations:
- "sentry.integration.my_custom_integration"
logger: "php"
max_breadcrumbs: 50
max_value_length: 2048
prefixes:
- "/local_dir/"
release: "abcde12345"
sample_rate: 1
traces_sample_rate: 0
enable_tracing: true
traces_sample_rate: 1
traces_sampler: "sentry.callback.traces_sampler"
send_attempts: 3
send_default_pii: false
server_name: "www.example.com"
attach_stacktrace: true
attach_metric_code_locations: true
context_lines: 5
environment: "%kernel.environment%"
logger: "php"
spotlight: true
spotlight_url: "http://localhost:8969"
release: "5.0.x-dev"
server_name: "localhost"
ignore_exceptions:
- "Symfony\\Component\\HttpKernel\\Exception\\BadRequestHttpException"
ignore_transactions:
- "GET /helath"
before_send: "sentry.callback.before_send"
before_send_transaction: "sentry.callback.before_send_transaction"
trace_propagation_targets:
- 'example.com'
tags:
tag1: "value1"
tag2: "value2"
error_types: "E_ALL & ~E_NOTICE"
max_breadcrumbs: 50
before_breadcrumb: "sentry.callback.before_breadcrumb"
in_app_exclude:
- '%kernel.cache_dir%'
in_app_include:
- '%kernel.project_dir%'
send_default_pii: true
max_value_length: 1024
transport: "sentry.transport"
transport: "sentry.http_client"
http_proxy: "proxy.example.com:8080"
http_proxy_authentication: "user:password"
http_connect_timeout: 15
http_timeout: 10
http_ssl_verify_peer: true
http_compression: true
capture_silenced_errors: true
max_request_body_size: "medium"
class_serializers:
App\User: "App\\Sentry\\Serializer\\UserSerializer"

```

The DSN option is the only required option: it sets the Sentry DSN, and so reports all events to the related project. If it's
Expand Down Expand Up @@ -106,29 +126,3 @@ class Sentry
}
}
```

## Exclude Some Exceptions

This example shows how to ignore not found exceptions, but you can ignore any exception you want.

1. Declare the integrations:

{/* <!-- prettier-ignore --> */}
```yaml {filename:config/packages/sentry.yaml}
sentry:
options:
integrations:
- 'Sentry\Integration\IgnoreErrorsIntegration'
```

2. Configure the list of ignored exceptions:

{/* <!-- prettier-ignore --> */}
```yaml {filename:config/services.yaml}
services:
Sentry\Integration\IgnoreErrorsIntegration:
arguments:
$options:
ignore_exceptions:
- Symfony\Component\HttpKernel\Exception\NotFoundHttpException
```
62 changes: 1 addition & 61 deletions docs/platforms/php/guides/symfony/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,9 @@ Install the `sentry/sentry-symfony` bundle:
composer require sentry/sentry-symfony
```

<Note>

Due to a bug in all versions below `6.0` of the [`SensioFrameworkExtraBundle`](https://github.com/sensiolabs/SensioFrameworkExtraBundle) bundle, you will likely receive an error during the execution of the command above related to the missing `Nyholm\Psr7\Factory\Psr17Factory` class. To workaround the issue, if you are not using the PSR-7 bridge, please change the configuration of that bundle as follows:

{/* <!-- prettier-ignore --> */}
```yaml
sensio_framework_extra:
psr_message:
enabled: false
```

For more details about the issue see [https://github.com/sensiolabs/SensioFrameworkExtraBundle/pull/710](https://github.com/sensiolabs/SensioFrameworkExtraBundle/pull/710).

</Note>

## Configure

Add your DSN to `config/packages/sentry.yaml`:

{/* <!-- prettier-ignore --> */}
```yaml {filename:config/packages/sentry.yaml}
sentry:
dsn: "%env(SENTRY_DSN)%"
```

And in your `.env` file:
Add your DSN to your `.env` file:

<SignInNote />

Expand All @@ -49,25 +26,6 @@ SENTRY_DSN="___PUBLIC_DSN___"
###< sentry/sentry-symfony ###
```

<Alert level= "warning" title="Performance">

Performance monitoring integrations to support tracing are enabled by default. To use them, update to the latest version of the SDK.

These integrations hook into critical paths of the framework and of the vendors. As a result, there may be a performance penalty. To disable tracing, please see the [Integrations documentation](/platforms/php/guides/symfony/performance/pm-integrations/).

</Alert>

If you **are not** using Symfony Flex, you'll also need to enable the bundle in `config/bundles.php`:

```php {filename:config/bundles.php}
<?php

return [
// ...
Sentry\SentryBundle\SentryBundle::class => ['all' => true],
];
```

### 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:
Expand All @@ -86,24 +44,6 @@ monolog:
hub_id: Sentry\State\HubInterface
```

If you are using a version of [MonologBundle](https://github.com/symfony/monolog-bundle) prior to `3.7`, you need to
configure the handler as a service instead:

{/* <!-- prettier-ignore --> */}
```yaml {filename:config/packages/sentry.yaml}
monolog:
handlers:
sentry:
type: service
id: Sentry\Monolog\Handler

services:
Sentry\Monolog\Handler:
arguments:
$hub: '@Sentry\State\HubInterface'
$level: !php/const Monolog\Logger::ERROR
```

Additionally, you can register the `PsrLogMessageProcessor` to resolve PSR-3 placeholders in reported messages:

{/* <!-- prettier-ignore --> */}
Expand Down
107 changes: 107 additions & 0 deletions docs/platforms/php/guides/symfony/metrics/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
title: Set Up Metrics
description: "Learn how to measure the data points you care about by configuring Metrics in your Symfony app."
---

<Include name="feature-stage-beta-metrics.mdx" />

<Note>

Metrics for Symfony are supported with Sentry Symfony SDK version `5.0.0` and above.

</Note>

Sentry metrics help you pinpoint and solve issues that impact user experience and app performance by measuring the data points that are important to you. You can track things like processing time, event size, user signups, and conversion rates, then correlate them back to tracing data in order to get deeper insights and solve issues faster.

## Emit a Counter

Counters are one of the more basic types of metrics and can be used to count certain event occurrences.

To emit a counter, do the following:

```php
// Increment a counter by one for each button click.
\Sentry\metrics()->increment(
key: 'button_click',
value: 1,
tags: [
'browser' => 'Firefox',
'app_version' => '1.0.0',
],
)
```

## Emit a Distribution

Distributions help you get the most insights from your data by allowing you to obtain aggregations such as `p90`, `min`, `max`, and `avg`.

To emit a distribution, do the following:

```php
// Add '15.0' to a distribution used for tracking the loading times per page.
\Sentry\metrics()->distribution(
key: 'page_load',
value: 15.0,
unit: \Sentry\Metrics\MetricsUnit::millisecond(),
tags: [
'page' => '/home',
],
)
```

## Emit a Set

Sets are useful for looking at unique occurrences and counting the unique elements you added.

To emit a set, do the following:

```php
// Add 'jane' to a set used for tracking the number of users that viewed a page.
\Sentry\metrics()->set(
key: 'user_view',
value: 'jane',
unit: \Sentry\Metrics\MetricsUnit::custom('username'),
tags: [
'page' => '/home',
],
)
```

## Emit a Gauge

Gauges let you obtain aggregates like `min`, `max`, `avg`, `sum`, and `count`. They can be represented in a more space-efficient way than distributions, but they can't be used to get percentiles. If percentiles aren't important to you, we recommend using gauges.

To emit a gauge, do the following:

```php
// Add '15.0' to a gauge used for tracking the loading times for a page.
\Sentry\metrics()->gauge(
key: 'page_load',
value: 15.0,
unit: \Sentry\Metrics\MetricsUnit::millisecond(),
tags: [
'page' => '/home',
],
)
```

## Emit a Timer

Timers can be used to measure the execution time of a specific block of code. They're implemented like distributions, but measured in seconds.

To emit a timer, do the following:

```php
\Sentry\metrics()->timing(
key: 'event_processing_time',
callback: static fn() => process(),
);
```

## Setup Code Locations

To attach the code location of your metrics, set `attach_metric_code_locations` to `true` (the default is `false`).

```yaml {filename:config/packages/sentry.yaml}
attach_metric_code_locations: true
```