Angular
Overview
BugSplat supports the collection of errors in Angular applications. The bugsplat-ng npm package implements Angular’s ErrorHandler interface in order to post errors to BugSplat where they can be tracked and managed.
Sample
This repository includes a sample my-angular-crasher application that has be pre-configured with BugSplat. A hosted version of my-angular-crasher can also be found here. Before you try the sample, you'll need to create an OAuth2 ClientId/ClientSecret pair as shown here.
Once you've genereated OAuth2 credentials, create a file with the name .env
at the root of the repository and populate with the correct values substituted for {{clientId}}
and {{clientSecret}}
:
To test the sample, perform the following steps:
git clone https://github.com/BugSplat-Git/bugsplat-ng
cd bugsplat-ng && npm i
npm start
The npm start
command will build the sample application and upload source maps to BugSplat so that the JavaScript call stack can be mapped back to TypeScript. Once the build has completed the source maps will be uploaded and http-server will serve the app.
Navigate to the url displayed in the console by http-server (usually localhost:8080). Click any of the button in the sample app to generate an error report. A link to the error report should display in the app shortly after clicking a button. Click the link to the error report and when prompted to log into BugSplat.
If everything worked correctly you should see information about your error as well as a TypeScript stack trace.
Integration
To collect errors and crashes in your Angular application, run the following command in terminal or cmd at the root of your project to install bugsplat-ng:
Add a database
property to your package.json
file with the value of your BugSplat database and subsitute {{database}}
with the value of your BugSplat database.
Add values for your BugSplat database, application and version to your application's environment files:
Add an import for BugSplatModule to your AppModule:
Add a call BugSplatModule.initializeApp
in your AppModule's imports array passing it your database, application and version:
Throw a new error in your application to test the bugsplat-ng integration:
Navigate to the Crashes page in BugSplat and you should see a new crash report for the application you just configured. Click the link in the ID column to see details about your crash on the Crash page:
Extended Integration
You can post additional information by creating a service that implements ErrorHandler. In the handlerError method make a call to BugSplat.post passing it the error and an optional options object:
BugSplat provides the following properties and methods that allow you to customize its functionality:
In your AppModule's NgModule definition, add a provider for your new ErrorHandler:
You can also configure BugSplat's logging preferences and provide your own logging implementation. Create a provider for BugSplatLogger with useValue set to a new instance of BugSplatLogger. Pass one of the BugSplatLogLevel options as the first parameter to BugSplatLogger. You can provide an instance of your own custom logger as the second parameter granted it has error, warn, info and log methods. If no custom logger is provided console will be used:
Source Maps
BugSplat supports unwinding uglified and minified JavaScript stack traces via source maps. To upload source maps to BugSplat during your build, install @bugsplat/symbol-upload.
Configure your angular.json
file to output source maps. We suggest enabling source maps for both your application code and any vendor chunks that are generated by Angular.
Add SYMBOL_UPLOAD_CLIENT_ID
and SYMBOL_UPLOAD_CLIENT_SECRET
environment variables for the BugSplat user that you will use to upload symbols. You can create these values as system environment variables or use dotenv.
Create a script for uploading source maps.
Add postbuild
and symbols
scripts to your package.json
.
For best results, please upload source maps for every released version of your application.
Contributing
BugSplat loves open source software! If you have suggestions on how we can improve this integration, please reach out to support@bugsplat.com, create an issue in our GitHub repo or send us a pull request.
With ❤️,
The BugSplat Team
Last updated