Skip to content

Commit

Permalink
Fix missing driver instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Jul 20, 2023
1 parent a7a57f0 commit 817641e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions DependencyInjection/DoctrineMongoDBExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Doctrine\Common\EventSubscriber;
use Doctrine\ODM\MongoDB\DocumentManager;
use InvalidArgumentException;
use Jean85\PrettyVersions;
use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension;
use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber;
use Symfony\Component\Cache\Adapter\ApcuAdapter;
Expand All @@ -32,6 +33,7 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Messenger\MessageBusInterface;

use Throwable;

Check failure on line 36 in DependencyInjection/DoctrineMongoDBExtension.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Expected 0 lines between same types of use statement, found 1.
use function array_keys;

Check failure on line 37 in DependencyInjection/DoctrineMongoDBExtension.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Expected 1 line between different types of use statement, found 0.
use function array_merge;
use function class_exists;
Expand All @@ -48,6 +50,9 @@
*/
class DoctrineMongoDBExtension extends AbstractDoctrineExtension
{
/** @var string */
private static $odmVersion;

/** @internal */
public const CONFIGURATION_TAG = 'doctrine.odm.configuration';

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

$driverOptions['driver'] = [
'name' => 'symfony-mongodb',
'version' => self::getODMVersion(),
];

return $driverOptions;
}

Expand Down Expand Up @@ -610,4 +620,17 @@ private function buildDeprecationArgs(string $version, string $message): array
? ['doctrine/mongodb-odm-bundle', $version, $message]
: [$message];
}

private static function getODMVersion(): string
{
if (self::$odmVersion === null) {
try {
self::$odmVersion = PrettyVersions::getVersion('doctrine/mongodb-odm')->getPrettyVersion();
} catch (Throwable $t) {
return 'unknown';
}
}

return self::$odmVersion;
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"doctrine/annotations": "^1.13",
"doctrine/mongodb-odm": "^2.3",
"doctrine/persistence": "^2.2|^3.0",
"jean85/pretty-package-versions": "^1.3.0 || ^2.0.1",
"psr/log": "^1.0|^2.0|^3.0",
"symfony/config": "^4.4|^5.3|^6.0",
"symfony/console": "^4.4.6|^5.3|^6.0",
Expand Down

0 comments on commit 817641e

Please sign in to comment.