Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
],
"require": {
"php": "^7.2||^8.0",
"composer-runtime-api": "^2.0",
"guzzlehttp/psr7": "^2.1.1",
"jean85/pretty-package-versions": "^1.5||^2.0",
"sentry/sentry": "^4.23.0",
"symfony/cache-contracts": "^1.1||^2.4||^3.0",
"symfony/config": "^4.4.20||^5.0.11||^6.0||^7.0||^8.0",
Expand Down Expand Up @@ -85,7 +85,6 @@
"config": {
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true,
"phpstan/extension-installer": true
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/SentryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Sentry\SentryBundle\DependencyInjection;

use Composer\InstalledVersions;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Jean85\PrettyVersions;
use Psr\Log\NullLogger;
use Sentry\Client;
use Sentry\ClientBuilder;
Expand Down Expand Up @@ -66,7 +66,7 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container
$loader->load('services.yaml');

if (!$container->hasParameter('env(SENTRY_RELEASE)')) {
$container->setParameter('env(SENTRY_RELEASE)', PrettyVersions::getRootPackageVersion()->getPrettyVersion());
$container->setParameter('env(SENTRY_RELEASE)', InstalledVersions::getRootPackage()['pretty_version']);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dev release version loses commit hash

Medium Severity

PrettyVersions::getPrettyVersion() appended a short commit reference for non-tagged packages (e.g. dev-main@7cd88c8), but InstalledVersions::getRootPackage()['pretty_version'] returns only the branch name. When release and SENTRY_RELEASE are unset, branch-based deploys now share one Sentry release identifier, weakening release tracking and suspect commits.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b8ef45f. Configure here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is true but I believe it is no relevant in the current context, because it just fetches the root package version as a fallback if there is no SENTRY_RELEASE env variable defined. If it is really an issue, I think we can preserve the previous behavior by using the root package reference when available and appending its short SHA (e.g. dev-main@7cd88c8). That keeps the dependency removal while maintaining unique release identifiers for branch-based deployments.

$rootPackage = InstalledVersions::getRootPackage();
$release = $rootPackage['pretty_version'];
if (
    isset($rootPackage['reference'])
    && $rootPackage['reference'] !== null
    && str_starts_with($release, 'dev-')
) {
    $release .= '@' . substr($rootPackage['reference'], 0, 7);
}

}

// Remove Twig extension service if Twig is not installed to avoid autoloading failures on Symfony 8
Expand Down
4 changes: 2 additions & 2 deletions tests/DependencyInjection/SentryExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Sentry\SentryBundle\Tests\DependencyInjection;

use Composer\InstalledVersions;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Jean85\PrettyVersions;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
use Sentry\ClientInterface;
Expand Down Expand Up @@ -565,7 +565,7 @@ public function releaseOptionDataProvider(): \Generator

yield 'If both the release option and the SENTRY_RELEASE environment variable are unset, then the root package version is used as fallback' => [
'release_option_fallback_to_composer_version',
PrettyVersions::getRootPackageVersion()->getPrettyVersion(),
InstalledVersions::getRootPackage()['pretty_version'],
];
}

Expand Down