Skip to content

Conversation

untitaker
Copy link
Member

In the span buffer we rely on the parent_span_id to cluster spans back
into transactions/segments. If we send out transactions that contain
"dangling" spans, then flatten those transactions into individual spans,
we won't be able to build the same segment back together.

In the span buffer we rely on the parent_span_id to cluster spans back
into transactions/segments. If we send out transactions that contain
"dangling" spans, then flatten those transactions into individual spans,
we won't be able to build the same segment back together.
@untitaker untitaker requested a review from a team as a code owner April 9, 2025 11:21
.filter_map(|span| span.value())
.filter_map(|span| span.span_id.value())
.chain(Some(root_span_id))
.cloned()
Copy link
Member Author

Choose a reason for hiding this comment

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

I really dislike this. In this expression we access span_id, in the for-loop we only access parent_span_id. In theory those are mutually exclusive accesses, and should be able to be borrowed at the same time. But it's tricky to convince the compiler of that, and so I have to clone here.

It would be better to make SpanId a u16 anyway...

Copy link
Member

Choose a reason for hiding this comment

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

Either this or we serialize like in ProjectKey which supports as_str and as_ref::<str>:

/// The public key used in a DSN to identify and authenticate a project at Sentry.
///
/// Project keys are always 32-character hexadecimal strings.
#[derive(Clone, Copy, Eq, Hash, Ord, PartialOrd, PartialEq)]
pub struct ProjectKey([u8; 32]);
)

Copy link
Member Author

Choose a reason for hiding this comment

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

tried to change this but too much stuff has to be adjusted to make it work since .0 is pub. let's just ship as-is

Copy link
Member

Choose a reason for hiding this comment

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

Right, part of this would be refactoring all usage to remove access to the field.

Comment on lines 337 to 339
if event.ty.value() == Some(&EventType::Transaction) {
span::fix_trees::fix_trees(event);
}
Copy link
Member

Choose a reason for hiding this comment

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

Should we not put this inside the conditional block below?

///
/// This is to avoid any nasty surprises in the span buffer specifically. Other readers of spans
/// (such as the frontend's tree component) were already able to deal with detached spans.
pub fn fix_trees(event: &mut Event) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a name along the lines of reparent_spans_to_root is more expressive?

@untitaker untitaker merged commit 3292e9a into master Apr 9, 2025
27 checks passed
@untitaker untitaker deleted the ref/span-tree-normalization branch April 9, 2025 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants