-
Notifications
You must be signed in to change notification settings - Fork 517
feat: API to modify/remove an existing entry from LogRecord attributes #2103
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2103 +/- ##
=======================================
+ Coverage 79.6% 79.7% +0.1%
=======================================
Files 124 124
Lines 23174 23400 +226
=======================================
+ Hits 18456 18670 +214
- Misses 4718 4730 +12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: Cijo Thomas <[email protected]>
…ry-rust into log-attributes-update
This is important, but trying to wrap up critical metric stuff/internal logging for the upcoming release, and will get back to this right after that. |
@lalitb Can you resurrect the PR? |
@@ -64,6 +64,16 @@ | |||
`LogExporter` trait no longer requires a mutable ref to `self`. If the exporter | |||
needs to mutate state, it should rely on interior mutability. | |||
[2764](https://github.com/open-telemetry/opentelemetry-rust/pull/2764) | |||
- Added Two new methods to the LogRecord struct's public API: |
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 Two new methods to the LogRecord struct's public API: | |
- Added Two new methods to the `SdkLogRecord` struct's public API: |
Can you share why we are not adding these new APIs to the LogRecord
trait itself?
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.
Can you share why we are not adding these new APIs to the LogRecord trait itself?
+1
update_attribute(&Key, &AnyValue) -> Option<AnyValue> | ||
``` | ||
- Updates the value of the first occurrence of an attribute with the specified key. | ||
- If the key exists, the old value is returned. If not, the new key-value pair is added, and None is returned. |
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 behavior of update-or-insert might call for a different name than update_attribute
. is set_attribute
better sounding?
#[allow(dead_code)] | ||
pub(crate) fn remove_at(&mut self, index: usize) -> Option<T> { | ||
if index < self.count { | ||
let removed_value = self.inline[index].clone(); |
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.
is clone necessary? Can we "take" ownership?
@@ -87,6 +87,71 @@ impl< | |||
self.count + self.overflow.as_ref().map_or(0, Vec::len) | |||
} | |||
|
|||
/// Removes the element at a specific position (index) while preserving the order. |
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.
Thanks for detailed writeup!
/// | ||
/// This method searches for the first occurrence of the attribute with the given key | ||
/// in the `attributes` collection. If the key is found, its value is updated with the | ||
/// provided value. If the key is not found, the attribute is added. |
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.
If the key is not found, the attribute is added.
We already have an add_attribute
method which is meant for adding a new attribute. I think we should do one of the following:
- Either make
update_attribute
strictly an update operation. - Or rename the method to
add_or_update_attribute
to reflect its true behavior.
@@ -201,6 +202,73 @@ impl SdkLogRecord { | |||
.flatten() | |||
.any(|(k, v)| k == key && v == value) | |||
} | |||
|
|||
/// Updates the first occurrence of an attribute with the specified key. |
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.
Similar to remove_attribute
, we should update all the occurrences of the given attribute key. For example, I think it would make it easier for redaction processor authors to redact a "secret" attribute with certainty.
/// - Removes the element at the specified index. | ||
/// - Shifts the remaining elements in the internal array to the left to fill the gap, preserving the order. | ||
/// - If an overflow vector exists: | ||
/// - Moves the first element from the overflow vector into the last position of the internal array, if available. |
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.
Can we avoid doing this? It seems like an unnecessary expensive operation. We maintain the count
of the items in the array. It should be okay to have the count
less than the array length while also having the vec
.
@lalitb Could you address review comments and resurrect this when you get a chance? |
Fixes #1986
Changes
This PR adds two new methods,
update_attribute
anddelete_attribute
, to the public API of theLogRecord
struct.Merge requirement checklist
CHANGELOG.md
files updated for non-trivial, user-facing changes