-
Notifications
You must be signed in to change notification settings - Fork 960
Update to declarative config 1.0-rc.1 #7436
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
jack-berg
merged 3 commits into
open-telemetry:main
from
jack-berg:declarative-config-1.0.0-rc.1
Jun 24, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
51 changes: 51 additions & 0 deletions
51
...ain/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ServiceResourceDetector.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,51 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.extension.incubator.fileconfig; | ||
|
|
||
| import io.opentelemetry.api.common.AttributeKey; | ||
| import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; | ||
| import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
| import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; | ||
| import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; | ||
| import io.opentelemetry.sdk.resources.Resource; | ||
| import io.opentelemetry.sdk.resources.ResourceBuilder; | ||
| import java.util.Collections; | ||
| import java.util.UUID; | ||
|
|
||
| public class ServiceResourceDetector implements ComponentProvider<Resource> { | ||
|
|
||
| private static final AttributeKey<String> SERVICE_NAME = AttributeKey.stringKey("service.name"); | ||
| private static final AttributeKey<String> SERVICE_INSTANCE_ID = | ||
| AttributeKey.stringKey("service.instance.id"); | ||
|
|
||
| // multiple calls to this resource provider should return the same value | ||
| private static final String RANDOM_SERVICE_INSTANCE_ID = UUID.randomUUID().toString(); | ||
|
|
||
| @Override | ||
| public Class<Resource> getType() { | ||
| return Resource.class; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return "service"; | ||
| } | ||
|
|
||
| @Override | ||
| public Resource create(DeclarativeConfigProperties config) { | ||
| ResourceBuilder builder = Resource.builder(); | ||
|
|
||
| ConfigProperties properties = DefaultConfigProperties.create(Collections.emptyMap()); | ||
| String serviceName = properties.getString("otel.service.name"); | ||
| if (serviceName != null) { | ||
| builder.put(SERVICE_NAME, serviceName).build(); | ||
| } | ||
|
|
||
| builder.put(SERVICE_INSTANCE_ID, RANDOM_SERVICE_INSTANCE_ID); | ||
|
|
||
| return builder.build(); | ||
| } | ||
| } | ||
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.sdk.extension.incubator.fileconfig.ServiceResourceDetector |
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
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
64 changes: 64 additions & 0 deletions
64
...java/io/opentelemetry/sdk/extension/incubator/fileconfig/ServiceResourceDetectorTest.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,64 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.extension.incubator.fileconfig; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatCode; | ||
|
|
||
| import io.opentelemetry.api.common.AttributeKey; | ||
| import io.opentelemetry.api.common.Attributes; | ||
| import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; | ||
| import io.opentelemetry.sdk.resources.Resource; | ||
| import java.util.Objects; | ||
| import java.util.UUID; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junitpioneer.jupiter.ClearSystemProperty; | ||
|
|
||
| class ServiceResourceDetectorTest { | ||
|
|
||
| @Test | ||
| void getTypeAndName() { | ||
| ServiceResourceDetector detector = new ServiceResourceDetector(); | ||
|
|
||
| assertThat(detector.getType()).isEqualTo(Resource.class); | ||
| assertThat(detector.getName()).isEqualTo("service"); | ||
| } | ||
|
|
||
| @Test | ||
| @ClearSystemProperty(key = "otel.service.name") | ||
| void create_SystemPropertySet() { | ||
| System.setProperty("otel.service.name", "test"); | ||
|
|
||
| assertThat(new ServiceResourceDetector().create(DeclarativeConfigProperties.empty())) | ||
| .satisfies( | ||
| resource -> { | ||
| Attributes attributes = resource.getAttributes(); | ||
| assertThat(attributes.get(AttributeKey.stringKey("service.name"))).isEqualTo("test"); | ||
| assertThatCode( | ||
| () -> | ||
| UUID.fromString( | ||
| Objects.requireNonNull( | ||
| attributes.get(AttributeKey.stringKey("service.instance.id"))))) | ||
| .doesNotThrowAnyException(); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| void create_NoSystemProperty() { | ||
| assertThat(new ServiceResourceDetector().create(DeclarativeConfigProperties.empty())) | ||
| .satisfies( | ||
| resource -> { | ||
| Attributes attributes = resource.getAttributes(); | ||
| assertThat(attributes.get(AttributeKey.stringKey("service.name"))).isNull(); | ||
| assertThatCode( | ||
| () -> | ||
| UUID.fromString( | ||
| Objects.requireNonNull( | ||
| attributes.get(AttributeKey.stringKey("service.instance.id"))))) | ||
| .doesNotThrowAnyException(); | ||
| }); | ||
| } | ||
| } |
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
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.
As defined in the spec: https://github.com/open-telemetry/opentelemetry-specification/blame/main/specification/resource/sdk.md#L166-L168