Commit 9552899
committed
Fix Jetty 12 HTTP server metrics collection without virtual threads
After upgrading to Dropwizard 5 (which uses Jetty 12), HTTP server metrics
were not being collected or exposed correctly when virtual threads were
disabled (enableVirtualThreads=false). The metrics appeared correctly only
when virtual threads were enabled.
Root Cause:
The Jetty12ServerInstrumentation was ending spans in two places:
1. In onMethodExit when the handle() method completed
2. In HttpStream callbacks (succeeded/failed) for request completion
When virtual threads were disabled, handle() often completed synchronously
BEFORE the HttpStream callbacks fired. This caused the span to end prematurely
in onMethodExit, and metrics were not properly captured. The HttpStream
callbacks would then try to end an already-ended span.
When virtual threads were enabled, the asynchronous nature ensured callbacks
fired before method exit, so metrics were captured correctly.
Solution:
1. Modified Jetty12ServerInstrumentation.HandlerAdvice.end() to NOT end the
span in onMethodExit (except when there's an exception). The span is now
ended exclusively by the HttpStream completion callbacks.
2. Added AtomicBoolean in Jetty12Helper.start() to ensure the span ends
exactly once, preventing double-ending issues regardless of callback order.
This ensures HTTP metrics (request counts, latency, body size, per-endpoint
and per-status-code metrics) are collected correctly whether virtual threads
are enabled or disabled.
Fixes the issue where Dropwizard 5 applications with enableVirtualThreads=false
would not report HTTP server metrics.1 parent ad6cc1b commit 9552899
File tree
2 files changed
+20
-3
lines changed- instrumentation/jetty/jetty-12.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jetty/v12_0
2 files changed
+20
-3
lines changedLines changed: 16 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
31 | 40 | | |
32 | 41 | | |
33 | 42 | | |
34 | 43 | | |
35 | 44 | | |
36 | 45 | | |
37 | 46 | | |
38 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
39 | 50 | | |
40 | 51 | | |
41 | 52 | | |
42 | 53 | | |
43 | 54 | | |
44 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
45 | 58 | | |
46 | 59 | | |
47 | 60 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
70 | 74 | | |
71 | 75 | | |
72 | 76 | | |
| |||
0 commit comments