Skip to content

Commit

Permalink
fix: context type
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasBa committed Jun 23, 2023
1 parent c7078fb commit 2da84a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
15 changes: 8 additions & 7 deletions packages/browser/src/profiling/hubextensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions packages/browser/src/profiling/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down

0 comments on commit 2da84a3

Please sign in to comment.