opentelemetry-java-instrume.../instrumentation/mongo/mongo-3.1/library
SylvainJuge 955470a63a
Semconv 1.25.0 migration (#10983)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-09 11:25:52 -07:00
..
src Semconv 1.25.0 migration (#10983) 2024-04-09 11:25:52 -07:00
README.md Small library doc updates (#9868) 2023-11-14 14:33:05 -08:00
build.gradle.kts Use .service instead of .getService() to get testcontainersBuildService (#8188) 2023-03-31 08:32:24 +00:00

README.md

MongoDB library instrumentation

This package contains the library to help instrument MongoDB Client.

Quickstart

Dependencies

Replace OPENTELEMETRY_VERSION with the latest release.

For Maven, add to your pom.xml dependencies:

<dependencies>
  <dependency>
    <groupId>io.opentelemetry.instrumentation</groupId>
    <artifactId>opentelemetry-mongo-3.1</artifactId>
    <version>OPENTELEMETRY_VERSION</version>
  </dependency>
</dependencies>

For Gradle, add to your dependencies:

implementation("io.opentelemetry.instrumentation:instrumentation:opentelemetry-mongo-3.1:OPENTELEMETRY_VERSION")

Usage

The instrumentation is initialized by passing a MongoTelemetry::newCommandListener() to the MongoClientSettings builder. You must set the OpenTelemetry to use with the feature.

OpenTelemetry openTelemetry = ...;

MongoTelemetry mongoTelemetry = MongoTelemetry.builder(openTelemetry).build();

MongoClientSettings settings = MongoClientSettings.builder()
    .applyConnectionString(ConnectionString("mongodb://localhost:27017"))
    .addCommandListener(mongoTelemetry.newCommandListener())
    .build();

// With Reactive Streams
MongoClient client = MongoClients.create(settings);