-
Notifications
You must be signed in to change notification settings - Fork 485
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
Feat/add resource builder #2322
Feat/add resource builder #2322
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2322 +/- ##
=======================================
+ Coverage 79.3% 79.4% +0.1%
=======================================
Files 122 122
Lines 21588 21708 +120
=======================================
+ Hits 17138 17255 +117
- Misses 4450 4453 +3 ☔ View full report in Codecov by Sentry. |
fdd9fd1
to
b0bbed5
Compare
I still need to expose the new builder to the API, and would like feedback on #2324 before going further since the changes are related :) |
@pitoniak32 Could you split this into two PRs? Have one PR just for removing the |
split those changes into: #2332 |
f08a237
to
afb8ba4
Compare
} | ||
|
||
/// Add a [KeyValue] to the resource. | ||
pub fn with_key_value(self, kv: KeyValue) -> Self { |
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.
interesting why this does not need mut self
...
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.
It might be since the with_detectors consumes the builder and its not a &mut
reference? That's just a guess I'm actually not sure about that 😅
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.
with_key_value
doesn’t need mut self
because it doesn’t directly modify the builder; it delegates to with_key_values
, which takes mut self to perform the actual mutation.
I was also thinking of doing something like this for with_key_value, I'm wondering what others think? let resource = Resource::builder()
.with_key_value(KeyValue::new("test1", "test_value"))
.build();
// vs
let resource = Resource::builder()
.with_key_value("test1", "test_value")
.build(); /// Add a [KeyValue] to the resource.
pub fn with_key_value<K, V>(self, key: K, value: V) -> Self
where
K: Into<Key>,
V: Into<Value>,
{
self.with_key_values(vec![KeyValue::new(key, value)])
} currently its: /// Add a [KeyValue] to the resource.
pub fn with_key_value(self, kv: KeyValue) -> Self {
self.with_key_values(vec![kv])
} |
5976ef0
to
e501d4f
Compare
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.
Thank you for the contribution 😊
9fca93a
to
155f875
Compare
} | ||
|
||
/// Add multiple [KeyValue]s to the resource. | ||
pub fn with_key_values<T: IntoIterator<Item = KeyValue>>(mut self, kvs: T) -> Self { |
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.
should the method be named with_attribute
and with_attributes
- Just that the spec uses the term "attribute" consistently when describing resource data.
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.
+1
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.
fixed this
self.resource = self.resource.merge(&Resource::new(kvs)); | ||
self | ||
} | ||
|
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.
should there also be a method with_schema_url
to add schema url ?
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.
How would we like the behavior of the with_schema_url
to act? Do we want to follow the rules that from_schema_url
has? Or override the current one with the specified one, or maybe use TypeState pattern to only allow the schema_url to be set once?
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.
added this, would love to hear feedback on the implementation!
I vote for this, it's similar to what is followed for opentelemetry-rust/opentelemetry-sdk/src/logs/record.rs Lines 98 to 102 in a3c469b
|
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.
LGTM.
I think we can keep few methods on Resource like new() as pub(mod) to reduce the amount of internal changes.
Please update changelog to callout the breaking change/migration snippets.
Thanks for patiently working through this!
c510398
to
9f86898
Compare
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.
Looks good overall! I left some non-blocking suggestions.
Thanks @pitoniak32 for helping with this refactoring!
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.
LGTM! This looks great. Thank you for making all the updates and for your patience in addressing the comments
ps. Integration test is failing.
does it make sense to keep using an empty resource for integration tests, or should it get updated to have the default detectors? |
either is fine! Do what is easiest for this PR. |
fixes #2320
Migration Guide
Creating a Resource with default detectors:
Creating an empty Resource:
Changes
ResourceBuilder
to more easily create resources.example usage:
Merge requirement checklist
CHANGELOG.md
files updated for non-trivial, user-facing changes