From c30860d4abf5c73045a5689557fb60d66744638d Mon Sep 17 00:00:00 2001 From: Thomas Schneider Date: Fri, 27 Mar 2026 13:58:23 +0100 Subject: [PATCH] =?UTF-8?q?Sentry-Integration=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 4 ++ composer.json | 1 + config/bundles.php | 1 + config/packages/sentry.yaml | 40 +++++++++++++++++++ config/reference.php | 80 +++++++++++++++++++++++++++++++++++++ symfony.lock | 12 ++++++ 6 files changed, 138 insertions(+) create mode 100644 config/packages/sentry.yaml diff --git a/.env b/.env index e101827..734aafc 100644 --- a/.env +++ b/.env @@ -47,3 +47,7 @@ MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0 ###> symfony/mailer ### MAILER_DSN=null://null ###< symfony/mailer ### + +###> sentry/sentry-symfony ### +SENTRY_DSN= +###< sentry/sentry-symfony ### diff --git a/composer.json b/composer.json index c0bfd07..f83dbf7 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ "doctrine/orm": "^3.6", "phpdocumentor/reflection-docblock": "^6.0", "phpstan/phpdoc-parser": "^2.3", + "sentry/sentry-symfony": "^5.9", "spatie/docker": "^1.13", "symfony/asset": "8.0.*", "symfony/asset-mapper": "8.0.*", diff --git a/config/bundles.php b/config/bundles.php index 4e3a560..f4e905d 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -13,4 +13,5 @@ return [ Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], + Sentry\SentryBundle\SentryBundle::class => ['prod' => true], ]; diff --git a/config/packages/sentry.yaml b/config/packages/sentry.yaml new file mode 100644 index 0000000..a2f0ffc --- /dev/null +++ b/config/packages/sentry.yaml @@ -0,0 +1,40 @@ +when@prod: + sentry: + dsn: '%env(SENTRY_DSN)%' + options: + # Add request headers, cookies, IP address and the authenticated user + # see https://docs.sentry.io/platforms/php/data-management/data-collected/ for more info + # send_default_pii: true + ignore_exceptions: + - 'Symfony\Component\ErrorHandler\Error\FatalError' + - 'Symfony\Component\Debug\Exception\FatalErrorException' + traces_sample_rate: 0.1 +# +# # If you are using Monolog, you also need this additional configuration to log the errors correctly: +# # https://docs.sentry.io/platforms/php/guides/symfony/integrations/monolog/ + register_error_listener: false + register_error_handler: false + + monolog: + handlers: +# # Use this only if you don't want to use structured logging and instead receive +# # certain log levels as errors. +# sentry: +# type: service +# id: Sentry\Monolog\Handler +# + # Use this for structured log integration + sentry_logs: + type: service + id: Sentry\SentryBundle\Monolog\LogsHandler + + # Enable one of the two services below, depending on your choice above + services: +# Sentry\Monolog\Handler: +# arguments: +# $hub: '@Sentry\State\HubInterface' +# $level: !php/const Monolog\Logger::ERROR +# $fillExtraContext: true # Enables sending monolog context to Sentry + Sentry\SentryBundle\Monolog\LogsHandler: + arguments: + - !php/const Monolog\Logger::INFO diff --git a/config/reference.php b/config/reference.php index 803d936..543c09d 100644 --- a/config/reference.php +++ b/config/reference.php @@ -1455,6 +1455,85 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param; * generate_final_classes?: bool|Param, // Default: true * generate_final_entities?: bool|Param, // Default: false * } + * @psalm-type SentryConfig = array{ + * dsn?: scalar|Param|null, // If this value is not provided, the SDK will try to read it from the SENTRY_DSN environment variable. If that variable also does not exist, the SDK will not send any events. + * register_error_listener?: bool|Param, // Default: true + * register_error_handler?: bool|Param, // Default: true + * logger?: scalar|Param|null, // The service ID of the PSR-3 logger used to log messages coming from the SDK client. Be aware that setting the same logger of the application may create a circular loop when an event fails to be sent. // Default: null + * options?: array{ + * integrations?: mixed, // Default: [] + * default_integrations?: bool|Param, + * prefixes?: list, + * sample_rate?: float|Param, // The sampling factor to apply to events. A value of 0 will deny sending any event, and a value of 1 will send all events. + * enable_tracing?: bool|Param, + * traces_sample_rate?: float|Param, // The sampling factor to apply to transactions. A value of 0 will deny sending any transaction, and a value of 1 will send all transactions. + * traces_sampler?: scalar|Param|null, + * profiles_sample_rate?: float|Param, // The sampling factor to apply to profiles. A value of 0 will deny sending any profiles, and a value of 1 will send all profiles. Profiles are sampled in relation to traces_sample_rate + * enable_logs?: bool|Param, + * enable_metrics?: bool|Param, // Default: true + * attach_stacktrace?: bool|Param, + * attach_metric_code_locations?: bool|Param, + * context_lines?: int|Param, + * environment?: scalar|Param|null, // Default: "%kernel.environment%" + * logger?: scalar|Param|null, + * spotlight?: bool|Param, + * spotlight_url?: scalar|Param|null, + * release?: scalar|Param|null, // Default: "%env(default::SENTRY_RELEASE)%" + * server_name?: scalar|Param|null, + * ignore_exceptions?: list, + * ignore_transactions?: list, + * before_send?: scalar|Param|null, + * before_send_transaction?: scalar|Param|null, + * before_send_check_in?: scalar|Param|null, + * before_send_metrics?: scalar|Param|null, + * before_send_log?: scalar|Param|null, + * before_send_metric?: scalar|Param|null, + * trace_propagation_targets?: mixed, + * tags?: array, + * error_types?: scalar|Param|null, + * max_breadcrumbs?: int|Param, + * before_breadcrumb?: mixed, + * in_app_exclude?: list, + * in_app_include?: list, + * send_default_pii?: bool|Param, + * max_value_length?: int|Param, + * transport?: scalar|Param|null, + * http_client?: scalar|Param|null, + * http_proxy?: scalar|Param|null, + * http_proxy_authentication?: scalar|Param|null, + * http_connect_timeout?: float|Param, // The maximum number of seconds to wait while trying to connect to a server. It works only when using the default transport. + * http_timeout?: float|Param, // The maximum execution time for the request+response as a whole. It works only when using the default transport. + * http_ssl_verify_peer?: bool|Param, + * http_compression?: bool|Param, + * capture_silenced_errors?: bool|Param, + * max_request_body_size?: "none"|"never"|"small"|"medium"|"always"|Param, + * class_serializers?: array, + * }, + * messenger?: bool|array{ + * enabled?: bool|Param, // Default: true + * capture_soft_fails?: bool|Param, // Default: true + * isolate_breadcrumbs_by_message?: bool|Param, // Default: false + * }, + * tracing?: bool|array{ + * enabled?: bool|Param, // Default: true + * dbal?: bool|array{ + * enabled?: bool|Param, // Default: true + * connections?: list, + * }, + * twig?: bool|array{ + * enabled?: bool|Param, // Default: true + * }, + * cache?: bool|array{ + * enabled?: bool|Param, // Default: true + * }, + * http_client?: bool|array{ + * enabled?: bool|Param, // Default: true + * }, + * console?: array{ + * excluded_commands?: list, + * }, + * }, + * } * @psalm-type ConfigType = array{ * imports?: ImportsConfig, * parameters?: ParametersConfig, @@ -1498,6 +1577,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param; * twig_extra?: TwigExtraConfig, * security?: SecurityConfig, * monolog?: MonologConfig, + * sentry?: SentryConfig, * }, * "when@test"?: array{ * imports?: ImportsConfig, diff --git a/symfony.lock b/symfony.lock index 08c91dc..0db00d4 100644 --- a/symfony.lock +++ b/symfony.lock @@ -50,6 +50,18 @@ "bin/phpunit" ] }, + "sentry/sentry-symfony": { + "version": "5.9", + "recipe": { + "repo": "github.com/symfony/recipes-contrib", + "branch": "main", + "version": "5.0", + "ref": "12f504985eb24e3b20a9e41e0ec7e398798d18f0" + }, + "files": [ + "config/packages/sentry.yaml" + ] + }, "symfony/asset-mapper": { "version": "8.0", "recipe": {