sentry / sentry-symfony
Symfony integration for Sentry (http://getsentry.com)
Fund package maintenance!
sentry.io/pricing
sentry.io
Installs: 8 746 084
Dependents: 37
Suggesters: 0
Security: 0
Stars: 487
Watchers: 29
Forks: 112
Open Issues: 16
Type:symfony-bundle
Requires
- php: ^7.2||^8.0
- jean85/pretty-package-versions: ^1.5 || ^2.0
- php-http/discovery: ^1.11
- sentry/sdk: ^3.1
- symfony/config: ^3.4.43||^4.4.11||^5.0.11
- symfony/console: ^3.4.43||^4.4.11||^5.0.11
- symfony/dependency-injection: ^3.4.43||^4.4.11||^5.0.11
- symfony/event-dispatcher: ^3.4.43||^4.4.11||^5.0.11
- symfony/http-kernel: ^3.4.43||^4.4.11||^5.0.11
- symfony/psr-http-message-bridge: ^2.0
- symfony/security-core: ^3.4.43||^4.4.11||^5.0.11
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.17
- jangregor/phpstan-prophecy: ^0.8
- monolog/monolog: ^1.3||^2.0
- phpspec/prophecy: !=1.11.0
- phpspec/prophecy-phpunit: ^1.1||^2.0
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^0.12
- phpstan/phpstan-phpunit: ^0.12
- phpunit/phpunit: ^8.5||^9.0
- symfony/browser-kit: ^3.4.43||^4.4.11||^5.0.11
- symfony/framework-bundle: ^3.4.43||^4.4.11||^5.0.11
- symfony/messenger: ^4.4.11||^5.0.11
- symfony/monolog-bundle: ^3.4
- symfony/phpunit-bridge: ^5.0
- symfony/polyfill-php80: ^1.22
- symfony/yaml: ^3.4.43||^4.4.11||^5.0.11
- vimeo/psalm: ^4.3
Suggests
- monolog/monolog: Allow sending log messages to Sentry by using the included Monolog handler.
- dev-master / 4.x-dev
- 4.0.0
- 3.5.x-dev
- 3.5.3
- 3.5.2
- 3.5.1
- 3.5.0
- 3.4.4
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.2
- 3.3.1
- 3.3.0
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.0
- 3.0.0-beta2
- 3.0.0-beta1
- 2.3.0
- 2.2.0
- 2.1
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0
- 0.8.8
- 0.8.7
- 0.8.6
- 0.8.5
- 0.8.4
- 0.8.3
- 0.8.2
- 0.8.1
- 0.8.0
- 0.7.1
- 0.7.0
- 0.6.0
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2.1
- 0.2.0
- 0.1.0
- dev-release/3.4.0
- dev-releases/2.x
- dev-releases/1.x
- dev-releases/0.8.x
- dev-releases/0.7.x
- dev-releases/0.6.x
- dev-releases/0.5.x
This package is auto-updated.
Last update: 2021-01-20 17:06:17 UTC
README
Symfony integration for Sentry.
Benefits
Use sentry-symfony
for:
- A fast Sentry setup
- Easy configuration in your Symfony app
- Automatic wiring in your app. Each event has the following things added automatically to it:
- user
- Symfony environment
- app path
- excluded paths (cache and vendor)
Installation with Symfony Flex (Symfony 4 or newer):
If you're using the Symfony Flex Composer plugin, you can install this bundle in a single, easy step:
composer require sentry/sentry-symfony
This could show a message similar to this:
The recipe for this package comes from the "contrib" repository, which is open to community contributions.
Review the recipe at https://github.com/symfony/recipes-contrib/tree/master/sentry/sentry-symfony/3.0
Do you want to execute this recipe?
Press y
and return to allow the installation.
Installation without Symfony Flex:
Step 1: Download the Bundle
You can install this bundle using Composer:
composer require sentry/sentry-symfony
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = [ // ... new \Sentry\SentryBundle\SentryBundle(), ]; // ... } // ... }
Note that, unlike before in version 3, the bundle will be enabled in all environments; event reporting, instead, is enabled only when providing a DSN (see the next step).
Configuration of the SDK
Add your Sentry DSN value of your project, if you have Symfony 3.4 add it to app/config/config_prod.yml
for Symfony 4 or newer add the value to config/packages/sentry.yaml
.
Keep in mind that leaving the dsn
value empty (or undeclared) in other environments will effectively disable Sentry reporting.
sentry: dsn: "https://public:secret@sentry.example.com/1" messenger: enabled: true # flushes Sentry messages at the end of each message handling capture_soft_fails: true # captures exceptions marked for retry too options: environment: '%kernel.environment%' release: '%env(VERSION)%' #your app version
The parameter options
allows to fine-tune exceptions. To discover more options, please refer to
the Unified APIs options and
the PHP specific ones.
Optional: use monolog handler provided by sentry/sentry
(available since 3.2.0)
Note: this step is optional
If you're using monolog
for logging e.g. in-app errors, you
can use this handler in order for them to show up in Sentry.
First, enable & configure the Sentry\Monolog\Handler
; you'll also need
to disable the Sentry\SentryBundle\EventListener\ErrorListener
to
avoid having duplicate events in Sentry:
sentry: register_error_listener: false # Disables the ErrorListener monolog: error_handler: enabled: true level: error
Then enable it in monolog
config:
monolog: handlers: sentry: type: service id: Sentry\Monolog\Handler
Additionally, you can register the PsrLogMessageProcessor
to resolve PSR-3 placeholders in reported messages:
services: Monolog\Processor\PsrLogMessageProcessor: tags: { name: monolog.processor, handler: sentry }
Optional: use custom HTTP factory/transport
Since SDK 2.0 uses HTTPlug to remain transport-agnostic, you need to have installed two packages that provides
php-http/async-client-implementation
and http-message-implementation
.
This bundle depends on sentry/sdk
, which is a metapackage that already solves this need, requiring our suggested HTTP
packages: the Curl client and Guzzle's message factories.
If instead you want to use a different HTTP client or message factory, you can override the sentry/sdk
package adding the following to your composer.json
after the require
section:
"replace": { "sentry/sdk": "*" }
This will prevent the installation of sentry/sdk
package and will allow you to install through Composer the HTTP client or message factory of your choice.
For example for using Guzzle's components:
composer require php-http/guzzle6-adapter guzzlehttp/psr7
A possible alternate solution is using pugx/sentry-sdk
, a metapackage that replaces sentry/sdk
and uses symfony/http-client
instead of guzzlehttp/guzzle
:
composer require pugx/sentry-sdk
Maintained versions
- 4.x is actively maintained and developed on the master branch, and uses Sentry SDK 3.0;
- 3.x is supported only for fixes and uses Sentry SDK 2.0;
- 2.x is no longer maintained; from this version onwards it requires Symfony 3+ and PHP 7.1+;
- 1.x is no longer maintained; you can use it for Symfony < 2.8 and PHP 5.6/7.0;
- 0.8.x is no longer maintained.
Upgrading to 4.0
The 4.0 version of the bundle uses the newest version (3.x) of the underlying Sentry SDK. If you need to migrate from previous versions, please check the UPGRADE-4.0.md
document.
Custom serializers
The option class_serializers can be used to send customized objects serialization.
sentry: options: class_serializers: YourValueObject: 'ValueObjectSerializer'
Several serializers can be added and the serializable check is done using instanceof. The serializer must implements the __invoke
method returning an array with the information to send to sentry (class name is always sent).
Serializer example:
final class ValueObjectSerializer { public function __invoke(YourValueObject $vo): array { return [ 'value' => $vo->value() ]; } }