Skip to content

Angular Integration Issue - console.log calls cause Change detection to run #1883

@ibedard16

Description

@ibedard16

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other:

Version:

4.5.4

Description

Using Sentry in an Angular project will cause Angular's change detection to fire any time console.log is called. This is because of Sentry's breadcrumb feature, which logs whatever was logged to the console, and how that interacts with zone.js.

I do not understand all of the mechanics behind it, but zone.js triggers change detection after the code to add a breadcrumb exits. An easy way to prevent the problem would be to wrap console.log statement to runOutsideAngular, which prevents zone.js from running change detection. However, the only two ways of doing would be either wrapping every call to console.log (which would be very unwieldy and not-obvious) or override the global console.log function with a different function that calls the original function outside of Angular.

I'm not entirely certain what can be done on Sentry's side to prevent the problem, as any solution would likely be very Angular-specific, in a package meant to be used with a variety of different frameworks. As such, I'm opening issues both here and against the Angular repo.

Edit: angular/angular#28647

Demo repro: https://github.com/ibedard16/sentry-recursion-demo
Instructions on how to run it are in the readme.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions