[sdk] Make ResourceBuilder.AddDetector factory pattern public (attempt 2)#4261
Merged
cijothomas merged 8 commits intoopen-telemetry:mainfrom Mar 6, 2023
Merged
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #4261 +/- ##
==========================================
+ Coverage 83.15% 83.17% +0.01%
==========================================
Files 296 296
Lines 11775 11789 +14
==========================================
+ Hits 9792 9805 +13
- Misses 1983 1984 +1
|
cijothomas
approved these changes
Mar 3, 2023
alanwest
approved these changes
Mar 4, 2023
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #4139
Fixes #4228
Relates to #4103
Relates to #4230
Changes
Public API Changes
namespace OpenTelemetry.Resources { public class ResourceBuilder { + public ResourceBuilder AddDetector(Func<IServiceProvider, IResourceDetector> resourceDetectorFactory) {} } }Details
The original API that was removed/hidden from 1.4:
public ResourceBuilder AddDetector(Func<IServiceProvider?, IResourceDetector> resourceDetectorFactory) {}The API being added here:
public ResourceBuilder AddDetector(Func<IServiceProvider, IResourceDetector> resourceDetectorFactory) {}The difference is the nullable behavior of the
IServiceProviderparameter.With the new API, doing this...
new ResourceBuilder().AddDector(sp => sp.GetRequiredService<MyResourceDetector>()).Build()...will lead to a
NotSupportedExceptionbecause theResourceBuilderis not associated to either anIServiceCollectionor anIServiceProvider.Using either of these APIs...
builder.SetResourceBuilder(new ResourceBuilder().AddDector(sp => sp.GetRequiredService<MyResourceDetector>()))builder.ConfigureResourceBuilder(builder => builder.AddDector(sp => sp.GetRequiredService<MyResourceDetector>()))...everything will work fine across traces, metrics, and logs.
The idea here is the common use cases will work as expected without the complexity of having to deal with the
nullcase.I really wanted to also add
AddDetector<T>()to be consistent with our other APIs but there isn't a good way for that to work in logs currently and I felt it being consistent for all signals was a good thing. Hopefully we can bring that in for ~1.6.TODOs
CHANGELOG.mdupdated for non-trivial changes