Commit 59ca90d
committed
feat(otel): optional OpenTelemetry export — metrics (alt to Prometheus) + GenAI spans
Add an optional OTLP export path, in two independent off-by-default parts.
Metrics export (mockserver.otelMetricsEnabled) — OtelMetricsExporter bridges the
existing Metrics.Name gauges (the same set exposed for Prometheus, incl. the LLM
and chaos counters) to OTLP as observable gauges that read the current values, so
the Prometheus and OTLP views stay consistent. An alternative to the Prometheus
endpoint, not a replacement.
GenAI span export (mockserver.otelTracesEnabled) — HttpLlmResponseActionHandler
calls GenAiSpans.recordCompletion on each served completion (streaming and
non-streaming), emitting one span with GenAI semantic-convention attributes:
gen_ai.system (mapped to the semconv registry value per provider, not the raw
enum name), gen_ai.request.model, gen_ai.usage.input/output_tokens,
gen_ai.response.finish_reasons (string[]), and a namespaced
mockserver.gen_ai.tool_call_count. Explicit spans MockServer codes — NO
auto-instrumentation, and no prompt/response content is captured (privacy).
Both: OTLP HTTP/protobuf with the JDK HttpClient sender (okhttp sender excluded,
no gRPC); share mockserver.otelEndpoint (a base collector URL, /v1/metrics and
/v1/traces appended by OtelEndpoints); started/stopped in LifeCycle; fail-soft
(a setup error logs one line and never stops the server or affects a response).
io.opentelemetry is relocated to shaded_package.io.opentelemetry in the uber-jar
(verified: the shaded mockserver-netty-no-dependencies jar builds cleanly).
Deps: opentelemetry-bom 1.45.0; api, sdk-common, sdk-metrics, sdk-trace,
exporter-otlp (+ sender-jdk), sdk-testing (test).
Docs: docs/code/llm-mocking.md (OpenTelemetry section + source refs), consumer
configuration-properties page, roadmap, changelog.
Tests: OtelMetricsExporterTest (observable gauge reads the metric; disabled→null),
GenAiSpansTest (semconv attributes incl. string[] finish_reasons, provider→system
mapping, no-op when disabled), OtelEndpointsTest (base/trailing-slash/signal-path
edge cases). All green.1 parent b2acd76 commit 59ca90d
16 files changed
Lines changed: 666 additions & 2 deletions
File tree
- docs
- code
- plans
- jekyll-www.mock-server.com/mock_server
- mockserver
- mockserver-core
- src
- main/java/org/mockserver
- configuration
- metrics
- mock/action/http
- telemetry
- test/java/org/mockserver
- metrics
- telemetry
- mockserver-netty/src/main/java/org/mockserver/lifecycle
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
303 | 312 | | |
304 | 313 | | |
305 | 314 | | |
| |||
381 | 390 | | |
382 | 391 | | |
383 | 392 | | |
| 393 | + | |
| 394 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
888 | 888 | | |
889 | 889 | | |
890 | 890 | | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
891 | 911 | | |
892 | 912 | | |
893 | 913 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
290 | 329 | | |
291 | 330 | | |
292 | 331 | | |
| |||
mockserver/mockserver-core/src/main/java/org/mockserver/configuration/ConfigurationProperties.java
Lines changed: 58 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
96 | 100 | | |
97 | 101 | | |
98 | 102 | | |
| |||
1068 | 1072 | | |
1069 | 1073 | | |
1070 | 1074 | | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
1071 | 1129 | | |
1072 | 1130 | | |
1073 | 1131 | | |
| |||
0 commit comments