@grafana/faro-react-native 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +176 -30
- package/android/build.gradle +17 -12
- package/android/src/main/java/com/grafana/faro/reactnative/FaroCrashIds.kt +44 -0
- package/android/src/main/java/com/grafana/faro/reactnative/FaroCrashReporter.kt +134 -38
- package/android/src/main/java/com/grafana/faro/reactnative/FaroCrashSessionStore.kt +433 -0
- package/android/src/main/java/com/grafana/faro/reactnative/FaroCrashTraceCache.kt +11 -2
- package/android/src/main/java/com/grafana/faro/reactnative/FaroReactNativeModule.kt +128 -17
- package/android/src/main/java/com/grafana/faro/reactnative/FaroSessionProcess.kt +88 -0
- package/android/src/main/java/com/grafana/faro/reactnative/FrameMonitor.kt +34 -42
- package/android/src/test/java/com/grafana/faro/reactnative/FaroCrashReporterBelowApi30Test.kt +21 -0
- package/android/src/test/java/com/grafana/faro/reactnative/FaroCrashReporterTest.kt +59 -0
- package/android/src/test/java/com/grafana/faro/reactnative/FaroCrashSessionStoreTest.kt +268 -0
- package/android/src/test/java/com/grafana/faro/reactnative/FaroCrashTraceCacheTest.kt +52 -0
- package/android/src/test/java/com/grafana/faro/reactnative/FaroSessionProcessTest.kt +127 -0
- package/dist/cjs/config/getRNInstrumentations.js +6 -8
- package/dist/cjs/config/getRNInstrumentations.js.map +1 -1
- package/dist/cjs/config/sampling.js.map +1 -1
- package/dist/cjs/config/types.js.map +1 -1
- package/dist/cjs/dataCollection/DataCollectionPolicy.js +1 -2
- package/dist/cjs/dataCollection/DataCollectionPolicy.js.map +1 -1
- package/dist/cjs/generated/faroRNPackageMeta.js +1 -1
- package/dist/cjs/generated/faroRNPackageMeta.js.map +1 -1
- package/dist/cjs/index.js +8 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/instrumentations/anr/instrumentation.js +10 -1
- package/dist/cjs/instrumentations/anr/instrumentation.js.map +1 -1
- package/dist/cjs/instrumentations/appState/index.js +8 -2
- package/dist/cjs/instrumentations/appState/index.js.map +1 -1
- package/dist/cjs/instrumentations/crashReporting/BaseCrashReportingInstrumentation.js +19 -6
- package/dist/cjs/instrumentations/crashReporting/BaseCrashReportingInstrumentation.js.map +1 -1
- package/dist/cjs/instrumentations/crashReporting/RecoveredCrashReportingInstrumentation.js +331 -0
- package/dist/cjs/instrumentations/crashReporting/RecoveredCrashReportingInstrumentation.js.map +1 -0
- package/dist/cjs/instrumentations/crashReporting/android/AndroidCrashReportingInstrumentation.js +2 -2
- package/dist/cjs/instrumentations/crashReporting/android/AndroidCrashReportingInstrumentation.js.map +1 -1
- package/dist/cjs/instrumentations/crashReporting/ios/IosCrashReportingInstrumentation.js +2 -2
- package/dist/cjs/instrumentations/crashReporting/ios/IosCrashReportingInstrumentation.js.map +1 -1
- package/dist/cjs/instrumentations/crashReporting/types.js.map +1 -1
- package/dist/cjs/instrumentations/errors/index.js +8 -3
- package/dist/cjs/instrumentations/errors/index.js.map +1 -1
- package/dist/cjs/instrumentations/frameMonitoring/instrumentation.js +20 -31
- package/dist/cjs/instrumentations/frameMonitoring/instrumentation.js.map +1 -1
- package/dist/cjs/instrumentations/frameMonitoring/types.js.map +1 -1
- package/dist/cjs/instrumentations/performance/index.js +2 -6
- package/dist/cjs/instrumentations/performance/index.js.map +1 -1
- package/dist/cjs/instrumentations/session/FaroSessionActivityBoundary.js +48 -0
- package/dist/cjs/instrumentations/session/FaroSessionActivityBoundary.js.map +1 -0
- package/dist/cjs/instrumentations/session/directSessionActivity.js +37 -0
- package/dist/cjs/instrumentations/session/directSessionActivity.js.map +1 -0
- package/dist/cjs/instrumentations/session/index.js +214 -45
- package/dist/cjs/instrumentations/session/index.js.map +1 -1
- package/dist/cjs/instrumentations/session/sessionActivity.js +43 -0
- package/dist/cjs/instrumentations/session/sessionActivity.js.map +1 -0
- package/dist/cjs/instrumentations/session/sessionAttributes.js +8 -8
- package/dist/cjs/instrumentations/session/sessionAttributes.js.map +1 -1
- package/dist/cjs/instrumentations/session/sessionManager/MmkvPersistentSessionsManager.js +199 -24
- package/dist/cjs/instrumentations/session/sessionManager/MmkvPersistentSessionsManager.js.map +1 -1
- package/dist/cjs/instrumentations/session/sessionManager/VolatileSessionManager.js +31 -13
- package/dist/cjs/instrumentations/session/sessionManager/VolatileSessionManager.js.map +1 -1
- package/dist/cjs/instrumentations/session/sessionManager/persistentSessionRecord.js +72 -0
- package/dist/cjs/instrumentations/session/sessionManager/persistentSessionRecord.js.map +1 -0
- package/dist/cjs/instrumentations/session/sessionManager/sessionConstants.js +1 -1
- package/dist/cjs/instrumentations/session/sessionManager/sessionConstants.js.map +1 -1
- package/dist/cjs/instrumentations/session/sessionManager/sessionManagerUtils.js +124 -96
- package/dist/cjs/instrumentations/session/sessionManager/sessionManagerUtils.js.map +1 -1
- package/dist/cjs/instrumentations/session/sessionManager/types.js.map +1 -1
- package/dist/cjs/instrumentations/session/sessionProcess.js +96 -0
- package/dist/cjs/instrumentations/session/sessionProcess.js.map +1 -0
- package/dist/cjs/instrumentations/startup/index.js +2 -6
- package/dist/cjs/instrumentations/startup/index.js.map +1 -1
- package/dist/cjs/navigation/utils.js +3 -1
- package/dist/cjs/navigation/utils.js.map +1 -1
- package/dist/cjs/transports/fetch/index.js.map +1 -1
- package/dist/cjs/transports/fetch/transport.js +56 -25
- package/dist/cjs/transports/fetch/transport.js.map +1 -1
- package/dist/cjs/transports/fetch/types.js.map +1 -1
- package/dist/cjs/transports/offline/ConnectivityService.js +1 -1
- package/dist/cjs/transports/offline/ConnectivityService.js.map +1 -1
- package/dist/cjs/transports/offline/OfflineCache.js +2 -2
- package/dist/cjs/transports/offline/OfflineCache.js.map +1 -1
- package/dist/cjs/transports/offline/transport.js +3 -4
- package/dist/cjs/transports/offline/transport.js.map +1 -1
- package/dist/cjs/userPersistence/UserPersistence.js +1 -2
- package/dist/cjs/userPersistence/UserPersistence.js.map +1 -1
- package/dist/esm/config/getRNInstrumentations.js +6 -8
- package/dist/esm/config/getRNInstrumentations.js.map +1 -1
- package/dist/esm/config/sampling.js.map +1 -1
- package/dist/esm/config/types.js.map +1 -1
- package/dist/esm/dataCollection/DataCollectionPolicy.js +1 -2
- package/dist/esm/dataCollection/DataCollectionPolicy.js.map +1 -1
- package/dist/esm/generated/faroRNPackageMeta.js +1 -1
- package/dist/esm/generated/faroRNPackageMeta.js.map +1 -1
- package/dist/esm/index.js +4 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/instrumentations/anr/instrumentation.js +6 -1
- package/dist/esm/instrumentations/anr/instrumentation.js.map +1 -1
- package/dist/esm/instrumentations/appState/index.js +8 -2
- package/dist/esm/instrumentations/appState/index.js.map +1 -1
- package/dist/esm/instrumentations/crashReporting/BaseCrashReportingInstrumentation.js +15 -4
- package/dist/esm/instrumentations/crashReporting/BaseCrashReportingInstrumentation.js.map +1 -1
- package/dist/esm/instrumentations/crashReporting/RecoveredCrashReportingInstrumentation.js +230 -0
- package/dist/esm/instrumentations/crashReporting/RecoveredCrashReportingInstrumentation.js.map +1 -0
- package/dist/esm/instrumentations/crashReporting/android/AndroidCrashReportingInstrumentation.js +2 -2
- package/dist/esm/instrumentations/crashReporting/android/AndroidCrashReportingInstrumentation.js.map +1 -1
- package/dist/esm/instrumentations/crashReporting/ios/IosCrashReportingInstrumentation.js +2 -2
- package/dist/esm/instrumentations/crashReporting/ios/IosCrashReportingInstrumentation.js.map +1 -1
- package/dist/esm/instrumentations/crashReporting/types.js.map +1 -1
- package/dist/esm/instrumentations/errors/index.js +8 -3
- package/dist/esm/instrumentations/errors/index.js.map +1 -1
- package/dist/esm/instrumentations/frameMonitoring/instrumentation.js +17 -32
- package/dist/esm/instrumentations/frameMonitoring/instrumentation.js.map +1 -1
- package/dist/esm/instrumentations/frameMonitoring/types.js.map +1 -1
- package/dist/esm/instrumentations/performance/index.js +2 -6
- package/dist/esm/instrumentations/performance/index.js.map +1 -1
- package/dist/esm/instrumentations/session/FaroSessionActivityBoundary.js +34 -0
- package/dist/esm/instrumentations/session/FaroSessionActivityBoundary.js.map +1 -0
- package/dist/esm/instrumentations/session/directSessionActivity.js +32 -0
- package/dist/esm/instrumentations/session/directSessionActivity.js.map +1 -0
- package/dist/esm/instrumentations/session/index.js +207 -46
- package/dist/esm/instrumentations/session/index.js.map +1 -1
- package/dist/esm/instrumentations/session/sessionActivity.js +38 -0
- package/dist/esm/instrumentations/session/sessionActivity.js.map +1 -0
- package/dist/esm/instrumentations/session/sessionAttributes.js +7 -7
- package/dist/esm/instrumentations/session/sessionAttributes.js.map +1 -1
- package/dist/esm/instrumentations/session/sessionManager/MmkvPersistentSessionsManager.js +190 -27
- package/dist/esm/instrumentations/session/sessionManager/MmkvPersistentSessionsManager.js.map +1 -1
- package/dist/esm/instrumentations/session/sessionManager/VolatileSessionManager.js +31 -14
- package/dist/esm/instrumentations/session/sessionManager/VolatileSessionManager.js.map +1 -1
- package/dist/esm/instrumentations/session/sessionManager/persistentSessionRecord.js +56 -0
- package/dist/esm/instrumentations/session/sessionManager/persistentSessionRecord.js.map +1 -0
- package/dist/esm/instrumentations/session/sessionManager/sessionConstants.js +1 -1
- package/dist/esm/instrumentations/session/sessionManager/sessionConstants.js.map +1 -1
- package/dist/esm/instrumentations/session/sessionManager/sessionManagerUtils.js +120 -44
- package/dist/esm/instrumentations/session/sessionManager/sessionManagerUtils.js.map +1 -1
- package/dist/esm/instrumentations/session/sessionManager/types.js.map +1 -1
- package/dist/esm/instrumentations/session/sessionProcess.js +89 -0
- package/dist/esm/instrumentations/session/sessionProcess.js.map +1 -0
- package/dist/esm/instrumentations/startup/index.js +2 -6
- package/dist/esm/instrumentations/startup/index.js.map +1 -1
- package/dist/esm/navigation/utils.js +2 -1
- package/dist/esm/navigation/utils.js.map +1 -1
- package/dist/esm/transports/fetch/index.js.map +1 -1
- package/dist/esm/transports/fetch/transport.js +38 -14
- package/dist/esm/transports/fetch/transport.js.map +1 -1
- package/dist/esm/transports/fetch/types.js.map +1 -1
- package/dist/esm/transports/offline/ConnectivityService.js +1 -1
- package/dist/esm/transports/offline/ConnectivityService.js.map +1 -1
- package/dist/esm/transports/offline/OfflineCache.js +2 -2
- package/dist/esm/transports/offline/OfflineCache.js.map +1 -1
- package/dist/esm/transports/offline/transport.js +3 -4
- package/dist/esm/transports/offline/transport.js.map +1 -1
- package/dist/esm/userPersistence/UserPersistence.js +1 -2
- package/dist/esm/userPersistence/UserPersistence.js.map +1 -1
- package/dist/types/config/getRNInstrumentations.d.ts +1 -2
- package/dist/types/config/sampling.d.ts +0 -3
- package/dist/types/config/types.d.ts +5 -3
- package/dist/types/dataCollection/DataCollectionPolicy.d.ts +1 -2
- package/dist/types/generated/faroRNPackageMeta.d.ts +1 -1
- package/dist/types/index.d.ts +4 -1
- package/dist/types/instrumentations/crashReporting/BaseCrashReportingInstrumentation.d.ts +14 -4
- package/dist/types/instrumentations/crashReporting/RecoveredCrashReportingInstrumentation.d.ts +27 -0
- package/dist/types/instrumentations/crashReporting/android/AndroidCrashReportingInstrumentation.d.ts +2 -2
- package/dist/types/instrumentations/crashReporting/ios/IosCrashReportingInstrumentation.d.ts +2 -2
- package/dist/types/instrumentations/crashReporting/types.d.ts +6 -0
- package/dist/types/instrumentations/frameMonitoring/instrumentation.d.ts +2 -2
- package/dist/types/instrumentations/frameMonitoring/types.d.ts +4 -6
- package/dist/types/instrumentations/performance/index.d.ts +0 -2
- package/dist/types/instrumentations/session/FaroSessionActivityBoundary.d.ts +8 -0
- package/dist/types/instrumentations/session/directSessionActivity.d.ts +13 -0
- package/dist/types/instrumentations/session/index.d.ts +20 -1
- package/dist/types/instrumentations/session/sessionActivity.d.ts +9 -0
- package/dist/types/instrumentations/session/sessionAttributes.d.ts +6 -3
- package/dist/types/instrumentations/session/sessionManager/MmkvPersistentSessionsManager.d.ts +16 -3
- package/dist/types/instrumentations/session/sessionManager/VolatileSessionManager.d.ts +9 -3
- package/dist/types/instrumentations/session/sessionManager/persistentSessionRecord.d.ts +4 -0
- package/dist/types/instrumentations/session/sessionManager/sessionManagerUtils.d.ts +19 -7
- package/dist/types/instrumentations/session/sessionManager/types.d.ts +6 -0
- package/dist/types/instrumentations/session/sessionProcess.d.ts +17 -0
- package/dist/types/instrumentations/startup/index.d.ts +2 -6
- package/dist/types/navigation/utils.d.ts +1 -0
- package/dist/types/transports/fetch/index.d.ts +1 -1
- package/dist/types/transports/fetch/transport.d.ts +8 -1
- package/dist/types/transports/fetch/types.d.ts +5 -0
- package/dist/types/transports/offline/ConnectivityService.d.ts +1 -1
- package/dist/types/transports/offline/OfflineCache.d.ts +2 -2
- package/dist/types/transports/offline/transport.d.ts +3 -4
- package/dist/types/userPersistence/UserPersistence.d.ts +1 -2
- package/ios/FaroCrashReporter.swift +214 -21
- package/ios/FaroReactNative.swift +24 -0
- package/ios/FaroReactNativeModule.h +2 -1
- package/ios/FaroReactNativeModule.mm +121 -6
- package/ios/RefreshRateVitals.swift +34 -38
- package/package.json +7 -5
- package/src/config/getRNInstrumentations.ts +6 -8
- package/src/config/makeRNConfig.test.ts +6 -0
- package/src/config/sampling.ts +0 -3
- package/src/config/types.ts +5 -3
- package/src/dataCollection/DataCollectionPolicy.ts +1 -2
- package/src/generated/faroRNPackageMeta.ts +1 -1
- package/src/index.ts +8 -2
- package/src/instrumentations/anr/instrumentation.ts +8 -1
- package/src/instrumentations/appState/index.ts +10 -2
- package/src/instrumentations/crashReporting/BaseCrashReportingInstrumentation.ts +28 -8
- package/src/instrumentations/crashReporting/RecoveredCrashReportingInstrumentation.ts +277 -0
- package/src/instrumentations/crashReporting/android/AndroidCrashReportingInstrumentation.ts +2 -2
- package/src/instrumentations/crashReporting/instrumentation.test.ts +433 -5
- package/src/instrumentations/crashReporting/ios/IosCrashReportingInstrumentation.ts +2 -2
- package/src/instrumentations/crashReporting/types.ts +7 -0
- package/src/instrumentations/errors/index.ts +12 -4
- package/src/instrumentations/errors/instrumentation.test.ts +35 -0
- package/src/instrumentations/frameMonitoring/instrumentation.test.ts +155 -0
- package/src/instrumentations/frameMonitoring/instrumentation.ts +19 -38
- package/src/instrumentations/frameMonitoring/types.ts +4 -6
- package/src/instrumentations/performance/index.ts +2 -6
- package/src/instrumentations/session/FaroSessionActivityBoundary.test.ts +60 -0
- package/src/instrumentations/session/FaroSessionActivityBoundary.tsx +41 -0
- package/src/instrumentations/session/beforeSendHook.test.ts +246 -0
- package/src/instrumentations/session/directSessionActivity.test.ts +158 -0
- package/src/instrumentations/session/directSessionActivity.ts +36 -0
- package/src/instrumentations/session/index.ts +269 -46
- package/src/instrumentations/session/persistentColdStart.test.ts +196 -0
- package/src/instrumentations/session/sessionActivity.test.ts +68 -0
- package/src/instrumentations/session/sessionActivity.ts +58 -0
- package/src/instrumentations/session/sessionAttributes.test.ts +37 -2
- package/src/instrumentations/session/sessionAttributes.ts +12 -6
- package/src/instrumentations/session/sessionCleanup.test.ts +410 -0
- package/src/instrumentations/session/sessionManager/MmkvPersistentSessionsManager.test.ts +552 -0
- package/src/instrumentations/session/sessionManager/MmkvPersistentSessionsManager.ts +249 -33
- package/src/instrumentations/session/sessionManager/VolatileSessionManager.ts +38 -18
- package/src/instrumentations/session/sessionManager/persistentSessionRecord.test.ts +103 -0
- package/src/instrumentations/session/sessionManager/persistentSessionRecord.ts +78 -0
- package/src/instrumentations/session/sessionManager/sampling.test.ts +1 -1
- package/src/instrumentations/session/sessionManager/sessionConstants.ts +1 -1
- package/src/instrumentations/session/sessionManager/sessionManagerUtils.test.ts +256 -18
- package/src/instrumentations/session/sessionManager/sessionManagerUtils.ts +180 -39
- package/src/instrumentations/session/sessionManager/types.ts +8 -0
- package/src/instrumentations/session/sessionManagerInstance.test.ts +65 -0
- package/src/instrumentations/session/sessionProcess.test.ts +136 -0
- package/src/instrumentations/session/sessionProcess.ts +114 -0
- package/src/instrumentations/session/startNewSession.test.ts +337 -0
- package/src/instrumentations/startup/index.ts +2 -6
- package/src/navigation/utils.ts +3 -1
- package/src/transports/fetch/index.ts +6 -1
- package/src/transports/fetch/transport.test.ts +86 -2
- package/src/transports/fetch/transport.ts +38 -16
- package/src/transports/fetch/types.ts +7 -0
- package/src/transports/offline/ConnectivityService.ts +1 -1
- package/src/transports/offline/OfflineCache.ts +2 -2
- package/src/transports/offline/transport.ts +3 -4
- package/src/userPersistence/UserPersistence.ts +1 -2
- package/dist/cjs/utils/throttle.js +0 -42
- package/dist/cjs/utils/throttle.js.map +0 -1
- package/dist/esm/utils/throttle.js +0 -34
- package/dist/esm/utils/throttle.js.map +0 -1
- package/dist/types/utils/throttle.d.ts +0 -9
- package/src/utils/throttle.test.ts +0 -141
- package/src/utils/throttle.ts +0 -34
package/dist/cjs/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.defaultLogLevel = exports.allLogLevels = exports.InternalLoggerLevel = exports.LogLevel = void 0;
|
|
3
|
+
exports.createNavigationStateChangeHandler = exports.useFaroNavigation = exports.ReactNativeNavigationIntegration = exports.setUserPersistence = exports.initializeUserPersistence = exports.getUserPersistence = exports.createUserPersistence = exports.setDataCollectionPolicy = exports.initializeDataCollectionPolicy = exports.getDataCollectionPolicy = exports.createDataCollectionPolicy = exports.OfflineTransport = exports.ConsoleTransport = exports.FetchTransport = exports.getSdkMeta = exports.getScreenMeta = exports.getPageMeta = exports.withFaroErrorBoundary = exports.FaroErrorBoundary = exports.notifyHttpRequestStart = exports.notifyHttpRequestEnd = exports.trackUserAction = exports.withFaroUserAction = exports.reactNativeLogArgsSerializer = exports.CrashReportingInstrumentation = exports.ANRInstrumentation = exports.FrameMonitoringInstrumentation = exports.StartupInstrumentation = exports.PerformanceInstrumentation = exports.XHRInstrumentation = exports.HttpInstrumentation = exports.UserActionInstrumentation = exports.AppStateInstrumentation = exports.ViewInstrumentation = exports.minimalSessionDeviceAttributes = exports.loadSessionDeviceAttributesForInit = exports.loadMobileMetaForInit = exports.getSessionAttributes = exports.notifySessionActivity = exports.FaroSessionActivityBoundary = exports.SessionInstrumentation = exports.startNewSession = exports.ConsoleInstrumentation = exports.ErrorsInstrumentation = exports.ErrorMechanism = exports.getRNInstrumentations = exports.SamplingRate = exports.SamplingFunction = exports.faro = exports.initializeFaro = void 0;
|
|
4
|
+
exports.defaultLogLevel = exports.allLogLevels = exports.InternalLoggerLevel = exports.LogLevel = exports.onNavigationStateChange = exports.getRouteName = exports.getCurrentRoute = void 0;
|
|
5
5
|
// Main entry point for @grafana/faro-react-native
|
|
6
6
|
// Apply PerformanceObserver polyfill first to prevent iOS bad_variant_access crash
|
|
7
7
|
var performanceObserverPolyfill_1 = require("./util/performanceObserverPolyfill");
|
|
@@ -10,7 +10,7 @@ var initialize_1 = require("./initialize");
|
|
|
10
10
|
Object.defineProperty(exports, "initializeFaro", { enumerable: true, get: function () { return initialize_1.initializeFaro; } });
|
|
11
11
|
var faro_core_1 = require("@grafana/faro-core");
|
|
12
12
|
Object.defineProperty(exports, "faro", { enumerable: true, get: function () { return faro_core_1.faro; } });
|
|
13
|
-
// Export sampling
|
|
13
|
+
// Export sampling
|
|
14
14
|
var sampling_1 = require("./config/sampling");
|
|
15
15
|
Object.defineProperty(exports, "SamplingFunction", { enumerable: true, get: function () { return sampling_1.SamplingFunction; } });
|
|
16
16
|
Object.defineProperty(exports, "SamplingRate", { enumerable: true, get: function () { return sampling_1.SamplingRate; } });
|
|
@@ -24,7 +24,12 @@ Object.defineProperty(exports, "ErrorsInstrumentation", { enumerable: true, get:
|
|
|
24
24
|
var console_1 = require("./instrumentations/console");
|
|
25
25
|
Object.defineProperty(exports, "ConsoleInstrumentation", { enumerable: true, get: function () { return console_1.ConsoleInstrumentation; } });
|
|
26
26
|
var session_1 = require("./instrumentations/session");
|
|
27
|
+
Object.defineProperty(exports, "startNewSession", { enumerable: true, get: function () { return session_1.startNewSession; } });
|
|
27
28
|
Object.defineProperty(exports, "SessionInstrumentation", { enumerable: true, get: function () { return session_1.SessionInstrumentation; } });
|
|
29
|
+
var FaroSessionActivityBoundary_1 = require("./instrumentations/session/FaroSessionActivityBoundary");
|
|
30
|
+
Object.defineProperty(exports, "FaroSessionActivityBoundary", { enumerable: true, get: function () { return FaroSessionActivityBoundary_1.FaroSessionActivityBoundary; } });
|
|
31
|
+
var directSessionActivity_1 = require("./instrumentations/session/directSessionActivity");
|
|
32
|
+
Object.defineProperty(exports, "notifySessionActivity", { enumerable: true, get: function () { return directSessionActivity_1.notifySessionActivity; } });
|
|
28
33
|
var sessionAttributes_1 = require("./instrumentations/session/sessionAttributes");
|
|
29
34
|
Object.defineProperty(exports, "getSessionAttributes", { enumerable: true, get: function () { return sessionAttributes_1.getSessionAttributes; } });
|
|
30
35
|
Object.defineProperty(exports, "loadMobileMetaForInit", { enumerable: true, get: function () { return sessionAttributes_1.loadMobileMetaForInit; } });
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,kDAAkD;AAClD,mFAAmF;AACnF,kFAAsF;AACtF,IAAA,8DAAgC,GAAE,CAAC;AACnC,2CAA8C;AAArC,4GAAA,cAAc,OAAA;AACvB,gDAA0C;AAAjC,iGAAA,IAAI,OAAA;AAKb,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,kDAAkD;AAClD,mFAAmF;AACnF,kFAAsF;AACtF,IAAA,8DAAgC,GAAE,CAAC;AACnC,2CAA8C;AAArC,4GAAA,cAAc,OAAA;AACvB,gDAA0C;AAAjC,iGAAA,IAAI,OAAA;AAKb,kBAAkB;AAClB,8CAAwG;AAA/F,4GAAA,gBAAgB,OAAA;AAAE,wGAAA,YAAY,OAAA;AAEvC,iCAAiC;AACjC,wEAAuE;AAA9D,8HAAA,qBAAqB,OAAA;AAE9B,0BAA0B;AAC1B,oDAAkF;AAAzE,wGAAA,cAAc,OAAA;AAAE,+GAAA,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OAAA;AAEnB,oBAAoB;AACpB,4CAAoD;AAA3C,uGAAA,cAAc,OAAA;AAEvB,gDAAwD;AAA/C,2GAAA,gBAAgB,OAAA;AAEzB,gDAAwD;AAA/C,2GAAA,gBAAgB,OAAA;AAGzB,gCAAgC;AAChC,mDAK0B;AAJxB,4HAAA,0BAA0B,OAAA;AAC1B,yHAAA,uBAAuB,OAAA;AACvB,gIAAA,8BAA8B,OAAA;AAC9B,yHAAA,uBAAuB,OAAA;AAIzB,0BAA0B;AAC1B,qDAK2B;AAJzB,wHAAA,qBAAqB,OAAA;AACrB,qHAAA,kBAAkB,OAAA;AAClB,4HAAA,yBAAyB,OAAA;AACzB,qHAAA,kBAAkB,OAAA;AAIpB,8BAA8B;AAC9B,sCAAmE;AAA1D,sHAAA,gCAAgC,OAAA;AACzC,2CAMsB;AALpB,+GAAA,iBAAiB,OAAA;AACjB,gIAAA,kCAAkC,OAAA;AAClC,6GAAA,eAAe,OAAA;AACf,0GAAA,YAAY,OAAA;AACZ,qHAAA,uBAAuB,OAAA;AAiBzB,oGAAoG;AACpG,mDAAgG;AAAvF,0GAAA,QAAQ,OAAA;AAAE,qHAAA,mBAAmB,OAAA;AAAE,8GAAA,YAAY,OAAA;AAAE,iHAAA,eAAe,OAAA","sourcesContent":["// Main entry point for @grafana/faro-react-native\n// Apply PerformanceObserver polyfill first to prevent iOS bad_variant_access crash\nimport { applyPerformanceObserverPolyfill } from './util/performanceObserverPolyfill';\napplyPerformanceObserverPolyfill();\nexport { initializeFaro } from './initialize';\nexport { faro } from '@grafana/faro-core';\n\n// Export types\nexport type { EnableTransportsConfig, ReactNativeConfig, ReactNativeSessionTrackingConfig } from './config/types';\n\n// Export sampling\nexport { SamplingFunction, SamplingRate, type Sampling, type SamplingContext } from './config/sampling';\n\n// Export instrumentation helpers\nexport { getRNInstrumentations } from './config/getRNInstrumentations';\n\n// Export instrumentations\nexport { ErrorMechanism, ErrorsInstrumentation } from './instrumentations/errors';\nexport type { ErrorMechanismType, ErrorsInstrumentationOptions } from './instrumentations/errors';\nexport { ConsoleInstrumentation } from './instrumentations/console';\nexport { startNewSession, SessionInstrumentation } from './instrumentations/session';\nexport {\n FaroSessionActivityBoundary,\n type FaroSessionActivityBoundaryProps,\n} from './instrumentations/session/FaroSessionActivityBoundary';\nexport { notifySessionActivity } from './instrumentations/session/directSessionActivity';\nexport {\n getSessionAttributes,\n loadMobileMetaForInit,\n loadSessionDeviceAttributesForInit,\n minimalSessionDeviceAttributes,\n} from './instrumentations/session/sessionAttributes';\nexport type { PreloadedMobileMeta, SessionAttributes } from './instrumentations/session/sessionAttributes';\nexport { ViewInstrumentation } from './instrumentations/view';\nexport { AppStateInstrumentation } from './instrumentations/appState';\nexport { UserActionInstrumentation } from './instrumentations/userActions';\nexport { HttpInstrumentation } from './instrumentations/http';\nexport { XHRInstrumentation } from './instrumentations/xhr';\nexport { PerformanceInstrumentation } from './instrumentations/performance';\nexport type { PerformanceInstrumentationOptions } from './instrumentations/performance/types';\nexport { StartupInstrumentation } from './instrumentations/startup';\nexport type { StartupInstrumentationOptions } from './instrumentations/startup/types';\nexport { FrameMonitoringInstrumentation } from './instrumentations/frameMonitoring';\nexport type { FrameMonitoringOptions } from './instrumentations/frameMonitoring';\nexport { ANRInstrumentation } from './instrumentations/anr';\nexport type { ANRInstrumentationOptions } from './instrumentations/anr';\nexport { CrashReportingInstrumentation } from './instrumentations/crashReporting';\nexport type { CrashReportingOptions } from './instrumentations/crashReporting';\n\n// Export console utilities\nexport { reactNativeLogArgsSerializer } from './instrumentations/console/utils';\n\n// Export user action helpers\nexport {\n withFaroUserAction,\n trackUserAction,\n type WithFaroUserActionProps,\n} from './instrumentations/userActions/withFaroUserAction';\nexport { notifyHttpRequestEnd, notifyHttpRequestStart } from './instrumentations/userActions/httpRequestMonitor';\nexport type { HttpRequestMessagePayload } from './instrumentations/userActions/httpRequestMonitor';\n\n// Export error boundary\nexport { FaroErrorBoundary } from './errorBoundary/FaroErrorBoundary';\nexport { withFaroErrorBoundary } from './errorBoundary/withFaroErrorBoundary';\nexport type {\n FaroErrorBoundaryProps,\n FaroErrorBoundaryState,\n FaroErrorBoundaryFallbackRender,\n} from './errorBoundary/types';\n\n// Export metas\nexport { getPageMeta } from './metas/page';\nexport { getScreenMeta } from './metas/screen';\nexport { getSdkMeta } from './metas/sdk';\n\n// Export transports\nexport { FetchTransport } from './transports/fetch';\nexport type { FetchTransportSendOutcome, FetchTransportSendResult } from './transports/fetch';\nexport { ConsoleTransport } from './transports/console';\nexport type { ConsoleTransportOptions } from './transports/console';\nexport { OfflineTransport } from './transports/offline';\nexport type { OfflineTransportOptions } from './transports/offline';\n\n// Export data collection policy\nexport {\n createDataCollectionPolicy,\n getDataCollectionPolicy,\n initializeDataCollectionPolicy,\n setDataCollectionPolicy,\n} from './dataCollection';\nexport type { DataCollectionPolicy, DataCollectionPolicyOptions } from './dataCollection';\n\n// Export user persistence\nexport {\n createUserPersistence,\n getUserPersistence,\n initializeUserPersistence,\n setUserPersistence,\n} from './userPersistence';\nexport type { UserPersistence, UserPersistenceOptions } from './userPersistence';\n\n// Export navigation utilities\nexport { ReactNativeNavigationIntegration } from './navigation/v6';\nexport {\n useFaroNavigation,\n createNavigationStateChangeHandler,\n getCurrentRoute,\n getRouteName,\n onNavigationStateChange,\n} from './navigation';\nexport type { ReactNavigationDependencies, ReactNavigationConfig } from './navigation/types';\n\n// Re-export core types and enums that consumers will need\nexport type {\n Config,\n Faro,\n Instrumentation,\n Meta,\n Transport,\n PushErrorOptions,\n PushEventOptions,\n PushLogOptions,\n PushMeasurementOptions,\n} from '@grafana/faro-core';\n\n// Export LogLevel and InternalLoggerLevel from our local copy (avoid bundling faro-core's web code)\nexport { LogLevel, InternalLoggerLevel, allLogLevels, defaultLogLevel } from './internalLogger';\n"]}
|
|
@@ -124,7 +124,16 @@ var ANRInstrumentation = /** @class */ (function (_super) {
|
|
|
124
124
|
void this.drainAllAnrSources(nativeModule);
|
|
125
125
|
this.startNativeTracking(nativeModule);
|
|
126
126
|
var emitter = new react_native_1.NativeEventEmitter(nativeModule);
|
|
127
|
-
this.anrEventSubscription = emitter.addListener('onANRDetected', function (
|
|
127
|
+
this.anrEventSubscription = emitter.addListener('onANRDetected', function () {
|
|
128
|
+
var args = [];
|
|
129
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
130
|
+
args[_i] = arguments[_i];
|
|
131
|
+
}
|
|
132
|
+
var anrJson = args[0];
|
|
133
|
+
if (typeof anrJson !== 'string') {
|
|
134
|
+
_this.logWarn('Ignoring onANRDetected event without a string payload');
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
128
137
|
void _this.handleLiveAnrEvent(nativeModule, anrJson);
|
|
129
138
|
});
|
|
130
139
|
void this.checkANRStatus(nativeModule);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../../../src/instrumentations/anr/instrumentation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA2E;AAE3E,gDAAkE;AAElE,qDAAsG;AACtG,yCAAiD;AAEjD,uCAAsD;AAGtD;;GAEG;AACH,IAAM,eAAe,GAAG,IAAI,CAAC;AAE7B;;;GAGG;AACH,IAAM,wBAAwB,GAAG,KAAK,CAAC;AAEvC,6DAA6D;AAC7D,IAAM,yBAAyB,GAAG,KAAM,CAAC;AAEzC,6DAA6D;AAC7D,IAAM,qBAAqB,GAAG,EAAE,CAAC;AAEjC;;;;;;;;;GASG;AACH;IAAwC,sCAAmB;IAUzD,4BAAY,OAAuC;QAAvC,wBAAA,EAAA,YAAuC;;QACjD,YAAA,MAAK,WAAE,SAAC;QAVD,UAAI,GAAG,gDAAgD,CAAC;QACxD,aAAO,GAAG,mBAAO,CAAC;QAGnB,uBAAiB,GAA0C,IAAI,CAAC;QAChE,0BAAoB,GAAyD,IAAI,CAAC;QACzE,2BAAqB,GAAG,IAAI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QACpC,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;QACjC,IAAI,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC;QAEnC,IAAI,uBAAQ,CAAC,EAAE,KAAK,SAAS,EAAE,CAAC;YAC9B,IAAM,YAAY,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;YAC5C,IAAI,YAAY,IAAI,OAAO,YAAY,CAAC,eAAe,KAAK,UAAU,EAAE,CAAC;gBACvE,IAAI,CAAC;oBACH,YAAY,CAAC,eAAe,EAAE,CAAC;gBACjC,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,IAAI,CAAC,QAAQ,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;gBAC7D,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,6BAA6B,CAAC,CAAC;IAC/C,CAAC;IACH,yBAAC;AAAD,CAAC,AA7XD,CAAwC,+BAAmB,GA6X1D;AA7XY,gDAAkB","sourcesContent":["import { NativeEventEmitter, NativeModules, Platform } from 'react-native';\n\nimport { BaseInstrumentation, VERSION } from '@grafana/faro-core';\n\nimport { normalizeJavaStackTraceForRetrace, parseAndroidCrashTrace } from '../crashReporting/android';\nimport { ErrorMechanism } from '../errors/const';\n\nimport { isInvalidAnrCaptureStack } from './anrStack';\nimport type { ANREvent, ANRInstrumentationOptions } from './types';\n\n/**\n * Default timeout for ANR detection (5 seconds, matching Android's threshold)\n */\nconst DEFAULT_TIMEOUT = 5000;\n\n/**\n * Default polling interval for ANR status. Kept short so debug ANRs surface without\n * waiting a full minute; native also emits onANRDetected for immediate delivery.\n */\nconst DEFAULT_POLLING_INTERVAL = 10000;\n\n/** Aligns with native FaroAnrCache.MAX_TIMESTAMP_DELTA_MS */\nconst TIMESTAMP_DEDUP_WINDOW_MS = 10_000;\n\n/** ApplicationExitInfo ANR traces (Android 11 / API 30+). */\nconst APP_EXIT_INFO_MIN_SDK = 30;\n\n/**\n * ANR (Application Not Responding) Detection Instrumentation.\n *\n * On Android 11+, historical ANRs are read from ApplicationExitInfo (Sentry AnrV2\n * style) on the next launch. ANRTracker remains a pre-API-30 fallback and a\n * persistence backup when the OS trace stream is empty.\n *\n * ANRs stay out of CrashReportingInstrumentation so they are not replayed as\n * generic previous-session `crash` rows with empty messages.\n */\nexport class ANRInstrumentation extends BaseInstrumentation {\n readonly name = '@grafana/faro-react-native:instrumentation-anr';\n readonly version = VERSION;\n\n private readonly options: Required<ANRInstrumentationOptions>;\n private pollingIntervalId: ReturnType<typeof setInterval> | null = null;\n private anrEventSubscription: ReturnType<NativeEventEmitter['addListener']> | null = null;\n private readonly reportedAnrTimestamps = new Set<number>();\n private readonly preferAppExitInfoAnr: boolean;\n\n constructor(options: ANRInstrumentationOptions = {}) {\n super();\n this.options = {\n timeout: options.timeout ?? DEFAULT_TIMEOUT,\n pollingInterval: options.pollingInterval ?? DEFAULT_POLLING_INTERVAL,\n };\n this.preferAppExitInfoAnr = Platform.OS === 'android' && Number(Platform.Version) >= APP_EXIT_INFO_MIN_SDK;\n }\n\n initialize(): void {\n if (Platform.OS !== 'android') {\n this.logDebug('ANR detection is only available on Android');\n return;\n }\n\n const nativeModule = this.getNativeModule();\n if (!nativeModule) {\n this.logWarn('Native module not available for ANR detection');\n return;\n }\n\n this.logDebug('Initializing ANR detection instrumentation');\n\n void this.drainAllAnrSources(nativeModule);\n\n this.startNativeTracking(nativeModule);\n\n const emitter = new NativeEventEmitter(nativeModule);\n this.anrEventSubscription = emitter.addListener('onANRDetected', (anrJson: string) => {\n void this.handleLiveAnrEvent(nativeModule, anrJson);\n });\n\n void this.checkANRStatus(nativeModule);\n this.pollingIntervalId = setInterval(() => {\n void this.checkANRStatus(nativeModule);\n }, this.options.pollingInterval);\n }\n\n private getNativeModule(): typeof NativeModules.FaroReactNativeModule | null {\n const { FaroReactNativeModule } = NativeModules;\n\n if (!FaroReactNativeModule) {\n return null;\n }\n\n return FaroReactNativeModule;\n }\n\n private startNativeTracking(nativeModule: typeof NativeModules.FaroReactNativeModule): void {\n try {\n if (typeof nativeModule.startANRTracking === 'function') {\n nativeModule.startANRTracking({\n timeout: this.options.timeout,\n });\n this.logDebug('Started native ANR tracking');\n }\n } catch (error) {\n this.logError('Failed to start native ANR tracking', error);\n }\n }\n\n private async drainAllAnrSources(nativeModule: typeof NativeModules.FaroReactNativeModule): Promise<void> {\n await this.drainHistoricalAnrs(nativeModule);\n await this.drainPendingANRs(nativeModule);\n }\n\n private async drainHistoricalAnrs(nativeModule: typeof NativeModules.FaroReactNativeModule): Promise<void> {\n if (typeof nativeModule.getHistoricalAnrReports !== 'function') {\n return;\n }\n\n try {\n const anrList = (await nativeModule.getHistoricalAnrReports()) as string[] | null;\n if (!anrList?.length) {\n return;\n }\n\n const ackTimestamps: number[] = [];\n let reportedCount = 0;\n\n for (const anrJson of anrList) {\n try {\n const anr = JSON.parse(anrJson) as ANREvent;\n if (this.reportANRIfNew(anr)) {\n reportedCount += 1;\n }\n ackTimestamps.push(anr.timestamp);\n await this.acknowledgeNearbyPendingAnrs(nativeModule, anr.timestamp);\n } catch (error) {\n this.logError('Failed to parse historical ANR report', error);\n }\n }\n\n if (reportedCount > 0) {\n this.api.pushMeasurement(\n {\n type: 'anr',\n values: { anr_count: reportedCount },\n },\n { skipDedupe: true }\n );\n this.logDebug(`Reported ${reportedCount} historical ANR event(s) from ApplicationExitInfo`);\n }\n } catch (error) {\n this.logError('Failed to drain historical ANRs', error);\n }\n }\n\n private async drainPendingANRs(nativeModule: typeof NativeModules.FaroReactNativeModule): Promise<void> {\n const anrList = await this.fetchPendingANRs(nativeModule);\n if (!anrList?.length) {\n return;\n }\n\n await this.reportAndAcknowledgePendingANRs(nativeModule, anrList);\n this.logDebug(`Processed ${anrList.length} persisted ANR event(s) from tracker cache`);\n }\n\n private async handleLiveAnrEvent(\n nativeModule: typeof NativeModules.FaroReactNativeModule,\n anrJson: string\n ): Promise<void> {\n try {\n const anr = JSON.parse(anrJson) as ANREvent;\n\n if (this.preferAppExitInfoAnr) {\n // Process death + ApplicationExitInfo on next launch delivers the main-thread dump.\n this.logDebug('Deferring live ANR to ApplicationExitInfo on next launch');\n return;\n }\n\n if (!this.shouldReportTrackerAnr(anr)) {\n await this.acknowledgeANRs(nativeModule, [anr.timestamp]);\n return;\n }\n\n if (this.reportANRIfNew(anr)) {\n this.api.pushMeasurement(\n {\n type: 'anr',\n values: { anr_count: 1 },\n },\n { skipDedupe: true }\n );\n }\n await this.acknowledgeANRs(nativeModule, [anr.timestamp]);\n } catch (error) {\n this.logError('Failed to parse native ANR event', error);\n }\n }\n\n private async fetchPendingANRs(nativeModule: typeof NativeModules.FaroReactNativeModule): Promise<string[] | null> {\n try {\n if (typeof nativeModule.getPendingANRs === 'function') {\n return (await nativeModule.getPendingANRs()) as string[] | null;\n }\n\n if (typeof nativeModule.getANRStatus === 'function') {\n return (await nativeModule.getANRStatus()) as string[] | null;\n }\n } catch (error) {\n this.logError('Failed to fetch pending ANRs', error);\n }\n\n return null;\n }\n\n private async acknowledgeANRs(\n nativeModule: typeof NativeModules.FaroReactNativeModule,\n timestamps: number[]\n ): Promise<void> {\n if (!timestamps.length || typeof nativeModule.acknowledgeANRs !== 'function') {\n return;\n }\n\n try {\n await nativeModule.acknowledgeANRs(timestamps);\n } catch (error) {\n this.logError('Failed to acknowledge ANRs', error);\n }\n }\n\n private async acknowledgeNearbyPendingAnrs(\n nativeModule: typeof NativeModules.FaroReactNativeModule,\n exitTimestamp: number\n ): Promise<void> {\n const pending = await this.fetchPendingANRs(nativeModule);\n if (!pending?.length) {\n return;\n }\n\n const ackTimestamps: number[] = [];\n for (const anrJson of pending) {\n try {\n const anr = JSON.parse(anrJson) as ANREvent;\n if (this.isNearbyTimestamp(anr.timestamp, exitTimestamp)) {\n ackTimestamps.push(anr.timestamp);\n }\n } catch {\n // ignore malformed cache entries\n }\n }\n\n if (ackTimestamps.length > 0) {\n await this.acknowledgeANRs(nativeModule, ackTimestamps);\n }\n }\n\n private async reportAndAcknowledgePendingANRs(\n nativeModule: typeof NativeModules.FaroReactNativeModule,\n anrList: string[]\n ): Promise<void> {\n const ackTimestamps: number[] = [];\n let reportedCount = 0;\n\n for (const anrJson of anrList) {\n try {\n const anr = JSON.parse(anrJson) as ANREvent;\n\n if (this.shouldReportTrackerAnr(anr) && this.reportANRIfNew(anr)) {\n reportedCount += 1;\n }\n\n ackTimestamps.push(anr.timestamp);\n } catch {\n const error = new Error('ANR (Application Not Responding)');\n error.stack = undefined;\n this.api.pushError(error, {\n context: {\n mechanism: ErrorMechanism.ANR,\n raw: anrJson,\n },\n fatal: true,\n type: 'ANR',\n });\n }\n }\n\n if (reportedCount > 0) {\n this.api.pushMeasurement(\n {\n type: 'anr',\n values: { anr_count: reportedCount },\n },\n { skipDedupe: true }\n );\n }\n\n if (ackTimestamps.length > 0) {\n await this.acknowledgeANRs(nativeModule, ackTimestamps);\n }\n }\n\n private shouldReportTrackerAnr(anr: ANREvent): boolean {\n if (this.isNearbyReportedTimestamp(anr.timestamp)) {\n return false;\n }\n\n if (isInvalidAnrCaptureStack(anr.stacktrace)) {\n return false;\n }\n\n // On API 30+, ApplicationExitInfo is preferred on launch; tracker pending entries\n // are reported only when historical did not already cover the same incident.\n return true;\n }\n\n private reportANRIfNew(anr: ANREvent): boolean {\n if (this.isNearbyReportedTimestamp(anr.timestamp)) {\n return false;\n }\n\n if (isInvalidAnrCaptureStack(anr.stacktrace)) {\n return false;\n }\n\n this.rememberReportedTimestamp(anr.timestamp);\n this.reportANR(anr);\n return true;\n }\n\n private rememberReportedTimestamp(timestamp: number): void {\n this.reportedAnrTimestamps.add(timestamp);\n }\n\n private isNearbyReportedTimestamp(timestamp: number): boolean {\n for (const reported of Array.from(this.reportedAnrTimestamps)) {\n if (this.isNearbyTimestamp(timestamp, reported)) {\n return true;\n }\n }\n return false;\n }\n\n private isNearbyTimestamp(a: number, b: number): boolean {\n if (a <= 0 || b <= 0) {\n return false;\n }\n return Math.abs(a - b) <= TIMESTAMP_DEDUP_WINDOW_MS;\n }\n\n private reportANR(anr: ANREvent): void {\n const rawStacktrace = anr.stacktrace?.trim() ?? '';\n const traceForRetrace = rawStacktrace ? normalizeJavaStackTraceForRetrace(rawStacktrace) : '';\n const parsed = traceForRetrace ? parseAndroidCrashTrace(traceForRetrace) : null;\n\n const message = anr.description?.trim() || 'ANR (Application Not Responding)';\n const error = new Error(message);\n error.stack = undefined;\n\n const context: Record<string, string> = {\n duration: String(anr.duration),\n mechanism: ErrorMechanism.ANR,\n timestamp: String(anr.timestamp),\n };\n if (anr.source) {\n context['source'] = anr.source;\n }\n if (traceForRetrace) {\n context['stacktrace'] = traceForRetrace;\n }\n\n const stackFrames = parsed?.frames ?? [];\n if (!stackFrames.length && rawStacktrace) {\n this.logWarn('ANR main-thread stack present but no Java/Kotlin frames parsed');\n }\n\n this.api.pushError(error, {\n type: 'ANR',\n context,\n fatal: true,\n ...(stackFrames.length ? { stackFrames } : {}),\n });\n }\n\n private async checkANRStatus(nativeModule: typeof NativeModules.FaroReactNativeModule): Promise<void> {\n try {\n const anrList = await this.fetchPendingANRs(nativeModule);\n\n if (anrList && anrList.length > 0) {\n await this.reportAndAcknowledgePendingANRs(nativeModule, anrList);\n this.logDebug(`Polled ${anrList.length} ANR event(s) from pending cache`);\n }\n } catch (error) {\n this.logError('Failed to check ANR status', error);\n }\n }\n\n unpatch(): void {\n if (this.pollingIntervalId !== null) {\n clearInterval(this.pollingIntervalId);\n this.pollingIntervalId = null;\n }\n\n this.anrEventSubscription?.remove();\n this.anrEventSubscription = null;\n this.reportedAnrTimestamps.clear();\n\n if (Platform.OS === 'android') {\n const nativeModule = this.getNativeModule();\n if (nativeModule && typeof nativeModule.stopANRTracking === 'function') {\n try {\n nativeModule.stopANRTracking();\n } catch (error) {\n this.logError('Failed to stop native ANR tracking', error);\n }\n }\n }\n\n this.logDebug('ANR instrumentation stopped');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../../../src/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AAe,EAAE,CAAC;gBACjC,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,IAAI,CAAC,QAAQ,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;gBAC7D,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,6BAA6B,CAAC,CAAC;IAC/C,CAAC;IACH,yBAAC;AAAD,CAAC,AApYD,CAAwC,+BAAmB,GAoY1D;AApYY,gDAAkB","sourcesContent":["import { NativeEventEmitter, NativeModules, Platform } from 'react-native';\n\nimport { BaseInstrumentation, VERSION } from '@grafana/faro-core';\n\nimport { normalizeJavaStackTraceForRetrace, parseAndroidCrashTrace } from '../crashReporting/android';\nimport { ErrorMechanism } from '../errors/const';\n\nimport { isInvalidAnrCaptureStack } from './anrStack';\nimport type { ANREvent, ANRInstrumentationOptions } from './types';\n\n/**\n * Default timeout for ANR detection (5 seconds, matching Android's threshold)\n */\nconst DEFAULT_TIMEOUT = 5000;\n\n/**\n * Default polling interval for ANR status. Kept short so debug ANRs surface without\n * waiting a full minute; native also emits onANRDetected for immediate delivery.\n */\nconst DEFAULT_POLLING_INTERVAL = 10000;\n\n/** Aligns with native FaroAnrCache.MAX_TIMESTAMP_DELTA_MS */\nconst TIMESTAMP_DEDUP_WINDOW_MS = 10_000;\n\n/** ApplicationExitInfo ANR traces (Android 11 / API 30+). */\nconst APP_EXIT_INFO_MIN_SDK = 30;\n\n/**\n * ANR (Application Not Responding) Detection Instrumentation.\n *\n * On Android 11+, historical ANRs are read from ApplicationExitInfo (Sentry AnrV2\n * style) on the next launch. ANRTracker remains a pre-API-30 fallback and a\n * persistence backup when the OS trace stream is empty.\n *\n * ANRs stay out of CrashReportingInstrumentation so they are not replayed as\n * generic previous-session `crash` rows with empty messages.\n */\nexport class ANRInstrumentation extends BaseInstrumentation {\n readonly name = '@grafana/faro-react-native:instrumentation-anr';\n readonly version = VERSION;\n\n private readonly options: Required<ANRInstrumentationOptions>;\n private pollingIntervalId: ReturnType<typeof setInterval> | null = null;\n private anrEventSubscription: ReturnType<NativeEventEmitter['addListener']> | null = null;\n private readonly reportedAnrTimestamps = new Set<number>();\n private readonly preferAppExitInfoAnr: boolean;\n\n constructor(options: ANRInstrumentationOptions = {}) {\n super();\n this.options = {\n timeout: options.timeout ?? DEFAULT_TIMEOUT,\n pollingInterval: options.pollingInterval ?? DEFAULT_POLLING_INTERVAL,\n };\n this.preferAppExitInfoAnr = Platform.OS === 'android' && Number(Platform.Version) >= APP_EXIT_INFO_MIN_SDK;\n }\n\n initialize(): void {\n if (Platform.OS !== 'android') {\n this.logDebug('ANR detection is only available on Android');\n return;\n }\n\n const nativeModule = this.getNativeModule();\n if (!nativeModule) {\n this.logWarn('Native module not available for ANR detection');\n return;\n }\n\n this.logDebug('Initializing ANR detection instrumentation');\n\n void this.drainAllAnrSources(nativeModule);\n\n this.startNativeTracking(nativeModule);\n\n const emitter = new NativeEventEmitter(nativeModule);\n this.anrEventSubscription = emitter.addListener('onANRDetected', (...args: readonly Object[]) => {\n const [anrJson] = args;\n\n if (typeof anrJson !== 'string') {\n this.logWarn('Ignoring onANRDetected event without a string payload');\n return;\n }\n\n void this.handleLiveAnrEvent(nativeModule, anrJson);\n });\n\n void this.checkANRStatus(nativeModule);\n this.pollingIntervalId = setInterval(() => {\n void this.checkANRStatus(nativeModule);\n }, this.options.pollingInterval);\n }\n\n private getNativeModule(): typeof NativeModules.FaroReactNativeModule | null {\n const { FaroReactNativeModule } = NativeModules;\n\n if (!FaroReactNativeModule) {\n return null;\n }\n\n return FaroReactNativeModule;\n }\n\n private startNativeTracking(nativeModule: typeof NativeModules.FaroReactNativeModule): void {\n try {\n if (typeof nativeModule.startANRTracking === 'function') {\n nativeModule.startANRTracking({\n timeout: this.options.timeout,\n });\n this.logDebug('Started native ANR tracking');\n }\n } catch (error) {\n this.logError('Failed to start native ANR tracking', error);\n }\n }\n\n private async drainAllAnrSources(nativeModule: typeof NativeModules.FaroReactNativeModule): Promise<void> {\n await this.drainHistoricalAnrs(nativeModule);\n await this.drainPendingANRs(nativeModule);\n }\n\n private async drainHistoricalAnrs(nativeModule: typeof NativeModules.FaroReactNativeModule): Promise<void> {\n if (typeof nativeModule.getHistoricalAnrReports !== 'function') {\n return;\n }\n\n try {\n const anrList = (await nativeModule.getHistoricalAnrReports()) as string[] | null;\n if (!anrList?.length) {\n return;\n }\n\n const ackTimestamps: number[] = [];\n let reportedCount = 0;\n\n for (const anrJson of anrList) {\n try {\n const anr = JSON.parse(anrJson) as ANREvent;\n if (this.reportANRIfNew(anr)) {\n reportedCount += 1;\n }\n ackTimestamps.push(anr.timestamp);\n await this.acknowledgeNearbyPendingAnrs(nativeModule, anr.timestamp);\n } catch (error) {\n this.logError('Failed to parse historical ANR report', error);\n }\n }\n\n if (reportedCount > 0) {\n this.api.pushMeasurement(\n {\n type: 'anr',\n values: { anr_count: reportedCount },\n },\n { skipDedupe: true }\n );\n this.logDebug(`Reported ${reportedCount} historical ANR event(s) from ApplicationExitInfo`);\n }\n } catch (error) {\n this.logError('Failed to drain historical ANRs', error);\n }\n }\n\n private async drainPendingANRs(nativeModule: typeof NativeModules.FaroReactNativeModule): Promise<void> {\n const anrList = await this.fetchPendingANRs(nativeModule);\n if (!anrList?.length) {\n return;\n }\n\n await this.reportAndAcknowledgePendingANRs(nativeModule, anrList);\n this.logDebug(`Processed ${anrList.length} persisted ANR event(s) from tracker cache`);\n }\n\n private async handleLiveAnrEvent(\n nativeModule: typeof NativeModules.FaroReactNativeModule,\n anrJson: string\n ): Promise<void> {\n try {\n const anr = JSON.parse(anrJson) as ANREvent;\n\n if (this.preferAppExitInfoAnr) {\n // Process death + ApplicationExitInfo on next launch delivers the main-thread dump.\n this.logDebug('Deferring live ANR to ApplicationExitInfo on next launch');\n return;\n }\n\n if (!this.shouldReportTrackerAnr(anr)) {\n await this.acknowledgeANRs(nativeModule, [anr.timestamp]);\n return;\n }\n\n if (this.reportANRIfNew(anr)) {\n this.api.pushMeasurement(\n {\n type: 'anr',\n values: { anr_count: 1 },\n },\n { skipDedupe: true }\n );\n }\n await this.acknowledgeANRs(nativeModule, [anr.timestamp]);\n } catch (error) {\n this.logError('Failed to parse native ANR event', error);\n }\n }\n\n private async fetchPendingANRs(nativeModule: typeof NativeModules.FaroReactNativeModule): Promise<string[] | null> {\n try {\n if (typeof nativeModule.getPendingANRs === 'function') {\n return (await nativeModule.getPendingANRs()) as string[] | null;\n }\n\n if (typeof nativeModule.getANRStatus === 'function') {\n return (await nativeModule.getANRStatus()) as string[] | null;\n }\n } catch (error) {\n this.logError('Failed to fetch pending ANRs', error);\n }\n\n return null;\n }\n\n private async acknowledgeANRs(\n nativeModule: typeof NativeModules.FaroReactNativeModule,\n timestamps: number[]\n ): Promise<void> {\n if (!timestamps.length || typeof nativeModule.acknowledgeANRs !== 'function') {\n return;\n }\n\n try {\n await nativeModule.acknowledgeANRs(timestamps);\n } catch (error) {\n this.logError('Failed to acknowledge ANRs', error);\n }\n }\n\n private async acknowledgeNearbyPendingAnrs(\n nativeModule: typeof NativeModules.FaroReactNativeModule,\n exitTimestamp: number\n ): Promise<void> {\n const pending = await this.fetchPendingANRs(nativeModule);\n if (!pending?.length) {\n return;\n }\n\n const ackTimestamps: number[] = [];\n for (const anrJson of pending) {\n try {\n const anr = JSON.parse(anrJson) as ANREvent;\n if (this.isNearbyTimestamp(anr.timestamp, exitTimestamp)) {\n ackTimestamps.push(anr.timestamp);\n }\n } catch {\n // ignore malformed cache entries\n }\n }\n\n if (ackTimestamps.length > 0) {\n await this.acknowledgeANRs(nativeModule, ackTimestamps);\n }\n }\n\n private async reportAndAcknowledgePendingANRs(\n nativeModule: typeof NativeModules.FaroReactNativeModule,\n anrList: string[]\n ): Promise<void> {\n const ackTimestamps: number[] = [];\n let reportedCount = 0;\n\n for (const anrJson of anrList) {\n try {\n const anr = JSON.parse(anrJson) as ANREvent;\n\n if (this.shouldReportTrackerAnr(anr) && this.reportANRIfNew(anr)) {\n reportedCount += 1;\n }\n\n ackTimestamps.push(anr.timestamp);\n } catch {\n const error = new Error('ANR (Application Not Responding)');\n error.stack = undefined;\n this.api.pushError(error, {\n context: {\n mechanism: ErrorMechanism.ANR,\n raw: anrJson,\n },\n fatal: true,\n type: 'ANR',\n });\n }\n }\n\n if (reportedCount > 0) {\n this.api.pushMeasurement(\n {\n type: 'anr',\n values: { anr_count: reportedCount },\n },\n { skipDedupe: true }\n );\n }\n\n if (ackTimestamps.length > 0) {\n await this.acknowledgeANRs(nativeModule, ackTimestamps);\n }\n }\n\n private shouldReportTrackerAnr(anr: ANREvent): boolean {\n if (this.isNearbyReportedTimestamp(anr.timestamp)) {\n return false;\n }\n\n if (isInvalidAnrCaptureStack(anr.stacktrace)) {\n return false;\n }\n\n // On API 30+, ApplicationExitInfo is preferred on launch; tracker pending entries\n // are reported only when historical did not already cover the same incident.\n return true;\n }\n\n private reportANRIfNew(anr: ANREvent): boolean {\n if (this.isNearbyReportedTimestamp(anr.timestamp)) {\n return false;\n }\n\n if (isInvalidAnrCaptureStack(anr.stacktrace)) {\n return false;\n }\n\n this.rememberReportedTimestamp(anr.timestamp);\n this.reportANR(anr);\n return true;\n }\n\n private rememberReportedTimestamp(timestamp: number): void {\n this.reportedAnrTimestamps.add(timestamp);\n }\n\n private isNearbyReportedTimestamp(timestamp: number): boolean {\n for (const reported of Array.from(this.reportedAnrTimestamps)) {\n if (this.isNearbyTimestamp(timestamp, reported)) {\n return true;\n }\n }\n return false;\n }\n\n private isNearbyTimestamp(a: number, b: number): boolean {\n if (a <= 0 || b <= 0) {\n return false;\n }\n return Math.abs(a - b) <= TIMESTAMP_DEDUP_WINDOW_MS;\n }\n\n private reportANR(anr: ANREvent): void {\n const rawStacktrace = anr.stacktrace?.trim() ?? '';\n const traceForRetrace = rawStacktrace ? normalizeJavaStackTraceForRetrace(rawStacktrace) : '';\n const parsed = traceForRetrace ? parseAndroidCrashTrace(traceForRetrace) : null;\n\n const message = anr.description?.trim() || 'ANR (Application Not Responding)';\n const error = new Error(message);\n error.stack = undefined;\n\n const context: Record<string, string> = {\n duration: String(anr.duration),\n mechanism: ErrorMechanism.ANR,\n timestamp: String(anr.timestamp),\n };\n if (anr.source) {\n context['source'] = anr.source;\n }\n if (traceForRetrace) {\n context['stacktrace'] = traceForRetrace;\n }\n\n const stackFrames = parsed?.frames ?? [];\n if (!stackFrames.length && rawStacktrace) {\n this.logWarn('ANR main-thread stack present but no Java/Kotlin frames parsed');\n }\n\n this.api.pushError(error, {\n type: 'ANR',\n context,\n fatal: true,\n ...(stackFrames.length ? { stackFrames } : {}),\n });\n }\n\n private async checkANRStatus(nativeModule: typeof NativeModules.FaroReactNativeModule): Promise<void> {\n try {\n const anrList = await this.fetchPendingANRs(nativeModule);\n\n if (anrList && anrList.length > 0) {\n await this.reportAndAcknowledgePendingANRs(nativeModule, anrList);\n this.logDebug(`Polled ${anrList.length} ANR event(s) from pending cache`);\n }\n } catch (error) {\n this.logError('Failed to check ANR status', error);\n }\n }\n\n unpatch(): void {\n if (this.pollingIntervalId !== null) {\n clearInterval(this.pollingIntervalId);\n this.pollingIntervalId = null;\n }\n\n this.anrEventSubscription?.remove();\n this.anrEventSubscription = null;\n this.reportedAnrTimestamps.clear();\n\n if (Platform.OS === 'android') {\n const nativeModule = this.getNativeModule();\n if (nativeModule && typeof nativeModule.stopANRTracking === 'function') {\n try {\n nativeModule.stopANRTracking();\n } catch (error) {\n this.logError('Failed to stop native ANR tracking', error);\n }\n }\n }\n\n this.logDebug('ANR instrumentation stopped');\n }\n}\n"]}
|
|
@@ -18,8 +18,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.AppStateInstrumentation = exports.EVENT_APP_STATE_CHANGED = void 0;
|
|
19
19
|
var react_native_1 = require("react-native");
|
|
20
20
|
var faro_core_1 = require("@grafana/faro-core");
|
|
21
|
-
// Event name aligned with Faro Flutter SDK (app_lifecycle_changed)
|
|
22
21
|
exports.EVENT_APP_STATE_CHANGED = 'app_lifecycle_changed';
|
|
22
|
+
var APP_STATE_STATUSES = ['inactive', 'background', 'active', 'extension', 'unknown'];
|
|
23
|
+
// RN types AppState.currentState as `null | undefined | string`: it stays null
|
|
24
|
+
// until the initial value is set, so narrow it instead of trusting the shape.
|
|
25
|
+
function isAppStateStatus(value) {
|
|
26
|
+
return typeof value === 'string' && APP_STATE_STATUSES.includes(value);
|
|
27
|
+
}
|
|
23
28
|
/**
|
|
24
29
|
* AppState instrumentation for React Native
|
|
25
30
|
* Tracks app foreground/background/inactive state changes
|
|
@@ -74,7 +79,8 @@ var AppStateInstrumentation = /** @class */ (function (_super) {
|
|
|
74
79
|
}
|
|
75
80
|
AppStateInstrumentation.prototype.initialize = function () {
|
|
76
81
|
// Get initial app state
|
|
77
|
-
|
|
82
|
+
var initialState = react_native_1.AppState.currentState;
|
|
83
|
+
this.currentState = isAppStateStatus(initialState) ? initialState : undefined;
|
|
78
84
|
this.stateStartTime = (0, faro_core_1.dateNow)();
|
|
79
85
|
this.logInfo('AppState instrumentation initialized', {
|
|
80
86
|
initialState: this.currentState,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/instrumentations/appState/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,6CAA6D;AAE7D,gDAA2E;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/instrumentations/appState/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,6CAA6D;AAE7D,gDAA2E;AAE9D,QAAA,uBAAuB,GAAG,uBAAuB,CAAC;AAE/D,IAAM,kBAAkB,GAAG,CAAC,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,CAAU,CAAC;AAEjG,+EAA+E;AAC/E,8EAA8E;AAC9E,SAAS,gBAAgB,CAAC,KAAc;IACtC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAK,kBAAwC,CAAC,QAAQ,CAAC,KAAK,CAAC,C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,KAAK,YAAY,CAAC;IAC5C,CAAC;IAED;;OAEG;IACH,yCAAO,GAAP;QACE,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC9B,IAAI,CAAC,oBAAoB,CAAC,MAAM,EAAE,CAAC;YACnC,IAAI,CAAC,oBAAoB,GAAG,SAAS,CAAC;YACtC,IAAI,CAAC,OAAO,CAAC,oCAAoC,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;IACH,8BAAC;AAAD,CAAC,AA5GD,CAA6C,+BAAmB,GA4G/D;AA5GY,0DAAuB","sourcesContent":["import { AppState, type AppStateStatus } from 'react-native';\n\nimport { BaseInstrumentation, dateNow, VERSION } from '@grafana/faro-core';\n\nexport const EVENT_APP_STATE_CHANGED = 'app_lifecycle_changed';\n\nconst APP_STATE_STATUSES = ['inactive', 'background', 'active', 'extension', 'unknown'] as const;\n\n// RN types AppState.currentState as `null | undefined | string`: it stays null\n// until the initial value is set, so narrow it instead of trusting the shape.\nfunction isAppStateStatus(value: unknown): value is AppStateStatus {\n return typeof value === 'string' && (APP_STATE_STATUSES as readonly string[]).includes(value);\n}\n\n/**\n * AppState instrumentation for React Native\n * Tracks app foreground/background/inactive state changes\n *\n * Emits `app_lifecycle_changed` with React Native `AppState` values in `fromState` / `toState`\n * (active, background, inactive, unknown, extension).\n */\nexport class AppStateInstrumentation extends BaseInstrumentation {\n readonly name = '@grafana/faro-react-native:instrumentation-appstate';\n readonly version = VERSION;\n\n private currentState: AppStateStatus | undefined;\n private stateStartTime: number | undefined;\n private appStateSubscription: ReturnType<typeof AppState.addEventListener> | undefined;\n\n initialize(): void {\n // Get initial app state\n const initialState = AppState.currentState;\n this.currentState = isAppStateStatus(initialState) ? initialState : undefined;\n this.stateStartTime = dateNow();\n\n this.logInfo('AppState instrumentation initialized', {\n initialState: this.currentState,\n });\n\n // Subscribe to app state changes\n this.appStateSubscription = AppState.addEventListener('change', this.handleAppStateChange);\n }\n\n /**\n * Handles app state changes and emits app_lifecycle_changed events\n * with native AppState status strings. Includes duration and timestamp for time-in-state analysis.\n */\n private handleAppStateChange = (nextAppState: AppStateStatus): void => {\n const previousState = this.currentState;\n const now = dateNow();\n const duration = this.stateStartTime ? now - this.stateStartTime : 0;\n\n // Update state tracking\n this.currentState = nextAppState;\n this.stateStartTime = now;\n\n // Log the state change (internal debug keeps RN state names)\n this.logDebug('App state changed', {\n from: previousState,\n to: nextAppState,\n duration,\n });\n\n // Emit app lifecycle change event (native RN AppState values + duration/timestamp)\n const fromState = previousState !== undefined ? previousState : '';\n const toState = nextAppState;\n this.api.pushEvent(\n EVENT_APP_STATE_CHANGED,\n {\n fromState,\n toState,\n duration: duration.toString(),\n timestamp: now.toString(),\n },\n undefined,\n { skipDedupe: true }\n );\n\n // Additional logging for specific transitions\n if (nextAppState === 'background') {\n this.logInfo('App moved to background', { fromState: previousState, duration });\n } else if (nextAppState === 'active' && previousState === 'background') {\n this.logInfo('App returned to foreground', { duration });\n } else if (nextAppState === 'inactive') {\n this.logDebug('App became inactive', { fromState: previousState });\n }\n };\n\n /**\n * Get the current app state\n */\n getCurrentState(): AppStateStatus | undefined {\n return this.currentState;\n }\n\n /**\n * Get the duration the app has been in the current state (in milliseconds)\n */\n getCurrentStateDuration(): number {\n if (!this.stateStartTime) {\n return 0;\n }\n return dateNow() - this.stateStartTime;\n }\n\n /**\n * Check if app is currently in the foreground (active state)\n */\n isActive(): boolean {\n return this.currentState === 'active';\n }\n\n /**\n * Check if app is currently in the background\n */\n isBackground(): boolean {\n return this.currentState === 'background';\n }\n\n /**\n * Cleanup: Remove app state listener\n */\n unpatch(): void {\n if (this.appStateSubscription) {\n this.appStateSubscription.remove();\n this.appStateSubscription = undefined;\n this.logInfo('AppState instrumentation unpatched');\n }\n }\n}\n"]}
|
|
@@ -99,14 +99,17 @@ var BaseCrashReportingInstrumentation = /** @class */ (function (_super) {
|
|
|
99
99
|
return [2 /*return*/];
|
|
100
100
|
}
|
|
101
101
|
this.logDebug('Initializing crash reporting instrumentation');
|
|
102
|
+
return [4 /*yield*/, this.prepareCrashReporting(nativeModule)];
|
|
103
|
+
case 1:
|
|
104
|
+
_a.sent();
|
|
102
105
|
// Wait for session attributes before sending crash reports
|
|
103
106
|
return [4 /*yield*/, this.waitForSessionAttributes()];
|
|
104
|
-
case
|
|
107
|
+
case 2:
|
|
105
108
|
// Wait for session attributes before sending crash reports
|
|
106
109
|
_a.sent();
|
|
107
110
|
// Get and process crash reports from previous session
|
|
108
111
|
return [4 /*yield*/, this.processCrashReports(nativeModule)];
|
|
109
|
-
case
|
|
112
|
+
case 3:
|
|
110
113
|
// Get and process crash reports from previous session
|
|
111
114
|
_a.sent();
|
|
112
115
|
return [2 /*return*/];
|
|
@@ -114,6 +117,9 @@ var BaseCrashReportingInstrumentation = /** @class */ (function (_super) {
|
|
|
114
117
|
});
|
|
115
118
|
});
|
|
116
119
|
};
|
|
120
|
+
BaseCrashReportingInstrumentation.prototype.prepareCrashReporting = function (_nativeModule) {
|
|
121
|
+
// Optional platform-specific setup.
|
|
122
|
+
};
|
|
117
123
|
BaseCrashReportingInstrumentation.prototype.waitForSessionAttributes = function () {
|
|
118
124
|
return __awaiter(this, arguments, void 0, function (maxWaitMs) {
|
|
119
125
|
var startTime, pollInterval, checkCount, sessionAttrs, attrCount, attrKeys, hasDeviceId, hasDeviceOsDetail, hasDeviceModelName, elapsed, finalAttrs, finalAttrCount, finalAttrKeys;
|
|
@@ -236,13 +242,10 @@ var BaseCrashReportingInstrumentation = /** @class */ (function (_super) {
|
|
|
236
242
|
});
|
|
237
243
|
});
|
|
238
244
|
};
|
|
239
|
-
BaseCrashReportingInstrumentation.prototype.
|
|
245
|
+
BaseCrashReportingInstrumentation.prototype.buildCrashReportDetails = function (crash) {
|
|
240
246
|
// Platform-specific parsing
|
|
241
247
|
var parsedTrace = crash.trace ? this.parseCrashTrace(crash.trace) : null;
|
|
242
248
|
var errorMessage = this.resolveCrashErrorMessage(crash, parsedTrace).trim() || 'Application crash';
|
|
243
|
-
// Use a message-only Error so pushError does not capture the JS reporter stack
|
|
244
|
-
var error = new Error(errorMessage);
|
|
245
|
-
error.stack = undefined;
|
|
246
249
|
// Build context from crash data
|
|
247
250
|
var context = {
|
|
248
251
|
mechanism: 'crash',
|
|
@@ -286,6 +289,16 @@ var BaseCrashReportingInstrumentation = /** @class */ (function (_super) {
|
|
|
286
289
|
.find(function (line) { return /#\d+\s+pc\s+/i.test(line); });
|
|
287
290
|
this.logInfo("[Faro crash native] Sending tombstone trace (".concat(crash.trace.split('\n').length, " lines) preview=").concat(framePreview !== null && framePreview !== void 0 ? framePreview : 'n/a'));
|
|
288
291
|
}
|
|
292
|
+
return {
|
|
293
|
+
context: context,
|
|
294
|
+
errorMessage: errorMessage,
|
|
295
|
+
stackFrames: stackFrames,
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
BaseCrashReportingInstrumentation.prototype.sendCrashReport = function (crash) {
|
|
299
|
+
var _a = this.buildCrashReportDetails(crash), context = _a.context, errorMessage = _a.errorMessage, stackFrames = _a.stackFrames;
|
|
300
|
+
var error = new Error(errorMessage);
|
|
301
|
+
error.stack = undefined;
|
|
289
302
|
this.api.pushError(error, {
|
|
290
303
|
stackFrames: stackFrames,
|
|
291
304
|
context: context,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseCrashReportingInstrumentation.js","sourceRoot":"","sources":["../../../../src/instrumentations/crashReporting/BaseCrashReportingInstrumentation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA6C;AAE7C,gDAAyD;AAEzD,uEAA+E;AAG/E;;;;;;GAMG;AACH;IAAgE,qDAAmB;IAMjF,2CAAY,OAAmC;QAAnC,wBAAA,EAAA,YAAmC;;QAC7C,YAAA,MAAK,WAAE,SAAC;QACR,KAAI,CAAC,OAAO,GAAG;YACb,OAAO,EAAE,MAAA,OAAO,CAAC,OAAO,mCAAI,IAAI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AAI,CAAC,QAAQ,CAAC,6BAAsB,YAAY,CAAE,CAAC,CAAC;IACtD,CAAC;IAED,kBAAkB;IACT,oDAAQ,GAAjB,UAAkB,OAAe;;QAAE,cAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,6BAAc;;QAC/C,MAAA,MAAA,IAAI,CAAC,cAAc,0CAAE,KAAK,4EAAG,OAAO,GAAK,IAAI,SAAC,CAAC;IACjD,CAAC;IAEQ,mDAAO,GAAhB,UAAiB,OAAe;;QAAE,cAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,6BAAc;;QAC9C,MAAA,MAAA,IAAI,CAAC,cAAc,0CAAE,IAAI,4EAAG,OAAO,GAAK,IAAI,SAAC,CAAC;IAChD,CAAC;IAEQ,mDAAO,GAAhB,UAAiB,OAAe;;QAAE,cAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,6BAAc;;QAC9C,MAAA,MAAA,IAAI,CAAC,cAAc,0CAAE,IAAI,4EAAG,OAAO,GAAK,IAAI,SAAC,CAAC;IAChD,CAAC;IAEQ,oDAAQ,GAAjB,UAAkB,OAAe;;QAAE,cAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,6BAAc;;QAC/C,MAAA,MAAA,IAAI,CAAC,cAAc,0CAAE,KAAK,4EAAG,OAAO,GAAK,IAAI,SAAC,CAAC;IACjD,CAAC;IAED,mDAAO,GAAP;QACE,sBAAsB;IACxB,CAAC;IACH,wCAAC;AAAD,CAAC,AApRD,CAAgE,+BAAmB,GAoRlF;AApRqB,8EAAiC","sourcesContent":["import { NativeModules } from 'react-native';\n\nimport { BaseInstrumentation } from '@grafana/faro-core';\n\nimport { looksLikeNativeTombstoneTrace } from './android/nativeTombstoneTrace';\nimport type { CrashReport, CrashReportingOptions } from './types';\n\n/**\n * Abstract base class for platform-specific crash reporting implementations.\n *\n * Defines the common contract that both Android and iOS implementations must follow.\n * Handles the shared logic for retrieving crash reports from native modules and\n * processing them, while delegating platform-specific parsing and validation to subclasses.\n */\nexport abstract class BaseCrashReportingInstrumentation extends BaseInstrumentation {\n abstract override readonly name: string;\n abstract override readonly version: string;\n\n protected readonly options: { enabled: boolean; releaseBundleFilename?: string };\n\n constructor(options: CrashReportingOptions = {}) {\n super();\n this.options = {\n enabled: options.enabled ?? true,\n releaseBundleFilename: options.releaseBundleFilename,\n };\n }\n\n async initialize(): Promise<void> {\n if (!this.options.enabled) {\n this.logDebug('Crash reporting is disabled');\n return;\n }\n\n const nativeModule = this.getNativeModule();\n if (!nativeModule) {\n this.logWarn('Native module not available for crash reporting');\n return;\n }\n\n this.logDebug('Initializing crash reporting instrumentation');\n\n // Wait for session attributes before sending crash reports\n await this.waitForSessionAttributes();\n\n // Get and process crash reports from previous session\n await this.processCrashReports(nativeModule);\n }\n\n /**\n * Platform-specific: Parse a crash trace string into structured stack frames.\n */\n protected abstract parseCrashTrace(trace: string): any | null;\n\n /**\n * Platform-specific: Resolve human-readable error message from crash data.\n */\n protected abstract resolveCrashErrorMessage(crash: CrashReport, parsedTrace: any | null): string;\n\n /**\n * Platform-specific: Determine if a crash report should be skipped.\n */\n protected abstract shouldSkipCrashReport(crash: CrashReport): boolean;\n\n /**\n * Platform-specific: Extract stack frames from parsed trace.\n */\n protected abstract getStackFrames(parsedTrace: any | null): any[];\n\n /**\n * Platform-specific: Build platform-specific context from parsed trace.\n */\n protected abstract buildPlatformContext(parsedTrace: any | null, context: Record<string, string>): void;\n\n /**\n * Platform-specific: Get warning message when trace parsing fails.\n */\n protected abstract getParseFailureWarning(): string;\n\n /**\n * Platform-specific: Get warning message when trace is unavailable.\n */\n protected abstract getTraceUnavailableWarning(): string;\n\n private async waitForSessionAttributes(maxWaitMs = 10000): Promise<void> {\n const startTime = Date.now();\n const pollInterval = 200;\n let checkCount = 0;\n\n while (Date.now() - startTime < maxWaitMs) {\n checkCount++;\n try {\n const sessionAttrs = this.metas?.value?.session?.attributes;\n\n if (sessionAttrs) {\n const attrCount = Object.keys(sessionAttrs).length;\n const attrKeys = JSON.stringify(Object.keys(sessionAttrs));\n\n // Look for multiple device-specific attributes that indicate full async collection is done.\n // getSessionAttributes() collects these asynchronously:\n // - device_id (SDK installation id, kept as a flat attr during migration)\n // - device_os_detail (async getDeviceOsDetail)\n // - device_model_name (DeviceInfo.getDeviceNameSync)\n // All three should be present when collection is complete.\n const hasDeviceId = 'device_id' in sessionAttrs && sessionAttrs['device_id'] !== 'unknown';\n const hasDeviceOsDetail =\n 'device_os_detail' in sessionAttrs && sessionAttrs['device_os_detail'] !== 'unknown';\n const hasDeviceModelName = 'device_model_name' in sessionAttrs;\n\n if (hasDeviceId && hasDeviceOsDetail && hasDeviceModelName) {\n const elapsed = Date.now() - startTime;\n this.logDebug(`Session attributes ready after ${elapsed}ms (${checkCount} checks, ${attrCount} attrs)`);\n return;\n } else {\n this.logDebug(\n `Check #${checkCount}: Found ${attrCount} session attributes: ${attrKeys} but still missing required attrs - device_id:${hasDeviceId}, device_os_detail:${hasDeviceOsDetail}, device_model_name:${hasDeviceModelName}`\n );\n }\n } else {\n this.logDebug(`Check #${checkCount}: No session attributes available yet`);\n }\n } catch (error) {\n this.logDebug(`Check #${checkCount}: Error accessing metas: ${error}`);\n }\n\n await new Promise((resolve) => setTimeout(resolve, pollInterval));\n }\n\n const finalAttrs = this.metas?.value?.session?.attributes;\n const finalAttrCount = finalAttrs ? Object.keys(finalAttrs).length : 0;\n const finalAttrKeys = finalAttrs ? JSON.stringify(Object.keys(finalAttrs)) : 'none';\n this.logWarn(\n `Session attributes not ready after ${maxWaitMs}ms timeout (${checkCount} checks, ${finalAttrCount} attrs: ${finalAttrKeys}). Sending crash report anyway.`\n );\n }\n\n private getNativeModule(): typeof NativeModules.FaroReactNativeModule | null {\n const { FaroReactNativeModule } = NativeModules;\n\n if (!FaroReactNativeModule) {\n return null;\n }\n\n return FaroReactNativeModule;\n }\n\n private async processCrashReports(nativeModule: typeof NativeModules.FaroReactNativeModule): Promise<void> {\n try {\n if (typeof nativeModule.getCrashReport !== 'function') {\n this.logDebug('getCrashReport method not available');\n return;\n }\n\n this.logDebug('Attempting to retrieve crash reports from native module');\n const crashReports = (await nativeModule.getCrashReport()) as string[] | null;\n\n if (!crashReports || crashReports.length === 0) {\n this.logDebug('No crash reports from previous session');\n return;\n }\n\n this.logDebug(`Processing ${crashReports.length} crash report(s) from previous session`);\n\n const reportedTimestamps = new Set<number>();\n\n for (const crashJson of crashReports) {\n try {\n this.logDebug(`Parsing crash report JSON: ${crashJson.substring(0, 200)}...`);\n const crash = JSON.parse(crashJson) as CrashReport;\n\n if (crash.timestamp && reportedTimestamps.has(crash.timestamp)) {\n this.logDebug(`Skipping duplicate crash report at ${crash.timestamp}`);\n continue;\n }\n\n if (this.shouldSkipCrashReport(crash)) {\n this.logDebug(`Skipping crash report at ${crash.timestamp} (platform-specific skip logic)`);\n continue;\n }\n\n if (crash.timestamp) {\n reportedTimestamps.add(crash.timestamp);\n }\n\n this.sendCrashReport(crash);\n } catch (parseError) {\n this.logError('Failed to parse crash report JSON', parseError);\n this.api.pushError(new Error('Application crash (parse error)'), {\n context: {\n mechanism: 'crash',\n parseError: String(parseError),\n raw: crashJson.substring(0, 500),\n },\n fatal: true,\n type: 'crash',\n });\n }\n }\n } catch (error) {\n this.logError('Failed to process crash reports', error);\n }\n }\n\n private sendCrashReport(crash: CrashReport): void {\n // Platform-specific parsing\n const parsedTrace = crash.trace ? this.parseCrashTrace(crash.trace) : null;\n const errorMessage = this.resolveCrashErrorMessage(crash, parsedTrace).trim() || 'Application crash';\n\n // Use a message-only Error so pushError does not capture the JS reporter stack\n const error = new Error(errorMessage);\n error.stack = undefined;\n\n // Build context from crash data\n const context: Record<string, string> = {\n mechanism: 'crash',\n };\n\n if (crash.trace) {\n context['trace'] = crash.trace;\n }\n if (crash.signal) {\n context['signal'] = crash.signal;\n }\n if (crash.timestamp) {\n context['timestamp'] = String(crash.timestamp);\n }\n if (crash.description) {\n context['description'] = crash.description;\n }\n if (crash.processName) {\n context['processName'] = crash.processName;\n }\n if (crash.pid) {\n context['pid'] = String(crash.pid);\n }\n if (crash.importance !== undefined) {\n context['importance'] = String(crash.importance);\n }\n\n // Platform-specific context\n this.buildPlatformContext(parsedTrace, context);\n\n // Platform-specific stack frames\n const stackFrames = this.getStackFrames(parsedTrace);\n\n // Warnings for missing/unparseable traces\n if (!stackFrames.length && crash.trace) {\n this.logWarn(this.getParseFailureWarning());\n } else if (!crash.trace) {\n this.logWarn(this.getTraceUnavailableWarning());\n } else if (looksLikeNativeTombstoneTrace(crash.trace)) {\n const framePreview = crash.trace\n .split('\\n')\n .map((line) => line.trim())\n .find((line) => /#\\d+\\s+pc\\s+/i.test(line));\n this.logInfo(\n `[Faro crash native] Sending tombstone trace (${crash.trace.split('\\n').length} lines) preview=${framePreview ?? 'n/a'}`\n );\n }\n\n this.api.pushError(error, {\n stackFrames,\n context,\n type: 'crash',\n fatal: true,\n });\n\n this.logDebug(`Sent crash report: ${errorMessage}`);\n }\n\n // Logging helpers\n override logDebug(message: string, ...args: any[]): void {\n this.internalLogger?.debug?.(message, ...args);\n }\n\n override logInfo(message: string, ...args: any[]): void {\n this.internalLogger?.info?.(message, ...args);\n }\n\n override logWarn(message: string, ...args: any[]): void {\n this.internalLogger?.warn?.(message, ...args);\n }\n\n override logError(message: string, ...args: any[]): void {\n this.internalLogger?.error?.(message, ...args);\n }\n\n unpatch(): void {\n // No patching to undo\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BaseCrashReportingInstrumentation.js","sourceRoot":"","sources":["../../../../src/instrumentations/crashReporting/BaseCrashReportingInstrumentation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA6C;AAE7C,gDAAyD;AAGzD,uEAA+E;AAS/E;;;;;;GAMG;AACH;IAAgE,qDAAmB;IAMjF,2CAAY,OAAmC;QAAnC,wBAAA,EAAA,YAAm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Ad,qBAAc,EAAd,IAAc;YAAd,6BAAc;;QAC/C,MAAA,MAAA,IAAI,CAAC,cAAc,0CAAE,KAAK,4EAAG,OAAO,GAAK,IAAI,SAAC,CAAC;IACjD,CAAC;IAED,mDAAO,GAAP;QACE,sBAAsB;IACxB,CAAC;IACH,wCAAC;AAAD,CAAC,AAjSD,CAAgE,+BAAmB,GAiSlF;AAjSqB,8EAAiC","sourcesContent":["import { NativeModules } from 'react-native';\n\nimport { BaseInstrumentation } from '@grafana/faro-core';\nimport type { ExceptionStackFrame } from '@grafana/faro-core';\n\nimport { looksLikeNativeTombstoneTrace } from './android/nativeTombstoneTrace';\nimport type { CrashReport, CrashReportingOptions } from './types';\n\ninterface CrashReportDetails {\n context: Record<string, string>;\n errorMessage: string;\n stackFrames: ExceptionStackFrame[];\n}\n\n/**\n * Abstract base class for platform-specific crash reporting implementations.\n *\n * Defines the common contract that both Android and iOS implementations must follow.\n * Handles the shared logic for retrieving crash reports from native modules and\n * processing them, while delegating platform-specific parsing and validation to subclasses.\n */\nexport abstract class BaseCrashReportingInstrumentation extends BaseInstrumentation {\n abstract override readonly name: string;\n abstract override readonly version: string;\n\n protected readonly options: { enabled: boolean; releaseBundleFilename?: string };\n\n constructor(options: CrashReportingOptions = {}) {\n super();\n this.options = {\n enabled: options.enabled ?? true,\n releaseBundleFilename: options.releaseBundleFilename,\n };\n }\n\n async initialize(): Promise<void> {\n if (!this.options.enabled) {\n this.logDebug('Crash reporting is disabled');\n return;\n }\n\n const nativeModule = this.getNativeModule();\n if (!nativeModule) {\n this.logWarn('Native module not available for crash reporting');\n return;\n }\n\n this.logDebug('Initializing crash reporting instrumentation');\n await this.prepareCrashReporting(nativeModule);\n\n // Wait for session attributes before sending crash reports\n await this.waitForSessionAttributes();\n\n // Get and process crash reports from previous session\n await this.processCrashReports(nativeModule);\n }\n\n /**\n * Platform-specific: Parse a crash trace string into structured stack frames.\n */\n protected abstract parseCrashTrace(trace: string): any | null;\n\n /**\n * Platform-specific: Resolve human-readable error message from crash data.\n */\n protected abstract resolveCrashErrorMessage(crash: CrashReport, parsedTrace: any | null): string;\n\n /**\n * Platform-specific: Determine if a crash report should be skipped.\n */\n protected abstract shouldSkipCrashReport(crash: CrashReport): boolean;\n\n /**\n * Platform-specific: Extract stack frames from parsed trace.\n */\n protected abstract getStackFrames(parsedTrace: any | null): any[];\n\n /**\n * Platform-specific: Build platform-specific context from parsed trace.\n */\n protected abstract buildPlatformContext(parsedTrace: any | null, context: Record<string, string>): void;\n\n /**\n * Platform-specific: Get warning message when trace parsing fails.\n */\n protected abstract getParseFailureWarning(): string;\n\n /**\n * Platform-specific: Get warning message when trace is unavailable.\n */\n protected abstract getTraceUnavailableWarning(): string;\n\n protected prepareCrashReporting(_nativeModule: typeof NativeModules.FaroReactNativeModule): void | Promise<void> {\n // Optional platform-specific setup.\n }\n\n protected async waitForSessionAttributes(maxWaitMs = 10000): Promise<void> {\n const startTime = Date.now();\n const pollInterval = 200;\n let checkCount = 0;\n\n while (Date.now() - startTime < maxWaitMs) {\n checkCount++;\n try {\n const sessionAttrs = this.metas?.value?.session?.attributes;\n\n if (sessionAttrs) {\n const attrCount = Object.keys(sessionAttrs).length;\n const attrKeys = JSON.stringify(Object.keys(sessionAttrs));\n\n // Look for multiple device-specific attributes that indicate full async collection is done.\n // getSessionAttributes() collects these asynchronously:\n // - device_id (SDK installation id, kept as a flat attr during migration)\n // - device_os_detail (async getDeviceOsDetail)\n // - device_model_name (DeviceInfo.getDeviceNameSync)\n // All three should be present when collection is complete.\n const hasDeviceId = 'device_id' in sessionAttrs && sessionAttrs['device_id'] !== 'unknown';\n const hasDeviceOsDetail =\n 'device_os_detail' in sessionAttrs && sessionAttrs['device_os_detail'] !== 'unknown';\n const hasDeviceModelName = 'device_model_name' in sessionAttrs;\n\n if (hasDeviceId && hasDeviceOsDetail && hasDeviceModelName) {\n const elapsed = Date.now() - startTime;\n this.logDebug(`Session attributes ready after ${elapsed}ms (${checkCount} checks, ${attrCount} attrs)`);\n return;\n } else {\n this.logDebug(\n `Check #${checkCount}: Found ${attrCount} session attributes: ${attrKeys} but still missing required attrs - device_id:${hasDeviceId}, device_os_detail:${hasDeviceOsDetail}, device_model_name:${hasDeviceModelName}`\n );\n }\n } else {\n this.logDebug(`Check #${checkCount}: No session attributes available yet`);\n }\n } catch (error) {\n this.logDebug(`Check #${checkCount}: Error accessing metas: ${error}`);\n }\n\n await new Promise((resolve) => setTimeout(resolve, pollInterval));\n }\n\n const finalAttrs = this.metas?.value?.session?.attributes;\n const finalAttrCount = finalAttrs ? Object.keys(finalAttrs).length : 0;\n const finalAttrKeys = finalAttrs ? JSON.stringify(Object.keys(finalAttrs)) : 'none';\n this.logWarn(\n `Session attributes not ready after ${maxWaitMs}ms timeout (${checkCount} checks, ${finalAttrCount} attrs: ${finalAttrKeys}). Sending crash report anyway.`\n );\n }\n\n protected getNativeModule(): typeof NativeModules.FaroReactNativeModule | null {\n const { FaroReactNativeModule } = NativeModules;\n\n if (!FaroReactNativeModule) {\n return null;\n }\n\n return FaroReactNativeModule;\n }\n\n protected async processCrashReports(nativeModule: typeof NativeModules.FaroReactNativeModule): Promise<void> {\n try {\n if (typeof nativeModule.getCrashReport !== 'function') {\n this.logDebug('getCrashReport method not available');\n return;\n }\n\n this.logDebug('Attempting to retrieve crash reports from native module');\n const crashReports = (await nativeModule.getCrashReport()) as string[] | null;\n\n if (!crashReports || crashReports.length === 0) {\n this.logDebug('No crash reports from previous session');\n return;\n }\n\n this.logDebug(`Processing ${crashReports.length} crash report(s) from previous session`);\n\n const reportedTimestamps = new Set<number>();\n\n for (const crashJson of crashReports) {\n try {\n this.logDebug(`Parsing crash report JSON: ${crashJson.substring(0, 200)}...`);\n const crash = JSON.parse(crashJson) as CrashReport;\n\n if (crash.timestamp && reportedTimestamps.has(crash.timestamp)) {\n this.logDebug(`Skipping duplicate crash report at ${crash.timestamp}`);\n continue;\n }\n\n if (this.shouldSkipCrashReport(crash)) {\n this.logDebug(`Skipping crash report at ${crash.timestamp} (platform-specific skip logic)`);\n continue;\n }\n\n if (crash.timestamp) {\n reportedTimestamps.add(crash.timestamp);\n }\n\n this.sendCrashReport(crash);\n } catch (parseError) {\n this.logError('Failed to parse crash report JSON', parseError);\n this.api.pushError(new Error('Application crash (parse error)'), {\n context: {\n mechanism: 'crash',\n parseError: String(parseError),\n raw: crashJson.substring(0, 500),\n },\n fatal: true,\n type: 'crash',\n });\n }\n }\n } catch (error) {\n this.logError('Failed to process crash reports', error);\n }\n }\n\n protected buildCrashReportDetails(crash: CrashReport): CrashReportDetails {\n // Platform-specific parsing\n const parsedTrace = crash.trace ? this.parseCrashTrace(crash.trace) : null;\n const errorMessage = this.resolveCrashErrorMessage(crash, parsedTrace).trim() || 'Application crash';\n\n // Build context from crash data\n const context: Record<string, string> = {\n mechanism: 'crash',\n };\n\n if (crash.trace) {\n context['trace'] = crash.trace;\n }\n if (crash.signal) {\n context['signal'] = crash.signal;\n }\n if (crash.timestamp) {\n context['timestamp'] = String(crash.timestamp);\n }\n if (crash.description) {\n context['description'] = crash.description;\n }\n if (crash.processName) {\n context['processName'] = crash.processName;\n }\n if (crash.pid) {\n context['pid'] = String(crash.pid);\n }\n if (crash.importance !== undefined) {\n context['importance'] = String(crash.importance);\n }\n\n // Platform-specific context\n this.buildPlatformContext(parsedTrace, context);\n\n // Platform-specific stack frames\n const stackFrames = this.getStackFrames(parsedTrace);\n\n // Warnings for missing/unparseable traces\n if (!stackFrames.length && crash.trace) {\n this.logWarn(this.getParseFailureWarning());\n } else if (!crash.trace) {\n this.logWarn(this.getTraceUnavailableWarning());\n } else if (looksLikeNativeTombstoneTrace(crash.trace)) {\n const framePreview = crash.trace\n .split('\\n')\n .map((line) => line.trim())\n .find((line) => /#\\d+\\s+pc\\s+/i.test(line));\n this.logInfo(\n `[Faro crash native] Sending tombstone trace (${crash.trace.split('\\n').length} lines) preview=${framePreview ?? 'n/a'}`\n );\n }\n\n return {\n context,\n errorMessage,\n stackFrames,\n };\n }\n\n protected sendCrashReport(crash: CrashReport): void {\n const { context, errorMessage, stackFrames } = this.buildCrashReportDetails(crash);\n const error = new Error(errorMessage);\n error.stack = undefined;\n\n this.api.pushError(error, {\n stackFrames,\n context,\n type: 'crash',\n fatal: true,\n });\n\n this.logDebug(`Sent crash report: ${errorMessage}`);\n }\n\n // Logging helpers\n override logDebug(message: string, ...args: any[]): void {\n this.internalLogger?.debug?.(message, ...args);\n }\n\n override logInfo(message: string, ...args: any[]): void {\n this.internalLogger?.info?.(message, ...args);\n }\n\n override logWarn(message: string, ...args: any[]): void {\n this.internalLogger?.warn?.(message, ...args);\n }\n\n override logError(message: string, ...args: any[]): void {\n this.internalLogger?.error?.(message, ...args);\n }\n\n unpatch(): void {\n // No patching to undo\n }\n}\n"]}
|