MongoDB.ApplicationInsights.DependencyInjection
1.0.0
See the version list below for details.
dotnet add package MongoDB.ApplicationInsights.DependencyInjection --version 1.0.0
NuGet\Install-Package MongoDB.ApplicationInsights.DependencyInjection -Version 1.0.0
<PackageReference Include="MongoDB.ApplicationInsights.DependencyInjection" Version="1.0.0" />
paket add MongoDB.ApplicationInsights.DependencyInjection --version 1.0.0
#r "nuget: MongoDB.ApplicationInsights.DependencyInjection, 1.0.0"
// Install MongoDB.ApplicationInsights.DependencyInjection as a Cake Addin #addin nuget:?package=MongoDB.ApplicationInsights.DependencyInjection&version=1.0.0 // Install MongoDB.ApplicationInsights.DependencyInjection as a Cake Tool #tool nuget:?package=MongoDB.ApplicationInsights.DependencyInjection&version=1.0.0
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 | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. 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 | 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. |
-
.NETStandard 2.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 2.2.0)
- MongoDB.ApplicationInsights (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.