-
Notifications
You must be signed in to change notification settings - Fork 442
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
base: main
Are you sure you want to change the base?
Feat/add resource builder #2322
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2322 +/- ##
=====================================
Coverage 79.5% 79.5%
=====================================
Files 123 124 +1
Lines 21295 21371 +76
=====================================
+ Hits 16935 16996 +61
- Misses 4360 4375 +15 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
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 😅
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])
} |
afb8ba4
to
5976ef0
Compare
5976ef0
to
e501d4f
Compare
"service.name", | ||
"metrics-advanced-example", | ||
)])) | ||
.with_resource(resource) |
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.
wondering if we can do with_servicename_resource("metrics-advanced-example")
? This will be the most common use case.
Or just Resource::builder().with_servicename("metrics-advanced-example")......build()
?
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.
I like that, I was using the go implementation for Resource builder this weekend and they had something similar to this and it felt pretty nice
sResource, err := resource.New(
ctx,
resource.WithTelemetrySDK(),
resource.WithAttributes(semconv.ServiceName("trace-export-service")),
)
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 😊
} | ||
|
||
/// Create ResourceBuilder with a default [Resource]. | ||
pub fn new_default() -> 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.
pub fn new_default() -> Self { | |
pub fn default() -> Self { |
Probably should be done as an impl Default for ResourceBuilder
to make it more generally compatible.
|
||
impl ResourceBuilder { | ||
/// Create ResourceBuilder with an empty [Resource]. | ||
pub fn new_empty() -> 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.
pub fn new_empty() -> Self { | |
pub fn new() -> Self { |
This makes it easier to reason about. Since on Resource
the new is the same as empty but it accepts key values. Since this is a builder most would assume it's empty.
fixes #2320
Changes
ResourceDetectors
.ResourceBuilder
to more easily create resources.example usage:
Merge requirement checklist
CHANGELOG.md
files updated for non-trivial, user-facing changes