Add executor thread pool metrics instrumentation
Relates to #11149
Motivation
Executor metrics provide visibility into utilization, saturation, queue pressure, completed work, and rejected work. This change adds an initial implementation to the existing Java executors instrumentation and makes the proposed metric model concrete for semantic-convention discussion.
Design and lifecycle
ThreadPoolExecutor instances are pre-registered at construction time, but no metrics are created and the configured ThreadFactory is not invoked then. Metrics are registered only after the first worker thread actually starts, using that worker's real thread name to derive jvm.executor.name.
When setThreadFactory() is called, the existing metric identity remains active until a worker created by the new factory starts. At that point, the registration is replaced using the new worker thread name.
Generic JDK instrumentation uses jvm.executor.owner.name=unknown. Framework-specific instrumentation can reuse reregister(...) to provide an owner name and a component-specific all or trailing name-normalization mode. This works both before the first worker starts and after metrics are already registered.
Rejected tasks are recorded after metrics have been registered. Metrics are unregistered only after an executor has actually entered the shutdown state. The registration cache and callbacks use weak references, so metrics do not retain an unclosed executor; callbacks close themselves after the observed executor is collected.
Metrics emitted by ThreadPoolExecutor
| Metric | Instrument | Unit | Attributes |
|---|---|---|---|
jvm.executor.thread.count |
Observable UpDownCounter | {thread} |
jvm.executor.name, jvm.executor.owner.name, jvm.executor.type, jvm.executor.state |
jvm.executor.thread.core |
Observable UpDownCounter | {thread} |
jvm.executor.name, jvm.executor.owner.name, jvm.executor.type |
jvm.executor.thread.max |
Observable UpDownCounter | {thread} |
jvm.executor.name, jvm.executor.owner.name, jvm.executor.type |
jvm.executor.queue.size |
Observable UpDownCounter | {task} |
jvm.executor.name, jvm.executor.owner.name, jvm.executor.type |
jvm.executor.queue.remaining |
Observable UpDownCounter | {task} |
jvm.executor.name, jvm.executor.owner.name, jvm.executor.type |
jvm.executor.task.completed |
Observable Counter | {task} |
jvm.executor.name, jvm.executor.owner.name, jvm.executor.type |
jvm.executor.task.rejected |
Counter | {task} |
jvm.executor.name, jvm.executor.owner.name, jvm.executor.type |
JDK 21 ThreadPerTaskExecutor is also covered. It currently emits only jvm.executor.thread.count with jvm.executor.state=active.
jvm.executor.name is derived from the first actual worker thread name. otel.instrumentation.executors.name-normalization=all is the default and replaces every digit group with *; trailing replaces only the final digit group. For example, tomcat-8080-exec-1 becomes tomcat-*-exec-* with all and tomcat-8080-exec-* with trailing. Empty thread names use unknown.
Scope and follow-up
This is an initial implementation intended to support discussion of experimental executor metric semantic conventions. ScheduledThreadPoolExecutor and jvm.executor.queue.wait.duration are intentionally out of scope. Once the metric and attribute semantics are agreed, the reusable registration path can evolve into an incubating shared helper for framework-specific instrumentations.
Pull request dashboard status
Waiting on the author · refreshed 2026-08-27 19:02 UTC
Respond to 2 review items (e.g. link a commit, explain why not, ask a follow-up):
Status above doesn't look right?
- Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
- Should this be with reviewers? Comment
/dashboard route:reviewersto route it to them. - Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.
@trask should there be a corresponding semconv issue for this?
@YaoYingLong can you submit a semconv PR for this, citing this PR as prototype?
Hi @YaoYingLong — just a friendly reminder that this pull request is waiting on you.
There are still items that need your attention. See the dashboard status comment for the full list and current routing; that comment is kept current. You don't need to push a code change to hand it back — replying to move each discussion forward is enough, whether that's answering a question, explaining why no change is needed, or asking a follow-up. The dashboard then automatically routes it back to reviewers.
If you believe this pull request is incorrectly routed as waiting on the author, comment /dashboard route:reviewers to route it from waiting on the author to waiting on reviewers. Use this command only while the live dashboard status still says the pull request is waiting on the author.
This reminder is a snapshot; the linked dashboard status is the current source of truth.
Outdated as of 2026-08-10 21:16 UTC: this reminder no longer reflects the current dashboard state. Check the dashboard status comment to see whether action is needed.
/dashboard route:reviewers
@trask accepted the reviewer-routing override; the reviewer handoff is waiting on the Copilot review.
Hi @YaoYingLong — just a friendly reminder that this pull request is waiting on you. The dashboard status comment has the open items and is kept current.
- Replying is enough to hand it off — answer, explain why no change is needed, or ask a follow-up. The dashboard routes it onward once nothing on the list is waiting on you.
- To hand it back for any other reason, including the dashboard getting this wrong, comment
/dashboard route:reviewers.