Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/DependencyInjection/SentryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Sentry\SentryBundle\Tracing\Doctrine\DBAL\ConnectionConfigurator;
use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverMiddleware;
use Sentry\SentryBundle\Tracing\Twig\TwigTracingExtension;
use Sentry\SentryBundle\Twig\SentryExtension as TwigSentryExtension;
use Sentry\Serializer\RepresentationSerializer;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Cache\CacheItem;
Expand Down Expand Up @@ -71,7 +72,7 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container

// Remove Twig extension service if Twig is not installed to avoid autoloading failures on Symfony 8
if (!class_exists(\Twig\Extension\AbstractExtension::class)) {
$container->removeDefinition(\Sentry\SentryBundle\Twig\SentryExtension::class);
$container->removeDefinition(TwigSentryExtension::class);
Copy link

Choose a reason for hiding this comment

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

Bug: TwigTracingExtension not removed when Twig unavailable

When AbstractExtension doesn't exist (Twig not installed), only TwigSentryExtension is removed. However, TwigTracingExtension also extends AbstractExtension and will cause autoloading failures if Twig is unavailable. Both extensions should be removed when checking for Twig availability to prevent compilation errors on Symfony 8.

Fix in Cursor Fix in Web

}

$this->registerConfiguration($container, $mergedConfig);
Expand Down Expand Up @@ -281,6 +282,7 @@ private function registerTwigTracingConfiguration(ContainerBuilder $container, a
}

if (!$isConfigEnabled) {
$container->removeDefinition(TwigSentryExtension::class);
Copy link

Choose a reason for hiding this comment

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

Bug: TwigSentryExtension incorrectly removed when tracing disabled

TwigSentryExtension is being removed when Twig tracing is disabled, preventing users from using Twig functions like sentry_trace_meta() even when Twig is installed. TwigSentryExtension provides general Sentry Twig functions and should only be removed when Twig itself isn't installed (already handled at line 75), not when tracing is disabled. Only TwigTracingExtension should be removed when tracing is disabled.

Fix in Cursor Fix in Web

$container->removeDefinition(TwigTracingExtension::class);
}
}
Expand Down
Loading