@@ -62,7 +62,7 @@ function dataSerialize(data?: any, wrapPrimitives?: boolean) {
62
62
}
63
63
}
64
64
65
- const FATAL_ERROR_REGEXP = / N a t i v e S c r i p t e n c o u n t e r e d a f a t a l e r r o r : ( . * ?) \n a t \n ( \t * ) ? ( . * ) $ / m;
65
+ const FATAL_ERROR_REGEXP = / N a t i v e S c r i p t e n c o u n t e r e d a f a t a l e r r o r : ( [ ^ ] * ?) a t ( [ \t \n \s ] * ) ? ( [ ^ ] * ) $ / m;
66
66
67
67
export namespace NATIVE {
68
68
let enableNative = true ;
@@ -324,7 +324,17 @@ export namespace NATIVE {
324
324
return false ;
325
325
}
326
326
sentryOptions = options ;
327
- const { tracesSampleRate, tracesSampler, beforeSend, beforeBreadcrumb, ...toPassOptions } = options ;
327
+ const {
328
+ enableCrashHandler,
329
+ enableNativeCrashHandling,
330
+ enableAutoPerformanceTracking,
331
+ tracesSampleRate,
332
+ tracesSampler,
333
+ beforeSend,
334
+ beforeBreadcrumb,
335
+ disabledNativeIntegrations,
336
+ ...toPassOptions
337
+ } = options ;
328
338
329
339
Object . keys ( toPassOptions ) . forEach ( ( k ) => {
330
340
const value = toPassOptions [ k ] ;
@@ -339,18 +349,29 @@ export namespace NATIVE {
339
349
340
350
// before send right now is never called when we send the envelope. Only on native crash
341
351
nSentryOptions . beforeSend = ( event : SentryEvent ) => {
342
- const exception = event . exceptions ?. objectAtIndex ( 0 ) ;
343
- const exceptionvalue = exception ?. value ;
344
- if ( exceptionvalue ) {
345
- const matches = exceptionvalue . match ( FATAL_ERROR_REGEXP ) ;
346
- if ( matches ) {
347
- const errorMessage = matches [ 1 ] ;
348
- const jsStackTrace = exceptionvalue . substring ( exceptionvalue . indexOf ( matches [ 2 ] ) ) ;
349
- const stack = parseErrorStack ( { stack : 'at ' + jsStackTrace } as any ) . reverse ( ) ;
350
- stack . forEach ( ( frame ) => rewriteFrameIntegration . _iteratee ( frame ) ) ;
351
- addJavascriptExceptionInterface ( event , 'Error' , errorMessage , stack . reverse ( ) ) ;
352
- exception . type = 'NativeScriptException' ;
353
- exception . value = errorMessage ;
352
+ const exceptions = event . exceptions ;
353
+ const count = exceptions ?. count ;
354
+ // if enableCrashHandler is disabled we actually dont disable it but prevent event Sending
355
+ // the reason is that without SentryCrashIntegration the scope does not get augmented and we loose info
356
+ if ( enableCrashHandler === false ) {
357
+ return null ;
358
+ }
359
+ if ( count ) {
360
+ for ( let index = 0 ; index < exceptions . count ; index ++ ) {
361
+ const exception = exceptions . objectAtIndex ( index ) ;
362
+ const exceptionvalue = exception . value ;
363
+ if ( exceptionvalue ) {
364
+ const matches = exceptionvalue . match ( FATAL_ERROR_REGEXP ) ;
365
+ if ( matches ) {
366
+ const errorMessage = matches [ 1 ] ;
367
+ const jsStackTrace = exceptionvalue . substring ( exceptionvalue . indexOf ( matches [ 2 ] ) ) ;
368
+ const stack = parseErrorStack ( { stack : 'at ' + jsStackTrace } as any ) . reverse ( ) ;
369
+ stack . forEach ( ( frame ) => rewriteFrameIntegration . _iteratee ( frame ) ) ;
370
+ addJavascriptExceptionInterface ( event , 'Error' , errorMessage , stack . reverse ( ) ) ;
371
+ exception . type = 'NativeScriptException' ;
372
+ exception . value = errorMessage ;
373
+ }
374
+ }
354
375
}
355
376
}
356
377
if ( beforeSend ) {
@@ -376,18 +397,29 @@ export namespace NATIVE {
376
397
}
377
398
return breadcrumb ;
378
399
} ;
379
- if ( toPassOptions . hasOwnProperty ( 'enableNativeCrashHandling' ) ) {
380
- if ( ! toPassOptions . enableNativeCrashHandling ) {
381
- const integrations = nSentryOptions . integrations . mutableCopy ( ) ;
382
- integrations . removeObject ( 'SentryCrashIntegration' ) ;
383
- nSentryOptions . integrations = integrations ;
400
+ if ( enableNativeCrashHandling === false ) {
401
+ const integrations = nSentryOptions . integrations . mutableCopy ( ) ;
402
+ integrations . removeObject ( 'SentryCrashIntegration' ) ;
403
+ nSentryOptions . integrations = integrations ;
404
+ }
405
+ if ( disabledNativeIntegrations ) {
406
+ const integrations = nSentryOptions . integrations . mutableCopy ( ) as NSMutableArray < any > ;
407
+ const size = integrations . count ;
408
+ for ( let index = size - 1 ; index >= 0 ; index -- ) {
409
+ const inte = integrations . objectAtIndex ( index ) ;
410
+ if ( disabledNativeIntegrations . indexOf ( inte ) !== - 1 ) {
411
+ integrations . removeObject ( inte ) ;
412
+ }
384
413
}
414
+ nSentryOptions . integrations = integrations ;
385
415
}
386
416
387
- if ( toPassOptions . hasOwnProperty ( ' enableAutoPerformanceTracking' ) ) {
388
- NSSentrySDK . appStartMeasurementHybridSDKMode = toPassOptions . enableAutoPerformanceTracking ;
389
- NSSentrySDK . framesTrackingMeasurementHybridSDKMode = toPassOptions . enableAutoPerformanceTracking ;
417
+ if ( enableAutoPerformanceTracking !== undefined ) {
418
+ NSSentrySDK . appStartMeasurementHybridSDKMode = enableAutoPerformanceTracking ;
419
+ NSSentrySDK . framesTrackingMeasurementHybridSDKMode = enableAutoPerformanceTracking ;
390
420
}
421
+ const sdkVersion = PrivateSentrySDKOnly . getSdkVersionString ( ) ;
422
+ PrivateSentrySDKOnly . setSdkNameAndVersionString ( 'sentry.cocoa.nativescript' , sdkVersion ) ;
391
423
NSSentrySDK . startWithOptions ( nSentryOptions ) ;
392
424
393
425
return true ;
@@ -422,7 +454,7 @@ export namespace NATIVE {
422
454
console . error ( 'fetchNativeDeviceContexts' , error , error . stack ) ;
423
455
}
424
456
} ) ;
425
- const contexts = serializedScope . context ;
457
+ const contexts = serializedScope . context || { } ;
426
458
const extraContextDict = PrivateSentrySDKOnly . getExtraContext ( ) ;
427
459
if ( extraContextDict ) {
428
460
const extraContext = dictToJSON ( extraContextDict ) ;
0 commit comments