Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Library Instrumentation for NATS version 2.17

Provides OpenTelemetry instrumentation for NATS Client.

Quickstart

Add these dependencies to your project

Replace OPENTELEMETRY_VERSION with the latest release.

For Maven, add to your pom.xml dependencies:

<dependencies>
  <dependency>
    <groupId>io.opentelemetry.instrumentation</groupId>
    <artifactId>opentelemetry-nats-2.17</artifactId>
    <version>OPENTELEMETRY_VERSION</version>
  </dependency>
</dependencies>

For Gradle, add to your dependencies:

implementation("io.opentelemetry.instrumentation:opentelemetry-nats-2.17:OPENTELEMETRY_VERSION")

Usage

The instrumentation library provides the class NatsTelemetry that has a builder method and allows the creation of an instance of the Connection to provide OpenTelemetry-based instrumentation:

import io.nats.client.Connection;
import io.nats.client.Nats;
import io.nats.client.Options;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.nats.v2_17.NatsTelemetry;
import java.io.IOException;

public class OpenTelemetryNatsConnection {

  private OpenTelemetry openTelemetry;
  private NatsTelemetry telemetry;

  public OpenTelemetryNatsConnection(OpenTelemetry openTelemetry) {
    this.openTelemetry = openTelemetry;
    this.telemetry = NatsTelemetry.create(openTelemetry);
  }

  public Connection newConnection() throws IOException, InterruptedException {
    return newConnection(Options.builder());
  }

  public Connection newConnection(Options.Builder options) throws IOException, InterruptedException {
    return telemetry.createConnection(options.build(), Nats::connect);
  }

}