|
13 | 13 | use Sentry\Integration\RequestFetcherInterface; |
14 | 14 | use Sentry\Integration\RequestIntegration; |
15 | 15 | use Sentry\Options; |
| 16 | +use Sentry\SentryBundle\Attribute\SentryMonitorCommand; |
16 | 17 | use Sentry\SentryBundle\EventListener\ConsoleListener; |
| 18 | +use Sentry\SentryBundle\EventListener\CronMonitorListener; |
17 | 19 | use Sentry\SentryBundle\EventListener\ErrorListener; |
18 | 20 | use Sentry\SentryBundle\EventListener\LoginListener; |
19 | 21 | use Sentry\SentryBundle\EventListener\MessengerListener; |
|
29 | 31 | use Symfony\Bundle\TwigBundle\TwigBundle; |
30 | 32 | use Symfony\Component\Cache\CacheItem; |
31 | 33 | use Symfony\Component\Config\FileLocator; |
| 34 | +use Symfony\Component\DependencyInjection\ChildDefinition; |
32 | 35 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
33 | 36 | use Symfony\Component\DependencyInjection\Definition; |
34 | 37 | use Symfony\Component\DependencyInjection\Loader; |
@@ -77,6 +80,7 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container |
77 | 80 | $this->registerTwigTracingConfiguration($container, $mergedConfig['tracing']); |
78 | 81 | $this->registerCacheTracingConfiguration($container, $mergedConfig['tracing']); |
79 | 82 | $this->registerHttpClientTracingConfiguration($container, $mergedConfig['tracing']); |
| 83 | + $this->registerCronMonitoringConfiguration($container, $mergedConfig); |
80 | 84 |
|
81 | 85 | if (!interface_exists(TokenStorageInterface::class)) { |
82 | 86 | $container->removeDefinition(LoginListener::class); |
@@ -285,6 +289,32 @@ private function registerHttpClientTracingConfiguration(ContainerBuilder $contai |
285 | 289 | $container->setParameter('sentry.tracing.http_client.enabled', $isConfigEnabled); |
286 | 290 | } |
287 | 291 |
|
| 292 | + /** |
| 293 | + * @param array<string, mixed> $config |
| 294 | + */ |
| 295 | + private function registerCronMonitoringConfiguration(ContainerBuilder $container, array $config): void |
| 296 | + { |
| 297 | + $container->setParameter('sentry.cron.enabled', (bool) $config['register_cron_monitor']); |
| 298 | + |
| 299 | + if (!$config['register_cron_monitor']) { |
| 300 | + $container->removeDefinition(CronMonitorListener::class); |
| 301 | + |
| 302 | + return; |
| 303 | + } |
| 304 | + |
| 305 | + if (\PHP_VERSION > 8.1) { |
| 306 | + $container->registerAttributeForAutoconfiguration( |
| 307 | + SentryMonitorCommand::class, |
| 308 | + static function ( |
| 309 | + ChildDefinition $definition, |
| 310 | + SentryMonitorCommand $attribute |
| 311 | + ) { |
| 312 | + $definition->addTag('sentry.monitor_command', ['slug' => $attribute->getSlug()]); |
| 313 | + } |
| 314 | + ); |
| 315 | + } |
| 316 | + } |
| 317 | + |
288 | 318 | /** |
289 | 319 | * @param string[] $integrations |
290 | 320 | * @param array<string, mixed> $config |
|
0 commit comments