Class OtelMetricsExporter

java.lang.Object
org.mockserver.metrics.OtelMetricsExporter

public class OtelMetricsExporter extends Object
Optional exporter that publishes MockServer's explicitly-defined metrics (the same Metrics.Name gauges exposed for Prometheus) via OpenTelemetry OTLP. Off unless mockserver.otelMetricsEnabled is set.

Deliberately metrics-only: it registers one OTel observable gauge per Metrics.Name whose callback reads the current Metrics.get(org.mockserver.metrics.Metrics.Name) value at each collection. No spans, no auto-instrumentation. The OTel SDK is self-configured here (MockServer usually runs standalone), using the OTLP HTTP/protobuf exporter with the JDK HttpClient sender.

  • Method Summary

    Modifier and Type
    Method
    Description
    Start the exporter if enabled in configuration, returning the running instance, or null if disabled or startup failed (fail-soft — telemetry must never prevent the server from running).
    startWithReader(io.opentelemetry.sdk.metrics.export.MetricReader reader)
    Build a meter provider with the given reader and register observable instruments: One gauge per Metrics.Name (existing behaviour). JVM memory, thread, and GC gauges (same data as JvmMetricsCollector on the Prometheus side). A gauge mirroring the slow-request counter so OTLP-only consumers can observe it without a Prometheus scrape. A gauge mirroring the per-fault-type chaos-injection counter. A gauge mirroring the active service-scoped chaos count. A histogram for request-handling duration (seconds), fed from the same observation path as the Prometheus histogram. Visible for testing (a test can pass an in-memory reader instead of the OTLP periodic reader).
    void
    Stop exporting and release resources.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • startIfEnabled

      public static OtelMetricsExporter startIfEnabled()
      Start the exporter if enabled in configuration, returning the running instance, or null if disabled or startup failed (fail-soft — telemetry must never prevent the server from running).
    • startWithReader

      public static OtelMetricsExporter startWithReader(io.opentelemetry.sdk.metrics.export.MetricReader reader)
      Build a meter provider with the given reader and register observable instruments:
      • One gauge per Metrics.Name (existing behaviour).
      • JVM memory, thread, and GC gauges (same data as JvmMetricsCollector on the Prometheus side).
      • A gauge mirroring the slow-request counter so OTLP-only consumers can observe it without a Prometheus scrape.
      • A gauge mirroring the per-fault-type chaos-injection counter.
      • A gauge mirroring the active service-scoped chaos count.
      • A histogram for request-handling duration (seconds), fed from the same observation path as the Prometheus histogram.
      Visible for testing (a test can pass an in-memory reader instead of the OTLP periodic reader).
    • stop

      public void stop()
      Stop exporting and release resources. Safe to call once.