Skip to content

Commit a24d71b

Browse files
committed
feat(sdk): add SdkLogRecord::retain_attributes
1 parent 223e242 commit a24d71b

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎opentelemetry-sdk/src/logs/record.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,23 @@ impl SdkLogRecord {
264264
self.attributes
265265
.retain_mut(|attr| !matches!(attr, Some((k, _)) if k.as_str() == key.as_ref()))
266266
}
267+
268+
/// Retains only the attributes specified by the predicate.
269+
///
270+
/// In other words, removes all pairs (k, v) for which f(&k, &mut v) returns
271+
/// `false`.
272+
///
273+
/// This gives mutable access to the values of the attributes, so they can
274+
/// be modified in place.
275+
pub fn retain_attributes<F>(&mut self, mut f: F) -> usize
276+
where
277+
F: FnMut(&Key, &mut AnyValue) -> bool,
278+
{
279+
self.attributes.retain_mut(|attr| match attr {
280+
Some((k, v)) => f(k, v),
281+
None => true,
282+
})
283+
}
267284
}
268285

269286
/// TraceContext stores the trace context for logs that have an associated

0 commit comments

Comments
 (0)