add thread details for declarative config#15209
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for configuring thread details (thread ID and thread name) as span attributes through declarative configuration in the instrumentation API. When enabled via configuration, an AttributesExtractor automatically adds thread information to spans created by instrumenters.
- Adds
ThreadDetailsAttributesExtractortoInstrumenterBuilderto capture thread ID and name - Integrates with declarative configuration under
instrumentation/java/thread_details/enabled - Adds comprehensive test coverage for both enabled and disabled states
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
InstrumenterBuilder.java |
Implements thread details extraction logic and configuration parsing |
AddThreadDetailsTest.java |
Tests thread details functionality with parameterized enabled/disabled scenarios |
build.gradle.kts |
Adds test dependency for declarative configuration support |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
6fb9796 to
29883b5
Compare
trask
left a comment
There was a problem hiding this comment.
can you update the PR description with a summary of the relationship between this and the existing thread details span processor? and mention it's off by default when using declarative config (and we can consider making it off by default in 3.0 for others)
acdc794 to
dd2b211
Compare
created #15334 |
|
@trask please check again |
There was a problem hiding this comment.
@jaydeluca can you take a look also?
let's also figure out where to document this, ideally in same place as other declarative config "common" attributes
|
@trask please have another look |
fff4d30 to
8c8a96c
Compare
|
@trask please have another look |
46e9ee9 to
aaea68d
Compare
|
@trask please have a look |
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
|
@trask can this be merged now? |
| public void customize(InstrumenterCustomizer customizer) { | ||
| if (AgentDistributionConfig.get().isThreadDetailsEnabled()) { | ||
| customizer.addAttributesExtractor(new ThreadDetailsAttributesExtractor<>()); | ||
| } |
| /** Called from OpenTelemetryAutoConfiguration for declarative config. */ | ||
| public static void configureDeclarativeConfig(Object model) { | ||
| enabled = isEnabled(model); | ||
| } | ||
|
|
||
| /** Called from OpenTelemetryAutoConfiguration for properties-based config. */ | ||
| public static void configureProperties(Environment environment) { | ||
| enabled = Boolean.TRUE.equals(environment.getProperty(LEGACY_PROPERTY, Boolean.class)); | ||
| } | ||
|
|
||
| @Override | ||
| public void customize(InstrumenterCustomizer customizer) { | ||
| if (enabled) { | ||
| customizer.addAttributesExtractor(new ThreadDetailsAttributesExtractor<>()); | ||
| } |
Registers AddThreadDetailsSpanProcessor through declarative config (a named ComponentProvider plus a DeclarativeConfigurationCustomizerProvider that injects the processor node) for both the javaagent and the spring starter. Because it is a SpanProcessor, thread.id/thread.name are added to manually-created spans too, not only Instrumenter-built spans. - agent: enabled via distribution.javaagent (otel.javaagent.add-thread-details) - spring starter: enabled via distribution.spring_starter.thread_details_enabled Alternative to the InstrumenterCustomizer/AttributesExtractor approach in open-telemetry#15209. Signed-off-by: Trask Stalnaker <trask.stalnaker@gmail.com>
Registers AddThreadDetailsSpanProcessor through declarative config (a named ComponentProvider plus a DeclarativeConfigurationCustomizerProvider that injects the processor node) for both the javaagent and the spring starter. Because it is a SpanProcessor, thread.id/thread.name are added to manually-created spans too, not only Instrumenter-built spans. - agent: enabled via distribution.javaagent (otel.javaagent.add-thread-details) - spring starter: enabled via distribution.spring_starter.thread_details_enabled Alternative to the InstrumenterCustomizer/AttributesExtractor approach in open-telemetry#15209. Signed-off-by: Trask Stalnaker <trask.stalnaker@gmail.com>
Registers AddThreadDetailsSpanProcessor through declarative config (a named ComponentProvider plus a DeclarativeConfigurationCustomizerProvider that injects the processor node) for both the javaagent and the spring starter. Because it is a SpanProcessor, thread.id/thread.name are added to manually-created spans too, not only Instrumenter-built spans. - agent: enabled via distribution.javaagent (otel.javaagent.add-thread-details) - spring starter: enabled via distribution.spring_starter.thread_details_enabled Alternative to the InstrumenterCustomizer/AttributesExtractor approach in open-telemetry#15209. Signed-off-by: Trask Stalnaker <trask.stalnaker@gmail.com>
Registers AddThreadDetailsSpanProcessor through declarative config (a named ComponentProvider plus a DeclarativeConfigurationCustomizerProvider that injects the processor node) for both the javaagent and the spring starter. Because it is a SpanProcessor, thread.id/thread.name are added to manually-created spans too, not only Instrumenter-built spans. - agent: enabled via distribution.javaagent (otel.javaagent.add-thread-details) - spring starter: enabled via distribution.spring_starter.thread_details_enabled Alternative to the InstrumenterCustomizer/AttributesExtractor approach in open-telemetry#15209. Signed-off-by: Trask Stalnaker <trask.stalnaker@gmail.com>
Registers AddThreadDetailsSpanProcessor through declarative config (a named ComponentProvider plus a DeclarativeConfigurationCustomizerProvider that injects the processor node) for both the javaagent and the spring starter. Because it is a SpanProcessor, thread.id/thread.name are added to manually-created spans too, not only Instrumenter-built spans. - agent: enabled via distribution.javaagent (otel.javaagent.add-thread-details) - spring starter: enabled via distribution.spring_starter.thread_details_enabled Alternative to the InstrumenterCustomizer/AttributesExtractor approach in open-telemetry#15209. Signed-off-by: Trask Stalnaker <trask.stalnaker@gmail.com>
Registers AddThreadDetailsSpanProcessor through declarative config (a named ComponentProvider plus a DeclarativeConfigurationCustomizerProvider that injects the processor node) for both the javaagent and the spring starter. Because it is a SpanProcessor, thread.id/thread.name are added to manually-created spans too, not only Instrumenter-built spans. - agent: enabled via distribution.javaagent (otel.javaagent.add-thread-details) - spring starter: enabled via distribution.spring_starter.thread_details_enabled Alternative to the InstrumenterCustomizer/AttributesExtractor approach in open-telemetry#15209. Signed-off-by: Trask Stalnaker <trask.stalnaker@gmail.com>
Registers AddThreadDetailsSpanProcessor through declarative config (a named ComponentProvider plus a DeclarativeConfigurationCustomizerProvider that injects the processor node) for both the javaagent and the spring starter. Because it is a SpanProcessor, thread.id/thread.name are added to manually-created spans too, not only Instrumenter-built spans. - agent: enabled via distribution.javaagent (otel.javaagent.add-thread-details) - spring starter: enabled via distribution.spring_starter.thread_details_enabled Alternative to the InstrumenterCustomizer/AttributesExtractor approach in open-telemetry#15209. Signed-off-by: Trask Stalnaker <trask.stalnaker@gmail.com>
Registers AddThreadDetailsSpanProcessor through declarative config (a named ComponentProvider plus a DeclarativeConfigurationCustomizerProvider that injects the processor node) for both the javaagent and the spring starter. Because it is a SpanProcessor, thread.id/thread.name are added to manually-created spans too, not only Instrumenter-built spans. - agent: enabled via distribution.javaagent (otel.javaagent.add-thread-details) - spring starter: enabled via distribution.spring_starter.thread_details_enabled Alternative to the InstrumenterCustomizer/AttributesExtractor approach in open-telemetry#15209. Signed-off-by: Trask Stalnaker <trask.stalnaker@gmail.com>
Registers AddThreadDetailsSpanProcessor through declarative config (a named ComponentProvider plus a DeclarativeConfigurationCustomizerProvider that injects the processor node) for both the javaagent and the spring starter. Because it is a SpanProcessor, thread.id/thread.name are added to manually-created spans too, not only Instrumenter-built spans. - agent: enabled via distribution.javaagent (otel.javaagent.add-thread-details) - spring starter: enabled via distribution.spring_starter.thread_details_enabled Alternative to the InstrumenterCustomizer/AttributesExtractor approach in open-telemetry#15209. Signed-off-by: Trask Stalnaker <trask.stalnaker@gmail.com>
Registers AddThreadDetailsSpanProcessor through declarative config (a named ComponentProvider plus a DeclarativeConfigurationCustomizerProvider that injects the processor node) for both the javaagent and the spring starter. Because it is a SpanProcessor, thread.id/thread.name are added to manually-created spans too, not only Instrumenter-built spans. - agent: enabled via distribution.javaagent (otel.javaagent.add-thread-details) - spring starter: enabled via distribution.spring_starter.thread_details_enabled Alternative to the InstrumenterCustomizer/AttributesExtractor approach in open-telemetry#15209. Signed-off-by: Trask Stalnaker <trask.stalnaker@gmail.com>
Registers AddThreadDetailsSpanProcessor through declarative config (a named ComponentProvider plus a DeclarativeConfigurationCustomizerProvider that injects the processor node) for both the javaagent and the spring starter. Because it is a SpanProcessor, thread.id/thread.name are added to manually-created spans too, not only Instrumenter-built spans. - agent: enabled via distribution.javaagent (otel.javaagent.add-thread-details) - spring starter: enabled via distribution.spring_starter.thread_details_enabled Alternative to the InstrumenterCustomizer/AttributesExtractor approach in open-telemetry#15209. Signed-off-by: Trask Stalnaker <trask.stalnaker@gmail.com>
|
I decided against moving thread attributes from span processor to instrumenter due to losing coverage for manual spans. I think losing coverage for manual spans may be worse (or at least no better) than the current situation of samplers not having access to thread attributes. See new PR #19008. |
|
Close in favor of #19008 |
Part of #14087
Alternative for #14564
Summary
Moves thread details (
thread.id,thread.name) from theAddThreadDetailsSpanProcessorto anInstrumenterCustomizer-based approach usingThreadDetailsAttributesExtractor. This means thread attributes are added viaAttributesExtractorat instrumentation build time rather than viaSpanProcessorat span start time.The existing
AddThreadDetailsSpanProcessoris still used for non-declarative-config agent mode (where it remains on by default viaotel.javaagent.add-thread-details=true). The newInstrumenterCustomizerpath is used for declarative config, where it is off by default — users must explicitly enable it:thread_details_enabled: trueunder thejava_agentdistribution node (default: false)thread_details.enabled: trueunderspring_starterinstrumentation config (default: false)otel.javaagent.add-thread-details(default: true, unchanged)Making it off by default in 3.0 for non-declarative-config users is tracked in #15334.
Approach
ThreadDetailsAttributesExtractorininstrumentation-api-incubatorcapturesthread.idandthread.nameon span startInstrumenterCustomizerProviderimplementations (one for agent, one for spring starter) register the extractor when enabledAgentDistributionConfig.isThreadDetailsEnabled()ExtendedOpenTelemetry.getInstrumentationConfig("spring_starter")instrumentation.common) per SIG feedback — this is controlled by agent/starter, not individual instrumentationsAddThreadDetailsSpanProcessorregistration is removed fromAgentTracerProviderConfigurer(the processor class itself is retained for non-DC use)