Skip to content

Tracing finalTimeout blocks Angular Zone stabilisation  #8983

Closed
@henry-alakazhang

Description

@henry-alakazhang

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/angular-ivy

SDK Version

7.57.0

Framework Version

Angular 15.2.0

Link to Sentry event

No response

SDK Setup

this.ngZone.runOutsideAngular(() => {
  const tracingIntegrations =
    tracesSampleRate !== undefined
      ? [
          new Sentry.BrowserTracing({
            tracePropagationTargets: [
              'localhost',
              this.httpConfig.baseUrl,
              /^\//,
            ],
          }),
        ]
      : [];

  Sentry.init({
    dsn: this.config.sentryDsn,
    release: "...",
    environment: this.environment,
    ignoreErrors: [
      // <snip>
    ],
    allowUrls: !this.pwa.isNative() ? [/\/assets\//] : undefined,
    denyUrls: [/^file:\/\//, /^moz-extension:\/\//],
    integrations: integrations =>
      // integrations will be all default integrations
      [
        ...integrations.filter(
          integration =>
            !['TryCatch', 'GlobalHandlers'].includes(integration.name),
        ),
        new SentryIntegrations.ExtraErrorData(),
        new SentryIntegrations.ReportingObserver(),
        ...tracingIntegrations,
      ],
    tracesSampler: context => {
      if (context.location?.search.includes('sentry-tracing=true')) {
        return 1;
      }
      return tracesSampleRate ?? 0;
    },
  });
});        

Steps to Reproduce

  1. Trigger a pageload or navigation operation

Expected Result

Angular's zone should stabilize and appRef.isStable/testability.whenStable should emit after network requests have finished and app is stable.

eg. code like this should log:

this.testability.whenStable(() => {
  console.log("App is stable.");
});

Actual Result

NgZone doesn't stabilise because of a pending timeout from finalTimeout. It only stabilises after 30 seconds (the default value of the finalTimeout), even if the idle timeout and heartbeat interval have already completed.

We utilise the stability API for a number of things (e2e tests, performance tracking) which have been affected by upgrading from Sentry 6 to 7. Our e2e tests against our dev environment take longer to run, and long task tracking is less accurate.

We've worked around it partially by running Sentry.init outside of the Angular zone (see snippet above) but this only affects the pageload event and not future navigations.

I've tested this using @sentry/browser, @sentry/angular and @sentry/angular-ivy and the behaviour is the same.

Thanks.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

No status

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions