MongoDB.ApplicationInsights 1.0.0

.NET Standard 1.6
There is a newer version of this package available.
See the version list below for details.
Install-Package MongoDB.ApplicationInsights -Version 1.0.0
dotnet add package MongoDB.ApplicationInsights --version 1.0.0
<PackageReference Include="MongoDB.ApplicationInsights" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MongoDB.ApplicationInsights --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MongoDB.ApplicationInsights, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install MongoDB.ApplicationInsights as a Cake Addin
#addin nuget:?package=MongoDB.ApplicationInsights&version=1.0.0

// Install MongoDB.ApplicationInsights as a Cake Tool
#tool nuget:?package=MongoDB.ApplicationInsights&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.


Adds application insights tracking into MongoDB in an easy to use way. There is also a second libary, MongoDB.ApplicationInsights.DependencyInjection which adds convenience functions for configuring the .NET core dependency injection system.

A simple example usage with the dependency injection helpers:

using Microsoft.ApplicationInsights;
using MongoDB.ApplicationInsights.DependencyInjection;

public class Startup
    public void ConfigureServices(IServiceCollection services)

public class MyClass
    private readonly IMongoClient _client;

    public MyClass(IMongoClient client)
        _client = client;

And without:

using Microsoft.ApplicationInsights;
using MongoDB.ApplicationInsights;

public class Program
    public static void Main(string[] args)
        var config = new TelemetryConfiguration
            InstrumentationKey = "your-appinsights-key"
        var telemetryClient = new TelemetryClient(config);
        var factory = new MongoClientFactory(telemetryClient);
        var client = factory.GetClient("mongodb://localhost:27017/");


The telemetry can be configured by passing an instance of MongoApplicationInsightsSettings to any of the functions that ultimately constructs a MongoClient instance.

    public class MongoApplicationInsightsSettings
        public HashSet<string> FilteredCommands { get; set; };
        public TimeSpan MaxQueryTime { get; set; };

FilteredCommands names the mongo commands to ignore. By default these are buildInfo, getLastError, isMaster, saslStart and saslContinue.

MaxQueryTime is a fallback to prevent memory leaks if mongo reports that a command has started, but does not later report whether it has succeeded or failed. It is set to 4 hours by default -- if you have queries that run for longer than this time then you will need to increase the setting to prevent telemetry for those queries from being discarded.


MongoClientFactory takes mongo settings, application insights settings and constructs instances of MongoClient with the settings applied.

public MongoClientFactory(TelemetryClient telemetryClient, MongoApplicationInsightsSettings settings = null)

The constructor takes an instance of the telemetry client to use, and the telemetry settings.

IMongoClient GetClient(MongoClientSettings clientSettings);
IMongoClient GetClient(MongoUrl mongoUrl);
IMongoClient GetClient(string connectionString);

These functions construct a MongoClient instance in the same way as the corresponding MongoClient constructor calls, but with telemetry applied.

The dependency injection helper will register a singleton MongoClientFactory:

public static IServiceCollection AddMongoClientFactory(
    this IServiceCollection services,
    MongoApplicationInsightsSettings settings = null

MongoApplicationInsightsSettings will be registered with the dependency injection container (or a default instance will be registered if it is not provided).

Dependency injection helpers

public static IServiceCollection AddMongoClient(
    this IServiceCollection services,
    string connectionString,
    MongoApplicationInsightsSettings settings = null
public static IServiceCollection AddMongoClient(
    this IServiceCollection services,
    MongoUrl url,
    MongoApplicationInsightsSettings settings = null
public static IServiceCollection AddMongoClient(
    this IServiceCollection services,
    MongoClientSettings clientSettings,
    MongoApplicationInsightsSettings settings = null

These three helpers register a singleton MongoClientFactory instance using the provided settings (if any), and then a singleton IMongoClient which will construct a client using the factory and the provided mongo client settings. There is a short example of using these at the start of this document.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp1.0 netcoreapp1.1 netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard1.6 netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen30 tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on MongoDB.ApplicationInsights:

Package Downloads

Adds application insights tracking into MongoDB with convenience functions for configuring the .NET core dependency injection system.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.34 96,523 10/28/2020
1.0.32 288 10/28/2020
1.0.30 9,760 6/18/2020
1.0.29 354 6/18/2020
1.0.23 389 6/12/2020
1.0.19 8,765 8/8/2019
1.0.18 438 8/5/2019
1.0.17 416 8/5/2019
1.0.16 426 8/5/2019
1.0.0 705 8/5/2019