Skip to content

Conversation

jjbayer
Copy link
Member

@jjbayer jjbayer commented Mar 15, 2024

Because span metrics extraction happens as part of transaction metrics extraction, at which point we did not convert the transaction into a span yet, span metrics were so far only extracted from child spans of transactions and standalone spans.

With this change, the transaction span gets its metrics extracted as well.

ref: #2494

@jjbayer jjbayer changed the title Fix/spans segment metrics fix(spans): Extract metrics from transaction spans Mar 15, 2024
@jjbayer jjbayer marked this pull request as ready for review March 15, 2024 11:30
@jjbayer jjbayer requested a review from a team as a code owner March 15, 2024 11:30
@jjbayer jjbayer requested a review from phacops March 15, 2024 11:30
struct NormalizeSpanConfig<'a> {
/// The time at which the event was received in this Relay.
pub received_at: DateTime<Utc>,
received_at: DateTime<Utc>,
Copy link
Member Author

Choose a reason for hiding this comment

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

drive-by fix.

#[cfg(test)]
#[cfg(feature = "processing")]
impl<'a, Group: TryFrom<ProcessingGroup>> ProcessEnvelopeState<'a, Group> {
fn simple(event_json: &str, group: ProcessingGroup, project_state: ProjectState) -> Self {
Copy link
Member Author

Choose a reason for hiding this comment

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

Just a helper method to create a state for testing.

Copy link
Member

Choose a reason for hiding this comment

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

I don't mind having it, but usually we just have free standing functions instead

return;
}

let mut add_span = |span: Annotated<Span>| {
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 used the opportunity to upgrade this helper to a real function.

/// Returns an untracked envelope that does not report to outcomes or test store.
#[cfg(test)]
pub fn silent(envelope: Box<Envelope>, group: ProcessingGroup) -> Self {
Self::standalone(envelope, Addr::custom().0, Addr::custom().0, group)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Self::standalone(envelope, Addr::custom().0, Addr::custom().0, group)
Self::standalone(envelope, Addr::dummy(), Addr::dummy(), group)

#[cfg(test)]
#[cfg(feature = "processing")]
impl<'a, Group: TryFrom<ProcessingGroup>> ProcessEnvelopeState<'a, Group> {
fn simple(event_json: &str, group: ProcessingGroup, project_state: ProjectState) -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

I don't mind having it, but usually we just have free standing functions instead

@jjbayer jjbayer marked this pull request as draft March 18, 2024 13:11
@jjbayer
Copy link
Member Author

jjbayer commented Mar 18, 2024

Requires change: Metrics extraction has to happen before dynamic sampling of the transaction.

@jjbayer jjbayer marked this pull request as ready for review March 19, 2024 18:39
@jjbayer jjbayer requested a review from Dav1dde March 19, 2024 18:39
Copy link
Contributor

@iker-barriocanal iker-barriocanal left a comment

Choose a reason for hiding this comment

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

LGTM.

Is it worth adding an integration test with multiple relays to ensure metrics from a transaction span are only extracted once (1x transaction, 1x span)? Since we're making changes around span<>transaction conversion, to ensure we don't break anything in the future. I'm not sure if that'd cover uncovered use cases, so your call.

@jjbayer
Copy link
Member Author

jjbayer commented Mar 20, 2024

Is it worth adding an integration test with multiple relays to ensure metrics from a transaction span are only extracted once (1x transaction, 1x span)?

Added span metrics to test_transaction_metrics now, which tests exactly that.

Copy link
Contributor

@iker-barriocanal iker-barriocanal left a comment

Choose a reason for hiding this comment

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

Thanks for extending the test!

@jjbayer jjbayer merged commit a5e8e33 into master Mar 20, 2024
@jjbayer jjbayer deleted the fix/spans-segment-metrics branch March 20, 2024 13:51
jjbayer added a commit that referenced this pull request Mar 26, 2024
Since #3273, we accidentally emit
the metric `d:transactions/measurements.score.total@ratio` twice for
every transaction.

This happens because the metric is not only extracted from transactions,
but also from spans:
https://github.com/getsentry/relay/blob/0b8687c03b3eaf23db368733754d17c446bcb482/relay-dynamic-config/src/defaults.rs#L459-L461

As a quick fix, extract that metric only if the span is not a segment
span extracted from a transaction. Long-term, we should stop extracting
that _transaction_ metric from spans, and base performance score
computation on `"d:spans/webvital.score.total@ratio` instead.
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