Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Deprecated [`Client::sample_should_send`](https://docs.rs/sentry-core/0.49.4/sentry_core/struct.Client.html#method.sample_should_send). We will remove this method from the public API in the next breaking release ([#1328](https://github.com/getsentry/sentry-rust/pull/1328)).

### Fixes

- [`TransactionContext::continue_from_span`](https://docs.rs/sentry-core/0.49.4/sentry_core/struct.TransactionContext.html#method.continue_from_span) now respects trace continuation rules: spans being recorded onto a client that reports to a different Sentry organization are no longer continued by this function. We also respect the `strict_trace_continuation` option ([#1329](https://github.com/getsentry/sentry-rust/pull/1329)).

## 0.49.3

### Features
Expand Down
68 changes: 57 additions & 11 deletions sentry-core/src/performance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::time::SystemTime;
use sentry_types::protocol::v7::client_report::Reason as ClientReportReason;
#[cfg(feature = "client")]
use sentry_types::protocol::v7::OrganizationId;
use sentry_types::protocol::v7::SpanId;
use sentry_types::protocol::v7::{SpanId, TraceId};

#[cfg(feature = "client")]
use self::sampling::FinishAction;
Expand Down Expand Up @@ -271,24 +271,53 @@ impl TransactionContext {
/// thread and should be connected to the calling thread via a distributed
/// tracing transaction.
pub fn continue_from_span(name: &str, op: &str, span: Option<TransactionOrSpan>) -> Self {
/// Helper struct for the match statement; this allows us to have `incoming_trace` be
/// guarded by the client feature.
struct IncomingSpanData {
trace_id: TraceId,
span_id: SpanId,
#[cfg(feature = "client")]
incoming_trace: IncomingTrace,
sampled: Option<bool>,
Comment thread
szokeasaurusrex marked this conversation as resolved.
Resolved
}

Comment on lines +274 to +283

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes here look more complicated than they really are; we needed to refactor the tuple used in the match statement to a named structure as incoming_trace is only available under the "client" feature.

Any other solution I could think of was more complicated

let span = match span {
Some(span) => span,
None => return Self::new(name, op),
};

let (trace_id, parent_span_id, sampled) = match span {
let IncomingSpanData {
trace_id,
span_id: parent_span_id,
#[cfg(feature = "client")]
incoming_trace,
sampled,
} = match span {
TransactionOrSpan::Transaction(transaction) => {
let inner = transaction.inner.lock().unwrap();
(
inner.context.trace_id,
inner.context.span_id,
inner.tracing_state.trace_sampled(),
)
IncomingSpanData {
trace_id: inner.context.trace_id,
span_id: inner.context.span_id,
#[cfg(feature = "client")]
incoming_trace: IncomingTrace {
org_id: inner.client.as_ref().and_then(|c| c.org_id()),
},
sampled: inner.tracing_state.trace_sampled(),
}
Comment thread
szokeasaurusrex marked this conversation as resolved.
Resolved
}
TransactionOrSpan::Span(span) => {
let trace_sampled = span.tracing_state.trace_sampled();
let span = span.span.lock().unwrap();
(span.trace_id, span.span_id, trace_sampled)
let sampled = span.tracing_state.trace_sampled();
let protocol_span = span.span.lock().unwrap();

IncomingSpanData {
trace_id: protocol_span.trace_id,
span_id: protocol_span.span_id,
#[cfg(feature = "client")]
incoming_trace: IncomingTrace {
org_id: span.org_id(),
},
sampled,
}
}
};

Expand All @@ -300,7 +329,7 @@ impl TransactionContext {
span_id: protocol::SpanId::default(),
sampled,
#[cfg(feature = "client")]
incoming_trace: None,
incoming_trace: incoming_trace.into(),
custom: None,
}
}
Expand Down Expand Up @@ -1084,6 +1113,17 @@ impl Transaction {
span: Arc::new(Mutex::new(span)),
}
}

/// Obtains the org_id of this transaction's [`Client`].
#[cfg(feature = "client")]
pub(crate) fn org_id(&self) -> Option<OrganizationId> {
self.inner
.lock()
.unwrap_or_else(|e| e.into_inner())
.client
.as_ref()
.and_then(|c| c.org_id())
}
}

impl PartialEq for Transaction {
Expand Down Expand Up @@ -1334,6 +1374,12 @@ impl Span {
}
}

/// Return the organization ID of the client this span is being recorded onto.
#[cfg(feature = "client")]
pub(crate) fn org_id(&self) -> Option<OrganizationId> {
self.transaction.org_id()
}

/// Starts a new child Span with the given `op` and `description`.
///
/// The span must be explicitly finished via [`Span::finish`].
Expand Down
Loading