You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I couldn't find AngularJS integration for new unified Javascript SDK. The legacy AngularJS plugin doesn't work the same way as an Integration with the new SDK so I converted the plugin myself using TypeScript in case anyone needs it in the future. The functionality is the same as an old plugin. I took inspiration from the way the Vue plugin was converted to Vue integration and used the same pattern.
import*asSentryfrom'@sentry/browser'import{Integration,SentryEvent}from'@sentry/types'// See https://github.com/angular/angular.js/blob/v1.4.7/src/minErr.jsconstangularPattern=/^\[((?:[$a-zA-Z0-9]+:)?(?:[$a-zA-Z0-9]+))\] (.*?)\n?(\S+)$/functionnormalizeData(event: SentryEvent){// We only care about mutating an exception// eslint-disable-next-line lodash/prefer-getconstexception=event.exception&&event.exception.values&&event.exception.values[0]if(exception){constmatches=angularPattern.exec(exception.value||'')if(matches){// This type now becomes something like: $rootScope:inprogexception.type=matches[1]exception.value=matches[2]event.message=exception.type+': '+exception.value// auto set a new tag specifically for the angular error urlevent.extra={ ...event.extra,angularDocs: matches[3].substr(0,250)}}}returnevent}/** * AngularJS integration * * Provides an $exceptionHandler for AngularJS */exportclassAngularIntegrationimplementsIntegration{publicname: string=AngularIntegration.idpublicstaticid: string='AngularJS'publicstaticmoduleName='ngSentry'privatereadonlyangular: ng.IAngularStaticpublicconstructor(options: {angular?: ng.IAngularStatic}={}){this.angular=options.angular||(windowasWindow&{angular: ng.IAngularStatic}).angular}publicsetupOnce(): void{if(!this.angular){console.error('AngularIntegration is missing an angular instance')return}function$exceptionHandlerDecorator($delegate: ng.IExceptionHandlerService){const$exceptionHandler: ng.IExceptionHandlerService=(exception,cause)=>{Sentry.withScope(scope=>{if(cause)scope.setExtra('cause',cause)scope.addEventProcessor((event,_hint)=>normalizeData(event)||event)Sentry.captureException(exception)})$delegate(exception,cause)}return$exceptionHandler}this.angular.module(AngularIntegration.moduleName,[]).config(['$provide',($provide: ng.auto.IProvideService)=>{$provide.decorator('$exceptionHandler',['$delegate',$exceptionHandlerDecorator])}])}}
You can then use it in your AngularJS app like this:
importangularfrom'angular'import{AngularIntegration}from'./utils/sentry'Sentry.init({dsn: __YOUR_DSN__,integrations: [newAngularIntegration({ angular })]})angular.module('common',[// other modules...AngularIntegration.moduleName])
The text was updated successfully, but these errors were encountered:
miluoshi
changed the title
AngularJS integration with new Javascript SDK
AngularJS integration for the new Javascript SDK
Feb 9, 2019
I couldn't find AngularJS integration for new unified Javascript SDK. The legacy AngularJS plugin doesn't work the same way as an Integration with the new SDK so I converted the plugin myself using TypeScript in case anyone needs it in the future. The functionality is the same as an old plugin. I took inspiration from the way the Vue plugin was converted to Vue integration and used the same pattern.
You can then use it in your AngularJS app like this:
The text was updated successfully, but these errors were encountered: