Connect Angular to Bugsink
When an Angular component fails in a user’s browser, Bugsink can show you the exception and the original TypeScript line behind the production bundle.
This guide adds error reporting to an Angular application, prepares its source maps, and triggers a deliberate component error. To follow along, create a Bugsink project and copy its DSN. The quickstart guide shows where to find it.
Install the Angular SDK
Install the open-source Sentry SDK for Angular. Bugsink accepts the Sentry event protocol, so the SDK can send errors directly to your Bugsink project:
npm install @sentry/angularnpm install @sentry/angular
Initialize the SDK before Angular starts
Keep the project DSN in an Angular environment file so the browser build can read it. A DSN identifies the destination project; it is not an administrative or source-map upload token:
export const environment = { bugsinkDsn: "https://key@bugsink.example/1", };export const environment = { bugsinkDsn: "https://key@bugsink.example/1", };
Import and initialize the SDK in src/main.ts before bootstrapping the
application. This gives the SDK time to install its browser error handlers:
import { bootstrapApplication } from "@angular/platform-browser"; import * as Sentry from "@sentry/angular"; import { App } from "./app/app"; import { appConfig } from "./app/app.config"; import { environment } from "./environments/environment"; Sentry.init({ dsn: environment.bugsinkDsn, }); bootstrapApplication(App, appConfig).catch((error) => console.error(error));import { bootstrapApplication } from "@angular/platform-browser"; import * as Sentry from "@sentry/angular"; import { App } from "./app/app"; import { appConfig } from "./app/app.config"; import { environment } from "./environments/environment"; Sentry.init({ dsn: environment.bugsinkDsn, }); bootstrapApplication(App, appConfig).catch((error) => console.error(error));
Let Angular report component errors
Angular sends errors from component event handlers to its ErrorHandler
service. Register the SDK’s error handler in your application configuration so
those failures reach Bugsink without adding capture calls to every component:
import { ApplicationConfig, ErrorHandler, provideBrowserGlobalErrorListeners, } from "@angular/core"; import * as Sentry from "@sentry/angular"; export const appConfig: ApplicationConfig = { providers: [ provideBrowserGlobalErrorListeners(), { provide: ErrorHandler, useValue: Sentry.createErrorHandler(), }, ], };import { ApplicationConfig, ErrorHandler, provideBrowserGlobalErrorListeners, } from "@angular/core"; import * as Sentry from "@sentry/angular"; export const appConfig: ApplicationConfig = { providers: [ provideBrowserGlobalErrorListeners(), { provide: ErrorHandler, useValue: Sentry.createErrorHandler(), }, ], };
Keep your existing providers alongside these entries.
Prepare production source maps
Production Angular builds bundle and minify your TypeScript. Source maps let Bugsink translate a generated browser frame back to the component or service you edit.
Install the custom Webpack builder and source-map plugin:
npm install --save-dev @angular-builders/custom-webpack @sentry/webpack-pluginnpm install --save-dev @angular-builders/custom-webpack @sentry/webpack-plugin
In angular.json, use the custom Webpack browser builder, point it at the
configuration below, and enable hidden script source maps for production. Keep
the rest of your application’s build options and configurations:
{ "builder": "@angular-builders/custom-webpack:browser", "options": { "customWebpackConfig": { "path": "webpack.config.mjs" } }, "configurations": { "production": { "sourceMap": { "scripts": true, "styles": false, "vendor": false, "hidden": true } } } }{ "builder": "@angular-builders/custom-webpack:browser", "options": { "customWebpackConfig": { "path": "webpack.config.mjs" } }, "configurations": { "production": { "sourceMap": { "scripts": true, "styles": false, "vendor": false, "hidden": true } } } }
Create webpack.config.mjs. The plugin adds the same debug ID to each browser
bundle and source map. Upload is disabled here because the explicit CLI step
below is the route currently supported by Bugsink:
import { sentryWebpackPlugin } from "@sentry/webpack-plugin"; export default { plugins: [ sentryWebpackPlugin({ telemetry: false, sourcemaps: { disable: "disable-upload", }, }), ], };import { sentryWebpackPlugin } from "@sentry/webpack-plugin"; export default { plugins: [ sentryWebpackPlugin({ telemetry: false, sourcemaps: { disable: "disable-upload", }, }), ], };
Build the application:
npm run buildnpm run build
Create a project-bound Bugsink token with the debug-files:upload capability
and keep it in your build environment. Then upload the output with
sentry-cli. Bugsink has no organization object, so --org is only a
compatibility value:
SENTRY_AUTH_TOKEN=your-project-token \ npx --yes @sentry/cli \ --url https://bugsink.example \ sourcemaps --org bugsink --project your-project-slug \ upload ./dist/your-angular-projectSENTRY_AUTH_TOKEN=your-project-token \ npx --yes @sentry/cli \ --url https://bugsink.example \ sourcemaps --org bugsink --project your-project-slug \ upload ./dist/your-angular-project
Upload source maps for every production build before it can report errors.
You may remove the .map files from the deployed output after a successful
upload.
Trigger a component error
Serve the production build, open the application, and follow the path which raises your test exception. In this inventory example, clicking Reserve desk lamp attempts to reserve an unavailable product:
export class ProductUnavailableError extends Error { override name = "ProductUnavailableError"; } export function reserveProduct(sku: string, requested: number, available: number): void { if (requested > available) { throw new ProductUnavailableError( `Cannot reserve ${requested} unit of ${sku}: only ${available} remain [angular-browser]`, ); } }export class ProductUnavailableError extends Error { override name = "ProductUnavailableError"; } export function reserveProduct(sku: string, requested: number, available: number): void { if (requested > available) { throw new ProductUnavailableError( `Cannot reserve ${requested} unit of ${sku}: only ${available} remain [angular-browser]`, ); } }
The component does not contain Bugsink-specific capture code. Its click handler calls this ordinary application function, and Angular passes the resulting exception to the registered error handler.
See the original TypeScript in Bugsink
Open the new issue in Bugsink. The uploaded map translates the production browser bundle back to the inventory function and shows the exact line that threw.
ProductUnavailableError
That’s it: failures from Angular’s component lifecycle now reach Bugsink with their original TypeScript context. Remove the deliberate failure and deploy the same SDK and source-map setup with your application.
Limitations
Angular 22 warns that its Webpack-based browser builder is deprecated. The
default application builder emits a debug ID in each file and map, but it does
not currently add the runtime mapping which lets the SDK attach that ID to an
event. Running sentry-cli sourcemaps inject afterwards sees the existing ID
and leaves the browser event without matching debug_meta.
The Webpack plugin’s automatic upload also cannot use the relative chunk URL returned by Bugsink. The configuration above keeps the plugin’s matching runtime IDs and uses the verified explicit CLI upload instead. The underlying exchange is tracked in Bugsink issue #157.
For SDK-wide capture options and other browser frameworks, return to the JavaScript guide.
