npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

csii-sentry-angular

v5.29.0

Published

Offical Sentry SDK for Angular

Downloads

2

Readme

Official Sentry SDK for Angular

Links

General

This package is a wrapper around csii-sentry-browser, with added functionality related to Angular. All methods available in csii-sentry-browser can be imported from csii-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 'csii-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

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

import { NgModule, ErrorHandler } from '@angular/core';
import { createErrorHandler } from 'csii-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

csii-sentry-angular exports a Trace Service, Directive and Decorators that leverage the csii-sentry-tracing Tracing integration to add Angular related spans to transactions. If the Tracing integration is not enabled, this functionality will not work. The service itself tracks route changes and durations, where directive and decorators are tracking components initializations.

Install

Registering a Trace Service is a 3-step process.

  1. Register and configure the BrowserTracing integration from csii-sentry-tracing, including custom Angular routing instrumentation:
import { init, routingInstrumentation } from 'csii-sentry-angular';
import { Integrations as TracingIntegrations } from 'csii-sentry-tracing';

init({
  dsn: '__DSN__',
  integrations: [
    new TracingIntegrations.BrowserTracing({
      tracingOrigins: ['localhost', 'https://yourserver.io/api'],
      routingInstrumentation: routingInstrumentation,
    }),
  ],
  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 'csii-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 { TraceDirective } from 'csii-sentry-angular';

@NgModule({
  // ...
  declarations: [TraceDirective],
  // ...
})
export class AppModule {}

Then inside your components template (keep in mind that directive name attribute is required):

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

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

import { Component } from '@angular/core';
import { TraceClassDecorator } from 'csii-sentry-angular';

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

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

import { Component, OnInit } from '@angular/core';
import { TraceMethodDecorator } from 'csii-sentry-angular';

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

You can also add your own custom spans by attaching them to the current active transaction using getActiveTransaction helper. 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, getActiveTransaction } from 'csii-sentry-angular';

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

// ...

const activeTransaction = getActiveTransaction();
const boostrapSpan =
  activeTransaction &&
  activeTransaction.startChild({
    description: 'platform-browser-dynamic',
    op: 'angular.bootstrap',
  });

platformBrowserDynamic()
  .bootstrapModule(AppModule)
  .then(() => console.log(`Bootstrap success`))
  .catch(err => console.error(err));
  .finally(() => {
    if (bootstrapSpan) {
      boostrapSpan.finish();
    }
  })