1
- let isSentryInstalled = false ;
1
+ "use strict" ;
2
+ var __assign = ( this && this . __assign ) || function ( ) {
3
+ __assign = Object . assign || function ( t ) {
4
+ for ( var s , i = 1 , n = arguments . length ; i < n ; i ++ ) {
5
+ s = arguments [ i ] ;
6
+ for ( var p in s ) if ( Object . prototype . hasOwnProperty . call ( s , p ) )
7
+ t [ p ] = s [ p ] ;
8
+ }
9
+ return t ;
10
+ } ;
11
+ return __assign . apply ( this , arguments ) ;
12
+ } ;
13
+ Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
14
+ var isSentryInstalled = false ;
2
15
function installSentry ( pluginConfig ) {
3
16
var _a , _b , _c ;
4
- const sentryClient = pluginConfig . sentryClient ;
17
+ var sentryClient = pluginConfig . sentryClient ;
5
18
if ( ! sentryClient ) {
6
19
console . error ( "Sentry client not found." ) ;
7
20
}
8
- const isLocalEnv = process . env . IS_OFFLINE || process . env . IS_LOCAL || ! process . env . LAMBDA_TASK_ROOT ;
21
+ var isLocalEnv = process . env . IS_OFFLINE || process . env . IS_LOCAL || ! process . env . LAMBDA_TASK_ROOT ;
9
22
if ( pluginConfig . filterLocal && isLocalEnv ) {
10
23
console . warn ( "Sentry disabled in local environment" ) ;
11
24
delete process . env . SENTRY_DSN ;
@@ -14,27 +27,27 @@ function installSentry(pluginConfig) {
14
27
return ;
15
28
}
16
29
if ( pluginConfig . sourceMaps ) {
17
- const RewriteFramesExists = Array . isArray ( ( _a = pluginConfig . init ) === null || _a === void 0 ? void 0 : _a . integrations ) && ( ( _b = pluginConfig . init ) === null || _b === void 0 ? void 0 : _b . integrations . find ( ( integration ) => integration . name === "RewriteFrames" ) ) ;
30
+ var RewriteFramesExists = Array . isArray ( ( _a = pluginConfig . init ) === null || _a === void 0 ? void 0 : _a . integrations ) && ( ( _b = pluginConfig . init ) === null || _b === void 0 ? void 0 : _b . integrations . find ( function ( integration ) { return integration . name === "RewriteFrames" ; } ) ) ;
18
31
if ( ! RewriteFramesExists ) {
19
32
pluginConfig . init = ( _c = pluginConfig . init ) !== null && _c !== void 0 ? _c : { } ;
20
33
if ( ! Array . isArray ( pluginConfig . init . integrations ) ) {
21
34
pluginConfig . init . integrations = [ ] ;
22
35
}
23
- const { RewriteFrames } = require ( "@sentry/integrations" ) ;
24
- const path = require ( "path" ) ;
36
+ var RewriteFrames = require ( "@sentry/integrations" ) . RewriteFrames ;
37
+ var path_1 = require ( "path" ) ;
25
38
pluginConfig . init . integrations . push ( new RewriteFrames ( {
26
- iteratee : ( frame ) => {
39
+ iteratee : function ( frame ) {
27
40
var _a ;
28
41
if ( ( ( _a = frame . filename ) === null || _a === void 0 ? void 0 : _a . startsWith ( "/" ) ) && ! frame . filename . includes ( "/node_modules/" ) ) {
29
- frame . filename = "app:///" + path . basename ( frame . filename ) ;
42
+ frame . filename = "app:///" + path_1 . basename ( frame . filename ) ;
30
43
}
31
44
return frame ;
32
45
} ,
33
46
} ) ) ;
34
47
}
35
48
}
36
- sentryClient . init ( Object . assign ( { dsn : process . env . SENTRY_DSN , release : process . env . SENTRY_RELEASE , environment : isLocalEnv ? "Local" : process . env . SENTRY_ENVIRONMENT } , pluginConfig . init ) ) ;
37
- const tags = {
49
+ sentryClient . init ( __assign ( { dsn : process . env . SENTRY_DSN , release : process . env . SENTRY_RELEASE , environment : isLocalEnv ? "Local" : process . env . SENTRY_ENVIRONMENT } , pluginConfig . init ) ) ;
50
+ var tags = {
38
51
lambda : String ( process . env . AWS_LAMBDA_FUNCTION_NAME ) ,
39
52
version : String ( process . env . AWS_LAMBDA_FUNCTION_VERSION ) ,
40
53
memory_size : String ( process . env . AWS_LAMBDA_FUNCTION_MEMORY_SIZE ) ,
@@ -48,65 +61,65 @@ function installSentry(pluginConfig) {
48
61
tags . stage = process . env . SERVERLESS_STAGE ;
49
62
if ( process . env . SERVERLESS_ALIAS )
50
63
tags . alias = process . env . SERVERLESS_ALIAS ;
51
- sentryClient . configureScope ( ( scope ) => {
64
+ sentryClient . configureScope ( function ( scope ) {
52
65
var _a ;
53
- scope . setTags ( Object . assign ( Object . assign ( { } , tags ) , ( _a = pluginConfig . scope ) === null || _a === void 0 ? void 0 : _a . tags ) ) ;
66
+ scope . setTags ( __assign ( __assign ( { } , tags ) , ( _a = pluginConfig . scope ) === null || _a === void 0 ? void 0 : _a . tags ) ) ;
54
67
} ) ;
55
68
isSentryInstalled = true ;
56
69
console . log ( "Sentry installed." ) ;
57
70
}
58
- let memoryWatch ;
59
- let timeoutWarning ;
60
- let timeoutError ;
71
+ var memoryWatch ;
72
+ var timeoutWarning ;
73
+ var timeoutError ;
61
74
function installTimers ( pluginConfig , lambdaContext ) {
62
- const timeRemaining = lambdaContext . getRemainingTimeInMillis ( ) ;
63
- const memoryLimit = Number ( lambdaContext . memoryLimitInMB ) ;
75
+ var timeRemaining = lambdaContext . getRemainingTimeInMillis ( ) ;
76
+ var memoryLimit = Number ( lambdaContext . memoryLimitInMB ) ;
64
77
function timeoutWarningFunc ( cb ) {
65
- const Sentry = pluginConfig . sentryClient ;
78
+ var Sentry = pluginConfig . sentryClient ;
66
79
if ( isSentryInstalled ) {
67
- Sentry . withScope ( ( scope ) => {
80
+ Sentry . withScope ( function ( scope ) {
68
81
scope . setLevel ( "warning" ) ;
69
82
scope . setExtras ( {
70
83
TimeRemainingInMsec : lambdaContext . getRemainingTimeInMillis ( ) ,
71
84
} ) ;
72
85
Sentry . captureMessage ( "Function Execution Time Warning" ) ;
73
86
} ) ;
74
87
Sentry . flush ( 5000 )
75
- . then ( ( ) => cb === null || cb === void 0 ? void 0 : cb ( ) )
88
+ . then ( function ( ) { return cb === null || cb === void 0 ? void 0 : cb ( ) ; } )
76
89
. catch ( null ) ;
77
90
}
78
91
}
79
92
function timeoutErrorFunc ( cb ) {
80
- const Sentry = pluginConfig . sentryClient ;
93
+ var Sentry = pluginConfig . sentryClient ;
81
94
if ( isSentryInstalled ) {
82
- Sentry . withScope ( ( scope ) => {
95
+ Sentry . withScope ( function ( scope ) {
83
96
scope . setLevel ( "error" ) ;
84
97
scope . setExtras ( {
85
98
TimeRemainingInMsec : lambdaContext . getRemainingTimeInMillis ( ) ,
86
99
} ) ;
87
100
Sentry . captureMessage ( "Function Timed Out" ) ;
88
101
} ) ;
89
102
Sentry . flush ( 5000 )
90
- . then ( ( ) => cb === null || cb === void 0 ? void 0 : cb ( ) )
103
+ . then ( function ( ) { return cb === null || cb === void 0 ? void 0 : cb ( ) ; } )
91
104
. catch ( null ) ;
92
105
}
93
106
}
94
107
function memoryWatchFunc ( cb ) {
95
- const used = process . memoryUsage ( ) . rss / 1048576 ;
96
- const p = used / memoryLimit ;
108
+ var used = process . memoryUsage ( ) . rss / 1048576 ;
109
+ var p = used / memoryLimit ;
97
110
if ( p >= 0.75 ) {
98
- const Sentry = pluginConfig . sentryClient ;
111
+ var Sentry_1 = pluginConfig . sentryClient ;
99
112
if ( isSentryInstalled ) {
100
- Sentry . withScope ( ( scope ) => {
113
+ Sentry_1 . withScope ( function ( scope ) {
101
114
scope . setLevel ( "warning" ) ;
102
115
scope . setExtras ( {
103
116
MemoryLimitInMB : memoryLimit ,
104
117
MemoryUsedInMB : Math . floor ( used ) ,
105
118
} ) ;
106
- Sentry . captureMessage ( "Low Memory Warning" ) ;
119
+ Sentry_1 . captureMessage ( "Low Memory Warning" ) ;
107
120
} ) ;
108
- Sentry . flush ( 5000 )
109
- . then ( ( ) => cb === null || cb === void 0 ? void 0 : cb ( ) )
121
+ Sentry_1 . flush ( 5000 )
122
+ . then ( function ( ) { return cb === null || cb === void 0 ? void 0 : cb ( ) ; } )
110
123
. catch ( null ) ;
111
124
}
112
125
}
@@ -137,13 +150,13 @@ function clearTimers() {
137
150
}
138
151
}
139
152
function wrapCallback ( pluginConfig , cb ) {
140
- return ( err , data ) => {
153
+ return function ( err , data ) {
141
154
clearTimers ( ) ;
142
155
if ( err && err !== "__emptyFailParamBackCompat" && pluginConfig . captureErrors && isSentryInstalled ) {
143
- const Sentry = pluginConfig . sentryClient ;
144
- Sentry . captureException ( err ) ;
145
- Sentry . flush ( 5000 )
146
- . then ( ( ) => cb ( err ) )
156
+ var Sentry_2 = pluginConfig . sentryClient ;
157
+ Sentry_2 . captureException ( err ) ;
158
+ Sentry_2 . flush ( 5000 )
159
+ . then ( function ( ) { return cb ( err ) ; } )
147
160
. catch ( null ) ;
148
161
return ;
149
162
}
@@ -156,7 +169,7 @@ function wrapCallback(pluginConfig, cb) {
156
169
} ;
157
170
}
158
171
function parseBoolean ( value , defaultValue ) {
159
- const v = String ( value ) . trim ( ) . toLowerCase ( ) ;
172
+ var v = String ( value ) . trim ( ) . toLowerCase ( ) ;
160
173
if ( [ "true" , "t" , "1" , "yes" , "y" ] . includes ( v ) ) {
161
174
return true ;
162
175
}
@@ -170,19 +183,21 @@ function parseBoolean(value, defaultValue) {
170
183
function isSentryInstance ( value ) {
171
184
return typeof ( value === null || value === void 0 ? void 0 : value . captureException ) === "function" && typeof ( value === null || value === void 0 ? void 0 : value . captureMessage ) === "function" ;
172
185
}
173
- export default class SentryLambdaWrapper {
174
- static handler ( pluginConfigOrSentry , handler ) {
186
+ var SentryLambdaWrapper = ( function ( ) {
187
+ function SentryLambdaWrapper ( ) {
188
+ }
189
+ SentryLambdaWrapper . handler = function ( pluginConfigOrSentry , handler ) {
175
190
var _a , _b , _c ;
176
- let pluginConfig ;
191
+ var pluginConfig ;
177
192
if ( isSentryInstance ( pluginConfigOrSentry ) ) {
178
193
pluginConfig = {
179
194
sentryClient : pluginConfigOrSentry ,
180
195
} ;
181
196
}
182
197
else {
183
- pluginConfig = Object . assign ( Object . assign ( { } , pluginConfigOrSentry ) , { init : Object . assign ( { } , pluginConfigOrSentry === null || pluginConfigOrSentry === void 0 ? void 0 : pluginConfigOrSentry . init ) , scope : Object . assign ( Object . assign ( { } , pluginConfigOrSentry === null || pluginConfigOrSentry === void 0 ? void 0 : pluginConfigOrSentry . scope ) , { tags : Object . assign ( { } , ( _a = pluginConfigOrSentry === null || pluginConfigOrSentry === void 0 ? void 0 : pluginConfigOrSentry . scope ) === null || _a === void 0 ? void 0 : _a . tags ) , extras : Object . assign ( { } , ( _b = pluginConfigOrSentry === null || pluginConfigOrSentry === void 0 ? void 0 : pluginConfigOrSentry . scope ) === null || _b === void 0 ? void 0 : _b . extras ) , user : Object . assign ( { } , ( _c = pluginConfigOrSentry === null || pluginConfigOrSentry === void 0 ? void 0 : pluginConfigOrSentry . scope ) === null || _c === void 0 ? void 0 : _c . user ) } ) } ) ;
198
+ pluginConfig = __assign ( __assign ( { } , pluginConfigOrSentry ) , { init : __assign ( { } , pluginConfigOrSentry === null || pluginConfigOrSentry === void 0 ? void 0 : pluginConfigOrSentry . init ) , scope : __assign ( __assign ( { } , pluginConfigOrSentry === null || pluginConfigOrSentry === void 0 ? void 0 : pluginConfigOrSentry . scope ) , { tags : __assign ( { } , ( _a = pluginConfigOrSentry === null || pluginConfigOrSentry === void 0 ? void 0 : pluginConfigOrSentry . scope ) === null || _a === void 0 ? void 0 : _a . tags ) , extras : __assign ( { } , ( _b = pluginConfigOrSentry === null || pluginConfigOrSentry === void 0 ? void 0 : pluginConfigOrSentry . scope ) === null || _b === void 0 ? void 0 : _b . extras ) , user : __assign ( { } , ( _c = pluginConfigOrSentry === null || pluginConfigOrSentry === void 0 ? void 0 : pluginConfigOrSentry . scope ) === null || _c === void 0 ? void 0 : _c . user ) } ) } ) ;
184
199
}
185
- const pluginConfigDefaults = {
200
+ var pluginConfigDefaults = {
186
201
init : { } ,
187
202
scope : { tags : { } , extras : { } , user : { } } ,
188
203
captureErrors : parseBoolean ( process . env . SENTRY_CAPTURE_ERRORS , true ) ,
@@ -200,12 +215,12 @@ export default class SentryLambdaWrapper {
200
215
if ( process . env . SENTRY_DSN && ! isSentryInstalled ) {
201
216
installSentry ( pluginConfig ) ;
202
217
}
203
- return ( event , context , callback ) => {
218
+ return function ( event , context , callback ) {
204
219
var _a , _b , _c , _d ;
205
220
if ( ! isSentryInstalled ) {
206
221
return handler ( event , context , callback ) ;
207
222
}
208
- const originalCallbacks = {
223
+ var originalCallbacks = {
209
224
done : ( _a = context . done ) === null || _a === void 0 ? void 0 : _a . bind ( context ) ,
210
225
succeed : ( _b = context . succeed ) === null || _b === void 0 ? void 0 : _b . bind ( context ) ,
211
226
fail : ( _c = context . fail ) === null || _c === void 0 ? void 0 : _c . bind ( context ) ,
@@ -221,19 +236,19 @@ export default class SentryLambdaWrapper {
221
236
: originalCallbacks . fail ;
222
237
context . succeed =
223
238
typeof originalCallbacks . succeed === "function"
224
- ? wrapCallback ( pluginConfig , ( err , result ) => originalCallbacks . succeed ( result ) ) . bind ( null , null )
239
+ ? wrapCallback ( pluginConfig , function ( err , result ) { return originalCallbacks . succeed ( result ) ; } ) . bind ( null , null )
225
240
: originalCallbacks . succeed ;
226
241
callback = originalCallbacks . callback
227
242
? wrapCallback ( pluginConfig , originalCallbacks . callback )
228
243
: originalCallbacks . callback ;
229
- const sentryScope = {
244
+ var sentryScope = {
230
245
extras : {
231
246
Event : event ,
232
247
Context : context ,
233
248
} ,
234
249
tags : { } ,
235
250
} ;
236
- const identity = ( ( _d = context . identity ) === null || _d === void 0 ? void 0 : _d . constructor ) === Object && Object . keys ( context . identity ) . length > 0
251
+ var identity = ( ( _d = context . identity ) === null || _d === void 0 ? void 0 : _d . constructor ) === Object && Object . keys ( context . identity ) . length > 0
237
252
? context . identity
238
253
: event . requestContext
239
254
? event . requestContext . identity
@@ -249,41 +264,45 @@ export default class SentryLambdaWrapper {
249
264
} ;
250
265
}
251
266
if ( event . requestContext ) {
252
- sentryScope . tags = Object . assign ( Object . assign ( { } , sentryScope . tags ) , { api_id : event . requestContext . apiId , api_stage : event . requestContext . stage , http_method : event . requestContext . httpMethod } ) ;
267
+ sentryScope . tags = __assign ( __assign ( { } , sentryScope . tags ) , { api_id : event . requestContext . apiId , api_stage : event . requestContext . stage , http_method : event . requestContext . httpMethod } ) ;
253
268
}
254
- const captureUnhandled = wrapCallback ( pluginConfig , ( err ) => {
269
+ var captureUnhandled = wrapCallback ( pluginConfig , function ( err ) {
255
270
err . _sentryHandled = true ;
256
271
throw err ;
257
272
} ) ;
258
- const Sentry = pluginConfig . sentryClient ;
259
- Sentry . configureScope ( ( scope ) => {
273
+ var Sentry = pluginConfig . sentryClient ;
274
+ Sentry . configureScope ( function ( scope ) {
260
275
sentryScope . user && scope . setUser ( sentryScope . user ) ;
261
276
sentryScope . extras && scope . setExtras ( sentryScope . extras ) ;
262
277
sentryScope . tags && scope . setTags ( sentryScope . tags ) ;
263
278
} ) ;
264
279
installTimers ( pluginConfig , context ) ;
265
280
try {
266
281
if ( pluginConfig . autoBreadcrumbs ) {
267
- const breadcrumb = {
282
+ var breadcrumb = {
268
283
message : process . env . AWS_LAMBDA_FUNCTION_NAME ,
269
284
category : "lambda" ,
270
285
level : "info" ,
271
286
data : { } ,
272
287
} ;
273
288
if ( event . requestContext ) {
274
- breadcrumb . data = Object . assign ( Object . assign ( { } , breadcrumb . data ) , { http_method : event . requestContext && event . requestContext . httpMethod , host : event . headers && event . headers . Host , path : event . path , user_agent : event . headers && event . headers [ "User-Agent" ] } ) ;
289
+ breadcrumb . data = __assign ( __assign ( { } , breadcrumb . data ) , { http_method : event . requestContext && event . requestContext . httpMethod , host : event . headers && event . headers . Host , path : event . path , user_agent : event . headers && event . headers [ "User-Agent" ] } ) ;
275
290
}
276
- const sentryClient = pluginConfig . sentryClient ;
291
+ var sentryClient = pluginConfig . sentryClient ;
277
292
sentryClient . addBreadcrumb ( breadcrumb ) ;
278
293
}
279
- const promise = handler ( event , context , callback ) ;
294
+ var promise = handler ( event , context , callback ) ;
280
295
if ( promise && typeof promise . then === "function" ) {
281
296
return promise
282
- . then ( ( ...data ) => {
297
+ . then ( function ( ) {
298
+ var data = [ ] ;
299
+ for ( var _i = 0 ; _i < arguments . length ; _i ++ ) {
300
+ data [ _i ] = arguments [ _i ] ;
301
+ }
283
302
clearTimers ( ) ;
284
- return Promise . resolve ( ... data ) ;
303
+ return Promise . resolve . apply ( Promise , data ) ;
285
304
} )
286
- . catch ( ( err ) => {
305
+ . catch ( function ( err ) {
287
306
clearTimers ( ) ;
288
307
return Promise . reject ( err ) ;
289
308
} ) ;
@@ -294,5 +313,7 @@ export default class SentryLambdaWrapper {
294
313
captureUnhandled ( err ) ;
295
314
}
296
315
} ;
297
- }
298
- }
316
+ } ;
317
+ return SentryLambdaWrapper ;
318
+ } ( ) ) ;
319
+ exports . default = SentryLambdaWrapper ;
0 commit comments