Add thread details for declarative config via span processor#19008
Conversation
There was a problem hiding this comment.
Pull request overview
Adds declarative-config support for emitting experimental thread span attributes (thread.id, thread.name) by registering the existing AddThreadDetailsSpanProcessor through the declarative configuration component model. This enables thread attributes for both instrumentation-created spans and manually created spans, across the javaagent and Spring Boot starter.
Changes:
- Introduce a declarative-config
ComponentProviderforAddThreadDetailsSpanProcessorand a reusable model customizer that injects it when enabled. - Wire enablement for the javaagent via
distribution.javaagent(backed byAgentDistributionConfig) and for the Spring starter viadistribution.spring_starter.thread_details_enabled. - Add/adjust tests and smoke-test config to validate Spring starter behavior and document the javaagent property behavior.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| smoke-tests-otel-starter/spring-boot-2/src/testDeclarativeConfig/resources/application.yaml | Enables thread details under distribution.spring_starter for declarative-config smoke testing. |
| smoke-tests-otel-starter/spring-boot-2/src/testDeclarativeConfig/java/io/opentelemetry/spring/smoketest/OtelSpringStarterSmokeTest.java | Asserts thread.id / thread.name are present in exported spans. |
| sdk-autoconfigure-support/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider | Registers the new declarative-config ComponentProvider via SPI. |
| sdk-autoconfigure-support/src/main/java/io/opentelemetry/instrumentation/thread/internal/AddThreadDetailsComponentProvider.java | Exposes AddThreadDetailsSpanProcessor as a named declarative-config component (thread_details). |
| sdk-autoconfigure-support/src/main/java/io/opentelemetry/instrumentation/thread/internal/AbstractThreadDetailsCustomizerProvider.java | Injects the thread_details span processor model when enabled, avoiding duplicates. |
| javaagent-tooling/src/test/java/io/opentelemetry/javaagent/tooling/config/ThreadDetailsCustomizerProviderTest.java | Tests javaagent-side customizer behavior (commented on coverage of true declarative-config path). |
| javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/config/ThreadDetailsCustomizerProvider.java | Javaagent declarative-config customizer provider that enables thread details based on AgentDistributionConfig. |
| javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/AgentTracerProviderConfigurer.java | Uses AgentDistributionConfig to decide whether to install AddThreadDetailsSpanProcessor in non-DC mode. |
| javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/extension/instrumentation/internal/AgentDistributionConfig.java | Adds thread_details_enabled to distribution config and maps system-property defaulting behavior. |
| instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/thread/ThreadDetailsCustomizerProviderTest.java | Tests Spring starter declarative-config enablement parsing and injection behavior. |
| instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java | Registers the Spring starter declarative-config customizer bean. |
| instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/thread/ThreadDetailsCustomizerProvider.java | Spring starter provider that reads distribution.spring_starter.thread_details_enabled. |
| docs/advanced-configuration-options.md | Documents otel.javaagent.add-thread-details behavior and defaults. |
919c98b to
fa7c908
Compare
301a0f9 to
eb8f3d6
Compare
eb8f3d6 to
94791f1
Compare
94791f1 to
0266809
Compare
0266809 to
2794cac
Compare
2794cac to
ad9b734
Compare
ad9b734 to
e3ba85d
Compare
e3ba85d to
7251549
Compare
7251549 to
0aad20d
Compare
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>
0aad20d to
c473016
Compare
|
I’m good with this PR and will approve — as maintainer it’s your call which tradeoff to prefer. If we ever want to have both:
then I think there are two possible follow-up directions: Option 1: hybridDo both:
That would let us have both for most practical cases:
The only thing this still would not give us is sampler visibility for manual spans, since the sampler runs before the span processor. Option 2: deeper workIf we want to fully have both — meaning:
then I think this needs a deeper hook than a span processor:
So as I see it:
References:
|
Adds support for the experimental
thread.id/thread.namespan attributes under declarative configuration, for both the javaagent and the spring starter.Rather than an
InstrumenterCustomizer/AttributesExtractor, this registers the existingThreadDetailsSpanProcessorvia declarative config (a namedComponentProviderplus aDeclarativeConfigurationCustomizerProviderthat injects the processor node when enabled). Because it stays aSpanProcessor, the attributes are added to manually-created spans too, not onlyInstrumenter-built spans.distribution.javaagent.thread_details_enableddeclarative-config node (the legacyotel.javaagent.add-thread-detailsproperty is still honored via non-declarativeConfigProperties)distribution.spring_starter.thread_details_enabledAlternative to the
InstrumenterCustomizer/AttributesExtractorapproach in #15209.Resolves #14087.