-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add thread details for declarative config via span processor #19008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
laurit
merged 1 commit into
open-telemetry:main
from
trask:thread-details-declarative-config-span-processor
Jun 16, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...spring/autoconfigure/internal/instrumentation/thread/ThreadDetailsCustomizerProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.spring.autoconfigure.internal.instrumentation.thread; | ||
|
|
||
| import io.opentelemetry.instrumentation.thread.internal.AbstractThreadDetailsCustomizerProvider; | ||
| import io.opentelemetry.sdk.autoconfigure.declarativeconfig.model.DistributionModel; | ||
| import io.opentelemetry.sdk.autoconfigure.declarativeconfig.model.DistributionPropertyModel; | ||
| import io.opentelemetry.sdk.autoconfigure.declarativeconfig.model.OpenTelemetryConfigurationModel; | ||
|
|
||
| /** | ||
| * Adds thread details span attributes when enabled via the {@code distribution.spring_starter} | ||
| * node. | ||
| * | ||
| * <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
| * at any time. | ||
| */ | ||
| public final class ThreadDetailsCustomizerProvider extends AbstractThreadDetailsCustomizerProvider { | ||
|
|
||
| @Override | ||
| protected boolean isEnabled(OpenTelemetryConfigurationModel model) { | ||
| DistributionModel distribution = model.getDistribution(); | ||
| if (distribution == null) { | ||
| return false; | ||
| } | ||
| DistributionPropertyModel springStarter = | ||
| distribution.getAdditionalProperties().get("spring_starter"); | ||
| if (springStarter == null) { | ||
| return false; | ||
| } | ||
| Object enabled = springStarter.getAdditionalProperties().get("thread_details_enabled"); | ||
| if (enabled instanceof Boolean) { | ||
| return (Boolean) enabled; | ||
| } | ||
| // a String when set via environment variable substitution (thread_details_enabled: ${OTEL_...}) | ||
| return enabled instanceof String && Boolean.parseBoolean((String) enabled); | ||
| } | ||
| } | ||
47 changes: 47 additions & 0 deletions
47
...ng/autoconfigure/internal/instrumentation/thread/ThreadDetailsCustomizerProviderTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.spring.autoconfigure.internal.instrumentation.thread; | ||
|
|
||
| import static java.nio.charset.StandardCharsets.UTF_8; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import io.opentelemetry.sdk.autoconfigure.declarativeconfig.DeclarativeConfiguration; | ||
| import io.opentelemetry.sdk.autoconfigure.declarativeconfig.model.OpenTelemetryConfigurationModel; | ||
| import java.io.ByteArrayInputStream; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.CsvSource; | ||
|
|
||
| class ThreadDetailsCustomizerProviderTest { | ||
|
|
||
| @ParameterizedTest | ||
| @CsvSource( | ||
| nullValues = "NULL", | ||
| value = { | ||
| "true, true", | ||
| "false, false", | ||
| "NULL, false", // distribution node not set | ||
| ", false", // thread_details_enabled key present with no value | ||
| "invalid, false", | ||
| }) | ||
| @SuppressWarnings("StringConcatToTextBlock") // latest dep allows text blocks | ||
| void isEnabled(String propertyValue, boolean expected) { | ||
| String enabled = | ||
| propertyValue == null | ||
| ? "" | ||
| : "distribution:\n" | ||
| + " spring_starter:\n" | ||
| + " thread_details_enabled: " | ||
| + propertyValue | ||
| + "\n"; | ||
|
|
||
| String yaml = "file_format: \"1.0\"\n" + enabled; | ||
|
|
||
| OpenTelemetryConfigurationModel model = | ||
| DeclarativeConfiguration.parse(new ByteArrayInputStream(yaml.getBytes(UTF_8))); | ||
|
|
||
| assertThat(new ThreadDetailsCustomizerProvider().isEnabled(model)).isEqualTo(expected); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
.../main/java/io/opentelemetry/javaagent/tooling/config/ThreadDetailsCustomizerProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.tooling.config; | ||
|
|
||
| import com.google.auto.service.AutoService; | ||
| import io.opentelemetry.instrumentation.thread.internal.AbstractThreadDetailsCustomizerProvider; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.internal.AgentDistributionConfig; | ||
| import io.opentelemetry.sdk.autoconfigure.declarativeconfig.DeclarativeConfigurationCustomizerProvider; | ||
| import io.opentelemetry.sdk.autoconfigure.declarativeconfig.model.OpenTelemetryConfigurationModel; | ||
|
|
||
| /** Adds thread details span attributes when enabled via the {@code distribution.javaagent} node. */ | ||
| @AutoService(DeclarativeConfigurationCustomizerProvider.class) | ||
| public final class ThreadDetailsCustomizerProvider extends AbstractThreadDetailsCustomizerProvider { | ||
|
|
||
| @Override | ||
| public int order() { | ||
| // run after JavaagentDistributionAccessCustomizerProvider (default order) has populated | ||
| // AgentDistributionConfig from the distribution.javaagent node | ||
| return 1; | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean isEnabled(OpenTelemetryConfigurationModel model) { | ||
| return AgentDistributionConfig.get().isThreadDetailsEnabled(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...pentelemetry/instrumentation/thread/internal/AbstractThreadDetailsCustomizerProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.thread.internal; | ||
|
|
||
| import io.opentelemetry.sdk.autoconfigure.declarativeconfig.DeclarativeConfigurationCustomizer; | ||
| import io.opentelemetry.sdk.autoconfigure.declarativeconfig.DeclarativeConfigurationCustomizerProvider; | ||
| import io.opentelemetry.sdk.autoconfigure.declarativeconfig.model.OpenTelemetryConfigurationModel; | ||
| import io.opentelemetry.sdk.autoconfigure.declarativeconfig.model.SpanProcessorModel; | ||
| import io.opentelemetry.sdk.autoconfigure.declarativeconfig.model.SpanProcessorPropertyModel; | ||
| import io.opentelemetry.sdk.autoconfigure.declarativeconfig.model.TracerProviderModel; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Adds the {@link ThreadDetailsSpanProcessor} (via the {@link ThreadDetailsComponentProvider}) to | ||
| * the declarative configuration model when {@link #isEnabled(OpenTelemetryConfigurationModel)} | ||
| * returns {@code true}. | ||
| * | ||
| * <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
| * at any time. | ||
| */ | ||
| public abstract class AbstractThreadDetailsCustomizerProvider | ||
| implements DeclarativeConfigurationCustomizerProvider { | ||
|
|
||
| protected abstract boolean isEnabled(OpenTelemetryConfigurationModel model); | ||
|
|
||
| @Override | ||
| public void customize(DeclarativeConfigurationCustomizer customizer) { | ||
| customizer.addModelCustomizer( | ||
| model -> { | ||
| maybeAddThreadDetailsProcessor(model); | ||
| return model; | ||
| }); | ||
| } | ||
|
|
||
| private void maybeAddThreadDetailsProcessor(OpenTelemetryConfigurationModel model) { | ||
| if (!isEnabled(model)) { | ||
| return; | ||
| } | ||
| TracerProviderModel tracerProvider = model.getTracerProvider(); | ||
| if (tracerProvider == null) { | ||
| tracerProvider = new TracerProviderModel(); | ||
| model.withTracerProvider(tracerProvider); | ||
| } | ||
| List<SpanProcessorModel> processors = tracerProvider.getProcessors(); | ||
| if (processors == null) { | ||
| processors = new ArrayList<>(); | ||
| tracerProvider.withProcessors(processors); | ||
| } | ||
| processors.add( | ||
| new SpanProcessorModel() | ||
| .withAdditionalProperty( | ||
| ThreadDetailsComponentProvider.NAME, new SpanProcessorPropertyModel())); | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
...java/io/opentelemetry/instrumentation/thread/internal/ThreadDetailsComponentProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.thread.internal; | ||
|
|
||
| import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; | ||
| import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; | ||
| import io.opentelemetry.sdk.trace.SpanProcessor; | ||
|
|
||
| /** | ||
| * Declarative configuration component provider that exposes {@link ThreadDetailsSpanProcessor} | ||
| * under the name {@value #NAME}. | ||
| * | ||
| * <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
| * at any time. | ||
| */ | ||
| public final class ThreadDetailsComponentProvider implements ComponentProvider { | ||
|
|
||
| public static final String NAME = "thread_details"; | ||
|
|
||
| @Override | ||
| public Class<SpanProcessor> getType() { | ||
| return SpanProcessor.class; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return NAME; | ||
| } | ||
|
|
||
| @Override | ||
| public SpanProcessor create(DeclarativeConfigProperties config) { | ||
| return new ThreadDetailsSpanProcessor(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...urces/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| io.opentelemetry.instrumentation.thread.internal.ThreadDetailsComponentProvider |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.