diff --git a/packages/browser/src/profiling/hubextensions.ts b/packages/browser/src/profiling/hubextensions.ts index 250b4eb41b10..5b45b593b2e2 100644 --- a/packages/browser/src/profiling/hubextensions.ts +++ b/packages/browser/src/profiling/hubextensions.ts @@ -4,12 +4,8 @@ import type { Transaction } from '@sentry/types'; import { logger, uuid4 } from '@sentry/utils'; import { WINDOW } from '../helpers'; -import type { - JSSelfProfile, - JSSelfProfiler, - JSSelfProfilerConstructor, -} from './jsSelfProfiling'; -import { addProfileToMap,isValidSampleRate } from './utils'; +import type { JSSelfProfile, JSSelfProfiler, JSSelfProfilerConstructor } from './jsSelfProfiling'; +import { addProfileToMap, 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 @@ -82,7 +78,12 @@ export function wrapTransactionWithProfiling(transaction: Transaction): Transact // Prefer sampler to sample rate if both are provided. if (typeof profilesSampler === 'function') { - profilesSampleRate = profilesSampler({ transactionContext: transaction.toContext() }); + const transactionContext = transaction.toContext(); + profilesSampleRate = profilesSampler({ + parentSampled: transactionContext.parentSampled, + transactionContext: transactionContext, + ...transaction.getDynamicSamplingContext(), + }); } // Since this is coming from the user (or from a function provided by the user), who knows what we might get. (The diff --git a/packages/browser/src/profiling/integration.ts b/packages/browser/src/profiling/integration.ts index a559cdff53ae..eee2691bddc6 100644 --- a/packages/browser/src/profiling/integration.ts +++ b/packages/browser/src/profiling/integration.ts @@ -39,7 +39,7 @@ export class BrowserProfilingIntegration implements Integration { client.on('beforeEnvelope', (envelope): void => { // if not profiles are in queue, there is nothing to add to the envelope. - if (!PROFILE_MAP.size) { + if (!PROFILE_MAP['size']) { return; } @@ -51,14 +51,12 @@ export class BrowserProfilingIntegration implements Integration { const profilesToAddToEnvelope: Profile[] = []; for (const profiledTransaction of profiledTransactionEvents) { - const profile_id = - profiledTransaction && - profiledTransaction.contexts && - profiledTransaction.contexts['profile'] && - profiledTransaction.contexts['profile']['profile_id'] as string + const context = profiledTransaction && profiledTransaction.contexts; + const profile_id = context && context['profile'] && (context['profile']['profile_id'] as string); if (!profile_id) { - __DEBUG_BUILD__ && logger.log('[Profiling] cannot find profile for a transaction without a profile context'); + __DEBUG_BUILD__ && + logger.log('[Profiling] cannot find profile for a transaction without a profile context'); continue; } diff --git a/packages/browser/src/profiling/jsSelfProfiling.ts b/packages/browser/src/profiling/jsSelfProfiling.ts index d2991e6ddb63..8dc981d3d5d3 100644 --- a/packages/browser/src/profiling/jsSelfProfiling.ts +++ b/packages/browser/src/profiling/jsSelfProfiling.ts @@ -45,4 +45,3 @@ declare global { Profiler: typeof JSSelfProfilerConstructor | undefined; } } - diff --git a/packages/browser/src/profiling/utils.ts b/packages/browser/src/profiling/utils.ts index 09c0f44e5046..6c9b4d8ed6b9 100644 --- a/packages/browser/src/profiling/utils.ts +++ b/packages/browser/src/profiling/utils.ts @@ -430,7 +430,7 @@ function isValidProfile(profile: JSSelfProfile): profile is JSSelfProfile & { pr } if (!profile.frames.length) { - if(__DEBUG_BUILD__) { + if (__DEBUG_BUILD__) { logger.log('[Profiling] Discarding profile because it contains no frames'); } return false;