Skip to content

fix(angular): Ensure navigations always create a transaction #10646

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

Merged
merged 2 commits into from
Feb 14, 2024

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Feb 13, 2024

This PR addresses the problematic check of getActiveSpan() in our Angular SDK's TraceService raised in #10634.

In certain situations (e.g. very quick navigations after the initial pageload) the check of getActiveSpan() could lead to navigations not getting their own transaction, as the pageload transaction was still active at that time.

I also checked the behaviour of multiple subsequent redirects and here, we only create one navigation transaction for all redirects. The reason for this is that the Angular router doesn't fire individual events for the redirects but only one for the final redirect. IMHO this is fine and should be expected behaviour.

ref #10634

Comment on lines +52 to +56
"overrides": {
"@sentry/browser": "latest || *",
"@sentry/core": "latest || *",
"@sentry/utils": "latest || *"
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Noticed that this seems to be required to ensure the local/verdaccio version of the dependencies of @sentry/angular-ivy are taken instead of the ones uploaded to NPM.

Comment on lines +32 to 34
fullyParallel: false,
workers: 1,
/* Fail the build on CI if you accidentally left test.only in the source code. */
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 to avoid bleeds of events due to the proxy. 5 tests shouldn't make much difference here.

Comment on lines +14 to +25
{
path: 'redirect1',
redirectTo: '/redirect2',
},
{
path: 'redirect2',
redirectTo: '/redirect3',
},
{
path: 'redirect3',
redirectTo: '/users/456',
},
Copy link
Member Author

Choose a reason for hiding this comment

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

Although these are 3 redirects, we'll only get one navigation root span and one routing span for them. I think this is fine (3 routing spans would have been nice to have but whatever)

@Lms24 Lms24 requested a review from mydea February 13, 2024 15:53
@Lms24
Copy link
Member Author

Lms24 commented Feb 14, 2024

I reworked the logic a bit to account for the edge case when the pageload root span already finished before the first NavigationStart event is emitted. This could happen if users intialize Angular (or maybe just the Router) in a delayed way. I don't have a concrete use case for this but it's possible.

In this case (i.e. no active pageload root span), we'll now immediately start a navigation root span, bypassing the "wait for the first emit" behaviour.

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