-
Notifications
You must be signed in to change notification settings - Fork 1k
declarative config: add thread details resource processor #14564
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
Open
zeitlinger
wants to merge
5
commits into
open-telemetry:main
Choose a base branch
from
zeitlinger:declarative-config-thread-details-provider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2e5f22a
add thread details resource processor
zeitlinger 4b81784
view config is now being loaded and "a" is not a valid value
zeitlinger 2418568
set enabled in test
zeitlinger e7b4370
set enabled in test
zeitlinger 72df93d
pr review
zeitlinger 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
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
31 changes: 31 additions & 0 deletions
31
...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,31 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
* any time. | ||
*/ | ||
public class ThreadDetailsComponentProvider implements ComponentProvider<SpanProcessor> { | ||
@Override | ||
public String getName() { | ||
return "thread_details"; | ||
} | ||
|
||
@Override | ||
public SpanProcessor create(DeclarativeConfigProperties config) { | ||
return new AddThreadDetailsSpanProcessor(); | ||
} | ||
|
||
@Override | ||
public Class<SpanProcessor> getType() { | ||
return SpanProcessor.class; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...ava/io/opentelemetry/instrumentation/thread/internal/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,48 @@ | ||
/* | ||
* 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.extension.incubator.fileconfig.DeclarativeConfigurationCustomizer; | ||
import io.opentelemetry.sdk.extension.incubator.fileconfig.DeclarativeConfigurationCustomizerProvider; | ||
import io.opentelemetry.sdk.extension.incubator.fileconfig.SdkConfigProvider; | ||
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel; | ||
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SpanProcessorModel; | ||
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.TracerProviderModel; | ||
|
||
/** | ||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
* any time. | ||
*/ | ||
public class ThreadDetailsCustomizerProvider implements DeclarativeConfigurationCustomizerProvider { | ||
@Override | ||
public void customize(DeclarativeConfigurationCustomizer customizer) { | ||
customizer.addModelCustomizer( | ||
model -> { | ||
TracerProviderModel tracerProvider = model.getTracerProvider(); | ||
if (tracerProvider != null && isEnabled(model)) { | ||
tracerProvider | ||
.getProcessors() | ||
.add(new SpanProcessorModel().withAdditionalProperty("thread_details", null)); | ||
} | ||
|
||
return model; | ||
}); | ||
} | ||
|
||
private static boolean isEnabled(OpenTelemetryConfigurationModel model) { | ||
DeclarativeConfigProperties properties = | ||
SdkConfigProvider.create(model).getInstrumentationConfig(); | ||
if (properties == null) { | ||
return false; | ||
} | ||
DeclarativeConfigProperties java = | ||
properties.getStructured("java", DeclarativeConfigProperties.empty()); | ||
|
||
return java.getStructured("thread_details", DeclarativeConfigProperties.empty()) | ||
.getBoolean("enabled", false); | ||
} | ||
} |
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 |
1 change: 1 addition & 0 deletions
1
...entelemetry.sdk.extension.incubator.fileconfig.DeclarativeConfigurationCustomizerProvider
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.ThreadDetailsCustomizerProvider |
56 changes: 56 additions & 0 deletions
56
...try/instrumentation/thread/internal/ThreadDetailsConfigurationCustomizerProviderTest.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,56 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.thread.internal; | ||
|
||
import static java.util.Collections.singletonMap; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.opentelemetry.sdk.OpenTelemetrySdk; | ||
import io.opentelemetry.sdk.extension.incubator.fileconfig.DeclarativeConfiguration; | ||
import io.opentelemetry.sdk.extension.incubator.fileconfig.DeclarativeConfigurationBuilder; | ||
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ExperimentalLanguageSpecificInstrumentationModel; | ||
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.InstrumentationModel; | ||
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel; | ||
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.TracerProviderModel; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ThreadDetailsConfigurationCustomizerProviderTest { | ||
|
||
static final String PROCESSOR = "AddThreadDetailsSpanProcessor"; | ||
|
||
@Test | ||
void disabledByDefault() { | ||
OpenTelemetryConfigurationModel model = modelWithTracer(); | ||
|
||
try (OpenTelemetrySdk sdk = DeclarativeConfiguration.create(model)) { | ||
assertThat(sdk.toString()).doesNotContain(PROCESSOR); | ||
} | ||
} | ||
|
||
@Test | ||
void enabled() { | ||
OpenTelemetryConfigurationModel model = | ||
modelWithTracer() | ||
.withInstrumentationDevelopment( | ||
new InstrumentationModel() | ||
.withJava( | ||
new ExperimentalLanguageSpecificInstrumentationModel() | ||
.withAdditionalProperty( | ||
"thread_details", singletonMap("enabled", true)))); | ||
|
||
try (OpenTelemetrySdk sdk = DeclarativeConfiguration.create(model)) { | ||
assertThat(sdk.toString()).containsOnlyOnce(PROCESSOR); | ||
} | ||
} | ||
|
||
private static OpenTelemetryConfigurationModel modelWithTracer() { | ||
return new DeclarativeConfigurationBuilder() | ||
.customizeModel( | ||
new OpenTelemetryConfigurationModel() | ||
.withFileFormat("1.0-rc.1") | ||
.withTracerProvider(new TracerProviderModel())); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still interested in
thread.name
being added before span start, especially in declarative config, so it can be used by the declarative config rule-based samplerI guess we could always have the rule-based sampler hard-code support for
thread.name
since it runs on the same thread, but that feels a little hacky (isthread.name
always available in the rule-based sampler then even if the attribute isn't being stamped onto the span?)I'm not sure how best to accomplish this though
cc @laurit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way I see it we have 2 options. Either let rule based sampler compute
thread.name
itself or add thethread.name
in instrumentation api.