Class OpenTelemetryMiddleware

java.lang.Object
com.commercetools.monitoring.opentelemetry.OpenTelemetryMiddleware
All Implemented Interfaces:
Middleware, TelemetryMiddleware

public class OpenTelemetryMiddleware extends Object implements TelemetryMiddleware

The OpenTelemetry middleware can be used to report metrics about outgoing request to commercetools. It can be registered as TelemetryMiddleware to the ClientBuilder or the ApiRootBuilder.

ApiHttpClient client = ApiRootBuilder.of()
        .defaultClient(ServiceRegion.GCP_EUROPE_WEST1.getApiUrl())
        .withTelemetryMiddleware(new OpenTelemetryMiddleware(GlobalOpenTelemetry.get()))
        .buildClient();

See the test code.

The middleware adds the following metrics: *
  • commercetools.client.duration: The duration of the request in milliseconds
  • commercetools.client.total_requests: The total number of requests
  • commercetools.client.error_requests: The total number of requests with a status code greater or equal to 400
  • *
The metrics are enriched with the response status code, server address, port and request method.

See also the Spring MVC example application in the examples folder for further details.

  • Constructor Details

    • OpenTelemetryMiddleware

      public OpenTelemetryMiddleware(io.opentelemetry.api.OpenTelemetry otel)
    • OpenTelemetryMiddleware

      public OpenTelemetryMiddleware(io.opentelemetry.api.OpenTelemetry otel, boolean enableHistogram)
    • OpenTelemetryMiddleware

      public OpenTelemetryMiddleware(io.opentelemetry.api.OpenTelemetry otel, boolean enableHistogram, String prefix)
  • Method Details