-
Notifications
You must be signed in to change notification settings - Fork 906
return resource in auto configured sdk #7639
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
9
commits into
open-telemetry:main
Choose a base branch
from
zeitlinger:declarative-config-return-resource
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 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1249421
return resource in auto configured sdk
zeitlinger c4c3fc7
don't create resource twice
zeitlinger 541f260
test coverage
zeitlinger 207e7c4
rebase
zeitlinger 7550915
format
zeitlinger f86f89b
rebase
zeitlinger 16e1492
move logic to incubating util
zeitlinger 84e061b
comment
zeitlinger 1079cdc
make sure resource is set when getting it (to help troubleshoot)
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,10 @@ | |
import io.opentelemetry.api.incubator.config.DeclarativeConfigException; | ||
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; | ||
import io.opentelemetry.api.metrics.MeterProvider; | ||
import io.opentelemetry.common.ComponentLoader; | ||
import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; | ||
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; | ||
import io.opentelemetry.sdk.resources.Resource; | ||
import java.io.Closeable; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
|
@@ -24,11 +26,17 @@ class DeclarativeConfigContext { | |
private final SpiHelper spiHelper; | ||
private final List<Closeable> closeables = new ArrayList<>(); | ||
@Nullable private volatile MeterProvider meterProvider; | ||
private Resource resource = Resource.empty(); | ||
|
||
// Visible for testing | ||
DeclarativeConfigContext(SpiHelper spiHelper) { | ||
this.spiHelper = spiHelper; | ||
} | ||
|
||
static DeclarativeConfigContext create(ComponentLoader componentLoader) { | ||
return new DeclarativeConfigContext(SpiHelper.create(componentLoader)); | ||
} | ||
|
||
/** | ||
* Add the {@code closeable} to the list of closeables to clean up if configuration fails | ||
* exceptionally, and return it. | ||
|
@@ -51,6 +59,19 @@ public void setMeterProvider(MeterProvider meterProvider) { | |
this.meterProvider = meterProvider; | ||
} | ||
|
||
Resource getResource() { | ||
// called via reflection from io.opentelemetry.sdk.autoconfigure.IncubatingUtil | ||
return resource; | ||
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. Maybe throw an exception if 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. good idea - added |
||
} | ||
|
||
void setResource(Resource resource) { | ||
this.resource = resource; | ||
} | ||
|
||
SpiHelper getSpiHelper() { | ||
return spiHelper; | ||
} | ||
|
||
/** | ||
* Find a registered {@link ComponentProvider} with {@link ComponentProvider#getType()} matching | ||
* {@code type}, {@link ComponentProvider#getName()} matching {@code name}, and call {@link | ||
|
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
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.
Do you think this comment may be useful?
On one hand it explains why no one should remove this method, but on the other hand it will be easy to forget to update/remove it when declarative config stuff goes out of incubator.
Maybe instead of this comment it would be better to add a unit test in IncubatingUtilTest that verifies that getResource is actually called.
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 test is already there - but I get how it can get out of sync