Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

jbogard/MongoDB.Driver.Core.Extensions.OpenTelemetry

Repository files navigation

MongoDB.Driver.Core.Extensions.OpenTelemetry

CI NuGet NuGet MyGet (dev)

Usage

This repo include the package:

The MongoDB.Driver.Core.Extensions.OpenTelemetry package provides adapters to OpenTelemetry.

To use MongoDB.Driver.Core.Extensions.OpenTelemetry, you need to configure your MongoClientSettings to add this MongoDB event subscriber through the MongoDB.Driver.Core.Extensions.DiagnosticSources package:

var clientSettings = MongoClientSettings.FromUrl(mongoUrl);
clientSettings.ClusterConfigurator = cb => cb.Subscribe(new DiagnosticsActivityEventSubscriber());
var mongoClient = new MongoClient(clientSettings);

That event subscriber exposes Activity events via a DiagnosticListener under the root activity name, MongoDB.Driver.Core.Events.Command. To subscribe, you may use the DiagnosticListener.AllListeners observable.

OpenTelemetry usage

Once you've configured your MongoDB client to expose diagnostics events as above, you can configure OpenTelemetry (typically through the OpenTelemetry.Extensions.Hosting package).

services.AddOpenTelemetryTracing(builder => {
    builder
        // Configure exporters
        .AddZipkinExporter()
        // Configure adapters
        .AddHttpClientInstrumentation()
        .AddAspNetCoreInstrumentation()
        .AddMongoDBInstrumentation(); // Adds MongoDB OTel support
});

This extension method only adds a source with the appropriate name:

public static TracerProviderBuilder AddMongoDBInstrumentation(this TracerProviderBuilder builder)
{
    return builder.AddSource("MongoDB.Driver.Core.Extensions.DiagnosticSources");
}

This package supports OpenTelemetry version 1.0.1.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published