diff --git a/packages/browser/src/profiling/hubextensions.ts b/packages/browser/src/profiling/hubextensions.ts index 292d4e672ae6..57e544942a45 100644 --- a/packages/browser/src/profiling/hubextensions.ts +++ b/packages/browser/src/profiling/hubextensions.ts @@ -4,14 +4,14 @@ import type { Transaction } from '@sentry/types'; import { logger, uuid4 } from '@sentry/utils'; import { WINDOW } from '../helpers'; -import { addToProfileQueue } from './integration'; import type { JSSelfProfile, JSSelfProfiler, JSSelfProfilerConstructor, ProcessedJSSelfProfile, } from './jsSelfProfiling'; -import { isValidSampleRate } from './utils'; +import { addToProfileQueue , isValidSampleRate } from './utils'; + export const MAX_PROFILE_DURATION_MS = 30_000; // Keep a flag value to avoid re-initializing the profiler constructor. If it fails @@ -270,3 +270,5 @@ export function wrapTransactionWithProfiling(transaction: Transaction): Transact transaction.finish = profilingWrappedTransactionFinish; return transaction; } + + diff --git a/packages/browser/src/profiling/integration.ts b/packages/browser/src/profiling/integration.ts index c8cbe4617161..1f5051371c5c 100644 --- a/packages/browser/src/profiling/integration.ts +++ b/packages/browser/src/profiling/integration.ts @@ -4,24 +4,8 @@ import { logger } from '@sentry/utils'; import type { BrowserClient } from './../client'; import { wrapTransactionWithProfiling } from './hubextensions'; -import type { ProcessedJSSelfProfile } from './jsSelfProfiling'; import type { ProfiledEvent } from './utils'; -import { addProfilesToEnvelope, createProfilingEvent, findProfiledTransactionsFromEnvelope } from './utils'; - -const MAX_PROFILE_QUEUE_SIZE = 50; -const PROFILE_QUEUE: ProcessedJSSelfProfile[] = []; - -/** - * Adds the profile to the queue of profiles to be sent - */ -export function addToProfileQueue(profile: ProcessedJSSelfProfile): void { - PROFILE_QUEUE.push(profile); - - // We only want to keep the last n profiles in the queue. - if (PROFILE_QUEUE.length > MAX_PROFILE_QUEUE_SIZE) { - PROFILE_QUEUE.shift(); - } -} +import { addProfilesToEnvelope, createProfilingEvent, findProfiledTransactionsFromEnvelope,PROFILE_QUEUE } from './utils'; /** * Browser profiling integration. Stores any event that has contexts["profile"]["profile_id"] diff --git a/packages/browser/src/profiling/utils.ts b/packages/browser/src/profiling/utils.ts index 1cf1f97d65bc..4c4f1a175fe8 100644 --- a/packages/browser/src/profiling/utils.ts +++ b/packages/browser/src/profiling/utils.ts @@ -450,3 +450,17 @@ export function createProfilingEvent(profile: ProcessedJSSelfProfile, event: Pro return createProfilePayload(event, profile); } + +const MAX_PROFILE_QUEUE_SIZE = 50; +export const PROFILE_QUEUE: ProcessedJSSelfProfile[] = []; +/** + * Adds the profile to the queue of profiles to be sent + */ +export function addToProfileQueue(profile: ProcessedJSSelfProfile): void { + PROFILE_QUEUE.push(profile); + + // We only want to keep the last n profiles in the queue. + if (PROFILE_QUEUE.length > MAX_PROFILE_QUEUE_SIZE) { + PROFILE_QUEUE.shift(); + } +} \ No newline at end of file