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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(tracing): Add method for accessing span data
  • Loading branch information
loewenheim committed Feb 6, 2023
commit 95096f58f771a9940cba1707374633775a2d6deb
29 changes: 29 additions & 0 deletions sentry-core/src/performance.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use std::collections::BTreeMap;
use std::ops::Deref;
use std::ops::DerefMut;
use std::sync::Arc;
use std::sync::Mutex;
use std::sync::MutexGuard;

#[cfg(all(feature = "profiling", target_family = "unix"))]
use crate::profiling;
Expand Down Expand Up @@ -601,6 +605,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 +642,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