Skip to content

Commit beb3ca0

Browse files
authored
Prefer the SENTRY_RELEASE environment variable over the package root version (#753)
1 parent b172a75 commit beb3ca0

18 files changed

+247
-5
lines changed

phpstan-baseline.neon

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,16 @@ parameters:
290290
count: 1
291291
path: tests/DependencyInjection/ConfigurationTest.php
292292

293+
-
294+
message: "#^Function Symfony\\\\Component\\\\DependencyInjection\\\\Loader\\\\Configurator\\\\ref not found\\.$#"
295+
count: 1
296+
path: tests/DependencyInjection/Fixtures/php/release_option_fallback_to_env_var.php
297+
298+
-
299+
message: "#^Used function Symfony\\\\Component\\\\DependencyInjection\\\\Loader\\\\Configurator\\\\ref not found\\.$#"
300+
count: 1
301+
path: tests/DependencyInjection/Fixtures/php/release_option_fallback_to_env_var.php
302+
293303
-
294304
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
295305
count: 1
@@ -305,6 +315,11 @@ parameters:
305315
count: 1
306316
path: tests/DependencyInjection/SentryExtensionTest.php
307317

318+
-
319+
message: "#^Cannot access offset 'release' on mixed\\.$#"
320+
count: 1
321+
path: tests/DependencyInjection/SentryExtensionTest.php
322+
308323
-
309324
message: "#^Class Symfony\\\\Component\\\\Debug\\\\Exception\\\\FatalErrorException not found\\.$#"
310325
count: 1

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Sentry\SentryBundle\DependencyInjection;
66

77
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
8-
use Jean85\PrettyVersions;
98
use Sentry\Options;
109
use Sentry\SentryBundle\ErrorTypesParser;
1110
use Sentry\Transport\TransportFactoryInterface;
@@ -102,7 +101,7 @@ public function getConfigTreeBuilder(): TreeBuilder
102101
->scalarNode('logger')->end()
103102
->scalarNode('release')
104103
->cannotBeEmpty()
105-
->defaultValue(PrettyVersions::getRootPackageVersion()->getPrettyVersion())
104+
->defaultValue('%env(default::SENTRY_RELEASE)%')
106105
->end()
107106
->scalarNode('server_name')->end()
108107
->scalarNode('before_send')->end()

src/DependencyInjection/SentryExtension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Sentry\SentryBundle\DependencyInjection;
66

77
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
8+
use Jean85\PrettyVersions;
89
use Psr\Log\NullLogger;
910
use Sentry\Client;
1011
use Sentry\ClientBuilder;
@@ -67,6 +68,10 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container
6768
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
6869
$loader->load('services.xml');
6970

71+
if (!$container->hasParameter('env(SENTRY_RELEASE)')) {
72+
$container->setParameter('env(SENTRY_RELEASE)', PrettyVersions::getRootPackageVersion()->getPrettyVersion());
73+
}
74+
7075
$this->registerConfiguration($container, $mergedConfig);
7176
$this->registerErrorListenerConfiguration($container, $mergedConfig);
7277
$this->registerMessengerListenerConfiguration($container, $mergedConfig['messenger']);

tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Sentry\SentryBundle\Tests\DependencyInjection;
66

77
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
8-
use Jean85\PrettyVersions;
98
use PHPUnit\Framework\TestCase;
109
use Sentry\SentryBundle\DependencyInjection\Configuration;
1110
use Symfony\Bundle\TwigBundle\TwigBundle;
@@ -29,7 +28,7 @@ public function testProcessConfigurationWithDefaultConfiguration(): void
2928
'integrations' => [],
3029
'prefixes' => array_merge(['%kernel.project_dir%'], array_filter(explode(\PATH_SEPARATOR, get_include_path() ?: ''))),
3130
'environment' => '%kernel.environment%',
32-
'release' => PrettyVersions::getRootPackageVersion()->getPrettyVersion(),
31+
'release' => '%env(default::SENTRY_RELEASE)%',
3332
'tags' => [],
3433
'in_app_exclude' => [
3534
'%kernel.cache_dir%',
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sentry\SentryBundle\Tests\DependencyInjection\Fixtures;
6+
7+
use Symfony\Component\DependencyInjection\EnvVarLoaderInterface;
8+
9+
final class StubEnvVarLoader implements EnvVarLoaderInterface
10+
{
11+
/**
12+
* @var array<string, string>
13+
*/
14+
private $envs = [];
15+
16+
/**
17+
* @param array<string, string> $envs
18+
*/
19+
public function __construct(array $envs)
20+
{
21+
$this->envs = $envs;
22+
}
23+
24+
public function loadEnvVars(): array
25+
{
26+
return $this->envs;
27+
}
28+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
7+
/** @var ContainerBuilder $container */
8+
$container->loadFromExtension('sentry', []);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Sentry\SentryBundle\Tests\DependencyInjection\Fixtures\StubEnvVarLoader;
6+
use Symfony\Component\DependencyInjection\EnvVarProcessor;
7+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
8+
9+
use function Symfony\Component\DependencyInjection\Loader\Configurator\ref;
10+
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
11+
use function Symfony\Component\DependencyInjection\Loader\Configurator\tagged_iterator;
12+
13+
return static function (ContainerConfigurator $container): void {
14+
$container->extension('sentry', []);
15+
16+
$container->services()
17+
->set(StubEnvVarLoader::class)
18+
->tag('container.env_var_loader')
19+
->args([['SENTRY_RELEASE' => '1.0.x-dev']])
20+
21+
->set(EnvVarProcessor::class)
22+
->tag('container.env_var_processor')
23+
->args([
24+
function_exists('Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\service') ? service('service_container') : ref('service_container'),
25+
tagged_iterator('container.env_var_loader'),
26+
]);
27+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
7+
/** @var ContainerBuilder $container */
8+
$container->loadFromExtension('sentry', [
9+
'options' => [
10+
'release' => '1.0.x-dev',
11+
],
12+
]);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
7+
/** @var ContainerBuilder $container */
8+
$container->setParameter('env(APP_RELEASE)', '1.0.x-dev');
9+
$container->loadFromExtension('sentry', [
10+
'options' => [
11+
'release' => '%env(APP_RELEASE)%',
12+
],
13+
]);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:sentry="https://sentry.io/schema/dic/sentry-symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
7+
https://sentry.io/schema/dic/sentry-symfony https://sentry.io/schema/dic/sentry-symfony/sentry-1.0.xsd">
8+
9+
<sentry:config />
10+
</container>

0 commit comments

Comments
 (0)