You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@sentry/angular

Package Overview
Dependencies
5
Maintainers
11
Versions
352
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sentry/angular

Official Sentry SDK for Angular


Version published
Maintainers
11
Created

Changelog

Source

8.0.0-alpha.7

This is the seventh alpha release of Sentry JavaScript SDK v8, which includes a variety of breaking changes.

Read the in-depth migration guide to find out how to address any breaking changes in your code.

Important Changes

  • feat(nextjs): Use OpenTelemetry for performance monitoring and tracing (#11016)

We now use OpenTelemetry under the hood to power performance monitoring and tracing in the Next.js SDK.

  • feat(v8/gatsby): Update SDK initialization for gatsby (#11292)

In v8, you cannot initialize the SDK anymore via Gatsby plugin options. Instead, you have to configure the SDK in a sentry.config.js file.

We also removed the automatic initialization of browserTracingIntegration. You now have to add this integration yourself.

Removal/Refactoring of deprecated functionality

  • feat(v8): Remove addGlobalEventProcessor (#11255)
  • feat(v8): Remove deprecated span id fields (#11180)
  • feat(v8): Remove makeMain export (#11278)
  • feat(v8/core): Remove deprecated span.sampled (#11274)
  • feat(v8/core): Remove getActiveTransaction (#11280)
  • feat(v8/core): Remove spanMetadata field (#11271)
  • feat(v8/ember): Remove deprecated StartTransactionFunction (#11270)
  • feat(v8/replay): Remove deprecated replay options (#11268)
  • feat(v8/svelte): Remove deprecated componentTrackingPreprocessor export (#11277)
  • ref: Remove more usages of getCurrentHub in the codebase (#11281)
  • ref(core): Remove scope.setSpan() and scope.getSpan() methods (#11051)
  • ref(profiling-node): Remove usage of getCurrentHub (#11275)
  • ref(v8): change integration.setupOnce signature (#11238)
  • ref: remove node-experimental references (#11290)

Other Changes

  • feat(feedback): Make "required" text for input elements configurable (#11152) (#11153)
  • feat(feedback): Update user feedback screenshot and cropping to align with designs (#11227)
  • feat(nextjs): Remove runtime and vercel tags (#11291)
  • feat(node): Add scope to ANR events (#11256)
  • feat(node): Do not include prismaIntegration by default (#11265)
  • feat(node): Ensure tracePropagationTargets are respected (#11285)
  • feat(node): Simplify SentrySpanProcessor (#11273)
  • feat(profiling): Use OTEL powered node package (#11239)
  • feat(utils): Allow text encoder/decoder polyfill from global SENTRY (#11283)
  • fix(nextjs): Show misconfiguration warning (no instrumentation.ts) (#11266)
  • fix(node): Add logs when node-fetch cannot be instrumented (#11289)
  • fix(node): Skip capturing Hapi Boom error responses. (#11151)
  • fix(node): Use suppressTracing to avoid capturing otel spans (#11288)
  • fix(opentelemetry): Do not stomp span status when startSpan callback throws (#11170)

Readme

Source

Sentry

Official Sentry SDK for Angular

npm version npm dm npm dt

Angular Version Compatibility

This SDK officially supports Angular 15 to 17.

If you're using an older Angular version please check the compatibility table in the docs.

If you're using an older version of Angular and experience problems with the Angular SDK, we recommend downgrading the SDK to version 7.x. Please note that we don't provide any support for Angular versions below 10.

General

This package is a wrapper around @sentry/browser, with added functionality related to Angular. All methods available in @sentry/browser can be imported from @sentry/angular.

To use this SDK, call Sentry.init(options) before you bootstrap your Angular application.

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { init } from '@sentry/angular';

import { AppModule } from './app/app.module';

init({
  dsn: '__DSN__',
  // ...
});

// ...

enableProdMode();
platformBrowserDynamic()
  .bootstrapModule(AppModule)
  .then(success => console.log(`Bootstrap success`))
  .catch(err => console.error(err));

ErrorHandler

@sentry/angular exports a function to instantiate an ErrorHandler provider that will automatically send Javascript errors captured by the Angular's error handler.

import { NgModule, ErrorHandler } from '@angular/core';
import { createErrorHandler } from '@sentry/angular';

@NgModule({
  // ...
  providers: [
    {
      provide: ErrorHandler,
      useValue: createErrorHandler({
        showDialog: true,
      }),
    },
  ],
  // ...
})
export class AppModule {}

Additionally, createErrorHandler accepts a set of options that allows you to configure its behavior. For more details see ErrorHandlerOptions interface in src/errorhandler.ts.

Tracing

@sentry/angular exports a Trace Service, Directive and Decorators that leverage the tracing features to add Angular-related spans to transactions. If tracing is not enabled, this functionality will not work. The SDK's TraceService itself tracks route changes and durations, while directive and decorators are tracking components initializations.

Install

Registering a Trace Service is a 3-step process.

  1. Register and configure the BrowserTracing integration, including custom Angular routing instrumentation:
import { init, browserTracingIntegration } from '@sentry/angular';

init({
  dsn: '__DSN__',
  integrations: [browserTracingIntegration()],
  tracePropagationTargets: ['localhost', 'https://yourserver.io/api'],
  tracesSampleRate: 1,
});
  1. Register SentryTrace as a provider in Angular's DI system, with a Router as its dependency:
import { NgModule } from '@angular/core';
import { Router } from '@angular/router';
import { TraceService } from '@sentry/angular';

@NgModule({
  // ...
  providers: [
    {
      provide: TraceService,
      deps: [Router],
    },
  ],
  // ...
})
export class AppModule {}
  1. Either require the TraceService from inside AppModule or use APP_INITIALIZER to force-instantiate Tracing.
@NgModule({
  // ...
})
export class AppModule {
  constructor(trace: TraceService) {}
}

or

import { APP_INITIALIZER } from '@angular/core';

@NgModule({
  // ...
  providers: [
    {
      provide: APP_INITIALIZER,
      useFactory: () => () => {},
      deps: [TraceService],
      multi: true,
    },
  ],
  // ...
})
export class AppModule {}
Use

To track Angular components as part of your transactions, you have 3 options.

TraceDirective: used to track a duration between OnInit and AfterViewInit lifecycle hooks in template:

import { TraceModule } from '@sentry/angular';

@NgModule({
  // ...
  imports: [TraceModule],
  // ...
})
export class AppModule {}

Then, inside your component's template (keep in mind that the directive's name attribute is required):

<app-header trace="header"></app-header>
<articles-list trace="articles-list"></articles-list>
<app-footer trace="footer"></app-footer>

TraceClass: used to track a duration between OnInit and AfterViewInit lifecycle hooks in components:

import { Component } from '@angular/core';
import { TraceClass } from '@sentry/angular';

@Component({
  selector: 'layout-header',
  templateUrl: './header.component.html',
})
@TraceClass()
export class HeaderComponent {
  // ...
}

TraceMethod: used to track a specific lifecycle hooks as point-in-time spans in components:

import { Component, OnInit } from '@angular/core';
import { TraceMethod } from '@sentry/angular';

@Component({
  selector: 'app-footer',
  templateUrl: './footer.component.html',
})
export class FooterComponent implements OnInit {
  @TraceMethod()
  ngOnInit() {}
}

You can also add your own custom spans via startSpan(). For example, if you'd like to track the duration of Angular boostraping process, you can do it as follows:

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { init, startSpan } from '@sentry/angular';

import { AppModule } from './app/app.module';

// ...
startSpan(
  {
    name: 'platform-browser-dynamic',
    op: 'ui.angular.bootstrap',
  },
  async () => {
    await platformBrowserDynamic().bootstrapModule(AppModule);
  },
);

FAQs

Package last updated on 27 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc