@@ -15,106 +15,122 @@ var MessageBuilder = require('./raygun.messageBuilder');
1515var OfflineStorage = require ( './raygun.offline' ) ;
1616
1717var Raygun = function ( ) {
18- var _apiKey , _filters , raygun = this , _user , _version , _host , _port , _useSSL , _onBeforeSend , _offlineStorage , _isOffline , _offlineStorageOptions , _groupingKey ;
19-
20- raygun . init = function ( options ) {
21- _apiKey = options . apiKey ;
22- _filters = options . filters ;
23- _host = options . host ;
24- _port = options . port ;
25- _useSSL = options . useSSL || true ;
26- _onBeforeSend = options . onBeforeSend ;
27- _offlineStorage = options . offlineStorage || new OfflineStorage ( ) ;
28- _offlineStorageOptions = options . offlineStorageOptions ;
29- _isOffline = options . isOffline ;
30- _groupingKey = options . groupingKey ;
31-
32- if ( _isOffline ) {
33- _offlineStorage . init ( _offlineStorageOptions ) ;
34- }
35-
36- return raygun ;
37- } ;
38-
39- raygun . user = function ( req ) {
40- return ;
41- } ;
42-
43- // This function is deprecated, is provided for legacy apps and will be
44- // removed in 1.0: use raygun.user instead
45- raygun . setUser = function ( user ) {
46- _user = user ;
47- return raygun ;
48- } ;
49-
50- raygun . setVersion = function ( version ) {
51- _version = version ;
52- return raygun ;
53- } ;
54-
55- raygun . onBeforeSend = function ( onBeforeSend ) {
56- _onBeforeSend = onBeforeSend ;
57- return raygun ;
58- } ;
59-
60- raygun . groupingKey = function ( groupingKey ) {
61- _groupingKey = groupingKey ;
62- return raygun ;
63- } ;
64-
65- raygun . offline = function ( ) {
66- _offlineStorage . init ( _offlineStorageOptions ) ;
67- _isOffline = true ;
68- } ;
69-
70- raygun . online = function ( callback ) {
71- _isOffline = false ;
72- _offlineStorage . send ( callback ) ;
73- } ;
74-
75- raygun . send = function ( exception , customData , callback , request , tags ) {
76- var builder = new MessageBuilder ( { filters : _filters } )
77- . setErrorDetails ( exception )
78- . setRequestDetails ( request )
79- . setMachineName ( )
80- . setEnvironmentDetails ( )
81- . setUserCustomData ( customData )
82- . setUser ( raygun . user ( request ) || _user )
83- . setVersion ( _version )
84- . setTags ( tags ) ;
85-
86- var message = builder . build ( ) ;
87-
88- if ( _groupingKey ) {
89- message . details . groupingKey = typeof _groupingKey === 'function' ? _groupingKey ( message , exception , customData , request , tags ) : null ;
90- }
91-
92- if ( raygun . onBeforeSend ) {
93- message = typeof _onBeforeSend === 'function' ? _onBeforeSend ( message , exception , customData , request , tags ) : message ;
94- }
95-
96- var transportMessage = {
97- message : message ,
98- apiKey : _apiKey ,
99- callback : callback ,
100- host : _host ,
101- port : _port ,
102- useSSL : _useSSL
18+ var _apiKey , _filters , raygun = this , _user , _version , _host , _port , _useSSL , _onBeforeSend , _offlineStorage , _isOffline , _offlineStorageOptions , _groupingKey , _tags ;
19+
20+ raygun . init = function ( options ) {
21+ _apiKey = options . apiKey ;
22+ _filters = options . filters ;
23+ _host = options . host ;
24+ _port = options . port ;
25+ _useSSL = options . useSSL || true ;
26+ _onBeforeSend = options . onBeforeSend ;
27+ _offlineStorage = options . offlineStorage || new OfflineStorage ( ) ;
28+ _offlineStorageOptions = options . offlineStorageOptions ;
29+ _isOffline = options . isOffline ;
30+ _groupingKey = options . groupingKey ;
31+ _tags = options . tags ;
32+
33+ if ( _isOffline ) {
34+ _offlineStorage . init ( _offlineStorageOptions ) ;
35+ }
36+
37+ return raygun ;
10338 } ;
10439
105- if ( _isOffline ) {
106- _offlineStorage . save ( transportMessage , callback ) ;
107- } else {
108- raygunTransport . send ( transportMessage ) ;
109- }
40+ raygun . user = function ( req ) {
41+ return ;
42+ } ;
11043
111- return message ;
112- } ;
44+ // This function is deprecated, is provided for legacy apps and will be
45+ // removed in 1.0: use raygun.user instead
46+ raygun . setUser = function ( user ) {
47+ _user = user ;
48+ return raygun ;
49+ } ;
11350
114- raygun . expressHandler = function ( err , req , res , next ) {
115- raygun . send ( err , { } , function ( ) { } , req ) ;
116- next ( err ) ;
117- } ;
51+ raygun . setVersion = function ( version ) {
52+ _version = version ;
53+ return raygun ;
54+ } ;
55+
56+ raygun . onBeforeSend = function ( onBeforeSend ) {
57+ _onBeforeSend = onBeforeSend ;
58+ return raygun ;
59+ } ;
60+
61+ raygun . groupingKey = function ( groupingKey ) {
62+ _groupingKey = groupingKey ;
63+ return raygun ;
64+ } ;
65+
66+ raygun . offline = function ( ) {
67+ _offlineStorage . init ( _offlineStorageOptions ) ;
68+ _isOffline = true ;
69+ } ;
70+
71+ raygun . online = function ( callback ) {
72+ _isOffline = false ;
73+ _offlineStorage . send ( callback ) ;
74+ } ;
75+
76+ raygun . setTags = function ( tags ) {
77+ _tags = tags ;
78+ } ;
79+
80+ raygun . send = function ( exception , customData , callback , request , tags ) {
81+ var mergedTags = [ ] ;
82+
83+ if ( _tags ) {
84+ mergedTags = mergedTags . concat ( _tags ) ;
85+ }
86+
87+ if ( tags ) {
88+ mergedTags = mergedTags . concat ( tags ) ;
89+ }
90+
91+ var builder = new MessageBuilder ( { filters : _filters } )
92+ . setErrorDetails ( exception )
93+ . setRequestDetails ( request )
94+ . setMachineName ( )
95+ . setEnvironmentDetails ( )
96+ . setUserCustomData ( customData )
97+ . setUser ( raygun . user ( request ) || _user )
98+ . setVersion ( _version )
99+ . setTags ( mergedTags ) ;
100+
101+ var message = builder . build ( ) ;
102+
103+ if ( _groupingKey ) {
104+ message . details . groupingKey = typeof _groupingKey === 'function' ? _groupingKey ( message , exception , customData , request , tags ) : null ;
105+ }
106+
107+ if ( raygun . onBeforeSend ) {
108+ message = typeof _onBeforeSend === 'function' ? _onBeforeSend ( message , exception , customData , request , tags ) : message ;
109+ }
110+
111+ var transportMessage = {
112+ message : message ,
113+ apiKey : _apiKey ,
114+ callback : callback ,
115+ host : _host ,
116+ port : _port ,
117+ useSSL : _useSSL
118+ } ;
119+
120+ if ( _isOffline ) {
121+ _offlineStorage . save ( transportMessage , callback ) ;
122+ } else {
123+ raygunTransport . send ( transportMessage ) ;
124+ }
125+
126+ return message ;
127+ } ;
128+
129+ raygun . expressHandler = function ( err , req , res , next ) {
130+ raygun . send ( err , { } , function ( ) {
131+ } , req ) ;
132+ next ( err ) ;
133+ } ;
118134} ;
119135
120136exports . Client = Raygun ;
0 commit comments