You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to customize the Event with before_send callback and adding the fingerprint that getting from event.contexts.
but since Event is Event<'static> so it needs static lifetime, therefore adding dynamic string to fingerprint is not straightforward (by using Box::leak, we can make string to be 'static lifetime but as name suggests, it causes memory leak).
Hi! All the references with lifetime 'a in Event are behind Cow smart pointers. For example, fingerprint has the type Cow<'a, [Cow<'a, str>]>. In case you're not familiar, a Cow<'a, T> is either a reference &'a T or the "owned form" of T. For example, a Cow<'a, str> is either a &'a str or a String. You can always get a Cow<'static, T> by using the owned form of T. For fingerprint, that means using Vec and String.
Edited to add: Here is your example snippet with my suggestion applied:
before_send:Some(Arc::new(|mut event| {let tracing_fields = event.contexts.get("Rust Tracing Fields");ifletSome(Context::Other(fields)) = tracing_fields {let fingerprint = fields.get("fingerprint");ifletSome(Value::String(fingerprint)) = fingerprint {
event.fingerprint = Cow::Owned(vec![// <-- This needs to be Owned because it's dynamicCow::Borrowed("{{ default }}"), // <-- This can be Borrowed because it's hardcodedCow::Owned(fingerprint.clone()), // <-- This needs to be Owned because it's dynamic])}}Some(event)})),
I want to customize the Event with before_send callback and adding the fingerprint that getting from event.contexts.
but since Event is
Event<'static>
so it needs static lifetime, therefore adding dynamic string to fingerprint is not straightforward (by usingBox::leak
, we can make string to be 'static lifetime but as name suggests, it causes memory leak).sentry-rust/sentry/examples/before-send.rs
Line 6 in 8c701e8
I would like to have Event as not 'static, and allow me to modify it dynamically.
Thank you.
The text was updated successfully, but these errors were encountered: