Skip to content

Add thread details for declarative config via span processor#19008

Merged
laurit merged 1 commit into
open-telemetry:mainfrom
trask:thread-details-declarative-config-span-processor
Jun 16, 2026
Merged

Add thread details for declarative config via span processor#19008
laurit merged 1 commit into
open-telemetry:mainfrom
trask:thread-details-declarative-config-span-processor

Conversation

@trask

@trask trask commented Jun 15, 2026

Copy link
Copy Markdown
Member

Adds support for the experimental thread.id / thread.name span attributes under declarative configuration, for both the javaagent and the spring starter.

Rather than an InstrumenterCustomizer / AttributesExtractor, this registers the existing ThreadDetailsSpanProcessor via declarative config (a named ComponentProvider plus a DeclarativeConfigurationCustomizerProvider that injects the processor node when enabled). Because it stays a SpanProcessor, the attributes are added to manually-created spans too, not only Instrumenter-built spans.

  • agent: enabled via the distribution.javaagent.thread_details_enabled declarative-config node (the legacy otel.javaagent.add-thread-details property is still honored via non-declarative ConfigProperties)
  • spring starter: enabled via distribution.spring_starter.thread_details_enabled

Alternative to the InstrumenterCustomizer/AttributesExtractor approach in #15209.

Resolves #14087.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ComponentProvider for AddThreadDetailsSpanProcessor and a reusable model customizer that injects it when enabled.
  • Wire enablement for the javaagent via distribution.javaagent (backed by AgentDistributionConfig) and for the Spring starter via distribution.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.

@trask trask force-pushed the thread-details-declarative-config-span-processor branch 2 times, most recently from 919c98b to fa7c908 Compare June 15, 2026 22:28
@trask trask requested a review from Copilot June 15, 2026 22:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

@trask trask force-pushed the thread-details-declarative-config-span-processor branch from 301a0f9 to eb8f3d6 Compare June 15, 2026 22:47
@trask trask requested a review from Copilot June 15, 2026 22:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Comment thread docs/advanced-configuration-options.md Outdated
@trask trask force-pushed the thread-details-declarative-config-span-processor branch from eb8f3d6 to 94791f1 Compare June 15, 2026 22:58
@trask trask requested a review from Copilot June 15, 2026 22:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

@trask trask force-pushed the thread-details-declarative-config-span-processor branch from 94791f1 to 0266809 Compare June 15, 2026 23:04
@trask trask requested a review from Copilot June 15, 2026 23:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Comment thread docs/advanced-configuration-options.md Outdated
@trask trask force-pushed the thread-details-declarative-config-span-processor branch from 0266809 to 2794cac Compare June 15, 2026 23:22
@trask trask requested a review from Copilot June 15, 2026 23:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.

@trask trask force-pushed the thread-details-declarative-config-span-processor branch from 2794cac to ad9b734 Compare June 15, 2026 23:28
@trask trask requested a review from Copilot June 15, 2026 23:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.

@trask trask force-pushed the thread-details-declarative-config-span-processor branch from ad9b734 to e3ba85d Compare June 15, 2026 23:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.

@trask trask force-pushed the thread-details-declarative-config-span-processor branch from e3ba85d to 7251549 Compare June 15, 2026 23:38
@trask trask requested a review from Copilot June 15, 2026 23:39
@trask trask force-pushed the thread-details-declarative-config-span-processor branch from 7251549 to 0aad20d Compare June 15, 2026 23:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated no new comments.

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>
@trask trask force-pushed the thread-details-declarative-config-span-processor branch from 0aad20d to c473016 Compare June 15, 2026 23:53
@trask trask requested a review from Copilot June 15, 2026 23:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.

@trask trask requested a review from Copilot June 16, 2026 03:17
@trask trask marked this pull request as ready for review June 16, 2026 03:18
@trask trask requested a review from a team as a code owner June 16, 2026 03:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated no new comments.

@trask trask added this to the v2.29.0 milestone Jun 16, 2026

Copy link
Copy Markdown
Member

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:

  • sampler visibility for thread.id / thread.name
  • and coverage for manual spans

then I think there are two possible follow-up directions:

Option 1: hybrid

Do both:

  • add thread.id / thread.name via an AttributesExtractor / instrumenter hook for Instrumenter-built spans
  • keep the SpanProcessor as a fallback for manual spans
  • make the SpanProcessor back off if those attributes are already present

That would let us have both for most practical cases:

  • instrumented spans: sampler can see the attrs before span start
  • manual spans: final span still gets the attrs

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 work

If we want to fully have both — meaning:

  • sampler-visible thread attrs
  • and manual-span coverage
  • and no behavior difference between instrumented vs manual spans

then I think this needs a deeper hook than a span processor:

  • either teach the declarative/rule-based sampler to compute thread.name / thread.id directly from Thread.currentThread()
  • or add some earlier SDK/start-span hook that can populate those values before sampling

So as I see it:

  • this PR chooses manual-span parity
  • the hybrid follow-up would let us have both for instrumented spans + final-span coverage for manual spans
  • deeper sampler/SDK work is the only way to fully have both

References:

@laurit laurit merged commit 8f759ee into open-telemetry:main Jun 16, 2026
97 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

Support otel.javaagent.add-thread-details and span logging with declarative config

4 participants