opentelemetry-rust icon indicating copy to clipboard operation
opentelemetry-rust copied to clipboard

API to modify/remove an existing entry from LogRecord attributes

Open lalitb opened this issue 5 months ago • 2 comments

Fixes #1986

Changes

This PR adds two new methods, update_attribute and delete_attribute, to the public API of the LogRecord struct.

pub fn update_attribute(&Key, &AnyValue) -> Option<AnyValue>
  • Updates the value of the first occurrence of an attribute with the specified key.
  • If the attribute already exists, its value is replaced, and the old value is returned.
  • If the attribute is not found, it is added as a new key-value pair, and None is returned.
pub fn remove_attribute(&mut self, key: &Key) -> usize
  • Removes all the occurrence of attributes with the specified key.
  • The count of deleted attributes is returned .

Merge requirement checklist

  • [x] CONTRIBUTING guidelines followed
  • [x] Unit tests added/updated (if applicable)
  • [ ] Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • [x] Changes in public API reviewed (if applicable)

lalitb avatar Sep 11 '24 15:09 lalitb