diff --git a/sentry-core/src/performance.rs b/sentry-core/src/performance.rs index 6439396b6..9cb7c3f31 100644 --- a/sentry-core/src/performance.rs +++ b/sentry-core/src/performance.rs @@ -62,7 +62,7 @@ pub type CustomTransactionContext = serde_json::Map; /// /// The Transaction Context defines the metadata for a Performance Monitoring /// Transaction, and also the connection point for distributed tracing. -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct TransactionContext { #[cfg_attr(not(feature = "client"), allow(dead_code))] name: String, @@ -260,6 +260,16 @@ impl TransactionOrSpan { } } + /// Get the TransactionContext of the Transaction/Span. + /// + /// Note that this clones the underlying value. + pub fn get_trace_context(&self) -> protocol::TraceContext { + match self { + TransactionOrSpan::Transaction(transaction) => transaction.get_trace_context(), + TransactionOrSpan::Span(span) => span.get_trace_context(), + } + } + /// Set the status of the Transaction/Span. pub fn get_status(&self) -> Option { match self { @@ -477,6 +487,14 @@ impl Transaction { } } + /// Get the TransactionContext of the Transaction. + /// + /// Note that this clones the underlying value. + pub fn get_trace_context(&self) -> protocol::TraceContext { + let inner = self.inner.lock().unwrap(); + inner.context.clone() + } + /// Get the status of the Transaction. pub fn get_status(&self) -> Option { let inner = self.inner.lock().unwrap(); @@ -601,6 +619,14 @@ impl Span { span.data.insert(key.into(), value); } + /// Get the TransactionContext of the Span. + /// + /// Note that this clones the underlying value. + pub fn get_trace_context(&self) -> protocol::TraceContext { + let transaction = self.transaction.lock().unwrap(); + transaction.context.clone() + } + /// Get the status of the Span. pub fn get_status(&self) -> Option { let span = self.span.lock().unwrap();