Skip to content

Commit 73a851b

Browse files
committed
Introduce TracingDriverForV3Point2
This driver does not implement the deprecated `VersionAwarePlatformDriver`. It's automatically picked when `doctrine/dbal` version `3.2.0` or higher is installed. Fixes #579
1 parent a39c362 commit 73a851b

File tree

3 files changed

+110
-1
lines changed

3 files changed

+110
-1
lines changed

.github/workflows/tests.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
- 6.*
3131
dependencies:
3232
- highest
33+
doctrine-dbal:
34+
- highest
3335
exclude:
3436
- php: '7.2'
3537
symfony-version: 6.*
@@ -47,6 +49,12 @@ jobs:
4749
- php: '8.0'
4850
symfony-version: 6.*
4951
dependencies: lowest
52+
- php: '8.1'
53+
symfony-version: 6.*
54+
doctrine-dbal: '^2.13'
55+
- php: '8.1'
56+
symfony-version: 6.*
57+
doctrine-dbal: '<3.2'
5058

5159
steps:
5260
- name: Checkout
@@ -68,6 +76,10 @@ jobs:
6876
run: composer require --dev phpunit/phpunit ^9.3.9 --no-update
6977
if: matrix.php == '8.0' && matrix.dependencies == 'lowest'
7078

79+
- name: Update Doctrine DBAL
80+
run: composer require --dev doctrine/dbal "${{ matrix.doctrine-dbal }}" --no-update
81+
if: matrix.doctrine-dbal != 'highest'
82+
7183
- name: Install dependencies
7284
uses: ramsey/composer-install@v1
7385
with:
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sentry\SentryBundle\Tracing\Doctrine\DBAL;
6+
7+
use Doctrine\DBAL\Connection;
8+
use Doctrine\DBAL\Driver;
9+
use Doctrine\DBAL\Driver\API\ExceptionConverter;
10+
use Doctrine\DBAL\Platforms\AbstractPlatform;
11+
use Doctrine\DBAL\Schema\AbstractSchemaManager;
12+
use Doctrine\DBAL\VersionAwarePlatformDriver;
13+
14+
/**
15+
* This is a simple implementation of the {@see Driver} interface that decorates
16+
* an existing driver to support distributed tracing capabilities. This implementation
17+
* is compatible with all versions of Doctrine DBAL >= 3.2.
18+
*
19+
* @internal
20+
*
21+
* @phpstan-import-type Params from \Doctrine\DBAL\DriverManager as ConnectionParams
22+
*/
23+
final class TracingDriverForV3Point2 implements Driver
24+
{
25+
/**
26+
* @var TracingDriverConnectionFactoryInterface The connection factory
27+
*/
28+
private $connectionFactory;
29+
30+
/**
31+
* @var Driver|VersionAwarePlatformDriver The instance of the decorated driver
32+
*/
33+
private $decoratedDriver;
34+
35+
/**
36+
* Constructor.
37+
*
38+
* @param TracingDriverConnectionFactoryInterface $connectionFactory The connection factory
39+
* @param Driver $decoratedDriver The instance of the driver to decorate
40+
*/
41+
public function __construct(TracingDriverConnectionFactoryInterface $connectionFactory, Driver $decoratedDriver)
42+
{
43+
$this->connectionFactory = $connectionFactory;
44+
$this->decoratedDriver = $decoratedDriver;
45+
}
46+
47+
/**
48+
* {@inheritdoc}
49+
*
50+
* @phpstan-param ConnectionParams $params
51+
*/
52+
public function connect(array $params): TracingDriverConnectionInterface
53+
{
54+
return $this->connectionFactory->create(
55+
$this->decoratedDriver->connect($params),
56+
$this->decoratedDriver->getDatabasePlatform(),
57+
$params
58+
);
59+
}
60+
61+
/**
62+
* {@inheritdoc}
63+
*/
64+
public function getDatabasePlatform(): AbstractPlatform
65+
{
66+
return $this->decoratedDriver->getDatabasePlatform();
67+
}
68+
69+
/**
70+
* {@inheritdoc}
71+
*
72+
* @phpstan-template T of AbstractPlatform
73+
*
74+
* @phpstan-param T $platform
75+
*
76+
* @phpstan-return AbstractSchemaManager<T>
77+
*/
78+
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
79+
{
80+
return $this->decoratedDriver->getSchemaManager($conn, $platform);
81+
}
82+
83+
/**
84+
* {@inheritdoc}
85+
*/
86+
public function getExceptionConverter(): ExceptionConverter
87+
{
88+
return $this->decoratedDriver->getExceptionConverter();
89+
}
90+
}

src/aliases.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Sentry\SentryBundle;
66

7+
use Composer\InstalledVersions;
78
use Doctrine\DBAL\Result;
89
use Sentry\SentryBundle\Tracing\Cache\TraceableCacheAdapter;
910
use Sentry\SentryBundle\Tracing\Cache\TraceableCacheAdapterForV2;
@@ -15,6 +16,7 @@
1516
use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverForV2;
1617
use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverForV3;
1718
use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingStatement;
19+
use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverForV3Point2;
1820
use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingStatementForV2;
1921
use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingStatementForV3;
2022
use Sentry\SentryBundle\Tracing\HttpClient\TraceableHttpClient;
@@ -53,7 +55,12 @@ class_alias(TraceableTagAwareCacheAdapterForV2::class, TraceableTagAwareCacheAda
5355
if (!class_exists(TracingStatement::class)) {
5456
if (class_exists(Result::class)) {
5557
class_alias(TracingStatementForV3::class, TracingStatement::class);
56-
class_alias(TracingDriverForV3::class, TracingDriver::class);
58+
59+
if (class_exists(InstalledVersions::class) && version_compare(InstalledVersions::getVersion('doctrine/dbal') ?? '0', '3.2', '>=')) {
60+
class_alias(TracingDriverForV3Point2::class, 'Sentry\\SentryBundle\\Tracing\\Doctrine\\DBAL\\TracingDriver');
61+
} else {
62+
class_alias(TracingDriverForV3::class, TracingDriver::class);
63+
}
5764
} elseif (interface_exists(Result::class)) {
5865
class_alias(TracingStatementForV2::class, TracingStatement::class);
5966
class_alias(TracingDriverForV2::class, TracingDriver::class);

0 commit comments

Comments
 (0)