2026-07-20 16:05:17 +00:00
// Module ID: 1076
2026-07-24 07:16:23 +00:00
// Function ID: 12361
2026-07-20 16:05:17 +00:00
// Name: UIProfiler
2026-07-23 10:11:24 +00:00
// Dependencies: [5, 6, 7, 1077, 1048, 794]
2026-07-20 16:05:17 +00:00
// Module 1076 (UIProfiler)
2026-07-23 10:11:24 +00:00
import asyncGeneratorStep from "registerSpanErrorInstrumentation" ;
import _classCallCheck from "_classCallCheck" ;
import _defineProperties from "_defineProperties" ;
2026-07-20 16:05:17 +00:00
Object . defineProperty ( exports , Symbol . toStringTag , { value : "Module" } ) ;
2026-07-23 10:11:24 +00:00
export const UIProfiler = ( ( ) => {
2026-07-20 16:05:17 +00:00
class UIProfiler {
constructor ( ) {
2026-07-23 10:11:24 +00:00
tmp = outer1 _3 ( this , UIProfiler ) ;
2026-07-20 16:05:17 +00:00
this . _client = undefined ;
this . _profiler = undefined ;
this . _chunkTimer = undefined ;
this . _profilerId = undefined ;
this . _isRunning = false ;
this . _sessionSampled = false ;
this . _lifecycleMode = undefined ;
set = new Set ( ) ;
this . _activeRootSpanIds = set ;
map = new Map ( ) ;
this . _rootSpanTimeouts = map ;
return ;
}
}
let obj = {
key : "initialize" ,
value : function initialize ( getOptions ) {
const self = this ;
const profileLifecycle = getOptions . getOptions ( ) . profileLifecycle ;
const shouldProfileSessionResult = callback ( UIProfiler [ 3 ] ) . shouldProfileSession ( getOptions . getOptions ( ) ) ;
if ( callback ( UIProfiler [ 4 ] ) . DEBUG _BUILD ) {
const debug = callback ( UIProfiler [ 5 ] ) . debug ;
const _HermesInternal = HermesInternal ;
debug . log ( "[Profiling] Initializing profiler (lifecycle='" + profileLifecycle + "')." ) ;
}
if ( ! shouldProfileSessionResult ) {
if ( callback ( UIProfiler [ 4 ] ) . DEBUG _BUILD ) {
const debug2 = callback ( UIProfiler [ 5 ] ) . debug ;
debug2 . log ( "[Profiling] Session not sampled. Skipping lifecycle profiler initialization." ) ;
}
}
const obj = callback ( UIProfiler [ 3 ] ) ;
self . _profilerId = callback ( UIProfiler [ 5 ] ) . uuid4 ( ) ;
self . _client = getOptions ;
self . _sessionSampled = shouldProfileSessionResult ;
self . _lifecycleMode = profileLifecycle ;
if ( "trace" === profileLifecycle ) {
const result = self . _setupTraceLifecycleListeners ( getOptions ) ;
}
}
} ;
2026-07-23 10:11:24 +00:00
let items = [ obj , , , , , , , , , , , , , , ] ;
2026-07-20 16:05:17 +00:00
obj = {
key : "start" ,
value : function start ( ) {
const self = this ;
if ( "trace" !== this . _lifecycleMode ) {
if ( self . _isRunning ) {
if ( callback ( UIProfiler [ 4 ] ) . DEBUG _BUILD ) {
const debug3 = callback ( UIProfiler [ 5 ] ) . debug ;
debug3 . warn ( "[Profiling] Profile session is already running, `uiProfiler.start()` is a no-op." ) ;
}
} else if ( self . _sessionSampled ) {
self . _beginProfiling ( ) ;
} else if ( callback ( UIProfiler [ 4 ] ) . DEBUG _BUILD ) {
const debug2 = callback ( UIProfiler [ 5 ] ) . debug ;
debug2 . warn ( "[Profiling] Session is not sampled, `uiProfiler.start()` is a no-op." ) ;
}
} else if ( callback ( UIProfiler [ 4 ] ) . DEBUG _BUILD ) {
const debug = callback ( UIProfiler [ 5 ] ) . debug ;
debug . warn ( "[Profiling] `profileLifecycle` is set to \"trace\". Calls to `uiProfiler.start()` are ignored in trace mode." ) ;
}
}
} ;
items [ 1 ] = obj ;
obj = {
key : "stop" ,
value : function stop ( ) {
const self = this ;
if ( "trace" !== this . _lifecycleMode ) {
if ( self . _isRunning ) {
self . _endProfiling ( ) ;
} else if ( callback ( UIProfiler [ 4 ] ) . DEBUG _BUILD ) {
const debug2 = callback ( UIProfiler [ 5 ] ) . debug ;
debug2 . warn ( "[Profiling] Profiler is not running, `uiProfiler.stop()` is a no-op." ) ;
}
} else if ( callback ( UIProfiler [ 4 ] ) . DEBUG _BUILD ) {
const debug = callback ( UIProfiler [ 5 ] ) . debug ;
debug . warn ( "[Profiling] `profileLifecycle` is set to \"trace\". Calls to `uiProfiler.stop()` are ignored in trace mode." ) ;
}
}
} ;
items [ 2 ] = obj ;
items [ 3 ] = {
key : "notifyRootSpanActive" ,
value : function notifyRootSpanActive ( rootSpan ) {
const self = this ;
if ( "trace" === this . _lifecycleMode ) {
if ( self . _sessionSampled ) {
const spanId = rootSpan . spanContext ( ) . spanId ;
if ( spanId ) {
const _activeRootSpanIds = self . _activeRootSpanIds ;
if ( ! _activeRootSpanIds . has ( spanId ) ) {
const result = self . _registerTraceRootSpan ( spanId ) ;
const size = self . _activeRootSpanIds . size ;
if ( 1 === size ) {
if ( callback ( UIProfiler [ 4 ] ) . DEBUG _BUILD ) {
const debug = callback ( UIProfiler [ 5 ] ) . debug ;
debug . log ( "[Profiling] Detected already active root span during setup. Active root spans now:" , size ) ;
}
self . _beginProfiling ( ) ;
}
}
}
}
}
}
} ;
items [ 4 ] = {
key : "_beginProfiling" ,
value : function _beginProfiling ( ) {
const self = this ;
if ( ! this . _isRunning ) {
self . _isRunning = true ;
if ( callback ( UIProfiler [ 4 ] ) . DEBUG _BUILD ) {
const debug = callback ( UIProfiler [ 5 ] ) . debug ;
debug . log ( "[Profiling] Started profiling with profiler ID:" , self . _profilerId ) ;
}
let obj = callback ( UIProfiler [ 5 ] ) ;
const globalScope = obj . getGlobalScope ( ) ;
obj = { profiler _id : self . _profilerId } ;
globalScope . setContext ( "profile" , obj ) ;
const result = self . _startProfilerInstance ( ) ;
if ( self . _profiler ) {
const result1 = self . _startPeriodicChunking ( ) ;
} else {
if ( callback ( UIProfiler [ 4 ] ) . DEBUG _BUILD ) {
const debug2 = callback ( UIProfiler [ 5 ] ) . debug ;
debug2 . log ( "[Profiling] Failed to start JS Profiler; stopping." ) ;
}
self . _resetProfilerInfo ( ) ;
}
}
}
} ;
items [ 5 ] = {
key : "_endProfiling" ,
value : function _endProfiling ( ) {
const self = this ;
if ( this . _isRunning ) {
self . _isRunning = false ;
if ( self . _chunkTimer ) {
const _clearTimeout = clearTimeout ;
clearTimeout ( self . _chunkTimer ) ;
self . _chunkTimer = undefined ;
}
const result = self . _clearAllRootSpanTimeouts ( ) ;
self . _collectCurrentChunk ( ) . catch ( ( arg0 ) => {
2026-07-23 10:11:24 +00:00
if ( callback ( UIProfiler [ 4 ] ) . DEBUG _BUILD ) {
const debug = callback ( UIProfiler [ 5 ] ) . debug ;
2026-07-20 16:05:17 +00:00
debug . error ( "[Profiling] Failed to collect current profile chunk on `stop()`:" , arg0 ) ;
}
} ) ;
if ( "manual" === self . _lifecycleMode ) {
const globalScope = callback ( UIProfiler [ 5 ] ) . getGlobalScope ( ) ;
globalScope . setContext ( "profile" , { } ) ;
const obj = callback ( UIProfiler [ 5 ] ) ;
}
const _collectCurrentChunkResult = self . _collectCurrentChunk ( ) ;
}
}
} ;
items [ 6 ] = {
key : "_setupTraceLifecycleListeners" ,
value : function _setupTraceLifecycleListeners ( on ) {
2026-07-23 10:11:24 +00:00
const self = this ;
2026-07-20 16:05:17 +00:00
on . on ( "spanStart" , ( isRecording ) => {
if ( self . _sessionSampled ) {
if ( isRecording === tmpResult . getRootSpan ( isRecording ) ) {
if ( isRecording . isRecording ( ) ) {
const spanId = isRecording . spanContext ( ) . spanId ;
if ( spanId ) {
const _activeRootSpanIds = self . _activeRootSpanIds ;
if ( ! _activeRootSpanIds . has ( spanId ) ) {
const result = self . _registerTraceRootSpan ( spanId ) ;
const size = self . _activeRootSpanIds . size ;
if ( 1 === size ) {
2026-07-23 10:11:24 +00:00
if ( _self ( UIProfiler [ 4 ] ) . DEBUG _BUILD ) {
const debug3 = _self ( UIProfiler [ 5 ] ) . debug ;
2026-07-20 16:05:17 +00:00
const _HermesInternal = HermesInternal ;
debug3 . log ( "[Profiling] Root span " + spanId + " started. Profiling active while there are active root spans (count=" + size + ")." ) ;
}
self . _beginProfiling ( ) ;
}
}
}
2026-07-23 10:11:24 +00:00
} else if ( _self ( UIProfiler [ 4 ] ) . DEBUG _BUILD ) {
const debug2 = _self ( UIProfiler [ 5 ] ) . debug ;
2026-07-20 16:05:17 +00:00
debug2 . log ( "[Profiling] Discarding profile because root span was not sampled." ) ;
}
}
2026-07-23 10:11:24 +00:00
tmpResult = tmp ( tmp2 [ 5 ] ) ;
2026-07-20 16:05:17 +00:00
} else if ( tmp ( tmp2 [ 4 ] ) . DEBUG _BUILD ) {
2026-07-23 10:11:24 +00:00
const debug = _self ( UIProfiler [ 5 ] ) . debug ;
2026-07-20 16:05:17 +00:00
debug . log ( "[Profiling] Span not profiled because of negative sampling decision for user session." ) ;
}
} ) ;
on . on ( "spanEnd" , ( spanContext ) => {
if ( self . _sessionSampled ) {
const spanId = spanContext . spanContext ( ) . spanId ;
if ( spanId ) {
const _activeRootSpanIds = self . _activeRootSpanIds ;
if ( _activeRootSpanIds . has ( spanId ) ) {
const _activeRootSpanIds2 = self . _activeRootSpanIds ;
_activeRootSpanIds2 . delete ( spanId ) ;
const size = self . _activeRootSpanIds . size ;
2026-07-23 10:11:24 +00:00
if ( _self ( UIProfiler [ 4 ] ) . DEBUG _BUILD ) {
let debug = _self ( UIProfiler [ 5 ] ) . debug ;
2026-07-20 16:05:17 +00:00
const _HermesInternal = HermesInternal ;
debug . log ( "[Profiling] Root span with ID " + spanId + " ended. Will continue profiling for as long as there are active root spans (currently: " + size + ")." ) ;
}
if ( 0 === size ) {
self . _collectCurrentChunk ( ) . catch ( ( arg0 ) => {
2026-07-23 10:11:24 +00:00
if ( callback ( UIProfiler [ 4 ] ) . DEBUG _BUILD ) {
const debug = callback ( UIProfiler [ 5 ] ) . debug ;
2026-07-20 16:05:17 +00:00
debug . error ( "[Profiling] Failed to collect current profile chunk on last `spanEnd`:" , arg0 ) ;
}
} ) ;
self . _endProfiling ( ) ;
const _collectCurrentChunkResult = self . _collectCurrentChunk ( ) ;
}
}
}
}
} ) ;
}
} ;
items [ 7 ] = {
key : "_resetProfilerInfo" ,
value : function _resetProfilerInfo ( ) {
this . _isRunning = false ;
const globalScope = callback ( UIProfiler [ 5 ] ) . getGlobalScope ( ) ;
globalScope . setContext ( "profile" , { } ) ;
}
} ;
items [ 8 ] = {
key : "_clearAllRootSpanTimeouts" ,
value : function _clearAllRootSpanTimeouts ( ) {
let _rootSpanTimeouts = this . _rootSpanTimeouts ;
const item = _rootSpanTimeouts . forEach ( ( arg0 ) => clearTimeout ( arg0 ) ) ;
_rootSpanTimeouts = this . _rootSpanTimeouts ;
_rootSpanTimeouts . clear ( ) ;
}
} ;
items [ 9 ] = {
key : "_registerTraceRootSpan" ,
value : function _registerTraceRootSpan ( spanId ) {
let closure _0 = spanId ;
2026-07-23 10:11:24 +00:00
const self = this ;
2026-07-20 16:05:17 +00:00
const _activeRootSpanIds = this . _activeRootSpanIds ;
_activeRootSpanIds . add ( spanId ) ;
const _rootSpanTimeouts = this . _rootSpanTimeouts ;
2026-07-23 10:11:24 +00:00
const result = _rootSpanTimeouts . set ( spanId , setTimeout ( ( ) => self . _onRootSpanTimeout ( closure _0 ) , 300000 ) ) ;
2026-07-20 16:05:17 +00:00
}
} ;
items [ 10 ] = {
key : "_startProfilerInstance" ,
value : function _startProfilerInstance ( ) {
const _profiler = this . _profiler ;
let stopped ;
if ( null != _profiler ) {
stopped = _profiler . stopped ;
}
if ( false !== stopped ) {
const startJSSelfProfileResult = callback ( UIProfiler [ 3 ] ) . startJSSelfProfile ( ) ;
if ( startJSSelfProfileResult ) {
this . _profiler = startJSSelfProfileResult ;
} else if ( callback ( UIProfiler [ 4 ] ) . DEBUG _BUILD ) {
const debug = callback ( UIProfiler [ 5 ] ) . debug ;
debug . log ( "[Profiling] Failed to start JS Profiler." ) ;
}
const obj = callback ( UIProfiler [ 3 ] ) ;
}
}
} ;
items [ 11 ] = {
key : "_startPeriodicChunking" ,
value : function _startPeriodicChunking ( ) {
2026-07-23 10:11:24 +00:00
const self = this ;
2026-07-20 16:05:17 +00:00
if ( this . _isRunning ) {
const _setTimeout = setTimeout ;
tmp . _chunkTimer = setTimeout ( ( ) => {
self . _collectCurrentChunk ( ) . catch ( ( arg0 ) => {
2026-07-23 10:11:24 +00:00
if ( callback ( UIProfiler [ 4 ] ) . DEBUG _BUILD ) {
const debug = callback ( UIProfiler [ 5 ] ) . debug ;
2026-07-20 16:05:17 +00:00
debug . error ( "[Profiling] Failed to collect current profile chunk during periodic chunking:" , arg0 ) ;
}
} ) ;
if ( self . _isRunning ) {
const result = self . _startProfilerInstance ( ) ;
if ( self . _profiler ) {
const result1 = obj . _startPeriodicChunking ( ) ;
} else {
obj . _resetProfilerInfo ( ) ;
}
}
} , 60000 ) ;
}
}
} ;
items [ 12 ] = {
key : "_onRootSpanTimeout" ,
2026-07-23 10:11:24 +00:00
value : function _onRootSpanTimeout ( closure _0 ) {
2026-07-20 16:05:17 +00:00
const self = this ;
const _rootSpanTimeouts = this . _rootSpanTimeouts ;
2026-07-23 10:11:24 +00:00
if ( _rootSpanTimeouts . has ( closure _0 ) ) {
2026-07-20 16:05:17 +00:00
const _rootSpanTimeouts2 = self . _rootSpanTimeouts ;
2026-07-23 10:11:24 +00:00
_rootSpanTimeouts2 . delete ( closure _0 ) ;
2026-07-20 16:05:17 +00:00
const _activeRootSpanIds = self . _activeRootSpanIds ;
2026-07-23 10:11:24 +00:00
if ( _activeRootSpanIds . has ( closure _0 ) ) {
2026-07-20 16:05:17 +00:00
if ( callback ( UIProfiler [ 4 ] ) . DEBUG _BUILD ) {
const debug = callback ( UIProfiler [ 5 ] ) . debug ;
const _HermesInternal = HermesInternal ;
2026-07-23 10:11:24 +00:00
debug . log ( "[Profiling] Reached 5-minute timeout for root span " + closure _0 + ". You likely started a manual root span that never called `.end()`." ) ;
2026-07-20 16:05:17 +00:00
}
const _activeRootSpanIds2 = self . _activeRootSpanIds ;
2026-07-23 10:11:24 +00:00
_activeRootSpanIds2 . delete ( closure _0 ) ;
2026-07-20 16:05:17 +00:00
if ( 0 === self . _activeRootSpanIds . size ) {
self . _endProfiling ( ) ;
}
}
}
}
} ;
const obj11 = { key : "_collectCurrentChunk" } ;
2026-07-23 10:11:24 +00:00
let closure _0 = asyncGeneratorStep ( async function ( ) {
2026-07-20 16:05:17 +00:00
const self = this ;
const _profiler = self . _profiler ;
self . _profiler = undefined ;
if ( _profiler ) {
const tmp2 = yield obj . stop ( ) ;
2026-07-23 10:11:24 +00:00
const profileChunkPayload = callback ( UIProfiler [ 3 ] ) . createProfileChunkPayload ( tmp2 , self . _client , self . _profilerId ) ;
const obj2 = callback ( UIProfiler [ 3 ] ) ;
const validateProfileChunkResult = callback ( UIProfiler [ 3 ] ) . validateProfileChunk ( profileChunkPayload ) ;
2026-07-20 16:05:17 +00:00
if ( "reason" in validateProfileChunkResult ) {
2026-07-23 10:11:24 +00:00
const DEBUG _BUILD = callback ( UIProfiler [ 4 ] ) . DEBUG _BUILD ;
2026-07-20 16:05:17 +00:00
if ( DEBUG _BUILD ) {
2026-07-23 10:11:24 +00:00
const debug2 = callback ( UIProfiler [ 5 ] ) . debug ;
2026-07-20 16:05:17 +00:00
debug2 . log ( "[Profiling] Discarding invalid profile chunk (this is probably a bug in the SDK):" , validateProfileChunkResult . reason ) ;
}
} else {
self . _sendProfileChunk ( profileChunkPayload ) ;
2026-07-23 10:11:24 +00:00
if ( callback ( UIProfiler [ 4 ] ) . DEBUG _BUILD ) {
const debug = callback ( UIProfiler [ 5 ] ) . debug ;
2026-07-20 16:05:17 +00:00
debug . log ( "[Profiling] Collected browser profile chunk." ) ;
}
}
2026-07-23 10:11:24 +00:00
const obj3 = callback ( UIProfiler [ 3 ] ) ;
2026-07-20 16:05:17 +00:00
}
} ) ;
obj11 . value = function _collectCurrentChunk ( ) {
return callback ( ... arguments ) ;
} ;
items [ 13 ] = obj11 ;
items [ 14 ] = {
key : "_sendProfileChunk" ,
value : function _sendProfileChunk ( profileChunkPayload ) {
const _client = this . _client ;
let obj = callback ( UIProfiler [ 5 ] ) ;
let sdkMetadata ;
if ( null != _client . getSdkMetadata ) {
sdkMetadata = _client . getSdkMetadata ( ) ;
}
const sdkMetadataForEnvelopeHeader = obj . getSdkMetadataForEnvelopeHeader ( sdkMetadata ) ;
const dsn = _client . getDsn ( ) ;
let obj1 = callback ( UIProfiler [ 5 ] ) ;
obj = { event _id : callback ( UIProfiler [ 5 ] ) . uuid4 ( ) } ;
const obj4 = callback ( UIProfiler [ 5 ] ) ;
obj . sent _at = new Date ( ) . toISOString ( ) ;
let tmp4 = sdkMetadataForEnvelopeHeader ;
if ( sdkMetadataForEnvelopeHeader ) {
obj = { sdk : sdkMetadataForEnvelopeHeader } ;
tmp4 = obj ;
}
const tmp5 = ! _client . getOptions ( ) . tunnel ;
let tmp6 = ! tmp5 ;
if ( ! tmp5 ) {
tmp6 = dsn ;
}
if ( tmp6 ) {
obj1 = { dsn : callback ( UIProfiler [ 5 ] ) . dsnToString ( dsn ) } ;
tmp6 = obj1 ;
const obj8 = callback ( UIProfiler [ 5 ] ) ;
}
const items = [ { type : "profile_chunk" } , profileChunkPayload ] ;
const items1 = [ items ] ;
const date = new Date ( ) ;
_client . sendEnvelope ( obj1 . createEnvelope ( Object . assign ( obj , tmp4 , tmp6 ) , items1 ) ) . then ( null , ( arg0 ) => {
2026-07-23 10:11:24 +00:00
if ( callback ( UIProfiler [ 4 ] ) . DEBUG _BUILD ) {
const debug = callback ( UIProfiler [ 5 ] ) . debug ;
2026-07-20 16:05:17 +00:00
debug . error ( "Error while sending profile chunk envelope:" , arg0 ) ;
}
} ) ;
}
} ;
2026-07-23 10:11:24 +00:00
return _defineProperties ( UIProfiler , items ) ;
} ) ( ) ;