1
- import { pointsFromBuffer } from '@nativescript-community/arraybuffers' ;
2
- import { getClass } from '@nativescript/core/utils/types' ;
3
- import { Scope } from '@sentry/core' ;
4
- import { Attachment , BaseEnvelopeItemHeaders , Breadcrumb , Envelope , EnvelopeItem , Event , SeverityLevel , User } from '@sentry/types' ;
1
+ import { BaseEnvelopeItemHeaders , Breadcrumb , Envelope , EnvelopeItem , Event , SeverityLevel } from '@sentry/types' ;
5
2
import { SentryError , logger } from '@sentry/utils' ;
6
3
import { isHardCrash } from './misc' ;
7
4
import { NativescriptOptions } from './options' ;
8
5
import { utf8ToBytes } from './vendor' ;
9
- import { UserFeedback } from './wrapper' ;
10
6
11
7
const numberHasDecimals = function ( value : number ) : boolean {
12
8
return ! ( value % 1 === 0 ) ;
@@ -187,54 +183,6 @@ export namespace NATIVE {
187
183
}
188
184
}
189
185
}
190
- export async function sendEvent ( event : Event ) {
191
- try {
192
- // Process and convert deprecated levels
193
- // event.level = event.level ? _processLevel(event.level) : undefined;
194
- console . error ( 'sendEvent' , JSON . stringify ( event ) ) ;
195
-
196
- const payload = {
197
- ...event ,
198
- message : {
199
- message : event . message
200
- }
201
- } ;
202
- payload . tags = payload . tags || { } ;
203
-
204
- payload . tags [ 'event.origin' ] = 'ios' ;
205
- payload . tags [ 'event.environment' ] = 'nativescript' ;
206
- // Serialize and remove any instances that will crash the native bridge such as Spans
207
- const serializedPayload = JSON . parse ( JSON . stringify ( payload ) ) ;
208
- const eventId = SentryId . alloc ( ) . initWithUUIDString ( event . event_id ) ;
209
- const envelopeHeader = SentryEnvelopeHeader . alloc ( ) . initWithId ( eventId ) ;
210
- const envelopeItemData = NSJSONSerialization . dataWithJSONObjectOptionsError ( serializedPayload , 0 ) ;
211
-
212
- let itemType = payload . type ;
213
- if ( ! itemType ) {
214
- // Default to event type.
215
- itemType = 'event' as any ;
216
- }
217
-
218
- const envelopeItemHeader = SentryEnvelopeItemHeader . alloc ( ) . initWithTypeLength ( itemType , envelopeItemData . length ) ;
219
- const envelopeItem = SentryEnvelopeItem . alloc ( ) . initWithHeaderData ( envelopeItemHeader , envelopeItemData ) ;
220
-
221
- const envelope = SentryEnvelope . alloc ( ) . initWithHeaderSingleItem ( envelopeHeader , envelopeItem ) ;
222
-
223
- if ( event . level === 'fatal' ) {
224
- // captureEvent queues the event for submission, so storing to disk happens asynchronously
225
- // We need to make sure the event is written to disk before resolving the promise.
226
- // This could be replaced by SentrySDK.flush() when available.
227
- NSSentrySDK . storeEnvelope ( envelope ) ;
228
- } else {
229
- NSSentrySDK . captureEnvelope ( envelope ) ;
230
- }
231
- // if (sentryOptions.flushSendEvent === true) {
232
-
233
- // }
234
- } catch ( err ) {
235
- console . error ( 'sendEvent' , err , err . stack ) ;
236
- }
237
- }
238
186
/**
239
187
* Sending the envelope over the bridge to native
240
188
* @param envelope Envelope
@@ -337,12 +285,12 @@ export namespace NATIVE {
337
285
delete toPassOptions [ k ] ;
338
286
}
339
287
} ) ;
340
- console . log ( 'toPassOptions' , Object . keys ( toPassOptions ) ) ;
341
288
const mutDict = NSMutableDictionary . alloc ( ) . initWithDictionary ( dataSerialize ( toPassOptions ) as any ) ;
342
289
343
290
nSentryOptions = SentryOptions . alloc ( ) . initWithDictDidFailWithError ( mutDict as any ) ;
344
- nSentryOptions . beforeSend = ( event : SentryEvent ) => {
345
- console . log ( 'beforeSend' , event ) ;
291
+
292
+ // before send right now is never called when we send the envelope
293
+ nSentryOptions . beforeSend = ( event : SentryEvent ) => {
346
294
if ( beforeSend ) {
347
295
beforeSend ( event as any , null ) ;
348
296
}
@@ -352,9 +300,8 @@ export namespace NATIVE {
352
300
if ( toPassOptions . hasOwnProperty ( 'enableNativeCrashHandling' ) ) {
353
301
if ( ! toPassOptions . enableNativeCrashHandling ) {
354
302
const integrations = nSentryOptions . integrations . mutableCopy ( ) ;
355
- // console.log('integrations', typeof nSentryOptions, nSentryOptions.length, nSentryOptions[0]);
356
303
integrations . removeObject ( 'SentryCrashIntegration' ) ;
357
- sentryOptions . integrations = integrations ;
304
+ nSentryOptions . integrations = integrations ;
358
305
}
359
306
}
360
307
@@ -364,26 +311,6 @@ export namespace NATIVE {
364
311
}
365
312
NSSentrySDK . startWithOptionsObject ( nSentryOptions ) ;
366
313
367
- // NSSentrySDK.startWithConfigureOptions((obj) => {
368
- // const beforeSend = options.beforeSend;
369
- // delete options.beforeSend;
370
-
371
- // obj.beforeSend = (event: SentryEvent)=>{
372
- // console.log('beforeSend', event);
373
- // if (beforeSend) {
374
- // beforeSend(event as any, null);
375
- // }
376
- // return event;
377
- // };
378
- // Object.keys(options).forEach((k) => {
379
- // if (options[k] !== undefined ) {
380
- // // console.log('setting sentry option',k, obj.hasOwnProperty(k), options[k] );
381
- // obj[k] = options[k];
382
-
383
- // }
384
- // });
385
- // nSentryOptions = obj;
386
- // });
387
314
return ( true ) ;
388
315
} catch ( error ) {
389
316
enableNative = false ;
@@ -392,115 +319,26 @@ export namespace NATIVE {
392
319
}
393
320
}
394
321
395
- // export function nativeLogLevel(level: number) {
396
- // let cocoaLevel;
397
- // switch (level) {
398
- // case 1:
399
- // cocoaLevel = SentryLevel.kSentryLevelError;
400
- // break;
401
- // case 2:
402
- // cocoaLevel = SentryLevel.kSentryLevelDebug;
403
- // break;
404
- // case 3:
405
- // cocoaLevel = SentryLevel.kSentryLevelVerbose;
406
- // break;
407
- // default:
408
- // cocoaLevel = SentryLevel.kSentryLevelNone;
409
- // }
410
- // return cocoaLevel;
411
- // }
412
- export function cranativeCrashsh ( ) {
322
+ export function nativeCrash ( ) {
413
323
NSSentrySDK . crash ( ) ;
414
324
}
415
325
export function flush ( timeout : number ) {
416
326
NSSentrySDK . flush ( timeout ) ;
417
327
}
418
- function toJsObject ( objCObj ) {
419
- if ( objCObj === null || typeof objCObj !== 'object' ) {
420
- return objCObj ;
421
- }
422
- let node , key , i , l ;
423
- const oKeyArr = objCObj . allKeys ;
424
-
425
- if ( oKeyArr === undefined && objCObj . count !== undefined ) {
426
- // array
427
- node = [ ] ;
428
- for ( i = 0 , l = objCObj . count ; i < l ; i ++ ) {
429
- key = objCObj . objectAtIndex ( i ) ;
430
- node . push ( toJsObject ( key ) ) ;
431
- }
432
- } else if ( oKeyArr !== undefined ) {
433
- // object
434
- node = { } ;
435
- for ( i = 0 , l = oKeyArr . count ; i < l ; i ++ ) {
436
- key = oKeyArr . objectAtIndex ( i ) ;
437
- const val = objCObj . valueForKey ( key ) ;
438
-
439
- // Firestore can store nulls
440
- if ( val === null ) {
441
- node [ key ] = null ;
442
- continue ;
443
- }
444
- node [ key ] = getValueForClass ( val ) ;
445
- }
446
- } else {
447
- node = getValueForClass ( objCObj ) ;
448
- }
449
-
450
- return node ;
451
- }
452
-
453
- function getValueForClass ( val ) {
454
- switch ( getClass ( val ) ) {
455
- case 'NSArray' :
456
- case 'NSMutableArray' :
457
- return toJsObject ( val ) ;
458
- case 'NSDictionary' :
459
- case 'NSMutableDictionary' :
460
- return toJsObject ( val ) ;
461
- case 'String' :
462
- return String ( val ) ;
463
- case 'Boolean' :
464
- return val ;
465
- case 'Number' :
466
- case 'NSDecimalNumber' :
467
- return Number ( String ( val ) ) ;
468
- case 'Date' :
469
- return new Date ( val ) ;
470
-
471
- default :
472
- return String ( val ) ;
473
- }
474
- }
475
328
476
329
function dictToJSON ( dict ) {
477
- JSON . parse ( NSString . alloc ( ) . initWithDataEncoding ( NSJSONSerialization . dataWithJSONObjectOptionsError ( dict , 0 ) , NSUTF8StringEncoding ) as any ) ;
330
+ return JSON . parse ( NSString . alloc ( ) . initWithDataEncoding ( NSJSONSerialization . dataWithJSONObjectOptionsError ( dict , 0 ) , NSUTF8StringEncoding ) as any ) ;
478
331
}
479
332
export async function fetchNativeDeviceContexts ( ) {
480
333
if ( ! enableNative ) {
481
334
throw _DisabledNativeError ;
482
335
}
483
- const contexts = { } ;
336
+ let contexts = { } ;
484
337
NSSentrySDK . configureScope ( ( scope ) => {
485
338
try {
486
-
487
- const serializedScope = scope . serialize ( ) ;
488
- // console.log('toto' , dictToJSON(serializedScope), NSString.alloc().initWithDataEncoding(NSJSONSerialization.dataWithJSONObjectOptionsError(serializedScope, 0), NSUTF8StringEncoding));
489
- // const context2 = SentryEvent.alloc().init().context;
490
- // console.log('context2' , context2 && dictToJSON(context2));
491
- const tempContexts = ( serializedScope . valueForKey ( 'context' ) ) ;
492
- const tempUser = serializedScope . valueForKey ( 'user' ) ;
493
- const user = { } ;
494
- if ( tempUser ) {
495
- Object . assign ( user , dictToJSON ( tempUser . valueForKey ( 'user' ) ) ) ;
496
- } else {
497
- user [ 'id' ] = NSSentrySDK . installationID ;
498
- }
499
- contexts [ 'user' ] = user ;
500
-
501
- if ( tempContexts ) {
502
- contexts [ 'context' ] = dictToJSON ( tempContexts ) ;
503
- }
339
+ const result = dictToJSON ( scope . serialize ( ) ) ;
340
+ result [ 'user' ] = result [ 'user' ] || { id : NSSentrySDK . installationID } ;
341
+ contexts = result ;
504
342
} catch ( error ) {
505
343
console . error ( 'fetchNativeDeviceContexts' , error , error . stack ) ;
506
344
}
@@ -524,21 +362,21 @@ export namespace NATIVE {
524
362
// }
525
363
// NSSentrySDK.captureUserFeedback(userFeedback);
526
364
// }
527
- function eventLevel ( level ) {
528
- switch ( level ) {
529
- case 'fatal' :
530
- return SentryLevel . kSentryLevelFatal ;
531
- case 'warning' :
532
- return SentryLevel . kSentryLevelWarning ;
533
- case 'info' :
534
- case 'log' :
535
- return SentryLevel . kSentryLevelInfo ;
536
- case 'debug' :
537
- return SentryLevel . kSentryLevelDebug ;
538
- default :
539
- return SentryLevel . kSentryLevelError ;
540
- }
541
- }
365
+ // function eventLevel(level) {
366
+ // switch (level) {
367
+ // case 'fatal':
368
+ // return SentryLevel.kSentryLevelFatal;
369
+ // case 'warning':
370
+ // return SentryLevel.kSentryLevelWarning;
371
+ // case 'info':
372
+ // case 'log':
373
+ // return SentryLevel.kSentryLevelInfo;
374
+ // case 'debug':
375
+ // return SentryLevel.kSentryLevelDebug;
376
+ // default:
377
+ // return SentryLevel.kSentryLevelError;
378
+ // }
379
+ // }
542
380
543
381
// export function setUser(user: User | null, otherUserKeys) {
544
382
// if (!enableNative) {
0 commit comments