Repository navigation
fix: Use strict trace continuation for continue_from_span
#1329
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
Open
szokeasaurusrex
wants to merge
1
commit into
szokeasuarusrex/deprecate-sample_should_send
from
szokeasaurusrex/continue_from_span-strict
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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 on lines
+274
to
+283
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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(), | ||
| } | ||
|
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, | ||
| } | ||
| } | ||
| }; | ||
|
|
||
|
|
@@ -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, | ||
| } | ||
| } | ||
|
|
@@ -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 { | ||
|
|
@@ -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`]. | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.