Skip to content
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(tracing): Add method for accessing span data #548

Merged
merged 5 commits into from Feb 8, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 28 additions & 2 deletions sentry-core/src/performance.rs
@@ -1,5 +1,6 @@
use std::sync::Arc;
use std::sync::Mutex;
use std::collections::BTreeMap;
use std::ops::{Deref, DerefMut};
use std::sync::{Arc, Mutex, MutexGuard};

#[cfg(all(feature = "profiling", target_family = "unix"))]
use crate::profiling;
Expand Down Expand Up @@ -601,6 +602,23 @@ impl Transaction {
}
}

/// A smart pointer to a span's [`data` field](protocol::Span::data).
pub struct Data<'a>(MutexGuard<'a, protocol::Span>);

impl<'a> Deref for Data<'a> {
type Target = BTreeMap<String, protocol::Value>;

fn deref(&self) -> &Self::Target {
&self.0.data
}
}

impl<'a> DerefMut for Data<'a> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0.data
}
}

/// A running Performance Monitoring Span.
///
/// The span needs to be explicitly finished via [`Span::finish`], otherwise it
Expand All @@ -621,6 +639,14 @@ impl Span {
span.data.insert(key.into(), value);
}

/// Returns a smart pointer to the span's [`data` field](protocol::Span::data).
///
/// Since [`Data`] implements `Deref` and `DerefMut`, this can be used to read and mutate
/// the span data.
pub fn data(&self) -> Data {
Data(self.span.lock().unwrap())
}

/// Get the TransactionContext of the Span.
///
/// Note that this clones the underlying value.
Expand Down