Atatus .NET APM traces MongoDB commands issued through the official MongoDB.Driver (2.4.4+), creating a span for each command inside an active transaction.

Package installation

Add the Atatus MongoDB instrumentation package to the application.

copy
icon/buttons/copy
dotnet add package Atatus.MongoDb --version 3.2.2
Note:

If you are already using the Atatus.NetCoreAll package, MongoDB calls are captured automatically once the client is configured as shown below, and no additional subscription code is required.

Configure the MongoDB client

A prerequisite for auto-instrumentation is to configure the MongoClient with MongoDbEventSubscriber in your database initialization code:

using Atatus.NetCoreAll;
using Atatus.MongoDb;

var settings = MongoClientSettings.FromConnectionString(mongoConnectionString);
settings.ClusterConfigurator = builder => builder.Subscribe(new MongoDbEventSubscriber());
var mongoClient = new MongoClient(settings);

In certain cases you may need to manually activate auto-instrumentation by passing MongoDbDiagnosticsSubscriber to the Agent.Subscribe method:

using Atatus;
using Atatus.MongoDb;

Agent.Subscribe(new MongoDbDiagnosticsSubscriber());

What Atatus captures ?

  • A span for each command executed through the MongoDB.Driver client.
Note:

MongoDB integration is supported on .NET Core and newer. Because the MongoDB.Driver assemblies are not strongly named, they cannot be used with Atatus strongly named assemblies on .NET Framework.