Skip to content

Commit 9bd50a2

Browse files
committed
wip
1 parent 91b44dd commit 9bd50a2

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/DependencyInjection/SentryExtension.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container
6969
$container->setParameter('env(SENTRY_RELEASE)', PrettyVersions::getRootPackageVersion()->getPrettyVersion());
7070
}
7171

72+
// Remove Twig extension service if Twig is not installed to avoid autoloading failures on Symfony 8
73+
if (!class_exists(\Twig\Extension\AbstractExtension::class)) {
74+
$container->removeDefinition(\Sentry\SentryBundle\Twig\SentryExtension::class);
75+
}
76+
7277
$this->registerConfiguration($container, $mergedConfig);
7378
$this->registerErrorListenerConfiguration($container, $mergedConfig);
7479
$this->registerMessengerListenerConfiguration($container, $mergedConfig['messenger']);
@@ -244,6 +249,19 @@ private function registerDbalTracingConfiguration(ContainerBuilder $container, a
244249
$container->setParameter('sentry.tracing.dbal.enabled', $isConfigEnabled);
245250
$container->setParameter('sentry.tracing.dbal.connections', $isConfigEnabled ? $config['dbal']['connections'] : []);
246251

252+
$factoryServiceId = 'sentry.tracing.dbal.connection_factory';
253+
if ($container->hasDefinition($factoryServiceId)) {
254+
$factoryClass = \Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverConnectionFactoryForV2V3::class;
255+
256+
// On Symfony 8+, the container validates FQCN-like service IDs at compile time. Classes provided
257+
// via aliases.php aren’t considered during this check, so FQCN IDs without loadable classes fail
258+
if (class_exists(\Doctrine\DBAL\Result::class) && !interface_exists(\Doctrine\DBAL\VersionAwarePlatformDriver::class)) {
259+
$factoryClass = \Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverConnectionFactoryForV4::class;
260+
}
261+
262+
$container->getDefinition($factoryServiceId)->setClass($factoryClass);
263+
}
264+
247265
if (!$isConfigEnabled) {
248266
$container->removeDefinition(ConnectionConfigurator::class);
249267
$container->removeDefinition(TracingDriverMiddleware::class);
@@ -298,7 +316,7 @@ private function registerHttpClientTracingConfiguration(ContainerBuilder $contai
298316
}
299317

300318
/**
301-
* @param string[] $integrations
319+
* @param string[] $integrations
302320
* @param array<string, mixed> $config
303321
*
304322
* @return array<Reference|Definition>
@@ -330,12 +348,12 @@ private function configureRequestIntegration(array $integrations, bool $useDefau
330348

331349
/**
332350
* @param class-string<IntegrationInterface> $integrationClass
333-
* @param array<Reference|Definition> $integrations
351+
* @param array<Reference|Definition> $integrations
334352
*/
335353
private function isIntegrationEnabled(string $integrationClass, array $integrations): bool
336354
{
337355
foreach ($integrations as $integration) {
338-
if ($integration instanceof Reference && $integrationClass === (string) $integration) {
356+
if ($integration instanceof Reference && $integrationClass === (string)$integration) {
339357
return true;
340358
}
341359

src/Resources/config/services.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ services:
44

55
Sentry\ClientInterface: '@sentry.client'
66
Sentry\SentryBundle\EventListener\ConsoleCommandListener: '@Sentry\SentryBundle\EventListener\ConsoleListener'
7-
Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverConnectionFactoryInterface: '@Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverConnectionFactory'
7+
Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverConnectionFactoryInterface: '@sentry.tracing.dbal.connection_factory'
8+
Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverConnectionFactory: '@sentry.tracing.dbal.connection_factory'
89

910
Sentry\State\HubInterface:
1011
factory: ['Sentry\State\HubAdapter', 'getInstance']
@@ -83,11 +84,12 @@ services:
8384
tags:
8485
- { name: console.command, command: 'sentry:test' }
8586

86-
Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverConnectionFactory:
87+
sentry.tracing.dbal.connection_factory:
88+
class: Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverConnectionFactoryForV2V3
8789
arguments: ['@Sentry\State\HubInterface']
8890

8991
Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverMiddleware:
90-
arguments: ['@Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverConnectionFactory']
92+
arguments: ['@Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverConnectionFactoryInterface']
9193

9294
Sentry\SentryBundle\Tracing\Doctrine\DBAL\ConnectionConfigurator:
9395
arguments: ['@Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverMiddleware']

0 commit comments

Comments
 (0)