@@ -76,9 +76,6 @@ public class SentryFlutterPlugin: NSObject, FlutterPlugin {
7676 case " closeNativeSdk " :
7777 closeNativeSdk ( call, result: result)
7878
79- case " fetchNativeAppStart " :
80- fetchNativeAppStart ( result: result)
81-
8279 case " setContexts " :
8380 let arguments = call. arguments as? [ String : Any ? ]
8481 let key = arguments ? [ " key " ] as? String
@@ -291,83 +288,6 @@ public class SentryFlutterPlugin: NSObject, FlutterPlugin {
291288 return !name. isEmpty
292289 }
293290
294- struct TimeSpan {
295- var startTimestampMsSinceEpoch : NSNumber
296- var stopTimestampMsSinceEpoch : NSNumber
297- var description : String
298-
299- func addToMap( _ map: inout [ String : Any ] ) {
300- map [ description] = [
301- " startTimestampMsSinceEpoch " : startTimestampMsSinceEpoch,
302- " stopTimestampMsSinceEpoch " : stopTimestampMsSinceEpoch
303- ]
304- }
305- }
306-
307- private func fetchNativeAppStart( result: @escaping FlutterResult ) {
308- #if os(iOS) || os(tvOS)
309- guard let appStartMeasurement = PrivateSentrySDKOnly . appStartMeasurement else {
310- print ( " warning: appStartMeasurement is null " )
311- result ( nil )
312- return
313- }
314-
315- var nativeSpanTimes : [ String : Any ] = [ : ]
316-
317- let appStartTimeMs = appStartMeasurement. appStartTimestamp. timeIntervalSince1970. toMilliseconds ( )
318- let runtimeInitTimeMs = appStartMeasurement. runtimeInitTimestamp. timeIntervalSince1970. toMilliseconds ( )
319- let moduleInitializationTimeMs =
320- appStartMeasurement. moduleInitializationTimestamp. timeIntervalSince1970. toMilliseconds ( )
321- let sdkStartTimeMs = appStartMeasurement. sdkStartTimestamp. timeIntervalSince1970. toMilliseconds ( )
322-
323- if !appStartMeasurement. isPreWarmed {
324- let preRuntimeInitDescription = " Pre Runtime Init "
325- let preRuntimeInitSpan = TimeSpan (
326- startTimestampMsSinceEpoch: NSNumber ( value: appStartTimeMs) ,
327- stopTimestampMsSinceEpoch: NSNumber ( value: runtimeInitTimeMs) ,
328- description: preRuntimeInitDescription
329- )
330- preRuntimeInitSpan. addToMap ( & nativeSpanTimes)
331-
332- let moduleInitializationDescription = " Runtime init to Pre Main initializers "
333- let moduleInitializationSpan = TimeSpan (
334- startTimestampMsSinceEpoch: NSNumber ( value: runtimeInitTimeMs) ,
335- stopTimestampMsSinceEpoch: NSNumber ( value: moduleInitializationTimeMs) ,
336- description: moduleInitializationDescription
337- )
338- moduleInitializationSpan. addToMap ( & nativeSpanTimes)
339- }
340-
341- let uiKitInitDescription = " UIKit init "
342- let uiKitInitSpan = TimeSpan (
343- startTimestampMsSinceEpoch: NSNumber ( value: moduleInitializationTimeMs) ,
344- stopTimestampMsSinceEpoch: NSNumber ( value: sdkStartTimeMs) ,
345- description: uiKitInitDescription
346- )
347- uiKitInitSpan. addToMap ( & nativeSpanTimes)
348-
349- // Info: We don't have access to didFinishLaunchingTimestamp,
350- // On HybridSDKs, the Cocoa SDK misses the didFinishLaunchNotification and the
351- // didBecomeVisibleNotification. Therefore, we can't set the
352- // didFinishLaunchingTimestamp
353-
354- let appStartTime = appStartMeasurement. appStartTimestamp. timeIntervalSince1970 * 1000
355- let isColdStart = appStartMeasurement. type == . cold
356-
357- let item : [ String : Any ] = [
358- " pluginRegistrationTime " : SentryFlutterPlugin . pluginRegistrationTime,
359- " appStartTime " : appStartTime,
360- " isColdStart " : isColdStart,
361- " nativeSpanTimes " : nativeSpanTimes
362- ]
363-
364- result ( item)
365- #else
366- print ( " note: appStartMeasurement not available on this platform " )
367- result ( nil )
368- #endif
369- }
370-
371291 private func setContexts( key: String ? , value: Any ? , result: @escaping FlutterResult ) {
372292 guard let key = key else {
373293 result ( " " )
@@ -565,6 +485,62 @@ public class SentryFlutterPlugin: NSObject, FlutterPlugin {
565485 }
566486 #endif
567487
488+ @objc public class func fetchNativeAppStartAsBytes( ) -> NSData ? {
489+ #if os(iOS) || os(tvOS)
490+ guard let appStartMeasurement = PrivateSentrySDKOnly . appStartMeasurement else {
491+ return nil
492+ }
493+
494+ var nativeSpanTimes : [ String : Any ] = [ : ]
495+
496+ let appStartTimeMs = appStartMeasurement. appStartTimestamp. timeIntervalSince1970. toMilliseconds ( )
497+ let runtimeInitTimeMs = appStartMeasurement. runtimeInitTimestamp. timeIntervalSince1970. toMilliseconds ( )
498+ let moduleInitializationTimeMs =
499+ appStartMeasurement. moduleInitializationTimestamp. timeIntervalSince1970. toMilliseconds ( )
500+ let sdkStartTimeMs = appStartMeasurement. sdkStartTimestamp. timeIntervalSince1970. toMilliseconds ( )
501+
502+ if !appStartMeasurement. isPreWarmed {
503+ let preRuntimeInitDescription = " Pre Runtime Init "
504+ let preRuntimeInitSpan : [ String : Any ] = [
505+ " startTimestampMsSinceEpoch " : NSNumber ( value: appStartTimeMs) ,
506+ " stopTimestampMsSinceEpoch " : NSNumber ( value: runtimeInitTimeMs)
507+ ]
508+ nativeSpanTimes [ preRuntimeInitDescription] = preRuntimeInitSpan
509+
510+ let moduleInitializationDescription = " Runtime init to Pre Main initializers "
511+ let moduleInitializationSpan : [ String : Any ] = [
512+ " startTimestampMsSinceEpoch " : NSNumber ( value: runtimeInitTimeMs) ,
513+ " stopTimestampMsSinceEpoch " : NSNumber ( value: moduleInitializationTimeMs)
514+ ]
515+ nativeSpanTimes [ moduleInitializationDescription] = moduleInitializationSpan
516+ }
517+
518+ let uiKitInitDescription = " UIKit init "
519+ let uiKitInitSpan : [ String : Any ] = [
520+ " startTimestampMsSinceEpoch " : NSNumber ( value: moduleInitializationTimeMs) ,
521+ " stopTimestampMsSinceEpoch " : NSNumber ( value: sdkStartTimeMs)
522+ ]
523+ nativeSpanTimes [ uiKitInitDescription] = uiKitInitSpan
524+
525+ let appStartTime = appStartMeasurement. appStartTimestamp. timeIntervalSince1970 * 1000
526+ let isColdStart = appStartMeasurement. type == . cold
527+
528+ let item : [ String : Any ] = [
529+ " pluginRegistrationTime " : pluginRegistrationTime,
530+ " appStartTime " : appStartTime,
531+ " isColdStart " : isColdStart,
532+ " nativeSpanTimes " : nativeSpanTimes
533+ ]
534+
535+ if let data = try ? JSONSerialization . data ( withJSONObject: item, options: [ ] ) {
536+ return data as NSData
537+ }
538+ return nil
539+ #else
540+ return nil
541+ #endif
542+ }
543+
568544 @objc ( loadDebugImagesAsBytes: )
569545 public class func loadDebugImagesAsBytes( instructionAddresses: Set < String > ) -> NSData ? {
570546 var debugImages : [ DebugMeta ] = [ ]
0 commit comments