11import * as Sentry from '@sentry/react-native' ;
2+ import { getBundleStartTimestampMs } from '@sentry/react-native/dist/js/tracing/utils' ;
23import { Platform } from 'react-native' ;
3- import { PerformanceObserver } from 'react-native-performance' ;
44import { isDevelopment } from '@libs/Environment/Environment' ;
55import { endSpan , startSpan } from '@libs/telemetry/activeSpans' ;
66import { breadcrumbsIntegration , browserProfilingIntegration , consoleIntegration , navigationIntegration , tracingIntegration } from '@libs/telemetry/integrations' ;
@@ -10,6 +10,8 @@ import CONST from '@src/CONST';
1010import pkg from '../../../package.json' ;
1111import makeDebugTransport from './debugTransport' ;
1212
13+ const bundleEndMs = Date . now ( ) ;
14+
1315export default function ( ) : void {
1416 // With Sentry enabled in dev mode, profiling on iOS and Android does not work
1517 // If you want to enable Sentry in dev, set ENABLE_SENTRY_ON_DEV=true in .env
@@ -41,25 +43,15 @@ export default function (): void {
4143 op : CONST . TELEMETRY . SPAN_APP_STARTUP ,
4244 } ) ;
4345
44- let jsParseStartMs : number | undefined ;
45- const observer = new PerformanceObserver ( ( list ) => {
46- const entries = list . getEntries ( ) ;
47- for ( const entry of entries ) {
48- if ( entry . name === 'runJsBundleStart' && jsParseStartMs === undefined ) {
49- jsParseStartMs = entry . startTime ;
50- startSpan ( CONST . TELEMETRY . SPAN_JS_PARSE_TIME , {
51- name : CONST . TELEMETRY . SPAN_JS_PARSE_TIME ,
52- op : CONST . TELEMETRY . SPAN_JS_PARSE_TIME ,
53- startTime : jsParseStartMs / 1000 ,
54- } ) ;
55- }
56- if ( entry . name === 'runJsBundleEnd' ) {
57- if ( jsParseStartMs !== undefined ) {
58- endSpan ( CONST . TELEMETRY . SPAN_JS_PARSE_TIME , entry . startTime / 1000 ) ;
59- }
60- observer . disconnect ( ) ;
61- }
62- }
63- } ) ;
64- observer . observe ( { type : 'react-native-mark' , buffered : true } ) ;
46+ const bundleStartMs = getBundleStartTimestampMs ( ) ;
47+ if ( bundleStartMs ) {
48+ const durationMs = bundleEndMs - bundleStartMs ;
49+ console . debug ( `[Telemetry] JS parse time: ${ durationMs } ms` ) ;
50+ startSpan ( CONST . TELEMETRY . SPAN_JS_PARSE_TIME , {
51+ name : CONST . TELEMETRY . SPAN_JS_PARSE_TIME ,
52+ op : CONST . TELEMETRY . SPAN_JS_PARSE_TIME ,
53+ startTime : bundleStartMs / 1000 ,
54+ } ) ;
55+ endSpan ( CONST . TELEMETRY . SPAN_JS_PARSE_TIME , bundleEndMs / 1000 ) ;
56+ }
6557}
0 commit comments