Skip to content

Commit 78849b4

Browse files
authored
Fix missing driver instrumentation (#775)
1 parent a7a57f0 commit 78849b4

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

DependencyInjection/DoctrineMongoDBExtension.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Doctrine\Common\EventSubscriber;
1717
use Doctrine\ODM\MongoDB\DocumentManager;
1818
use InvalidArgumentException;
19+
use Jean85\PrettyVersions;
1920
use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension;
2021
use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber;
2122
use Symfony\Component\Cache\Adapter\ApcuAdapter;
@@ -31,6 +32,7 @@
3132
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
3233
use Symfony\Component\DependencyInjection\Reference;
3334
use Symfony\Component\Messenger\MessageBusInterface;
35+
use Throwable;
3436

3537
use function array_keys;
3638
use function array_merge;
@@ -48,6 +50,9 @@
4850
*/
4951
class DoctrineMongoDBExtension extends AbstractDoctrineExtension
5052
{
53+
/** @var string */
54+
private static $odmVersion;
55+
5156
/** @internal */
5257
public const CONFIGURATION_TAG = 'doctrine.odm.configuration';
5358

@@ -407,6 +412,11 @@ private function normalizeDriverOptions(array $connection)
407412
$driverOptions['context'] = new Reference($driverOptions['context']);
408413
}
409414

415+
$driverOptions['driver'] = [
416+
'name' => 'symfony-mongodb',
417+
'version' => self::getODMVersion(),
418+
];
419+
410420
return $driverOptions;
411421
}
412422

@@ -610,4 +620,17 @@ private function buildDeprecationArgs(string $version, string $message): array
610620
? ['doctrine/mongodb-odm-bundle', $version, $message]
611621
: [$message];
612622
}
623+
624+
private static function getODMVersion(): string
625+
{
626+
if (self::$odmVersion === null) {
627+
try {
628+
self::$odmVersion = PrettyVersions::getVersion('doctrine/mongodb-odm')->getPrettyVersion();
629+
} catch (Throwable $t) {
630+
return 'unknown';
631+
}
632+
}
633+
634+
return self::$odmVersion;
635+
}
613636
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"doctrine/annotations": "^1.13",
1818
"doctrine/mongodb-odm": "^2.3",
1919
"doctrine/persistence": "^2.2|^3.0",
20+
"jean85/pretty-package-versions": "^1.3.0 || ^2.0.1",
2021
"psr/log": "^1.0|^2.0|^3.0",
2122
"symfony/config": "^4.4|^5.3|^6.0",
2223
"symfony/console": "^4.4.6|^5.3|^6.0",

0 commit comments

Comments
 (0)