MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / setup

Function setup

packages/browser/src/profiling/integration.ts:27–159  ·  view source on GitHub ↗
(client)

Source from the content-addressed store, hash-verified

25 return {
26 name: INTEGRATION_NAME,
27 setup(client) {
28 const options = client.getOptions() as BrowserOptions;
29 const profiler = new UIProfiler();
30
31 if (!hasLegacyProfiling(options) && !options.profileLifecycle) {
32 // Set default lifecycle mode
33 options.profileLifecycle = 'manual';
34 }
35
36 // eslint-disable-next-line typescript/no-deprecated
37 if (hasLegacyProfiling(options) && !options.profilesSampleRate) {
38 DEBUG_BUILD && debug.log('[Profiling] Profiling disabled, no profiling options found.');
39 return;
40 }
41
42 const activeSpan = getActiveSpan();
43 const rootSpan = activeSpan && getRootSpan(activeSpan);
44
45 if (hasLegacyProfiling(options) && options.profileSessionSampleRate !== undefined) {
46 DEBUG_BUILD &&
47 debug.warn(
48 '[Profiling] Both legacy profiling (`profilesSampleRate`) and UI profiling settings are defined. `profileSessionSampleRate` has no effect when legacy profiling is enabled.',
49 );
50 }
51
52 // UI PROFILING (Profiling V2)
53 if (!hasLegacyProfiling(options)) {
54 const lifecycleMode = options.profileLifecycle;
55
56 // Registering hooks in all lifecycle modes to be able to notify users in case they want to start/stop the profiler manually in `trace` mode
57 client.on('startUIProfiler', () => profiler.start());
58 client.on('stopUIProfiler', () => profiler.stop());
59
60 if (lifecycleMode === 'manual') {
61 profiler.initialize(client);
62 } else if (lifecycleMode === 'trace') {
63 if (!hasSpansEnabled(options)) {
64 DEBUG_BUILD &&
65 debug.warn(
66 "[Profiling] `profileLifecycle` is 'trace' but tracing is disabled. Set a `tracesSampleRate` or `tracesSampler` to enable span tracing.",
67 );
68 return;
69 }
70
71 profiler.initialize(client);
72
73 // If there is an active, sampled root span already, notify the profiler
74 if (rootSpan) {
75 profiler.notifyRootSpanActive(rootSpan);
76 }
77
78 // In case rootSpan is created slightly after setup -> schedule microtask to re-check and notify.
79 WINDOW.setTimeout(() => {
80 const laterActiveSpan = getActiveSpan();
81 const laterRootSpan = laterActiveSpan && getRootSpan(laterActiveSpan);
82 if (laterRootSpan) {
83 profiler.notifyRootSpanActive(laterRootSpan);
84 }

Callers

nothing calls this directly

Calls 15

startMethod · 0.95
stopMethod · 0.95
initializeMethod · 0.95
notifyRootSpanActiveMethod · 0.95
hasLegacyProfilingFunction · 0.90
isAutomatedPageLoadSpanFunction · 0.90
shouldProfileSpanLegacyFunction · 0.90
startProfileForSpanFunction · 0.90
setThreadAttributesFunction · 0.90
getActiveProfilesCountFunction · 0.90

Tested by

no test coverage detected