OpenTracing Instrumentation for Mongo Async Driver


License

License

GroupId

GroupId

io.opentracing.contrib
ArtifactId

ArtifactId

opentracing-mongo-driver-async
Last Version

Last Version

0.1.5
Release Date

Release Date

Type

Type

jar
Description

Description

OpenTracing Instrumentation for Mongo Async Driver
OpenTracing Instrumentation for Mongo Async Driver

Download opentracing-mongo-driver-async

How to add to project

<!-- https://jarcasting.com/artifacts/io.opentracing.contrib/opentracing-mongo-driver-async/ -->
<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-mongo-driver-async</artifactId>
    <version>0.1.5</version>
</dependency>
// https://jarcasting.com/artifacts/io.opentracing.contrib/opentracing-mongo-driver-async/
implementation 'io.opentracing.contrib:opentracing-mongo-driver-async:0.1.5'
// https://jarcasting.com/artifacts/io.opentracing.contrib/opentracing-mongo-driver-async/
implementation ("io.opentracing.contrib:opentracing-mongo-driver-async:0.1.5")
'io.opentracing.contrib:opentracing-mongo-driver-async:jar:0.1.5'
<dependency org="io.opentracing.contrib" name="opentracing-mongo-driver-async" rev="0.1.5">
  <artifact name="opentracing-mongo-driver-async" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.opentracing.contrib', module='opentracing-mongo-driver-async', version='0.1.5')
)
libraryDependencies += "io.opentracing.contrib" % "opentracing-mongo-driver-async" % "0.1.5"
[io.opentracing.contrib/opentracing-mongo-driver-async "0.1.5"]

Dependencies

compile (2)

Group / Artifact Type Version
io.opentracing.contrib : opentracing-mongo-common jar 0.1.5
io.opentracing : opentracing-util jar 0.33.0

provided (2)

Group / Artifact Type Version
org.mongodb : mongo-java-driver jar 3.10.2
org.mongodb : mongodb-driver-async jar 3.10.2

test (4)

Group / Artifact Type Version
org.mockito : mockito-core jar 2.28.2
de.flapdoodle.embed : de.flapdoodle.embed.mongo jar 2.2.0
io.opentracing : opentracing-mock jar 0.33.0
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Build Status Coverage Status Released Version Apache-2.0 license

OpenTracing Mongo Driver Instrumentation

OpenTracing instrumentation for Mongo Driver.

Installation

Mongo Driver

pom.xml

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-mongo-driver</artifactId>
    <version>VERSION</version>
</dependency>

Mongo Driver Async

pom.xml

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-mongo-driver-async</artifactId>
    <version>VERSION</version>
</dependency>

Mongo Driver Reactive Streams

pom.xml

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-mongo-driver-reactivestreams</artifactId>
    <version>VERSION</version>
</dependency>

Usage

// Instantiate tracer
Tracer tracer = ...

// Optionally register tracer with GlobalTracer
GlobalTracer.register(tracer);

There are 2 ways to instrument MongoClient:

  • using Mongo Tracing Client
  • using MongoClientSettings.Builder with TracingCommandListener

Mongo Tracing Client

// Instantiate TracingCommandListener
TracingCommandListener listener = new TracingCommandListener.Builder(tracer).build()

// Instantiate Synchronous Tracing MongoClient
MongoClient mongoClient = new TracingMongoClient(listener, ...);

// Instantiate Asynchronous Tracing MongoClient
MongoClient mongoClient = new TracingAsyncMongoClient(listener, ...);

MongoClientSettings.Builder with TracingCommandListener

// Instantiate TracingCommandListener
TracingCommandListener listener = new TracingCommandListener.Builder(tracer).build()

// Add TracingCommandListener to MongoClientSettings.Builder
MongoClient mongoClient = MongoClients.create(
        MongoClientSettings.builder()
                .addCommandListener(listener)
                ...
                .build());

Mongo Span Name

By default, span names are set to the operation performed by the Mongo client. To customize the span name, provide a MongoSpanNameProvider to the client that alters the span name. If a provider is not provided, the span name will remain the default.

// Create TracingCommandListener with custom span name provider
TracingCommandListener listener = new TracingCommandListener.Builder(tracer)\
    .withSpanNameProvider(new PrefixSpanNameProvider("mongo."))
    .build();

// Create TracingMongoClient
TracingMongoClient client = new TracingMongoClient(
    listener, 
    replicaSetAddresses, 
    credentials, 
    clientOptions 
    );
Document doc = new Document();
client.getDatabase("db").getCollection("collection).insertOne(doc);
// Span name is now set to "mongo.insert"

Exclude commands from tracing

To exclude specific Mongo commands from tracing add ExcludedCommand to TracingCommandListener:

List<ExcludedCommand> excludedCommands = new ArrayList<>();
ExcludedCommand excludedCommand = new ExcludedCommand();
excludedCommand.put("getMore",  BsonNull.VALUE);
excludedCommand.put("collection",  new BsonString("oplog.rs"));

excludedCommands.add(excludedCommand);

    
TracingCommandListener listener =  new TracingCommandListener.Builder(tracer)
    .withExcludedCommands(excludedCommands).build();    
    

License

Apache 2.0 License.

io.opentracing.contrib

3rd-Party OpenTracing API Contributions

3rd-party contributions that use OpenTracing. **The repositories in this org are *not* affiliated with the CNCF.**

Versions

Version
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1