Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing driver instrumentation #775

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it have more value if augmented with bundle's version as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. I'm not sure what other hosters use this for, but at MongoDB we use the data from MongoDB Atlas to judge version adoption and to influence strategic decisions (e.g. around what PHP versions to support/not support). In that sense the relevant info for us is a) the fact that someone is using the ODM through Symfony, and b) what ODM version they are using.

];

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
Loading