-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DbalTracingPass is overridden by DoctrineBundle's own MiddlewaresPass #805
Comments
So, adding autoconfigure="true" for TracingDriverMiddleware in the bundle's services.xml magically made it work! (even though I can't choose which connections to trace like this) I can see that Doctrine lets you specify a connection on a tag, so rewriting DbalTracingPass to just add the middleware tag(s) manually should make this much more robust - unless I missed something? |
Can you please try registering the Sentry bundle after |
Makes no difference, unfortunately. MiddlewaresPass still seems to run first |
For now, I'm working around this with the following snippet in services.yaml: Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverMiddleware:
autoconfigure: true
arguments:
- '@Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverConnectionFactoryInterface' This is basically what I did before, just in my application's service configuration so I don't need to modify dependency code. It seems to work, even though it needlessly instantiates protected static function getDoctrine_Dbal_DefaultConnectionService($container)
{
$a = new \Doctrine\DBAL\Configuration();
$b = new \Doctrine\Bundle\DoctrineBundle\Middleware\DebugMiddleware(($container->privates['doctrine.debug_data_holder'] ??= new \Doctrine\Bundle\DoctrineBundle\Middleware\BacktraceDebugDataHolder([])), ($container->services['debug.stopwatch'] ??= new \Symfony\Component\Stopwatch\Stopwatch(true)));
$b->setConnectionName('default');
$a->setSchemaManagerFactory(new \Doctrine\DBAL\Schema\LegacySchemaManagerFactory());
$a->setMiddlewares([($container->services['Sentry\\SentryBundle\\Tracing\\Doctrine\\DBAL\\TracingDriverMiddleware'] ?? self::getTracingDriverMiddlewareService($container))]);
$a->setMiddlewares([new \Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverMiddleware(($container->privates['Sentry\\SentryBundle\\Tracing\\Doctrine\\DBAL\\TracingDriverConnectionFactory'] ?? self::getTracingDriverConnectionFactoryService($container))), $b]);
// ...
} |
How do you use Sentry?
Sentry SaaS (sentry.io)
SDK version
4.13.2
Steps to reproduce
Relevant dependencies:
Nothing special otherwise, just have Sentry-Symfony and its profiling integration activated.
Expected result
Sentry hooks into DBAL, to enable its profiling functionality for queries
Actual result
Sentry fails to hook into DBAL, because DBALs
MiddlewarePass
adds another setMiddlewares invocation that ends up overwriting the call placed there byDbalTracingPass
.MiddlewarePass
always seems to place that call, no matter if the set of middlewares it adds is empty or not (e.g. with or without Symfony's own profiling middleware).I suppose the order in which these passes run is important (it'll work if DbalTracingPass runs last (because it removes a previous setMiddlewares call anyway), but it won't work the other way around)
Looking at the generated container in var/cache:
It seems to me that the proper way to go here if possible, is to cooperate with the MiddlewarePass instead of fighting it, e.g. attempting to get TracingDriverMiddleware tagged properly.
Usually, the appropriate tag needed for MiddlewarePass to find middlewares should be added automatically through autowiring to anything implementing its
Middleware
interface, or marked through theAsMiddleware
PHP attribute. The tagging is done byDoctrineExtension
.I don't know enough about autowiring and Symfony's DI system to answer why this isn't working:
The text was updated successfully, but these errors were encountered: