Skip to content

adding navigation log support for angular#10147

Open
ssakhamu wants to merge 3 commits into
crashlytics-traces2from
angular-log-boundary
Open

adding navigation log support for angular#10147
ssakhamu wants to merge 3 commits into
crashlytics-traces2from
angular-log-boundary

Conversation

@ssakhamu

Copy link
Copy Markdown

Adding a function to call on the client side to set up a navigation listener to create navigation logs.

Also refactored getSafeRoutePath to be a shared function between error logging and navigation tracking.

@ssakhamu ssakhamu requested review from a team as code owners July 10, 2026 12:54
@changeset-bot

changeset-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: ab951e2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces automatic Angular router navigation tracking for Firebase Crashlytics by adding 'setupNavigationTracking', 'getSafeRoutePath', and 'getRawPath' functions. Feedback is provided to optimize 'setupNavigationTracking' to prevent redundant initial telemetry logs before the router completes its initial navigation, and to simplify the type annotation of 'currentRoute' in 'getSafeRoutePath'.

Comment thread packages/crashlytics/src/angular/index.ts Outdated
Comment thread packages/crashlytics/src/angular/index.ts Outdated
Comment thread packages/crashlytics/src/angular/index.test.ts Outdated

@MaesterChestnut MaesterChestnut left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nice stuff!

export function getRawPath(url: string): string;

// @public
export function getSafeRoutePath(router: Router): string;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why do these two functions (getRawPath and getSafeRoutePath) need to be publicly exported?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

added @internal tags for them so that they are not public

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can they actually just be private functions in angular/index.ts? And then they don't need to be exposed in the API at all?

const subscription = router.events.subscribe(event => {
if (event instanceof NavigationEnd) {
const currentRawPath = getRawPath(event.urlAfterRedirects);
if (currentRawPath !== lastRawPath) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm not familiar with angular routing - if the user refreshes the page, would that trigger a NavigationEnd event?

@ssakhamu ssakhamu Jul 10, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

If the user refreshes the page, then it is the equivalent of the page loading again for the first time. My comment on the AI's comment above mentions the two cases that may occur on the page load.

Essentially, a NavigationEnd would trigger for case 2. That particular check on 177 shouldn't be relevant for the page reload. It is for if only a query parameter or hash changes in the url; in which case, those NavigationEnd events are ignored.

* Extracts the raw path portion from a full URL by stripping query parameters and hashes.
*/
export function getRawPath(url: string): string {
return url.split('?')[0].split('#')[0];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

String manipulation in general is brittle and generally avoided. Specifically, in this case it won't work when sanitizing angular matrix parameters. Apparently you should use UrlTree 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