-
Notifications
You must be signed in to change notification settings - Fork 900
add config model customizer #7118
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 9 commits into
open-telemetry:main
from
zeitlinger:add-config-mode-customizer
Mar 21, 2025
+164
−3
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5f31860
add config model customizer
zeitlinger 3416e26
add config model customizer
zeitlinger 0af474e
Update sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/ex…
zeitlinger 6e304de
fix rebase
zeitlinger 5fd3e48
use same strategy as AutoConfigurationCustomizerProvider
zeitlinger aad4c62
add javadoc
zeitlinger 1e919ef
improve test
zeitlinger 701b811
improve test
zeitlinger 76b3607
improve test
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
35 changes: 35 additions & 0 deletions
35
.../io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigurationBuilder.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,35 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.extension.incubator.fileconfig; | ||
|
||
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel; | ||
import java.util.function.Function; | ||
|
||
/** Builder for the declarative configuration. */ | ||
public class DeclarativeConfigurationBuilder implements DeclarativeConfigurationCustomizer { | ||
private Function<OpenTelemetryConfigurationModel, OpenTelemetryConfigurationModel> | ||
modelCustomizer = Function.identity(); | ||
|
||
@Override | ||
public void addModelCustomizer( | ||
Function<OpenTelemetryConfigurationModel, OpenTelemetryConfigurationModel> customizer) { | ||
modelCustomizer = mergeCustomizer(modelCustomizer, customizer); | ||
} | ||
|
||
private static <I, O1, O2> Function<I, O2> mergeCustomizer( | ||
Function<? super I, ? extends O1> first, Function<? super O1, ? extends O2> second) { | ||
return (I configured) -> { | ||
O1 firstResult = first.apply(configured); | ||
return second.apply(firstResult); | ||
}; | ||
} | ||
|
||
/** Customize the configuration model. */ | ||
public OpenTelemetryConfigurationModel customizeModel( | ||
OpenTelemetryConfigurationModel configurationModel) { | ||
return modelCustomizer.apply(configurationModel); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
.../opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigurationCustomizer.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,21 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.extension.incubator.fileconfig; | ||
|
||
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel; | ||
import java.util.function.Function; | ||
|
||
/** A service provider interface (SPI) for customizing declarative configuration. */ | ||
public interface DeclarativeConfigurationCustomizer { | ||
zeitlinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* Method invoked when configuring the SDK to allow further customization of the declarative | ||
* configuration. | ||
* | ||
* @param customizer the customizer to add | ||
*/ | ||
void addModelCustomizer( | ||
Function<OpenTelemetryConfigurationModel, OpenTelemetryConfigurationModel> customizer); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just realizing that this is going to be a problematic contract from a packaging standpoint..
Idk, let's cross that bridge when we get there. |
||
} |
18 changes: 18 additions & 0 deletions
18
...emetry/sdk/extension/incubator/fileconfig/DeclarativeConfigurationCustomizerProvider.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,18 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.extension.incubator.fileconfig; | ||
|
||
import io.opentelemetry.sdk.autoconfigure.spi.Ordered; | ||
|
||
/** A service provider interface (SPI) for customizing declarative configuration. */ | ||
public interface DeclarativeConfigurationCustomizerProvider extends Ordered { | ||
/** | ||
* Method invoked when configuring the SDK to allow further customization of the declarative | ||
* | ||
* @param customizer the customizer to add | ||
*/ | ||
void customize(DeclarativeConfigurationCustomizer customizer); | ||
} |
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
38 changes: 38 additions & 0 deletions
38
...ry/sdk/extension/incubator/fileconfig/TestDeclarativeConfigurationCustomizerProvider.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,38 @@ | ||
package io.opentelemetry.sdk.extension.incubator.fileconfig; | ||
|
||
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AttributeNameValueModel; | ||
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ResourceModel; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class TestDeclarativeConfigurationCustomizerProvider | ||
implements DeclarativeConfigurationCustomizerProvider { | ||
@Override | ||
public void customize(DeclarativeConfigurationCustomizer customizer) { | ||
customizer.addModelCustomizer( | ||
model -> { | ||
ResourceModel resource = model.getResource(); | ||
if (resource == null) { | ||
resource = new ResourceModel(); | ||
model.withResource(resource); | ||
} | ||
List<AttributeNameValueModel> attributes = resource.getAttributes(); | ||
if (attributes == null) { | ||
attributes = new ArrayList<>(); | ||
resource.withAttributes(attributes); | ||
} | ||
attributes.add( | ||
new AttributeNameValueModel() | ||
.withName("foo") | ||
.withType(AttributeNameValueModel.Type.STRING) | ||
.withValue("bar")); | ||
attributes.add( | ||
new AttributeNameValueModel() | ||
.withName("color") | ||
.withType(AttributeNameValueModel.Type.STRING) | ||
.withValue("blue")); | ||
return model; | ||
}); | ||
} | ||
} |
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.sdk.extension.incubator.fileconfig.TestDeclarativeConfigurationCustomizerProvider |
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.
In the future, we might consider adding opt-in logging to print the out change in the model after each stage of customization, but I'm happy to come back to that type of thing later. This is a good start!
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.
let's leave that as a next step then