Coder Social home page Coder Social logo

mongodb.driver.core.extensions.diagnosticsources's Introduction

MongoDB.Driver.Core.Extensions.DiagnosticSources

CI NuGet NuGet MyGet (dev)

Usage

This repo includes the package:

The MongoDB.Driver.Core.Extensions.DiagnosticSources package extends the core MongoDB C# driver to expose telemetry information via System.Diagnostics.

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

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

To capture the command text as part of the activity:

var clientSettings = MongoClientSettings.FromUrl(mongoUrl);
var options = new InstrumentationOptions { CaptureCommandText = true };
clientSettings.ClusterConfigurator = cb => cb.Subscribe(new DiagnosticsActivityEventSubscriber(options));
var mongoClient = new MongoClient(clientSettings);

To filter activities by collection name:

var clientSettings = MongoClientSettings.FromUrl(mongoUrl);
var options = new InstrumentationOptions { ShouldStartActivity = @event => !"collectionToIgnore".Equals(@event.GetCollectionName()) };
clientSettings.ClusterConfigurator = cb => cb.Subscribe(new DiagnosticsActivityEventSubscriber(options));
var mongoClient = new MongoClient(clientSettings);

This package exposes an ActivitySource with a Name the same as the assembly, MongoDB.Driver.Core.Extensions.DiagnosticSources. Use this name in any ActivityListener-based listeners.

All the available OpenTelemetry semantic tags are set.

This package supports MongoDB C# Driver versions 2.28.0 to 3.0.

mongodb.driver.core.extensions.diagnosticsources's People

Contributors

aaguilartablada avatar jbogard avatar joegoldman2 avatar kielek avatar ledouxpl avatar mishamyte avatar norekz avatar pengweiqhca avatar techgeek03 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mongodb.driver.core.extensions.diagnosticsources's Issues

System.Net.Security 4.0.0 dependency has high severity vulnerability

I am using version 1.1.0 of this library (not directly but by referencing MongoDB.Driver.Core.Extensions.OpenTelemtry package version 1.0.0)


This package is taking a dependency on System.Net.Security 4.0.0 DLL,
which has 2 vulnerabilities
one high
one moderate

here is a screenshot from the solution explorer from Visual Studio

image

here is a screenshot from the Error List from Visual Studio

image

here is a screenshot from the Nuget page of the System.Net.Security 4.0.0

image

I think it's best to update those packages.

If you like I can make the PR to fix this


Very important note, I am not referencing this dll directly, I am referencing MongoDB.Driver.Core.Extensions.OpenTelemetry which take a dependency on MongoDB.Driver.Core.Extensions.DiagnosticSources

I can open this bug also on that repo, if you want.

Support for latest MongoDB library with signing

As of version 2.28.0, the MongoDB library has strong-named assemblies as per release notes: https://github.com/mongodb/mongo-csharp-driver/releases/tag/v2.28.0
Updating to this version fails when also using MongoDB.Driver.Core.Extensions.DiagnosticSources.

With the introduction of strong-naming, it may no longer be possible to target a version lower than 2.28.0. I wanted to create a PR to make this the lowest version but I am unsure if you are okay with this.

Can ActivitySourceName be public?

Although the activity source name is mentioned in readme, I think it will be a bit more convenient to have a public constant when we configure OTEL in our code.

[RFC] Adjust activity tags to correspond OTEL specification

Hello @jbogard,
Just reviewed current version of OTEL spec and found that some tags, set by this lib are outdated.

So I propose to discuss next changes. Will be happy to make a PR after founding a concern.

Tag Problem Proposal Spec reference
db.user Now crafted as a part of connection string with address + port. It doesn't correspond spec and this data is covered by another tags Delete tag https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/database.md#mongodb
net.peer.ip Doesn't exists Rename tag to net.sock.peer.addr https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/span-general.md
net.transport Doesn't exists Set to ip_tcp value https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/span-general.md
otel.status_code Doesn't respect case Adjust case to upper https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/mapping-to-non-otlp.md#span-status
error.type Doesn't exists Use exception.type tag https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/exceptions.md#attributes
error.msg Doesn't exists Use exception.message tag https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/exceptions.md#attributes
error.stack Doesn't exists Use exception.stacktrace tag https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/exceptions.md#attributes
db.connection_id Custom tag, used by .NET's instrumentation libs for SQL drivers Add it with property value of @event.ConnectionId

Activity for an async mongo command is not stopped

When the async command is executed in Mongo driver, the async flow is not properly followed and in the command succeeded handler the Activity.Current is not the activity started in the command started handler. If before calling the

I add the

Activity.Current = activity;

it fixes the problem, but I'm not sure what consequences that could cause as I'm not familiar with the API yet.

Support DiagnosticSource based instrumentations by sending Activity start and stop events to DiagnosticSource

We use OpenTracing and opentracing-contrib package for instrumentation of asp.net core application that uses MongoDB.

Opentracing-contrib docs says:

It will create a span for every Activity

It provides code to process any arbitary Activity but in fact it uses DiagnosticSource to subscribe and handle events. As far as I understand Activity does not send start and stop events to DiagnosticSource automatically. It requires DiagnosticSource.StartActivity(Activity, object) to be called.

We could make to packages works together if send start and stop Activity events to DiagnosticSource by StartActivity and StopActivity methods.

Drawback is that we will still need dummy ActivityListener for MongoDB.Driver.Core.Extensions.DiagnosticSources source.

Lot of InvalidOperationExceptions

Hi,
I'm spammed with following exceptions, when running [MongoDB.Driver.Core.Extensions.DiagnosticSources] as a Source in Otel Tracing

System.InvalidOperationException
HResult=0x80131509
Message=Trying to set an Activity that is not running
Source=System.Diagnostics.DiagnosticSource
StackTrace:
at System.Diagnostics.Activity.NotifyError(Exception exception) in System.Diagnostics\Activity.cs:line 1146

Here's a stacktrace of issue

image

Any Idea why is this happening?

I can provide snippets if needed.

Thanks

db.statement displays getMore command rather than actual query

I've got a mongo query that returns results using a cursor. Mongo then uses the getMore command to pull back pages of results.

When using this library, with CaptureCommandText set to true, the db.statement tag gets set to the getMore command and not the initial mongo command that was called.

Some spans are not useful

The c# mongo library is often running the commands to check on the status of the cluster. These will create single span traces which are not very useful

the traces that get created are:
mongodb.ismaster
mongodb.getlasterror
mongodb.buildinfo

It would be great if there was an option to not create activities for these commands.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.