├── .nvmrc ├── src ├── rollbar.service.spec.ts ├── index.ts ├── environments │ └── environment.ts ├── 001.sanity.spec.ts ├── polyfills.ts ├── tsconfig.test.json ├── rollbar.module.ts ├── test.ts └── rollbar.service.ts ├── .travis.yml ├── .gitignore ├── .npmignore ├── .clang-format ├── tsconfig.json ├── .github └── workflows │ └── build-and-release.yaml ├── LICENCE.md ├── angular-cli.json ├── karma.conf.js ├── README.md └── package.json /.nvmrc: -------------------------------------------------------------------------------- 1 | 7.4 2 | -------------------------------------------------------------------------------- /src/rollbar.service.spec.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './rollbar.module'; 2 | export * from './rollbar.service'; -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | export const environment: any = { 2 | production: false, 3 | }; 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | lib 3 | *.d.ts 4 | *.js.map 5 | *.js 6 | *.un~ 7 | coverage 8 | doc 9 | *.tgz 10 | package 11 | -------------------------------------------------------------------------------- /src/001.sanity.spec.ts: -------------------------------------------------------------------------------- 1 | describe('Global Outlook', function() { 2 | it('The world is sane', function() { 3 | expect(2+2).toEqual(4); 4 | }) 5 | }) -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | angular-cli.json 3 | coverage 4 | src 5 | tsconfig.json 6 | manup-demo 7 | *.un~ 8 | karma.conf.js 9 | .travis.yml 10 | .nvmrc 11 | *.tar.gz 12 | *.tgz 13 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | Language: JavaScript 2 | BasedOnStyle: Google 3 | ColumnLimit: 100 4 | 5 | TabWidth: 2 6 | ContinuationIndentWidth: 4 7 | MaxEmptyLinesToKeep : 2 8 | 9 | AllowShortBlocksOnASingleLine: false 10 | AllowShortIfStatementsOnASingleLine: false 11 | AllowShortLoopsOnASingleLine: false 12 | AllowShortFunctionsOnASingleLine: Empty 13 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | import 'core-js/es6/symbol'; 2 | import 'core-js/es6/object'; 3 | import 'core-js/es6/function'; 4 | import 'core-js/es6/parse-int'; 5 | import 'core-js/es6/parse-float'; 6 | import 'core-js/es6/number'; 7 | import 'core-js/es6/math'; 8 | import 'core-js/es6/string'; 9 | import 'core-js/es6/date'; 10 | import 'core-js/es6/array'; 11 | import 'core-js/es6/regexp'; 12 | import 'core-js/es6/map'; 13 | import 'core-js/es6/set'; 14 | import 'core-js/es6/reflect'; 15 | 16 | import 'core-js/es7/reflect'; 17 | import 'zone.js/dist/zone'; -------------------------------------------------------------------------------- /src/tsconfig.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "", 4 | "declaration": false, 5 | "emitDecoratorMetadata": true, 6 | "experimentalDecorators": true, 7 | "lib": ["es6", "dom"], 8 | "mapRoot": "./", 9 | "module": "es6", 10 | "moduleResolution": "node", 11 | "outDir": "../dist/out-tsc", 12 | "sourceMap": true, 13 | "target": "es5", 14 | "typeRoots": [ 15 | "../node_modules/@types" 16 | ] 17 | }, 18 | "exclude": [ 19 | "index.ts", 20 | "src/index.ts" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "moduleResolution": "node", 6 | "sourceMap": true, 7 | "declaration": true, 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "lib": [ "es2015", "dom" ], 11 | "noImplicitAny": false, 12 | "suppressImplicitAnyIndexErrors": true, 13 | "outDir": "lib", 14 | "rootDir": "src" 15 | }, 16 | "exclude": [ 17 | "node_modules", 18 | "manup-demo", 19 | "lib", 20 | "src/test.ts" 21 | ], 22 | "angularCompilerOptions": { 23 | "genDir": "lib" 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /.github/workflows/build-and-release.yaml: -------------------------------------------------------------------------------- 1 | name: Build and Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - releases/* 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | 11 | strategy: 12 | matrix: 13 | node-version: [12.x] 14 | 15 | steps: 16 | - uses: actions/checkout@v2 17 | - name: Use Node.js ${{ matrix.node-version }} 18 | uses: actions/setup-node@v1 19 | with: 20 | node-version: ${{ matrix.node-version }} 21 | - run: npm install 22 | - run: | 23 | npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN 24 | npm publish --access public 25 | env: 26 | CI: true 27 | NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} 28 | -------------------------------------------------------------------------------- /src/rollbar.module.ts: -------------------------------------------------------------------------------- 1 | import { ModuleWithProviders, NgModule } from "@angular/core"; 2 | import { Configuration } from "rollbar"; 3 | import { RollbarService, ROLLBAR_CONFIGURATION } from "./rollbar.service"; 4 | 5 | @NgModule({ 6 | providers: [RollbarService], 7 | }) 8 | /** 9 | * Rollbar Logging support for Angular 2. 10 | */ 11 | export class RollbarModule { 12 | /** 13 | * 14 | * Setup the module in your application's root bootstrap. 15 | * 16 | * @static 17 | * @param {RollbarConfig} config The configuration for Rollbar logging 18 | * @returns {ModuleWithProviders} The module ready for your bootstrap 19 | * 20 | * @memberOf RollbarModule 21 | */ 22 | static forRoot(config: Configuration): ModuleWithProviders { 23 | return { 24 | ngModule: RollbarModule, 25 | providers: [{ provide: ROLLBAR_CONFIGURATION, useValue: config }], 26 | }; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /LICENCE.md: -------------------------------------------------------------------------------- 1 | Copyright 2017 NextFaze PTY LTD. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "project": { 3 | "version": "1.0.0-beta.22-1", 4 | "name": "ionic2-tdd" 5 | }, 6 | "apps": [ 7 | { 8 | "root": "src", 9 | "outDir": "dist", 10 | "index": "index.html", 11 | "main": "main.ts", 12 | "test": "test.ts", 13 | "tsconfig": "tsconfig.test.json", 14 | "prefix": "", 15 | "mobile": false, 16 | "styles": [ 17 | "styles.css" 18 | ], 19 | "scripts": [], 20 | "environmentSource": "environments/environment.ts", 21 | "environments": { 22 | "dev": "environments/environment.ts" 23 | } 24 | } 25 | ], 26 | "addons": [], 27 | "packages": [], 28 | "test": { 29 | "karma": { 30 | "config": "./karma.conf.js" 31 | } 32 | }, 33 | "defaults": { 34 | "styleExt": "css", 35 | "prefixInterfaces": false, 36 | "inline": { 37 | "style": false, 38 | "template": false 39 | }, 40 | "spec": { 41 | "class": false, 42 | "component": true, 43 | "directive": true, 44 | "module": false, 45 | "pipe": true, 46 | "service": true 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | import './polyfills.ts'; 2 | 3 | import 'zone.js/dist/long-stack-trace-zone'; 4 | import 'zone.js/dist/proxy.js'; 5 | import 'zone.js/dist/sync-test'; 6 | import 'zone.js/dist/jasmine-patch'; 7 | import 'zone.js/dist/async-test'; 8 | import 'zone.js/dist/fake-async-test'; 9 | 10 | import { getTestBed, TestBed } from '@angular/core/testing'; 11 | import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; 12 | 13 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. 14 | declare var __karma__: any; 15 | declare var require: any; 16 | 17 | // Prevent Karma from running prematurely. 18 | __karma__.loaded = function (): void { 19 | // noop 20 | }; 21 | 22 | // First, initialize the Angular testing environment. 23 | getTestBed().initTestEnvironment( 24 | BrowserDynamicTestingModule, 25 | platformBrowserDynamicTesting(), 26 | ); 27 | 28 | // Then we find all the tests. 29 | let context: any = require.context('./', true, /\.spec\.ts/); 30 | 31 | // And load the modules. 32 | context.keys().map(context); 33 | 34 | // Finally, start Karma to run the tests. 35 | __karma__.start(); 36 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/0.13/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular/cli'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-phantomjs-launcher'), 12 | require('karma-remap-istanbul'), 13 | require('karma-mocha-reporter'), 14 | require('karma-coverage-istanbul-reporter'), 15 | require('@angular/cli/plugins/karma') 16 | ], 17 | files: [ 18 | { pattern: './src/test.ts', watched: false } 19 | ], 20 | preprocessors: { 21 | './src/test.ts': ['@angular/cli'] 22 | }, 23 | mime: { 24 | 'text/x-typescript': ['ts','tsx'] 25 | }, 26 | remapIstanbulReporter: { 27 | reports: { 28 | html: 'coverage', 29 | lcovonly: './coverage/coverage.lcov' 30 | } 31 | }, 32 | angularCli: { 33 | config: './angular-cli.json', 34 | environment: 'dev' 35 | }, 36 | reporters: config.angularCli && config.angularCli.codeCoverage 37 | ? ['mocha', 'karma-remap-istanbul'] 38 | : ['mocha'], 39 | port: 9876, 40 | colors: true, 41 | logLevel: config.LOG_INFO, 42 | autoWatch: true, 43 | browsers: ['PhantomJS'], 44 | singleRun: false 45 | }); 46 | }; 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Angular (2+) Rollbar Integration 2 | 3 | [![Build Status](https://travis-ci.org/NextFaze/angular-rollbar.svg?branch=master)](https://travis-ci.org/NextFaze/angular-rollbar) [![Coverage Status](https://coveralls.io/repos/github/NextFaze/angular-rollbar/badge.svg?branch=master)](https://coveralls.io/github/NextFaze/angular-rollbar?branch=master) 4 | 5 | This package provides an Angular 2+ service for logging to Rollbar. 6 | 7 | ## Installation 8 | 9 | npm install angular-rollbar 10 | 11 | ### Dependencies 12 | 13 | This module relies on the official `rollbar-browser` npm package. In addition, it has Angular >= 2 as a peer dependency. 14 | 15 | ## Usage 16 | 17 | ### Bootstrap the module 18 | 19 | ```ts 20 | import { RollbarModule, RollbarService } from 'angular-rollbar' 21 | 22 | NgModule({ 23 | imports: [ 24 | RollbarModule.forRoot({ 25 | accessToken: 'YOUR ROLLBAR CLIENT TOKEN' 26 | }) 27 | ], 28 | providers: [ 29 | { provide: ErrorHandler, useClass: RollbarService } 30 | ] 31 | }) 32 | export class MyAngularApp {} 33 | 34 | ``` 35 | 36 | ### Use the service 37 | 38 | Let the Angular DI do all the magic for you. 39 | 40 | ```ts 41 | import { Component } from '@angular/core' 42 | import { RollbarService } from 'angular-rollbar'; 43 | 44 | @Component(...) 45 | export class MyComponent { 46 | 47 | constructor (rollbar: RollbarService) { 48 | rollbar.info('Logging to Rollbar!'); 49 | } 50 | } 51 | ``` 52 | 53 | ## Development 54 | 55 | We are using Angular CLI to make things a little bearable. 56 | 57 | ```sh 58 | npm install 59 | npm test 60 | ``` 61 | 62 | ## Disclaimer 63 | 64 | This project is not affiliated in anyway with Rollbar Inc. We do like their 65 | service though. 66 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-rollbar", 3 | "version": "1.0.0", 4 | "description": "Angular 2+ Service for Rollbar error logging", 5 | "main": "lib/index.js", 6 | "typings": "lib/index", 7 | "scripts": { 8 | "clean": "rm -rf lib", 9 | "doc": "./node_modules/.bin/typedoc --out doc --mode modules --excludeNotExported --excludeExternals src", 10 | "test": "ng test --single-run --code-coverage", 11 | "posttest": "npm run coveralls", 12 | "tsc": "node_modules/.bin/tsc", 13 | "ngc": "node_modules/.bin/ngc", 14 | "build": "npm run ngc", 15 | "prebuild": "npm run clean", 16 | "prepublish": "npm run build", 17 | "coveralls": "./node_modules/coveralls/bin/coveralls.js < coverage/coverage.lcov" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "https://github.com/NextFaze/angular-rollbar" 22 | }, 23 | "keywords": [ 24 | "angular", 25 | "rollbar", 26 | "logging" 27 | ], 28 | "author": "Michael Marner ", 29 | "license": "MIT", 30 | "devDependencies": { 31 | "@angular/cli": "10.0.1", 32 | "@angular/common": "10.0.2", 33 | "@angular/compiler": "10.0.2", 34 | "@angular/compiler-cli": "10.0.2", 35 | "@angular/core": "10.0.2", 36 | "@angular/language-service": "10.0.2", 37 | "@angular/platform-browser": "10.0.2", 38 | "@angular/platform-browser-dynamic": "10.0.2", 39 | "@types/jasmine": "~2.5.53", 40 | "@types/jasminewd2": "~2.0.2", 41 | "@types/node": "^14.0.14", 42 | "codecov": "^1.0.1", 43 | "codelyzer": "^4.0.1", 44 | "coveralls": "^2.11.16", 45 | "jasmine-core": "~2.6.2", 46 | "jasmine-spec-reporter": "~4.1.0", 47 | "karma": "~1.7.0", 48 | "karma-chrome-launcher": "~2.1.1", 49 | "karma-cli": "~1.0.1", 50 | "karma-coverage-istanbul-reporter": "^1.2.1", 51 | "karma-jasmine": "~1.1.0", 52 | "karma-jasmine-html-reporter": "^0.2.2", 53 | "karma-mocha-reporter": "^2.2.2", 54 | "karma-phantomjs-launcher": "^1.0.2", 55 | "karma-remap-istanbul": "^0.6.0", 56 | "mocha": "^3.2.0", 57 | "protractor": "~5.1.2", 58 | "rxjs": "^6.6.0", 59 | "ts-node": "~3.2.0", 60 | "tslint": "~5.7.0", 61 | "tslint-eslint-rules": "^3.3.0", 62 | "typedoc": "^0.5.9", 63 | "typescript": "3.9.6", 64 | "webpack": "^2.1.0-beta.25", 65 | "zone.js": "^0.10.3" 66 | }, 67 | "peerDependencies": { 68 | "@angular/common": ">=9.0.0", 69 | "@angular/core": ">=9.0.0" 70 | }, 71 | "dependencies": { 72 | "rollbar": "^2.3.8" 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/rollbar.service.ts: -------------------------------------------------------------------------------- 1 | import {ErrorHandler, Injectable, Inject} from '@angular/core'; 2 | import * as Rollbar from 'rollbar'; 3 | import { Configuration} from 'rollbar'; 4 | import { InjectionToken } from '@angular/core'; 5 | 6 | export const ROLLBAR_CONFIGURATION = new InjectionToken('Angular Rollbar Configuration Object'); 7 | 8 | @Injectable() 9 | /** 10 | * Rollbar Logging Service. 11 | * 12 | * Wraps the logging functions of Rollbar in an Angular 2+ service to make 13 | * things a little smoother. 14 | * Follows the Rollbar browser API as closely as possible. 15 | */ 16 | export class RollbarService implements ErrorHandler { 17 | private rollbar: any; 18 | 19 | /** 20 | * Creates an instance of RollbarService. 21 | * 22 | * @param {RollbarConfig} options The configuration options for your Rollbar 23 | * account. 24 | * 25 | * @memberOf RollbarService 26 | */ 27 | constructor(@Inject(ROLLBAR_CONFIGURATION) options: Configuration) { 28 | this.rollbar = new Rollbar(options); 29 | } 30 | 31 | /** 32 | * Sets Rollbar configuration options at runtime. 33 | * 34 | * @param options A partial configuration object 35 | */ 36 | public configure(options: Configuration) { 37 | return this.rollbar.configure(options); 38 | } 39 | 40 | public handleError(err: any): void { 41 | this.rollbar.error(err.originalError || err); 42 | } 43 | 44 | /** 45 | * Logs a message to Rollbar at the default log level 46 | * 47 | * @param {String} message The content of the message 48 | * @param {Error} [error] An exception to pass along with the message 49 | * @param {Object} [data] Custom data object to log with the message 50 | * @param {Function} [callback] If you aren't into promises, provide a callback. 51 | * @returns 52 | * 53 | * @memberOf RollbarService 54 | */ 55 | public log(message: String, error?: Error, data?: Object, callback?: Function): Promise { 56 | return this.rollbar.log(message, error, data, callback); 57 | } 58 | 59 | /** 60 | * Logs an info level log message to Rollbar 61 | * 62 | * @param {String} message The content of the message 63 | * @param {Error} [error] An exception to pass along with the message 64 | * @param {Object} [data] Custom data object to log with the message 65 | * @param {Function} [callback] If you aren't into promises, provide a callback. 66 | * @returns 67 | * 68 | * @memberOf RollbarService 69 | */ 70 | public info(message: String, error?: Error, data?: Object, callback?: Function): Promise { 71 | return this.rollbar.info(message, error, data, callback); 72 | } 73 | 74 | /** 75 | * Logs a WARN level log message to Rollbar 76 | * 77 | * @param {String} message The content of the message 78 | * @param {Error} [error] An exception to pass along with the message 79 | * @param {Object} [data] Custom data object to log with the message 80 | * @param {Function} [callback] If you aren't into promises, provide a callback. 81 | * @returns 82 | * 83 | * @memberOf RollbarService 84 | */ 85 | public warn(message: String, error?: Error, data?: Object, callback?: Function): Promise { 86 | return this.rollbar.warn(message, error, data, callback); 87 | } 88 | 89 | /** 90 | * Logs an ERROR level log message to Rollbar 91 | * 92 | * @param {String} message The content of the message 93 | * @param {Error} [error] An exception to pass along with the message 94 | * @param {Object} [data] Custom data object to log with the message 95 | * @param {Function} [callback] If you aren't into promises, provide a callback. 96 | * @returns 97 | * 98 | * @memberOf RollbarService 99 | */ 100 | public error(message: String, error?: Error, data?: Object, callback?: Function): Promise { 101 | return this.rollbar.error(message, error, data, callback); 102 | } 103 | 104 | /** 105 | * Logs a CRITICAL ERROR log message to Rollbar 106 | * 107 | * @param {String} message The content of the message 108 | * @param {Error} [error] An exception to pass along with the message 109 | * @param {Object} [data] Custom data object to log with the message 110 | * @param {Function} [callback] If you aren't into promises, provide a callback. 111 | * @returns 112 | * 113 | * @memberOf RollbarService 114 | */ 115 | public critical(message: String, error?: Error, data?: Object, callback?: Function): 116 | Promise { 117 | return this.rollbar.critical(message, error, data, callback); 118 | } 119 | } --------------------------------------------------------------------------------