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 OtelMetricsExporterstartIfEnabled(Configuration configuration) AsstartIfEnabled()but preferring the values carried on the suppliedConfigurationinstance, falling back to the staticConfigurationPropertiesstore for each value the instance leaves unset.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). -
startIfEnabled
AsstartIfEnabled()but preferring the values carried on the suppliedConfigurationinstance, falling back to the staticConfigurationPropertiesstore for each value the instance leaves unset. This is what makes OTLP metric export settings applied programmatically or overPUT /mockserver/configurationactually take effect, rather than round-tripping through the DTO and being silently ignored here.- Parameters:
configuration- the live server configuration, ornullto read the static store
-
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.
-