Skip to content
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

feat: Add Async Stack Tagging API support #46693

Closed
wants to merge 2 commits into from

Conversation

JiaLiPassion
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

Chrome has an experimental API to improve the debug experience of the
async tasks.
The details can be found here https://bugs.chromium.org/p/chromium/issues/detail?id=332624#c29

This commit add the async stack tagging support in the zone.js.
User can import 'zone.js/plugins/async-stack-tagging'; to enable this
feature.

Here is a sample when enable this feature

image

So we can use console.trace to print the async tasks chain information.

@JiaLiPassion JiaLiPassion requested a review from mgechev July 4, 2022 08:02
@ngbot ngbot bot added this to the Backlog milestone Jul 4, 2022
@pullapprove pullapprove bot requested review from atscott and gkalpak July 4, 2022 08:02
@JiaLiPassion JiaLiPassion force-pushed the async-tagging-console branch 3 times, most recently from 06dd4ec to a39c231 Compare July 4, 2022 10:06
@atscott atscott added feature Issue that requests a new feature target: minor This PR is targeted for the next minor release labels Jul 6, 2022

import {ifEnvSupports, ifEnvSupportsWithDone} from '../test-util';

fdescribe('AsyncTaggingConsoleTest', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fdescribe('AsyncTaggingConsoleTest', () => {
describe('AsyncTaggingConsoleTest', () => {

Chrome has an experimental API to improve the debug experience of the
async tasks.
The details can be found here https://bugs.chromium.org/p/chromium/issues/detail?id=332624#c29

This commit add the `async stack tagging` support in the `zone.js`.
User can `import 'zone.js/plugins/async-stack-tagging';` to enable this
feature.
Import `AsyncStackTaggingZoneSpec` if the user imported
`zone.js/plugins/async-stack-tagging` bundle. So the user can
use `console.trace` to output the `async task` information more
clearly.
Copy link
Contributor

@jessicajaniuk jessicajaniuk left a comment

Choose a reason for hiding this comment

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

reviewed-for: size-tracking

@jessicajaniuk jessicajaniuk added the action: merge The PR is ready for merge by the caretaker label Jul 11, 2022
@jessicajaniuk
Copy link
Contributor

This PR was merged into the repository by commit 19e6d9c.

jessicajaniuk pushed a commit that referenced this pull request Jul 11, 2022
Import `AsyncStackTaggingZoneSpec` if the user imported
`zone.js/plugins/async-stack-tagging` bundle. So the user can
use `console.trace` to output the `async task` information more
clearly.

PR Close #46693
@ArielGueta
Copy link

@JiaLiPassion what is different from the current behavior? I don't have this feature and I still see the same as your image:
Screen Shot 2022-07-12 at 9 14 10

See the async tag for setTimeout.

Thanks.

@JiaLiPassion
Copy link
Contributor Author

@ArielGueta , good point, I will ask the author of the async tagging api about the difference and let you know the result.

@victorporof
Copy link
Contributor

victorporof commented Jul 12, 2022

With this API, there are a few improvements that make the Angular debugging experience better across Chrome DevTools:

  1. There are now more situations in which async stacks are collected. For example, when using Promises (or even chained Promises) with Zone.js, the promise scheduling site will now also be a part of the stack trace.

  2. It's not just console.trace that emits the complete stack traces. You'll also see them on thrown errors (when you expand the error), in the Console panel.

  3. In addition, you'll also see the complete stack traces when paused at a breakpoint or exception, in the Call Stack inside the Sources panel (the debugger). They'll also interop with ignore-listing.

Note: support is currently behind a --js-flags="--experimental-async-stack-tagging-api". We plan to enable this by default in Chrome DevTools soon.

@JiaLiPassion
Copy link
Contributor Author

Thank you @victorporof , here are some screenshots of the debugger breakpoints.

  1. without async tagging support.
    without-async-tagging-debugger

  2. with async tagging support
    with-async-tagging-debugger

@ArielGueta
Copy link

Thanks @victorporof @JiaLiPassion

crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Jul 24, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@angular/animations](https://github.com/angular/angular) | dependencies | minor | [`14.0.6` -> `14.1.0`](https://renovatebot.com/diffs/npm/@angular%2fanimations/14.0.6/14.1.0) |
| [@angular/common](https://github.com/angular/angular) | dependencies | minor | [`14.0.6` -> `14.1.0`](https://renovatebot.com/diffs/npm/@angular%2fcommon/14.0.6/14.1.0) |
| [@angular/compiler](https://github.com/angular/angular) | dependencies | minor | [`14.0.6` -> `14.1.0`](https://renovatebot.com/diffs/npm/@angular%2fcompiler/14.0.6/14.1.0) |
| [@angular/compiler-cli](https://github.com/angular/angular) | devDependencies | minor | [`14.0.6` -> `14.1.0`](https://renovatebot.com/diffs/npm/@angular%2fcompiler-cli/14.0.6/14.1.0) |
| [@angular/core](https://github.com/angular/angular) | dependencies | minor | [`14.0.6` -> `14.1.0`](https://renovatebot.com/diffs/npm/@angular%2fcore/14.0.6/14.1.0) |
| [@angular/forms](https://github.com/angular/angular) | dependencies | minor | [`14.0.6` -> `14.1.0`](https://renovatebot.com/diffs/npm/@angular%2fforms/14.0.6/14.1.0) |
| [@angular/platform-browser](https://github.com/angular/angular) | dependencies | minor | [`14.0.6` -> `14.1.0`](https://renovatebot.com/diffs/npm/@angular%2fplatform-browser/14.0.6/14.1.0) |
| [@angular/platform-browser-dynamic](https://github.com/angular/angular) | dependencies | minor | [`14.0.6` -> `14.1.0`](https://renovatebot.com/diffs/npm/@angular%2fplatform-browser-dynamic/14.0.6/14.1.0) |

---

### Release Notes

<details>
<summary>angular/angular</summary>

### [`v14.1.0`](https://github.com/angular/angular/blob/HEAD/CHANGELOG.md#&#8203;1410-2022-07-20)

[Compare Source](angular/angular@14.0.7...14.1.0)

#### Deprecations

##### core

-   The `createNgModuleRef` is deprecated in favor of newly added `createNgModule` one.
-   The bit field signature of `inject()` has been deprecated, in favor of the
    new options object. Correspondingly, `InjectFlags` is deprecated as well.

##### animations

| Commit | Type | Description |
| -- | -- | -- |
| [55308f2df5](angular/angular@55308f2) | feat | add `provideAnimations()` and `provideNoopAnimations()` functions ([#&#8203;46793](angular/angular#46793)) |

##### common

| Commit | Type | Description |
| -- | -- | -- |
| [4a2e7335b1](angular/angular@4a2e733) | feat | make the `CommonModule` pipes standalone ([#&#8203;46401](angular/angular#46401)) |
| [a7597dd080](angular/angular@a7597dd) | feat | make the CommonModule directives standalone ([#&#8203;46469](angular/angular#46469)) |

##### compiler

| Commit | Type | Description |
| -- | -- | -- |
| [33ce3883a5](angular/angular@33ce388) | feat | Add extended diagnostic to warn when missing let on ngForOf ([#&#8203;46683](angular/angular#46683)) |
| [6f11a58040](angular/angular@6f11a58) | feat | Add extended diagnostic to warn when text attributes are intended to be bindings ([#&#8203;46161](angular/angular#46161)) |
| [9e836c232f](angular/angular@9e836c2) | feat | warn when style suffixes are used with attribute bindings ([#&#8203;46651](angular/angular#46651)) |

##### compiler-cli

| Commit | Type | Description |
| -- | -- | -- |
| [93c65e7b14](angular/angular@93c65e7) | feat | add extended diagnostic for non-nullable optional chains ([#&#8203;46686](angular/angular#46686)) |
| [131d029da1](angular/angular@131d029) | feat | detect missing control flow directive imports in standalone components ([#&#8203;46146](angular/angular#46146)) |
| [6b8e60c06a](angular/angular@6b8e60c) | fix | improve the missingControlFlowDirective message ([#&#8203;46846](angular/angular#46846)) |

##### core

| Commit | Type | Description |
| -- | -- | -- |
| [e8e8e5f171](angular/angular@e8e8e5f) | feat | add `createComponent` function |
| [b5153814af](angular/angular@b515381) | feat | add `reflectComponentType` function |
| [96c6139c9a](angular/angular@96c6139) | feat | add ability to set inputs on ComponentRef ([#&#8203;46641](angular/angular#46641)) |
| [a6d5fe202c](angular/angular@a6d5fe2) | feat | alias `createNgModuleRef` as `createNgModule` ([#&#8203;46789](angular/angular#46789)) |
| [71e606d3c3](angular/angular@71e606d) | feat | expose EnvironmentInjector on ApplicationRef ([#&#8203;46665](angular/angular#46665)) |
| [19e6d9ccd3](angular/angular@19e6d9c) | feat | import AsyncStackTaggingZone if available ([#&#8203;46693](angular/angular#46693)) |
| [a7a14df5f8](angular/angular@a7a14df) | feat | introduce `EnvironmentInjector.runInContext` API ([#&#8203;46653](angular/angular#46653)) |
| [fa52b6e906](angular/angular@fa52b6e) | feat | options object to supersede bit flags for `inject()` ([#&#8203;46649](angular/angular#46649)) |
| [af20112222](angular/angular@af20112) | feat | support the descendants option for ContentChild queries ([#&#8203;46638](angular/angular#46638)) |
| [945a3ad359](angular/angular@945a3ad) | fix | Fix `runInContext` for `NgModuleRef` injector ([#&#8203;46877](angular/angular#46877)) |
| [bb7c80477b](angular/angular@bb7c804) | fix | make parent injector argument required in `createEnvironmentInjector` ([#&#8203;46397](angular/angular#46397)) |

##### http

| Commit | Type | Description |
| -- | -- | -- |
| [82acbf919b](angular/angular@82acbf9) | feat | improve error message for nullish header ([#&#8203;46059](angular/angular#46059)) |

##### router

| Commit | Type | Description |
| -- | -- | -- |
| [53ca936366](angular/angular@53ca936) | feat | Add ability to create `UrlTree` from any `ActivatedRouteSnapshot` ([#&#8203;45877](angular/angular#45877)) |
| [de058bba99](angular/angular@de058bb) | feat | Add CanMatch guard to control whether a Route should match ([#&#8203;46021](angular/angular#46021)) |
| [6c1357dd7d](angular/angular@6c1357d) | feat | Add stable cancelation code to `NavigationCancel` event ([#&#8203;46675](angular/angular#46675)) |
| [a4ce273e50](angular/angular@a4ce273) | feat | Add the target `RouterStateSnapshot` to `NavigationError` ([#&#8203;46731](angular/angular#46731)) |
| [abe3759e24](angular/angular@abe3759) | fix | allow to return `UrlTree` from `CanMatchFn` ([#&#8203;46455](angular/angular#46455)) |
| [e8c7dd10e9](angular/angular@e8c7dd1) | fix | Ensure `APP_INITIALIZER` of `enabledBlocking` option completes ([#&#8203;46026](angular/angular#46026)) |
| [ce20ed067f](angular/angular@ce20ed0) | fix | Ensure Route injector is created before running CanMatch guards ([#&#8203;46394](angular/angular#46394)) |
| [6a7b818d94](angular/angular@6a7b818) | fix | Ensure target `RouterStateSnapshot` is defined in `NavigationError` ([#&#8203;46842](angular/angular#46842)) |
| [f94c6f433d](angular/angular@f94c6f4) | fix | Expose CanMatchFn as public API ([#&#8203;46394](angular/angular#46394)) |
| [e8ae0fe3e9](angular/angular@e8ae0fe) | fix | Fix cancellation code for canLoad rejections ([#&#8203;46752](angular/angular#46752)) |

##### upgrade

| Commit | Type | Description |
| -- | -- | -- |
| [e9cb0454dc](angular/angular@e9cb045) | feat | more closely align `UpgradeModule#bootstrap()` with `angular.bootstrap()` ([#&#8203;46214](angular/angular#46214)) |

#### Special Thanks

AleksanderBodurri, Alex Rickabaugh, Andrew Kushnir, Andrew Scott, Cédric Exbrayat, Dmitrij Kuba, Dylan Hunn, George Kalpakas, Jessica Janiuk, JiaLiPassion, Joey Perrott, John Vandenberg, JoostK, Keith Li, Or'el Ben-Ya'ir, Paul Gschwendtner, Pawel Kozlowski, SyedAhm3r, arturovt, mariu, markostanimirovic and mgechev

<!-- CHANGELOG SPLIT MARKER -->

### [`v14.0.7`](https://github.com/angular/angular/blob/HEAD/CHANGELOG.md#&#8203;1407-2022-07-20)

[Compare Source](angular/angular@14.0.6...14.0.7)

##### animations

| Commit | Type | Description |
| -- | -- | -- |
| [5bdbb6285b](angular/angular@5bdbb62) | fix | make sure falsy values are added to \_globalTimelineStyles ([#&#8203;46863](angular/angular#46863)) |

##### compiler

| Commit | Type | Description |
| -- | -- | -- |
| [41253f9c46](angular/angular@41253f9) | fix | inputs/outputs incorrectly parsed in jit mode ([#&#8203;46813](angular/angular#46813)) |

##### core

| Commit | Type | Description |
| -- | -- | -- |
| [4e77c7fbf3](angular/angular@4e77c7f) | fix | do not invoke jasmine `done` callback multiple times with `waitForAsync` |

#### Special Thanks

Andrew Kushnir, Andrew Scott, Bob Watson, Cédric Exbrayat, Doug Parker, George Kalpakas, Jessica Janiuk, Kristiyan Kostadinov, Paul Gschwendtner, acvi, dario-piotrowicz, jnizet and piyush132000

<!-- CHANGELOG SPLIT MARKER -->

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzMi4xMTkuMiIsInVwZGF0ZWRJblZlciI6IjMyLjExOS4yIn0=-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1472
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Jul 24, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [zone.js](https://github.com/angular/angular) ([changelog](https://github.com/angular/angular/blob/master/packages/zone.js/CHANGELOG.md)) | dependencies | patch | [`0.11.6` -> `0.11.7`](https://renovatebot.com/diffs/npm/zone.js/0.11.6/0.11.7) |

---

### Release Notes

<details>
<summary>angular/angular</summary>

### [`v0.11.7`](https://github.com/angular/angular/blob/HEAD/packages/zone.js/CHANGELOG.md#&#8203;0117-httpsgithubcomangularangularcomparezonejs-0116zonejs-0117-2022-07-20)

[Compare Source](angular/angular@zone.js-0.11.6...zone.js-0.11.7)

##### Bug Fixes

-   **zone.js:** do not invoke jasmine done callback multiple times with `waitForAsync` ([4e77c7fbf38](angular/angular@4e77c7f))

##### Features

-   **zone.js:** add AsyncStackTaggingZoneSpec implementation ([#&#8203;46693](angular/angular#46693)) ([848a009](angular/angular@848a009))
-   **zone.js:** include jasmine `describe` block name when raising unexpected task error ([de86285](angular/angular@de86285))
-   **zone.js:** include zone name when sync-test zone reports tasks ([72c2567](angular/angular@72c2567))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzMi4xMjAuMCIsInVwZGF0ZWRJblZlciI6IjMyLjEyMi4yIn0=-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1474
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
@LanderBeeuwsaert
Copy link

Hi @JiaLiPassion,
is there somewhere a description of how to add this feature for now?
Do we add it in the angular.json scripts array as "node_modules/zone.js/plugins/async-stack-tagging.min"
or do we add it to app module or app component?
On top of that, each user for now needs to add the flag when booting chrome?

Will this be simplified later on and it's better to wait for now or do we go ahead and implement it in our app as-is?

@JiaLiPassion
Copy link
Contributor Author

@LanderBeeuwsaert , to make it work for now, you need to

  1. update polyfills.ts
import 'zone.js';
import 'zone.js/plgins/async-stack-tagging';
  1. in main.ts,
const AsyncStackTaggingZoneSpec = (Zone as any)['AsyncStackTaggingZoneSpec'];
Zone.current
  .fork(new AsyncStackTaggingZoneSpec('angular'))
  .run(() => {
    platformBrowserDynamic()
      .bootstrapModule(AppModule)
      .catch((err) => console.error(err));
  });

After the new release of the @angular/core, you just need to do the 1st step to make it work, or maybe the angular cli will provide some option to do the 1st step for you.

@victorporof
Copy link
Contributor

Heads-up: we are making some changes to the Chrome DevTools console API that drives this feature, so this might not do anything in very recent versions of Chrome Canary. This will be updated in #46958.

JiaLiPassion added a commit to JiaLiPassion/angular-cli that referenced this pull request Aug 16, 2022
…ync tagging API support

1. Update to `zone.js` 0.11.8
2. `import 'zone.js/plugins/async-stack-tagging` in `development` mode
to support `async tagging API` for better debugging experience.

For more information, please refer to this PR angular/angular#46693
JiaLiPassion added a commit to JiaLiPassion/angular-cli that referenced this pull request Aug 16, 2022
…ging API support

1. Update to `zone.js` 0.11.8
2. `import 'zone.js/plugins/async-stack-tagging` in `development` mode
to support `async tagging API` for better debugging experience.

For more information, please refer to this PR angular/angular#46693
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: zones feature Issue that requests a new feature target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants