{"version":3,"file":"utils.js","sources":["../../../../../src/profiling/utils.ts"],"sourcesContent":["/* eslint-disable max-lines */\nimport type {\n Client,\n ContinuousThreadCpuProfile,\n DebugImage,\n Envelope,\n Event,\n EventEnvelope,\n Profile,\n ProfileChunk,\n Span,\n ThreadCpuProfile,\n} from '@sentry/core/browser';\nimport {\n browserPerformanceTimeOrigin,\n debug,\n DEFAULT_ENVIRONMENT,\n forEachEnvelopeItem,\n getClient,\n getDebugImagesForResources,\n GLOBAL_OBJ,\n spanToJSON,\n timestampInSeconds,\n uuid4,\n} from '@sentry/core/browser';\nimport type { BrowserOptions } from '../client';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { WINDOW } from '../helpers';\nimport type { JSSelfProfile, JSSelfProfiler, JSSelfProfilerConstructor, JSSelfProfileStack } from './jsSelfProfiling';\n\nconst MS_TO_NS = 1e6;\n\n// Checking if we are in Main or Worker thread: `self` (not `window`) is the `globalThis` in Web Workers and `importScripts` are only available in Web Workers\nconst isMainThread = 'window' in GLOBAL_OBJ && GLOBAL_OBJ.window === GLOBAL_OBJ && typeof importScripts === 'undefined';\n\n// Setting ID to 0 as we cannot get an ID from Web Workers\nexport const PROFILER_THREAD_ID_STRING = String(0);\nexport const PROFILER_THREAD_NAME = isMainThread ? 'main' : 'worker';\n\n// We force make this optional to be on the safe side...\nconst navigator = WINDOW.navigator as typeof WINDOW.navigator | undefined;\n\n// Machine properties (eval only once)\nlet OS_PLATFORM = '';\nlet OS_PLATFORM_VERSION = '';\nlet OS_ARCH = '';\nlet OS_BROWSER = navigator?.userAgent || '';\nlet OS_MODEL = '';\nconst OS_LOCALE = navigator?.language || navigator?.languages?.[0] || '';\n\ntype UAData = {\n platform?: string;\n architecture?: string;\n model?: string;\n platformVersion?: string;\n fullVersionList?: {\n brand: string;\n version: string;\n }[];\n};\n\ninterface UserAgentData {\n getHighEntropyValues: (keys: string[]) => Promise;\n}\n\nfunction isUserAgentData(data: unknown): data is UserAgentData {\n return typeof data === 'object' && data !== null && 'getHighEntropyValues' in data;\n}\n\n// @ts-expect-error userAgentData is not part of the navigator interface yet\nconst userAgentData = navigator?.userAgentData;\n\nif (isUserAgentData(userAgentData)) {\n userAgentData\n .getHighEntropyValues(['architecture', 'model', 'platform', 'platformVersion', 'fullVersionList'])\n .then((ua: UAData) => {\n OS_PLATFORM = ua.platform || '';\n OS_ARCH = ua.architecture || '';\n OS_MODEL = ua.model || '';\n OS_PLATFORM_VERSION = ua.platformVersion || '';\n\n if (ua.fullVersionList?.length) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const firstUa = ua.fullVersionList[ua.fullVersionList.length - 1]!;\n OS_BROWSER = `${firstUa.brand} ${firstUa.version}`;\n }\n })\n .catch(e => void e);\n}\n\nfunction isProcessedJSSelfProfile(profile: ThreadCpuProfile | JSSelfProfile): profile is JSSelfProfile {\n return !('thread_metadata' in profile);\n}\n\n// Enriches the profile with threadId of the current thread.\n// This is done in node as we seem to not be able to get the info from C native code.\n/**\n *\n */\nexport function enrichWithThreadInformation(profile: ThreadCpuProfile | JSSelfProfile): ThreadCpuProfile {\n if (!isProcessedJSSelfProfile(profile)) {\n return profile;\n }\n\n return convertJSSelfProfileToSampledFormat(profile);\n}\n\n// Profile is marked as optional because it is deleted from the metadata\n// by the integration before the event is processed by other integrations.\nexport interface ProfiledEvent extends Event {\n sdkProcessingMetadata: {\n profile?: JSSelfProfile;\n };\n}\n\nfunction getTraceId(event: Event): string {\n const traceId: unknown = event.contexts?.trace?.trace_id;\n // Log a warning if the profile has an invalid traceId (should be uuidv4).\n // All profiles and transactions are rejected if this is the case and we want to\n // warn users that this is happening if they enable debug flag\n if (typeof traceId === 'string' && traceId.length !== 32) {\n if (DEBUG_BUILD) {\n debug.log(`[Profiling] Invalid traceId: ${traceId} on profiled event`);\n }\n }\n if (typeof traceId !== 'string') {\n return '';\n }\n\n return traceId;\n}\n/**\n * Creates a profiling event envelope from a Sentry event. If profile does not pass\n * validation, returns null.\n * @param event\n * @param dsn\n * @param metadata\n * @param tunnel\n * @returns {EventEnvelope | null}\n */\n\n/**\n * Creates a profiling event envelope from a Sentry event.\n */\nexport function createProfilePayload(\n profile_id: string,\n start_timestamp: number | undefined,\n processed_profile: JSSelfProfile,\n event: ProfiledEvent,\n): Profile {\n if (event.type !== 'transaction') {\n // createProfilingEventEnvelope should only be called for transactions,\n // we type guard this behavior with isProfiledTransactionEvent.\n throw new TypeError('Profiling events may only be attached to transactions, this should never occur.');\n }\n\n if (processed_profile === undefined || processed_profile === null) {\n throw new TypeError(\n `Cannot construct profiling event envelope without a valid profile. Got ${processed_profile} instead.`,\n );\n }\n\n const traceId = getTraceId(event);\n const enrichedThreadProfile = enrichWithThreadInformation(processed_profile);\n const transactionStartMs = start_timestamp\n ? start_timestamp\n : typeof event.start_timestamp === 'number'\n ? event.start_timestamp * 1000\n : timestampInSeconds() * 1000;\n const transactionEndMs = typeof event.timestamp === 'number' ? event.timestamp * 1000 : timestampInSeconds() * 1000;\n\n const profile: Profile = {\n event_id: profile_id,\n timestamp: new Date(transactionStartMs).toISOString(),\n platform: 'javascript',\n version: '1',\n release: event.release || '',\n environment: event.environment || DEFAULT_ENVIRONMENT,\n runtime: {\n name: 'javascript',\n version: WINDOW.navigator.userAgent,\n },\n os: {\n name: OS_PLATFORM,\n version: OS_PLATFORM_VERSION,\n build_number: OS_BROWSER,\n },\n device: {\n locale: OS_LOCALE,\n model: OS_MODEL,\n manufacturer: OS_BROWSER,\n architecture: OS_ARCH,\n is_emulator: false,\n },\n debug_meta: {\n images: applyDebugMetadata(processed_profile.resources),\n },\n profile: enrichedThreadProfile,\n transactions: [\n {\n name: event.transaction || '',\n id: event.event_id || uuid4(),\n trace_id: traceId,\n active_thread_id: PROFILER_THREAD_ID_STRING,\n relative_start_ns: '0',\n relative_end_ns: ((transactionEndMs - transactionStartMs) * 1e6).toFixed(0),\n },\n ],\n };\n\n return profile;\n}\n\n/**\n * Create a profile chunk envelope item\n */\nexport function createProfileChunkPayload(\n jsSelfProfile: JSSelfProfile,\n client: Client,\n profilerId?: string,\n): ProfileChunk {\n // only == to catch null and undefined\n if (jsSelfProfile == null) {\n throw new TypeError(\n `Cannot construct profiling event envelope without a valid profile. Got ${jsSelfProfile} instead.`,\n );\n }\n\n const continuousProfile = convertToContinuousProfile(jsSelfProfile);\n\n const options = client.getOptions();\n const sdk = client.getSdkMetadata?.()?.sdk;\n\n return {\n chunk_id: uuid4(),\n client_sdk: {\n name: sdk?.name ?? 'sentry.javascript.browser',\n version: sdk?.version ?? '0.0.0',\n },\n profiler_id: profilerId || uuid4(),\n platform: 'javascript',\n version: '2',\n release: options.release ?? '',\n environment: options.environment ?? 'production',\n debug_meta: {\n // function name obfuscation\n images: applyDebugMetadata(jsSelfProfile.resources),\n },\n profile: continuousProfile,\n };\n}\n\n/**\n * Validate a profile chunk against the Sample Format V2 requirements.\n * https://develop.sentry.dev/sdk/telemetry/profiles/sample-format-v2/\n * - Presence of samples, stacks, frames\n * - Required metadata fields\n */\nexport function validateProfileChunk(chunk: ProfileChunk): { valid: true } | { reason: string } {\n try {\n // Required metadata\n if (!chunk || typeof chunk !== 'object') {\n return { reason: 'chunk is not an object' };\n }\n\n // profiler_id and chunk_id must be 32 lowercase hex chars\n const isHex32 = (val: unknown): boolean => typeof val === 'string' && /^[a-f0-9]{32}$/.test(val);\n if (!isHex32(chunk.profiler_id)) {\n return { reason: 'missing or invalid profiler_id' };\n }\n if (!isHex32(chunk.chunk_id)) {\n return { reason: 'missing or invalid chunk_id' };\n }\n\n if (!chunk.client_sdk) {\n return { reason: 'missing client_sdk metadata' };\n }\n\n // Profile data must have frames, stacks, samples\n const profile = chunk.profile as { frames?: unknown[]; stacks?: unknown[]; samples?: unknown[] } | undefined;\n if (!profile) {\n return { reason: 'missing profile data' };\n }\n\n if (!Array.isArray(profile.frames) || !profile.frames.length) {\n return { reason: 'profile has no frames' };\n }\n if (!Array.isArray(profile.stacks) || !profile.stacks.length) {\n return { reason: 'profile has no stacks' };\n }\n if (!Array.isArray(profile.samples) || !profile.samples.length) {\n return { reason: 'profile has no samples' };\n }\n\n return { valid: true };\n } catch (e) {\n return { reason: `unknown validation error: ${e}` };\n }\n}\n\n/**\n * Convert from JSSelfProfile format to ContinuousThreadCpuProfile format.\n */\nfunction convertToContinuousProfile(input: {\n frames: { name: string; resourceId?: number; line?: number; column?: number }[];\n stacks: { frameId: number; parentId?: number }[];\n samples: { timestamp: number; stackId?: number }[];\n resources: string[];\n}): ContinuousThreadCpuProfile {\n // Frames map 1:1 by index; fill only when present to avoid sparse writes\n const frames: ContinuousThreadCpuProfile['frames'] = [];\n for (let i = 0; i < input.frames.length; i++) {\n const frame = input.frames[i];\n if (!frame) {\n continue;\n }\n frames[i] = {\n function: frame.name,\n abs_path: typeof frame.resourceId === 'number' ? input.resources[frame.resourceId] : undefined,\n lineno: frame.line,\n colno: frame.column,\n };\n }\n\n // Build stacks by following parent links, top->down order (root last)\n const stacks: ContinuousThreadCpuProfile['stacks'] = [];\n for (let i = 0; i < input.stacks.length; i++) {\n const stackHead = input.stacks[i];\n if (!stackHead) {\n continue;\n }\n const list: number[] = [];\n let current: { frameId: number; parentId?: number } | undefined = stackHead;\n while (current) {\n list.push(current.frameId);\n current = current.parentId === undefined ? undefined : input.stacks[current.parentId];\n }\n stacks[i] = list;\n }\n\n // Align timestamps to SDK time origin to match span/event timelines\n const perfOrigin = browserPerformanceTimeOrigin();\n const origin = typeof performance.timeOrigin === 'number' ? performance.timeOrigin : perfOrigin || 0;\n const adjustForOriginChange = origin - (perfOrigin || origin);\n\n const samples: ContinuousThreadCpuProfile['samples'] = [];\n for (let i = 0; i < input.samples.length; i++) {\n const sample = input.samples[i];\n if (!sample) {\n continue;\n }\n // Convert ms to seconds epoch-based timestamp\n const timestampSeconds = (origin + (sample.timestamp - adjustForOriginChange)) / 1000;\n samples[i] = {\n stack_id: sample.stackId ?? 0,\n thread_id: PROFILER_THREAD_ID_STRING,\n timestamp: timestampSeconds,\n };\n }\n\n return {\n frames,\n stacks,\n samples,\n thread_metadata: { [PROFILER_THREAD_ID_STRING]: { name: PROFILER_THREAD_NAME } },\n };\n}\n\n/**\n *\n */\nexport function isProfiledTransactionEvent(event: Event): event is ProfiledEvent {\n return !!event.sdkProcessingMetadata?.profile;\n}\n\n/*\n See packages/browser-utils/src/browser/router.ts\n*/\n/**\n *\n */\nexport function isAutomatedPageLoadSpan(span: Span): boolean {\n return spanToJSON(span).op === 'pageload';\n}\n\n/**\n * Converts a JSSelfProfile to a our sampled format.\n * Does not currently perform stack indexing.\n */\nexport function convertJSSelfProfileToSampledFormat(input: JSSelfProfile): Profile['profile'] {\n let EMPTY_STACK_ID: undefined | number = undefined;\n let STACK_ID = 0;\n\n // Initialize the profile that we will fill with data\n const profile: Profile['profile'] = {\n samples: [],\n stacks: [],\n frames: [],\n thread_metadata: {\n [PROFILER_THREAD_ID_STRING]: { name: PROFILER_THREAD_NAME },\n },\n };\n\n const firstSample = input.samples[0];\n if (!firstSample) {\n return profile;\n }\n\n // We assert samples.length > 0 above and timestamp should always be present\n const start = firstSample.timestamp;\n // The JS SDK might change it's time origin based on some heuristic (see See packages/utils/src/time.ts)\n // when that happens, we need to ensure we are correcting the profile timings so the two timelines stay in sync.\n // Since JS self profiling time origin is always initialized to performance.timeOrigin, we need to adjust for\n // the drift between the SDK selected value and our profile time origin.\n const perfOrigin = browserPerformanceTimeOrigin();\n const origin = typeof performance.timeOrigin === 'number' ? performance.timeOrigin : perfOrigin || 0;\n const adjustForOriginChange = origin - (perfOrigin || origin);\n\n input.samples.forEach((jsSample, i) => {\n // If sample has no stack, add an empty sample\n if (jsSample.stackId === undefined) {\n if (EMPTY_STACK_ID === undefined) {\n EMPTY_STACK_ID = STACK_ID;\n profile.stacks[EMPTY_STACK_ID] = [];\n STACK_ID++;\n }\n\n profile['samples'][i] = {\n // convert ms timestamp to ns\n elapsed_since_start_ns: ((jsSample.timestamp + adjustForOriginChange - start) * MS_TO_NS).toFixed(0),\n stack_id: EMPTY_STACK_ID,\n thread_id: PROFILER_THREAD_ID_STRING,\n };\n return;\n }\n\n let stackTop: JSSelfProfileStack | undefined = input.stacks[jsSample.stackId];\n\n // Functions in top->down order (root is last)\n // We follow the stackTop.parentId trail and collect each visited frameId\n const stack: number[] = [];\n\n while (stackTop) {\n stack.push(stackTop.frameId);\n\n const frame = input.frames[stackTop.frameId];\n\n // If our frame has not been indexed yet, index it\n if (frame && profile.frames[stackTop.frameId] === undefined) {\n profile.frames[stackTop.frameId] = {\n function: frame.name,\n abs_path: typeof frame.resourceId === 'number' ? input.resources[frame.resourceId] : undefined,\n lineno: frame.line,\n colno: frame.column,\n };\n }\n\n stackTop = stackTop.parentId === undefined ? undefined : input.stacks[stackTop.parentId];\n }\n\n const sample: Profile['profile']['samples'][0] = {\n // convert ms timestamp to ns\n elapsed_since_start_ns: ((jsSample.timestamp + adjustForOriginChange - start) * MS_TO_NS).toFixed(0),\n stack_id: STACK_ID,\n thread_id: PROFILER_THREAD_ID_STRING,\n };\n\n profile['stacks'][STACK_ID] = stack;\n profile['samples'][i] = sample;\n STACK_ID++;\n });\n\n return profile;\n}\n\n/**\n * Adds items to envelope if they are not already present - mutates the envelope.\n * @param envelope\n */\nexport function addProfilesToEnvelope(envelope: EventEnvelope, profiles: Profile[]): Envelope {\n if (!profiles.length) {\n return envelope;\n }\n\n for (const profile of profiles) {\n envelope[1].push([{ type: 'profile' }, profile]);\n }\n return envelope;\n}\n\n/**\n * Finds transactions with profile_id context in the envelope\n * @param envelope\n * @returns\n */\nexport function findProfiledTransactionsFromEnvelope(envelope: Envelope): Event[] {\n const events: Event[] = [];\n\n forEachEnvelopeItem(envelope, (item, type) => {\n if (type !== 'transaction') {\n return;\n }\n\n for (let j = 1; j < item.length; j++) {\n const event = item[j] as Event;\n\n if (event?.contexts?.profile?.profile_id) {\n events.push(item[j] as Event);\n }\n }\n });\n\n return events;\n}\n\n/**\n * Applies debug meta data to an event from a list of paths to resources (sourcemaps)\n */\nexport function applyDebugMetadata(resource_paths: ReadonlyArray): DebugImage[] {\n const client = getClient();\n const options = client?.getOptions();\n const stackParser = options?.stackParser;\n\n if (!stackParser) {\n return [];\n }\n\n return getDebugImagesForResources(stackParser, resource_paths);\n}\n\n/**\n * Checks the given sample rate to make sure it is valid type and value (a boolean, or a number between 0 and 1).\n */\nexport function isValidSampleRate(rate: unknown): boolean {\n // we need to check NaN explicitly because it's of type 'number' and therefore wouldn't get caught by this typecheck\n if ((typeof rate !== 'number' && typeof rate !== 'boolean') || (typeof rate === 'number' && isNaN(rate))) {\n DEBUG_BUILD &&\n debug.warn(\n `[Profiling] Invalid sample rate. Sample rate must be a boolean or a number between 0 and 1. Got ${JSON.stringify(\n rate,\n )} of type ${JSON.stringify(typeof rate)}.`,\n );\n return false;\n }\n\n // Boolean sample rates are always valid\n if (rate === true || rate === false) {\n return true;\n }\n\n // in case sampleRate is a boolean, it will get automatically cast to 1 if it's true and 0 if it's false\n if (rate < 0 || rate > 1) {\n DEBUG_BUILD && debug.warn(`[Profiling] Invalid sample rate. Sample rate must be between 0 and 1. Got ${rate}.`);\n return false;\n }\n return true;\n}\n\nfunction isValidProfile(profile: JSSelfProfile): profile is JSSelfProfile & { profile_id: string } {\n if (profile.samples.length < 2) {\n if (DEBUG_BUILD) {\n // Log a warning if the profile has less than 2 samples so users can know why\n // they are not seeing any profiling data and we cant avoid the back and forth\n // of asking them to provide us with a dump of the profile data.\n debug.log('[Profiling] Discarding profile because it contains less than 2 samples');\n }\n return false;\n }\n\n if (!profile.frames.length) {\n if (DEBUG_BUILD) {\n debug.log('[Profiling] Discarding profile because it contains no frames');\n }\n return false;\n }\n\n return true;\n}\n\n// Keep a flag value to avoid re-initializing the profiler constructor. If it fails\n// once, it will always fail and this allows us to early return.\nlet PROFILING_CONSTRUCTOR_FAILED: boolean = false;\nexport const MAX_PROFILE_DURATION_MS = 30_000;\n\n/**\n * Check if profiler constructor is available.\n * @param maybeProfiler\n */\nfunction isJSProfilerSupported(maybeProfiler: unknown): maybeProfiler is typeof JSSelfProfilerConstructor {\n return typeof maybeProfiler === 'function';\n}\n\n/**\n * Starts the profiler and returns the profiler instance.\n */\nexport function startJSSelfProfile(): JSSelfProfiler | undefined {\n // Feature support check first\n const JSProfilerConstructor = WINDOW.Profiler;\n\n if (!isJSProfilerSupported(JSProfilerConstructor)) {\n if (DEBUG_BUILD) {\n debug.log('[Profiling] Profiling is not supported by this browser, Profiler interface missing on window object.');\n }\n return;\n }\n\n // From initial testing, it seems that the minimum value for sampleInterval is 10ms.\n const samplingIntervalMS = 10;\n // Start the profiler\n const maxSamples = Math.floor(MAX_PROFILE_DURATION_MS / samplingIntervalMS);\n\n // Attempt to initialize the profiler constructor, if it fails, we disable profiling for the current user session.\n // This is likely due to a missing 'Document-Policy': 'js-profiling' header. We do not want to throw an error if this happens\n // as we risk breaking the user's application, so just disable profiling and log an error.\n try {\n return new JSProfilerConstructor({ sampleInterval: samplingIntervalMS, maxBufferSize: maxSamples });\n } catch (_e) {\n if (DEBUG_BUILD) {\n debug.log(\n \"[Profiling] Failed to initialize the Profiling constructor, this is likely due to a missing 'Document-Policy': 'js-profiling' header.\",\n );\n debug.log('[Profiling] Disabling profiling for current user session.');\n }\n PROFILING_CONSTRUCTOR_FAILED = true;\n }\n\n return;\n}\n\n/**\n * Determine if a profile should be profiled.\n */\nexport function shouldProfileSpanLegacy(span: Span): boolean {\n // If constructor failed once, it will always fail, so we can early return.\n if (PROFILING_CONSTRUCTOR_FAILED) {\n if (DEBUG_BUILD) {\n debug.log('[Profiling] Profiling has been disabled for the duration of the current user session.');\n }\n return false;\n }\n\n if (!span.isRecording()) {\n DEBUG_BUILD && debug.log('[Profiling] Discarding profile because root span was not sampled.');\n return false;\n }\n\n const client = getClient();\n const options = client?.getOptions();\n if (!options) {\n DEBUG_BUILD && debug.log('[Profiling] Profiling disabled, no options found.');\n return false;\n }\n\n // eslint-disable-next-line deprecation/deprecation\n const profilesSampleRate = (options as BrowserOptions).profilesSampleRate as\n | BrowserOptions['profilesSampleRate']\n | boolean;\n\n // Since this is coming from the user (or from a function provided by the user), who knows what we might get. (The\n // only valid values are booleans or numbers between 0 and 1.)\n if (!isValidSampleRate(profilesSampleRate)) {\n DEBUG_BUILD && debug.warn('[Profiling] Discarding profile because of invalid sample rate.');\n return false;\n }\n\n // if the function returned 0 (or false), or if `profileSampleRate` is 0, it's a sign the profile should be dropped\n if (!profilesSampleRate) {\n DEBUG_BUILD &&\n debug.log(\n '[Profiling] Discarding profile because a negative sampling decision was inherited or profileSampleRate is set to 0',\n );\n return false;\n }\n\n // Now we roll the dice. Math.random is inclusive of 0, but not of 1, so strict < is safe here. In case sampleRate is\n // a boolean, the < comparison will cause it to be automatically cast to 1 if it's true and 0 if it's false.\n const sampled = profilesSampleRate === true ? true : Math.random() < profilesSampleRate;\n // Check if we should sample this profile\n if (!sampled) {\n DEBUG_BUILD &&\n debug.log(\n `[Profiling] Discarding profile because it's not included in the random sample (sampling rate = ${Number(\n profilesSampleRate,\n )})`,\n );\n return false;\n }\n\n return true;\n}\n\n/**\n * Determine if a profile should be created for the current session.\n */\nexport function shouldProfileSession(options: BrowserOptions): boolean {\n // If constructor failed once, it will always fail, so we can early return.\n if (PROFILING_CONSTRUCTOR_FAILED) {\n if (DEBUG_BUILD) {\n debug.log(\n '[Profiling] Profiling has been disabled for the duration of the current user session as the JS Profiler could not be started.',\n );\n }\n return false;\n }\n\n if (options.profileLifecycle !== 'trace' && options.profileLifecycle !== 'manual') {\n DEBUG_BUILD && debug.warn('[Profiling] Session not sampled. Invalid `profileLifecycle` option.');\n return false;\n }\n\n // Session sampling: profileSessionSampleRate gates whether profiling is enabled for this session\n const profileSessionSampleRate = options.profileSessionSampleRate;\n\n if (!isValidSampleRate(profileSessionSampleRate)) {\n DEBUG_BUILD && debug.warn('[Profiling] Discarding profile because of invalid profileSessionSampleRate.');\n return false;\n }\n\n if (!profileSessionSampleRate) {\n DEBUG_BUILD &&\n debug.log('[Profiling] Discarding profile because profileSessionSampleRate is not defined or set to 0');\n return false;\n }\n\n return Math.random() <= profileSessionSampleRate;\n}\n\n/**\n * Checks if legacy profiling is configured.\n */\nexport function hasLegacyProfiling(options: BrowserOptions): boolean {\n // eslint-disable-next-line deprecation/deprecation\n return typeof options.profilesSampleRate !== 'undefined';\n}\n\n/**\n * Creates a profiling envelope item, if the profile does not pass validation, returns null.\n * @param event\n * @returns {Profile | null}\n */\nexport function createProfilingEvent(\n profile_id: string,\n start_timestamp: number | undefined,\n profile: JSSelfProfile,\n event: ProfiledEvent,\n): Profile | null {\n if (!isValidProfile(profile)) {\n return null;\n }\n\n return createProfilePayload(profile_id, start_timestamp, profile, event);\n}\n\n// TODO (v8): We need to obtain profile ids in @sentry-internal/tracing,\n// but we don't have access to this map because importing this map would\n// cause a circular dependency. We need to resolve this in v8.\nconst PROFILE_MAP: Map = new Map();\n/**\n *\n */\nexport function getActiveProfilesCount(): number {\n return PROFILE_MAP.size;\n}\n\n/**\n * Retrieves profile from global cache and removes it.\n */\nexport function takeProfileFromGlobalCache(profile_id: string): JSSelfProfile | undefined {\n const profile = PROFILE_MAP.get(profile_id);\n if (profile) {\n PROFILE_MAP.delete(profile_id);\n }\n return profile;\n}\n/**\n * Adds profile to global cache and evicts the oldest profile if the cache is full.\n */\nexport function addProfileToGlobalCache(profile_id: string, profile: JSSelfProfile): void {\n PROFILE_MAP.set(profile_id, profile);\n\n if (PROFILE_MAP.size > 30) {\n const last = PROFILE_MAP.keys().next().value;\n if (last !== undefined) {\n PROFILE_MAP.delete(last);\n }\n }\n}\n\nexport const PROFILED_ROOT_SPANS = new WeakSet();\n\nexport function setThreadAttributes(span: Span): void {\n span.setAttribute('thread.id', PROFILER_THREAD_ID_STRING);\n span.setAttribute('thread.name', PROFILER_THREAD_NAME);\n}\n"],"names":["GLOBAL_OBJ","WINDOW","DEBUG_BUILD","debug","timestampInSeconds","DEFAULT_ENVIRONMENT","uuid4","browserPerformanceTimeOrigin","spanToJSON","forEachEnvelopeItem","getClient","getDebugImagesForResources"],"mappings":";;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