Skip to content

Commit

Permalink
Fix missing driver instrumentation (#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus authored Jul 20, 2023
1 parent a7a57f0 commit 78849b4
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 @@ -31,6 +32,7 @@
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Messenger\MessageBusInterface;
use Throwable;

use function array_keys;
use function array_merge;
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 78849b4

Please sign in to comment.