diff --git a/.env b/.env index 006892250..0f334e04a 100644 --- a/.env +++ b/.env @@ -263,4 +263,4 @@ NEWRELIC_LICENSE_KEY= SENTRY_DSN= SENTRY_ENVIRONMENT=prod -SENTRY_RELEASE= +SENTRY_RELEASE=unknown diff --git a/databox/api/config/packages/alchemy_core.yaml b/databox/api/config/packages/alchemy_core.yaml index fb31387e3..4dd916c26 100644 --- a/databox/api/config/packages/alchemy_core.yaml +++ b/databox/api/config/packages/alchemy_core.yaml @@ -1,4 +1,5 @@ alchemy_core: - app_url: '%env(DATABOX_API_URL)%' - healthcheck: ~ - sentry: ~ + app_name: databox + app_url: '%env(DATABOX_API_URL)%' + healthcheck: ~ + sentry: ~ diff --git a/databox/api/config/routes/alchemy_core.yaml b/databox/api/config/routes/alchemy_core.yaml index 3e6410758..498840e88 100644 --- a/databox/api/config/routes/alchemy_core.yaml +++ b/databox/api/config/routes/alchemy_core.yaml @@ -1,6 +1,6 @@ alchemy_core_healthcheck: - controller: Alchemy\CoreBundle\Controller\HealthCheckAction - path: / + resource: Alchemy\CoreBundle\Controller\HealthCheckAction + type: attribute alchemy_core_sentry_test: - controller: Alchemy\CoreBundle\Controller\SentryTestController - path: / + resource: Alchemy\CoreBundle\Controller\SentryTestController + type: attribute diff --git a/expose/api/config/packages/alchemy_core.yaml b/expose/api/config/packages/alchemy_core.yaml index 1eb7cb480..0373528cf 100644 --- a/expose/api/config/packages/alchemy_core.yaml +++ b/expose/api/config/packages/alchemy_core.yaml @@ -1,4 +1,5 @@ alchemy_core: - app_url: '%env(EXPOSE_API_URL)%' - healthcheck: ~ - sentry: ~ + app_name: expose + app_url: '%env(EXPOSE_API_URL)%' + healthcheck: ~ + sentry: ~ diff --git a/expose/api/config/packages/alchemy_report.yml b/expose/api/config/packages/alchemy_report.yml deleted file mode 100644 index 845428b25..000000000 --- a/expose/api/config/packages/alchemy_report.yml +++ /dev/null @@ -1,2 +0,0 @@ -alchemy_report: - app_name: expose diff --git a/expose/api/config/routes/alchemy_core.yaml b/expose/api/config/routes/alchemy_core.yaml index 597924087..498840e88 100644 --- a/expose/api/config/routes/alchemy_core.yaml +++ b/expose/api/config/routes/alchemy_core.yaml @@ -1,6 +1,6 @@ alchemy_core_healthcheck: - controller: Alchemy\CoreBundle\Controller\HealthCheckAction - path: / + resource: Alchemy\CoreBundle\Controller\HealthCheckAction + type: attribute alchemy_core_sentry_test: - controller: Alchemy\CoreBundle\Controller\SentryTestController - path: / + resource: Alchemy\CoreBundle\Controller\SentryTestController + type: attribute diff --git a/lib/php/core-bundle/Controller/SentryTestController.php b/lib/php/core-bundle/Controller/SentryTestController.php index 4214a5499..6ed5fbb39 100644 --- a/lib/php/core-bundle/Controller/SentryTestController.php +++ b/lib/php/core-bundle/Controller/SentryTestController.php @@ -5,10 +5,14 @@ namespace Alchemy\CoreBundle\Controller; use Psr\Log\LoggerInterface; +use Symfony\Component\DependencyInjection\Attribute\Autoconfigure; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\Routing\Annotation\Route; #[Route(path: '/_health/sentry-test')] +#[AsController] +#[Autoconfigure] readonly class SentryTestController { public function __construct(private LoggerInterface $logger) diff --git a/lib/php/core-bundle/DependencyInjection/AlchemyCoreExtension.php b/lib/php/core-bundle/DependencyInjection/AlchemyCoreExtension.php index c1240b761..f68b8087b 100644 --- a/lib/php/core-bundle/DependencyInjection/AlchemyCoreExtension.php +++ b/lib/php/core-bundle/DependencyInjection/AlchemyCoreExtension.php @@ -28,6 +28,9 @@ public function load(array $configs, ContainerBuilder $container): void $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); + $container->setParameter('alchemy_core.app_id', $config['app_id']); + $container->setParameter('alchemy_core.app_name', $config['app_name']); + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yaml'); @@ -69,8 +72,8 @@ private function loadHealthCheckers(ContainerBuilder $container): void private function loadSentry(ContainerBuilder $container): void { - $env = $container->getParameter('kernel.environment'); - if ('prod' === $env) { + $bundles = $container->getParameter('kernel.bundles'); + if (isset($bundles['SentryBundle'])) { $def = new Definition(PsrLogMessageProcessor::class); $def->addTag('monolog.processor', [ 'handler' =>'sentry', @@ -111,9 +114,8 @@ public function prepend(ContainerBuilder $container): void ] ]); } - if (isset($bundles['SentryBundle']) && 'prod' === $env) { + if (isset($bundles['SentryBundle'])) { $container->prependExtensionConfig('sentry', [ - 'dsn' => '%env(SENTRY_DSN)%', 'register_error_listener' => false, // Disables the ErrorListener to avoid duplicated log in sentry 'tracing' => [ 'dbal' => [ @@ -124,11 +126,26 @@ public function prepend(ContainerBuilder $container): void 'environment' => '%env(SENTRY_ENVIRONMENT)%', 'release' => '%env(SENTRY_RELEASE)%', 'send_default_pii' => true, + 'tags' => [ + 'app.name' => '%alchemy_core.app_name%', + 'app.id' => '%alchemy_core.app_id%', + ], 'ignore_exceptions' => [ TooManyRequestsHttpException::class, ], ] ]); + + if (isset($bundles['MonologBundle'])) { + $container->prependExtensionConfig('monolog', [ + 'handlers' => [ + 'sentry' => [ + 'type' => 'service', + 'id' => \Sentry\Monolog\Handler::class, + ], + ], + ]); + } } } } diff --git a/lib/php/core-bundle/DependencyInjection/Configuration.php b/lib/php/core-bundle/DependencyInjection/Configuration.php index 8d51b817d..64a904808 100644 --- a/lib/php/core-bundle/DependencyInjection/Configuration.php +++ b/lib/php/core-bundle/DependencyInjection/Configuration.php @@ -17,6 +17,8 @@ public function getConfigTreeBuilder(): TreeBuilder $treeBuilder = new TreeBuilder('alchemy_core'); $treeBuilder->getRootNode() ->children() + ->scalarNode('app_name')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('app_id')->defaultValue('%env(APP_ID)%')->cannotBeEmpty()->end() ->scalarNode('app_url')->defaultNull()->end() ->arrayNode('healthcheck') ->canBeEnabled() diff --git a/lib/php/core-bundle/README.md b/lib/php/core-bundle/README.md index 704b9227a..988a0ef38 100644 --- a/lib/php/core-bundle/README.md +++ b/lib/php/core-bundle/README.md @@ -22,10 +22,11 @@ Add route: ```yaml # config/routes/alchemy_core.yaml alchemy_core_healthcheck: - controller: Alchemy\CoreBundle\Controller\HealthCheckAction + resource: Alchemy\CoreBundle\Controller\HealthCheckAction + type: attribute alchemy_core_sentry_test: - controller: Alchemy\CoreBundle\Controller\SentryTestController - + resource: Alchemy\CoreBundle\Controller\SentryTestController + type: attribute ``` Ensure the route is not protected: diff --git a/lib/php/core-bundle/Resources/config/sentry.yaml b/lib/php/core-bundle/Resources/config/sentry.yaml index 65243d25b..758b9c41f 100644 --- a/lib/php/core-bundle/Resources/config/sentry.yaml +++ b/lib/php/core-bundle/Resources/config/sentry.yaml @@ -2,3 +2,15 @@ parameters: env(SENTRY_DSN): ~ env(SENTRY_ENVIRONMENT): prod env(SENTRY_RELEASE): 'undefined' + +services: + _defaults: + autowire: true + autoconfigure: true + + Alchemy\CoreBundle\Controller\SentryTestController: ~ + + Sentry\Monolog\Handler: + arguments: + $hub: '@Sentry\State\HubInterface' + $level: !php/const Monolog\Logger::ERROR diff --git a/lib/php/report-bundle/DependencyInjection/AlchemyReportExtension.php b/lib/php/report-bundle/DependencyInjection/AlchemyReportExtension.php index 1ee522adc..c3631c47b 100644 --- a/lib/php/report-bundle/DependencyInjection/AlchemyReportExtension.php +++ b/lib/php/report-bundle/DependencyInjection/AlchemyReportExtension.php @@ -19,9 +19,6 @@ public function load(array $configs, ContainerBuilder $container): void $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); - $container->setParameter('alchemy_report.app_name', $config['app_name']); - $container->setParameter('alchemy_report.app_id', $config['app_id']); - $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yaml'); diff --git a/lib/php/report-bundle/DependencyInjection/Configuration.php b/lib/php/report-bundle/DependencyInjection/Configuration.php index 62546fab3..1bcd1d392 100644 --- a/lib/php/report-bundle/DependencyInjection/Configuration.php +++ b/lib/php/report-bundle/DependencyInjection/Configuration.php @@ -17,8 +17,6 @@ public function getConfigTreeBuilder(): TreeBuilder $treeBuilder = new TreeBuilder('alchemy_report'); $treeBuilder->getRootNode() ->children() - ->scalarNode('app_id')->defaultValue('%env(APP_ID)%')->end() - ->scalarNode('app_name')->isRequired()->end() ->end() ; diff --git a/lib/php/report-bundle/README.md b/lib/php/report-bundle/README.md index e9abe7cf8..f6db12ef1 100644 --- a/lib/php/report-bundle/README.md +++ b/lib/php/report-bundle/README.md @@ -6,10 +6,12 @@ If user is authenticated, user ID will be provided automatically. ## Configuration +Config is taken from alchemy_core extension: + ```yaml -# config/packages/alchemy_report.yml +# config/packages/alchemy_core.yml -alchemy_report: +alchemy_core: app_name: my-app-name ``` diff --git a/lib/php/report-bundle/Resources/config/services.yaml b/lib/php/report-bundle/Resources/config/services.yaml index af25d2833..a746ae37f 100644 --- a/lib/php/report-bundle/Resources/config/services.yaml +++ b/lib/php/report-bundle/Resources/config/services.yaml @@ -20,8 +20,8 @@ services: Alchemy\ReportSDK\ReportClient: arguments: - $appName: "%alchemy_report.app_name%" - $appId: "%alchemy_report.app_id%" + $appName: "%alchemy_core.app_name%" + $appId: "%alchemy_core.app_id%" $client: "@alchemy_report.http_client" Alchemy\ReportBundle\ReportUserService: diff --git a/notify/api/config/packages/alchemy_core.yaml b/notify/api/config/packages/alchemy_core.yaml index 7ee85b1ff..939195948 100644 --- a/notify/api/config/packages/alchemy_core.yaml +++ b/notify/api/config/packages/alchemy_core.yaml @@ -1,3 +1,4 @@ alchemy_core: - healthcheck: ~ - sentry: ~ + app_name: notify + healthcheck: ~ + sentry: ~ diff --git a/notify/api/config/routes/alchemy_core.yaml b/notify/api/config/routes/alchemy_core.yaml index 597924087..498840e88 100644 --- a/notify/api/config/routes/alchemy_core.yaml +++ b/notify/api/config/routes/alchemy_core.yaml @@ -1,6 +1,6 @@ alchemy_core_healthcheck: - controller: Alchemy\CoreBundle\Controller\HealthCheckAction - path: / + resource: Alchemy\CoreBundle\Controller\HealthCheckAction + type: attribute alchemy_core_sentry_test: - controller: Alchemy\CoreBundle\Controller\SentryTestController - path: / + resource: Alchemy\CoreBundle\Controller\SentryTestController + type: attribute diff --git a/uploader/api/config/packages/alchemy_core.yaml b/uploader/api/config/packages/alchemy_core.yaml index 53c2539aa..ed8aedcef 100644 --- a/uploader/api/config/packages/alchemy_core.yaml +++ b/uploader/api/config/packages/alchemy_core.yaml @@ -1,4 +1,5 @@ alchemy_core: - app_url: '%env(UPLOADER_API_URL)%' - healthcheck: ~ - sentry: ~ + app_name: uploader + app_url: '%env(UPLOADER_API_URL)%' + healthcheck: ~ + sentry: ~ diff --git a/uploader/api/config/packages/alchemy_report.yml b/uploader/api/config/packages/alchemy_report.yml deleted file mode 100644 index ef7b9dbc2..000000000 --- a/uploader/api/config/packages/alchemy_report.yml +++ /dev/null @@ -1,2 +0,0 @@ -alchemy_report: - app_name: uploader diff --git a/uploader/api/config/routes/alchemy_core.yaml b/uploader/api/config/routes/alchemy_core.yaml index 597924087..498840e88 100644 --- a/uploader/api/config/routes/alchemy_core.yaml +++ b/uploader/api/config/routes/alchemy_core.yaml @@ -1,6 +1,6 @@ alchemy_core_healthcheck: - controller: Alchemy\CoreBundle\Controller\HealthCheckAction - path: / + resource: Alchemy\CoreBundle\Controller\HealthCheckAction + type: attribute alchemy_core_sentry_test: - controller: Alchemy\CoreBundle\Controller\SentryTestController - path: / + resource: Alchemy\CoreBundle\Controller\SentryTestController + type: attribute