MongoDB.ApplicationInsights 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package MongoDB.ApplicationInsights --version 1.0.0
NuGet\Install-Package MongoDB.ApplicationInsights -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<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
#r "nuget: MongoDB.ApplicationInsights, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. 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

ci.appveyor.com codecov.io

MongoDB.ApplicationInsights

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)
    {
        services.AddApplicationInsightsTelemetry();
        services.AddMongoClient("mongodb://localhost:27017/");
    }
}

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/");
    }
}

MongoApplicationInsightsSettings

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

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 Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.6 is compatible.  netstandard2.0 was computed.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

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

Package Downloads
MongoDB.ApplicationInsights.DependencyInjection

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

Parlem.Provisioning.MasStack.Facade

MasStack Provisioning Library

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.34 519,329 10/28/2020
1.0.32 1,340 10/28/2020
1.0.30 14,990 6/18/2020
1.0.29 1,389 6/18/2020
1.0.23 1,380 6/12/2020
1.0.19 11,633 8/8/2019
1.0.18 1,451 8/5/2019
1.0.17 1,457 8/5/2019
1.0.16 1,479 8/5/2019
1.0.0 1,770 8/5/2019