Package org.mockserver.metrics
Class OtelMetricsExporter
java.lang.Object
org.mockserver.metrics.OtelMetricsExporter
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 TypeMethodDescriptionstatic OtelMetricsExporterStart the exporter if enabled in configuration, returning the running instance, ornullif disabled or startup failed (fail-soft — telemetry must never prevent the server from running).static OtelMetricsExporterstartWithReader(io.opentelemetry.sdk.metrics.export.MetricReader reader) Build a meter provider with the given reader and register observable instruments: One gauge perMetrics.Name(existing behaviour). JVM memory, thread, and GC gauges (same data asJvmMetricsCollectoron 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).voidstop()Stop exporting and release resources.
-
Method Details
-
startIfEnabled
Start the exporter if enabled in configuration, returning the running instance, ornullif 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
JvmMetricsCollectoron 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.
- One gauge per
-
stop
public void stop()Stop exporting and release resources. Safe to call once.
-