Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Sentry bundle breaks Symfony cache adapter #530

@Jeroeny

Description

@Jeroeny

Environment

PHP: 8.0.8
Sentry dependencies installed via composer 2.1.3:

  • sentry/sdk 3.1.0
  • sentry/sentry 3.3.1
  • sentry/sentry-symfony 4.1.4

Steps to Reproduce

  1. Install symfony/cache 5.3.* (haven't checked other major/minor versions, but I expect the same behaviour in other supported versions) and doctrine/dbal 3.1.1
  2. Configure a doctrine connection in cache/packages/{env}/doctrine.php:
return static function (ContainerConfigurator $containerConfigurator): void {
    $containerConfigurator
        ->extension('doctrine', [
            'dbal' => [
                'default_connection' => 'mysql',
                'connections' => [
                    'mysql' => [
                        'driver' => 'pdo_mysql',
                        'host' => env('..'),
                        'dbname' => env('..'),
                        'user' => env('..'),
                        'password' => env('..'),
                        'server_version' => param('..'),
                        'mapping_types' => ['enum' => 'string'],
                    ],
                ]
            ]
        ]);
  1. Configure a cache adapter in cache/packages/{env}/cache.php:
return static function (ContainerConfigurator $containerConfigurator): void {
    $containerConfigurator->extension('framework', [
        'cache' => [
            'pools' => [
                'pdo' => [
                    'default_lifetime' => 86400,
                    'adapters' => [
                        [
                            'name' => 'cache.adapter.pdo',
                            'provider' => 'doctrine.dbal.mysql_connection',
                        ],
                    ],
                ],
           ]
      ]
]);
  1. Configure Sentry in cache/packages/{env}/sentry.php:
return static function (SentryConfig $configurator): void {
    $configurator
        ->dsn('..');

    $tracing = $configurator
        ->tracing()
            ->enabled(true);

    $tracing
        ->dbal()
            ->enabled(true)
            ->connections(['mysql']);

(This uses the new generated Config objects, but can be achieved with regular php or yaml config as well).

This results in:

  • A Symfony DI-service: doctrine.dbal.mysql_connection
  • Sentry wraps the Connection of the driver of this mysql connection with the TracingDriver (similar with Dbal v2)
  • A PDO Cache adapter that using this mysql connection

Expected Result

The cache adapter continues to work and Sentry is able to do its tracing on dbal queries.

Actual Result

14:22:03 WARNING   [cache] Failed to save key "xxx" of type string: Creating the cache table is currently not implemented for PDO driver "Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriver".

Which is thrown here: https://github.com/symfony/symfony/blob/5.4/src/Symfony/Component/Cache/Adapter/PdoAdapter.php#L156

That method expects the driver to be one of Dbal's known drivers, but instead gets the TracingDriver (set at https://github.com/symfony/symfony/blob/5.4/src/Symfony/Component/Cache/Adapter/PdoAdapter.php#L477).

Is this a known issue and/or something I can do to prevent this? If needed I can try to provide a reproducer project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions