integration.js.map 7.3 KB

1
  1. {"version":3,"file":"integration.js","sources":["../../../../src/profiling/integration.ts"],"sourcesContent":["import { convertIntegrationFnToClass, defineIntegration, getCurrentScope } from '@sentry/core';\nimport type { Client, EventEnvelope, Integration, IntegrationClass, IntegrationFn, Transaction } from '@sentry/types';\nimport type { Profile } from '@sentry/types/src/profiling';\nimport { logger } from '@sentry/utils';\n\nimport { DEBUG_BUILD } from '../debug-build';\nimport { startProfileForTransaction } from './hubextensions';\nimport type { ProfiledEvent } from './utils';\nimport {\n addProfilesToEnvelope,\n createProfilingEvent,\n findProfiledTransactionsFromEnvelope,\n getActiveProfilesCount,\n isAutomatedPageLoadTransaction,\n shouldProfileTransaction,\n takeProfileFromGlobalCache,\n} from './utils';\n\nconst INTEGRATION_NAME = 'BrowserProfiling';\n\nconst _browserProfilingIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n // TODO v8: Remove this\n setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function\n setup(client) {\n const scope = getCurrentScope();\n\n // eslint-disable-next-line deprecation/deprecation\n const transaction = scope.getTransaction();\n\n if (transaction && isAutomatedPageLoadTransaction(transaction)) {\n if (shouldProfileTransaction(transaction)) {\n startProfileForTransaction(transaction);\n }\n }\n\n if (typeof client.on !== 'function') {\n logger.warn('[Profiling] Client does not support hooks, profiling will be disabled');\n return;\n }\n\n client.on('startTransaction', (transaction: Transaction) => {\n if (shouldProfileTransaction(transaction)) {\n startProfileForTransaction(transaction);\n }\n });\n\n client.on('beforeEnvelope', (envelope): void => {\n // if not profiles are in queue, there is nothing to add to the envelope.\n if (!getActiveProfilesCount()) {\n return;\n }\n\n const profiledTransactionEvents = findProfiledTransactionsFromEnvelope(envelope);\n if (!profiledTransactionEvents.length) {\n return;\n }\n\n const profilesToAddToEnvelope: Profile[] = [];\n\n for (const profiledTransaction of profiledTransactionEvents) {\n const context = profiledTransaction && profiledTransaction.contexts;\n const profile_id = context && context['profile'] && context['profile']['profile_id'];\n const start_timestamp = context && context['profile'] && context['profile']['start_timestamp'];\n\n if (typeof profile_id !== 'string') {\n DEBUG_BUILD && logger.log('[Profiling] cannot find profile for a transaction without a profile context');\n continue;\n }\n\n if (!profile_id) {\n DEBUG_BUILD && logger.log('[Profiling] cannot find profile for a transaction without a profile context');\n continue;\n }\n\n // Remove the profile from the transaction context before sending, relay will take care of the rest.\n if (context && context['profile']) {\n delete context.profile;\n }\n\n const profile = takeProfileFromGlobalCache(profile_id);\n if (!profile) {\n DEBUG_BUILD && logger.log(`[Profiling] Could not retrieve profile for transaction: ${profile_id}`);\n continue;\n }\n\n const profileEvent = createProfilingEvent(\n profile_id,\n start_timestamp as number | undefined,\n profile,\n profiledTransaction as ProfiledEvent,\n );\n if (profileEvent) {\n profilesToAddToEnvelope.push(profileEvent);\n }\n }\n\n addProfilesToEnvelope(envelope as EventEnvelope, profilesToAddToEnvelope);\n });\n },\n };\n}) satisfies IntegrationFn;\n\nexport const browserProfilingIntegration = defineIntegration(_browserProfilingIntegration);\n\n/**\n * Browser profiling integration. Stores any event that has contexts[\"profile\"][\"profile_id\"]\n * This exists because we do not want to await async profiler.stop calls as transaction.finish is called\n * in a synchronous context. Instead, we handle sending the profile async from the promise callback and\n * rely on being able to pull the event from the cache when we need to construct the envelope. This makes the\n * integration less reliable as we might be dropping profiles when the cache is full.\n *\n * @experimental\n * @deprecated Use `browserProfilingIntegration()` instead.\n */\n// eslint-disable-next-line deprecation/deprecation\nexport const BrowserProfilingIntegration = convertIntegrationFnToClass(\n INTEGRATION_NAME,\n browserProfilingIntegration,\n) as IntegrationClass<Integration & { setup: (client: Client) => void }>;\n\n// eslint-disable-next-line deprecation/deprecation\nexport type BrowserProfilingIntegration = typeof BrowserProfilingIntegration;\n"],"names":[],"mappings":";;;;;;AAkBA,MAAM,gBAAA,GAAmB,kBAAkB,CAAA;AAC3C;AACA,MAAM,4BAA6B,IAAG,MAAM;AAC5C,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B;AAC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