From 2da84a369cd1547b3728325a448b591df578a510 Mon Sep 17 00:00:00 2001 From: JonasBa Date: Fri, 23 Jun 2023 09:31:03 -0400 Subject: [PATCH] fix: context type --- packages/browser/src/profiling/hubextensions.ts | 15 ++++++++------- packages/browser/src/profiling/integration.ts | 12 +++++------- 2 files changed, 13 insertions(+), 14 deletions(-) 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; }