@grafana/faro-react-native 1.0.0 → 1.2.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.
Files changed (47) hide show
  1. package/README.md +80 -3
  2. package/android/build.gradle +145 -0
  3. package/dist/cjs/config/getRNInstrumentations.js +3 -1
  4. package/dist/cjs/config/getRNInstrumentations.js.map +1 -1
  5. package/dist/cjs/config/makeRNConfig.js +7 -4
  6. package/dist/cjs/config/makeRNConfig.js.map +1 -1
  7. package/dist/cjs/config/types.js.map +1 -1
  8. package/dist/cjs/generated/faroRNPackageMeta.js +1 -1
  9. package/dist/cjs/generated/faroRNPackageMeta.js.map +1 -1
  10. package/dist/cjs/instrumentations/errors/index.js +3 -2
  11. package/dist/cjs/instrumentations/errors/index.js.map +1 -1
  12. package/dist/cjs/instrumentations/errors/stackTraceParser.js +98 -37
  13. package/dist/cjs/instrumentations/errors/stackTraceParser.js.map +1 -1
  14. package/dist/cjs/util/performanceObserverPolyfill.js +32 -3
  15. package/dist/cjs/util/performanceObserverPolyfill.js.map +1 -1
  16. package/dist/esm/config/getRNInstrumentations.js +3 -1
  17. package/dist/esm/config/getRNInstrumentations.js.map +1 -1
  18. package/dist/esm/config/makeRNConfig.js +7 -4
  19. package/dist/esm/config/makeRNConfig.js.map +1 -1
  20. package/dist/esm/config/types.js.map +1 -1
  21. package/dist/esm/generated/faroRNPackageMeta.js +1 -1
  22. package/dist/esm/generated/faroRNPackageMeta.js.map +1 -1
  23. package/dist/esm/instrumentations/errors/index.js +3 -2
  24. package/dist/esm/instrumentations/errors/index.js.map +1 -1
  25. package/dist/esm/instrumentations/errors/stackTraceParser.js +97 -37
  26. package/dist/esm/instrumentations/errors/stackTraceParser.js.map +1 -1
  27. package/dist/esm/util/performanceObserverPolyfill.js +32 -3
  28. package/dist/esm/util/performanceObserverPolyfill.js.map +1 -1
  29. package/dist/types/config/types.d.ts +5 -0
  30. package/dist/types/generated/faroRNPackageMeta.d.ts +1 -1
  31. package/dist/types/instrumentations/errors/index.d.ts +5 -0
  32. package/dist/types/instrumentations/errors/stackTraceParser.d.ts +19 -3
  33. package/dist/types/util/performanceObserverPolyfill.d.ts +5 -2
  34. package/ios/faro-upload-composed-source-map.sh +87 -0
  35. package/package.json +7 -10
  36. package/react-native.config.js +9 -1
  37. package/src/config/getRNInstrumentations.ts +5 -1
  38. package/src/config/makeRNConfig.test.ts +11 -0
  39. package/src/config/makeRNConfig.ts +7 -4
  40. package/src/config/types.ts +5 -0
  41. package/src/generated/faroRNPackageMeta.ts +1 -1
  42. package/src/initialize.test.ts +25 -0
  43. package/src/instrumentations/errors/index.ts +25 -8
  44. package/src/instrumentations/errors/stackTraceParser.test.ts +65 -0
  45. package/src/instrumentations/errors/stackTraceParser.ts +121 -37
  46. package/src/util/performanceObserverPolyfill.test.ts +48 -0
  47. package/src/util/performanceObserverPolyfill.ts +43 -3
@@ -21,6 +21,9 @@ const globalObj =
21
21
  (typeof window !== 'undefined' && window) ||
22
22
  {};
23
23
 
24
+ const RESOURCE_ENTRY_TYPE = 'resource';
25
+ const FARO_RESOURCE_TIMING_PATCH = '__faroResourceTimingPatch';
26
+
24
27
  interface PerformanceEntry {
25
28
  readonly duration: number;
26
29
  readonly entryType: string;
@@ -71,15 +74,20 @@ class NoopPerformanceObserver {
71
74
  }
72
75
 
73
76
  /**
74
- * Apply polyfill on React Native iOS to prevent bad_variant_access crash.
75
- * Must run before any code that might use PerformanceObserver.
77
+ * Apply React Native performance API compatibility patches.
78
+ *
79
+ * Resource Timing lookup is patched on all platforms because OTel web
80
+ * instrumentation can probe it. The PerformanceObserver replacement is
81
+ * iOS-only to avoid the native bad_variant_access crash.
76
82
  */
77
83
  export function applyPerformanceObserverPolyfill(): void {
84
+ const record = globalObj as Record<string, unknown>;
85
+ patchUnsupportedResourceTimingLookup(record);
86
+
78
87
  if (Platform.OS !== 'ios') {
79
88
  return;
80
89
  }
81
90
 
82
- const record = globalObj as Record<string, unknown>;
83
91
  const existing = record['PerformanceObserver'];
84
92
  if (existing && (existing as unknown as { name?: string }).name === 'NoopPerformanceObserver') {
85
93
  return; // Already applied
@@ -91,3 +99,35 @@ export function applyPerformanceObserverPolyfill(): void {
91
99
  // Ignore if global is frozen (e.g. in some test environments)
92
100
  }
93
101
  }
102
+
103
+ function patchUnsupportedResourceTimingLookup(record: Record<string, unknown>): void {
104
+ const performance = record['performance'] as
105
+ | {
106
+ getEntriesByType?: ((entryType: string) => PerformanceEntry[]) & Record<string, boolean>;
107
+ }
108
+ | undefined;
109
+
110
+ if (!performance?.getEntriesByType || performance.getEntriesByType[FARO_RESOURCE_TIMING_PATCH]) {
111
+ return;
112
+ }
113
+
114
+ const originalGetEntriesByType = performance.getEntriesByType.bind(performance);
115
+ const patchedGetEntriesByType = ((entryType: string): PerformanceEntry[] => {
116
+ if (entryType === RESOURCE_ENTRY_TYPE) {
117
+ // OTel web fetch instrumentation probes browser Resource Timing APIs.
118
+ // React Native does not expose resource entries, and calling through emits
119
+ // "Deprecated API for given entry type." warnings in development.
120
+ return [];
121
+ }
122
+
123
+ return originalGetEntriesByType(entryType);
124
+ }) as typeof performance.getEntriesByType;
125
+
126
+ patchedGetEntriesByType[FARO_RESOURCE_TIMING_PATCH] = true;
127
+
128
+ try {
129
+ performance.getEntriesByType = patchedGetEntriesByType;
130
+ } catch {
131
+ // Ignore if performance is read-only in a test or host environment.
132
+ }
133
+ }