Skip to main content
The @sentry/angular package provides error tracking and performance monitoring for Angular applications. It includes Angular-specific integrations like ErrorHandler, TraceService, and component tracking.

Prerequisites

  • Node.js 18 or newer
  • Angular 14 to 21
  • RxJS 6.5.5+ or 7.x
  • A Sentry account and project DSN
Angular versions 14-21 are officially supported. For older versions, check the compatibility table.

Installation

1

Install the Package

Install @sentry/angular using your preferred package manager:
Current Version: 10.42.0
2

Initialize Sentry

Initialize Sentry before you bootstrap your Angular application in main.ts:
3

Configure Error Handler

Register the Sentry ErrorHandler provider in your app configuration:
For NgModule-based apps, add the provider to your AppModule instead.
4

Verify Installation

Test that Sentry is working:
Check your Sentry dashboard to see the error.

NgModule Configuration (Legacy)

For older Angular applications using NgModule:

Error Handler Options

Customize the error handler behavior:

Performance Monitoring

Basic Configuration

1

Enable Browser Tracing

Add the browser tracing integration:
2

Initialize TraceService

Inject the TraceService in your app initialization to enable Angular Router tracking:
Angular 19+: Use provideAppInitializer:

NgModule Configuration

For NgModule-based apps:

Component Tracking

Track Angular component performance with three different methods:

1. TraceDirective

Track component lifecycle in templates:
The directive’s name attribute is required and will be used as the span name.

2. TraceClass Decorator

Track component lifecycle in component classes:

3. TraceMethod Decorator

Track specific lifecycle hooks:

Custom Spans

Create custom performance spans:

Tracking Application Bootstrap

Measure how long your Angular app takes to bootstrap:

Usage

Capturing Errors

Setting Context

Adding Breadcrumbs

HttpClient Integration

Automatically capture HTTP errors:
The SDK will automatically:
  • Create spans for HTTP requests
  • Capture HTTP errors
  • Add breadcrumbs for requests

Session Replay

Capture session replays:

Advanced Configuration

TypeScript

The SDK is written in TypeScript and includes full type definitions:

Custom Transport

Filtering Events

Troubleshooting

Source Maps

For Angular CLI projects:
  1. Install the Sentry Webpack plugin:
  2. Configure in angular.json:
  3. Add custom webpack config with @angular-builders/custom-webpack

Zone.js Compatibility

Sentry is compatible with Zone.js. Make sure Zone.js is loaded before Sentry:

Errors Not Captured

Make sure:
  1. Sentry.init() is called before bootstrapping Angular
  2. The ErrorHandler provider is registered
  3. The error is not caught without re-throwing
Initialize Sentry before calling bootstrapApplication() or platformBrowserDynamic().bootstrapModule().

Performance Not Tracked

Ensure:
  1. browserTracingIntegration() is added
  2. TraceService is injected via APP_INITIALIZER
  3. tracesSampleRate is greater than 0

Next Steps