Repository: getsentry/sentry
Pull request #86986: profiling: update profiling onboarding to use new API
Author: login: JonasBa
Labels: name: Scope: Frontend
description: Automatically applied to PRs that change frontend components
Created: 2025-03-13T13:41:10Z | Merged: 2025-03-21T17:57:42Z

Counterpart to https://github.com/getsentry/sentry/pull/85560/files#diff-62a09aa797d7e6058c0c4ad9552bad52c0a8a5cec5679a5002da90ebf6570267.

Requires https://github.com/getsentry/sentry-javascript/pull/15635/files to be released


Diff:
diff --git a/static/app/gettingStartedDocs/node/awslambda.spec.tsx b/static/app/gettingStartedDocs/node/awslambda.spec.tsx
index e12988ba7b21..2c6072f2cda6 100644
--- a/static/app/gettingStartedDocs/node/awslambda.spec.tsx
+++ b/static/app/gettingStartedDocs/node/awslambda.spec.tsx
@@ -40,7 +40,7 @@ describe('awslambda onboarding docs', function () {
       screen.getByText(textWithMarkupMatcher(/tracesSampleRate/))
     ).toBeInTheDocument();
     expect(
-      screen.getByText(textWithMarkupMatcher(/profilesSampleRate/))
+      screen.getByText(textWithMarkupMatcher(/profileSessionSampleRate: 1.0/))
     ).toBeInTheDocument();
   });
 
@@ -70,7 +70,7 @@ describe('awslambda onboarding docs', function () {
       )
     ).toBeInTheDocument();
     expect(
-      screen.getByText(textWithMarkupMatcher(/profilesSampleRate: 1\.0/))
+      screen.getByText(textWithMarkupMatcher(/profileLifecycle: 'trace'/))
     ).toBeInTheDocument();
   });
 
@@ -97,7 +97,7 @@ describe('awslambda onboarding docs', function () {
 
     // Profiles sample rate should not be set for continuous profiling
     expect(
-      screen.queryByText(textWithMarkupMatcher(/profilesSampleRate: 1\.0/))
+      screen.queryByText(textWithMarkupMatcher(/profileLifecycle: 'trace'/))
     ).not.toBeInTheDocument();
 
     // Should have start and stop profiling calls
diff --git a/static/app/gettingStartedDocs/node/azurefunctions.spec.tsx b/static/app/gettingStartedDocs/node/azurefunctions.spec.tsx
index 39bb9b2d626e..be3f1221496c 100644
--- a/static/app/gettingStartedDocs/node/azurefunctions.spec.tsx
+++ b/static/app/gettingStartedDocs/node/azurefunctions.spec.tsx
@@ -38,9 +38,6 @@ describe('express onboarding docs', function () {
     expect(
       screen.getByText(textWithMarkupMatcher(/tracesSampleRate/))
     ).toBeInTheDocument();
-    expect(
-      screen.getByText(textWithMarkupMatcher(/profilesSampleRate/))
-    ).toBeInTheDocument();
   });
 
   it('enables performance setting the tracesSampleRate to 1', () => {
@@ -69,7 +66,10 @@ describe('express onboarding docs', function () {
       )
     ).toBeInTheDocument();
     expect(
-      screen.getByText(textWithMarkupMatcher(/profilesSampleRate: 1\.0/))
+      screen.getByText(textWithMarkupMatcher(/profileLifecycle: 'trace'/))
+    ).toBeInTheDocument();
+    expect(
+      screen.getByText(textWithMarkupMatcher(/profileSessionSampleRate: 1.0/))
     ).toBeInTheDocument();
   });
 
@@ -96,7 +96,7 @@ describe('express onboarding docs', function () {
 
     // Profiles sample rate should not be set for continuous profiling
     expect(
-      screen.queryByText(textWithMarkupMatcher(/profilesSampleRate: 1\.0/))
+      screen.queryByText(textWithMarkupMatcher(/profileLifecycle: 'trace'/))
     ).not.toBeInTheDocument();
 
     // Should have start and stop profiling calls
diff --git a/static/app/gettingStartedDocs/node/connect.spec.tsx b/static/app/gettingStartedDocs/node/connect.spec.tsx
index 2748cfd231ce..fc36eef3e226 100644
--- a/static/app/gettingStartedDocs/node/connect.spec.tsx
+++ b/static/app/gettingStartedDocs/node/connect.spec.tsx
@@ -47,7 +47,7 @@ describe('connect onboarding docs', function () {
       screen.getByText(textWithMarkupMatcher(/tracesSampleRate/))
     ).toBeInTheDocument();
     expect(
-      screen.getByText(textWithMarkupMatcher(/profilesSampleRate/))
+      screen.getByText(textWithMarkupMatcher(/profileSessionSampleRate: 1.0/))
     ).toBeInTheDocument();
   });
 
@@ -77,7 +77,7 @@ describe('connect onboarding docs', function () {
       )
     ).toBeInTheDocument();
     expect(
-      screen.getByText(textWithMarkupMatcher(/profilesSampleRate: 1\.0/))
+      screen.getByText(textWithMarkupMatcher(/profileLifecycle: 'trace'/))
     ).toBeInTheDocument();
   });
 
@@ -104,7 +104,7 @@ describe('connect onboarding docs', function () {
 
     // Profiles sample rate should not be set for continuous profiling
     expect(
-      screen.queryByText(textWithMarkupMatcher(/profilesSampleRate: 1\.0/))
+      screen.queryByText(textWithMarkupMatcher(/profileLifecycle: 'trace'/))
     ).not.toBeInTheDocument();
 
     // Should have start and stop profiling calls
diff --git a/static/app/gettingStartedDocs/node/express.spec.tsx b/static/app/gettingStartedDocs/node/express.spec.tsx
index 1bf52c75c23f..462621fa2719 100644
--- a/static/app/gettingStartedDocs/node/express.spec.tsx
+++ b/static/app/gettingStartedDocs/node/express.spec.tsx
@@ -47,9 +47,6 @@ describe('express onboarding docs', function () {
     expect(
       screen.getByText(textWithMarkupMatcher(/tracesSampleRate/))
     ).toBeInTheDocument();
-    expect(
-      screen.getByText(textWithMarkupMatcher(/profilesSampleRate/))
-    ).toBeInTheDocument();
   });
 
   it('enables performance setting the tracesSampleRate to 1', () => {
@@ -63,6 +60,9 @@ describe('express onboarding docs', function () {
     expect(
       screen.getByText(textWithMarkupMatcher(/tracesSampleRate: 1\.0/))
     ).toBeInTheDocument();
+    expect(
+      screen.getByText(textWithMarkupMatcher(/profileSessionSampleRate: 1.0/))
+    ).toBeInTheDocument();
   });
 
   it('enables profiling by setting profiling samplerates', () => {
@@ -78,7 +78,7 @@ describe('express onboarding docs', function () {
       )
     ).toBeInTheDocument();
     expect(
-      screen.getByText(textWithMarkupMatcher(/profilesSampleRate: 1\.0/))
+      screen.getByText(textWithMarkupMatcher(/profileLifecycle: 'trace'/))
     ).toBeInTheDocument();
   });
   it('continuous profiling', () => {
@@ -104,7 +104,7 @@ describe('express onboarding docs', function () {
 
     // Profiles sample rate should not be set for continuous profiling
     expect(
-      screen.queryByText(textWithMarkupMatcher(/profilesSampleRate: 1\.0/))
+      screen.queryByText(textWithMarkupMatcher(/profileLifecycle: 'trace'/))
     ).not.toBeInTheDocument();
 
     // Should have start and stop profiling calls
diff --git a/static/app/gettingStartedDocs/node/fastify.spec.tsx b/static/app/gettingStartedDocs/node/fastify.spec.tsx
index 5e829e334aff..e029f0bcc55d 100644
--- a/static/app/gettingStartedDocs/node/fastify.spec.tsx
+++ b/static/app/gettingStartedDocs/node/fastify.spec.tsx
@@ -47,9 +47,6 @@ describe('fastify onboarding docs', function () {
     expect(
       screen.getByText(textWithMarkupMatcher(/tracesSampleRate/))
     ).toBeInTheDocument();
-    expect(
-      screen.getByText(textWithMarkupMatcher(/profilesSampleRate/))
-    ).toBeInTheDocument();
   });
 
   it('enables performance setting the tracesSampleRate to 1', () => {
@@ -63,6 +60,9 @@ describe('fastify onboarding docs', function () {
     expect(
       screen.getByText(textWithMarkupMatcher(/tracesSampleRate: 1\.0/))
     ).toBeInTheDocument();
+    expect(
+      screen.getByText(textWithMarkupMatcher(/profileSessionSampleRate: 1.0/))
+    ).toBeInTheDocument();
   });
 
   it('enables profiling by setting profiling samplerates', () => {
@@ -78,7 +78,7 @@ describe('fastify onboarding docs', function () {
       )
     ).toBeInTheDocument();
     expect(
-      screen.getByText(textWithMarkupMatcher(/profilesSampleRate: 1\.0/))
+      screen.getByText(textWithMarkupMatcher(/profileLifecycle: 'trace'/))
     ).toBeInTheDocument();
   });
 
@@ -105,7 +105,7 @@ describe('fastify onboarding docs', function () {
 
     // Profiles sample rate should not be set for continuous profiling
     expect(
-      screen.queryByText(textWithMarkupMatcher(/profilesSampleRate: 1\.0/))
+      screen.queryByText(textWithMarkupMatcher(/profileLifecycle: 'trace'/))
     ).not.toBeInTheDocument();
 
     // Should have start and stop profiling calls
diff --git a/static/app/gettingStartedDocs/node/gcpfunctions.spec.tsx b/static/app/gettingStartedDocs/node/gcpfunctions.spec.tsx
index f0df91ca70c9..b3171f418c0f 100644
--- a/static/app/gettingStartedDocs/node/gcpfunctions.spec.tsx
+++ b/static/app/gettingStartedDocs/node/gcpfunctions.spec.tsx
@@ -41,9 +41,6 @@ describe('gcpfunctions onboarding docs', function () {
     expect(
       screen.getByText(textWithMarkupMatcher(/tracesSampleRate/))
     ).toBeInTheDocument();
-    expect(
-      screen.getByText(textWithMarkupMatcher(/profilesSampleRate/))
-    ).toBeInTheDocument();
   });
 
   it('enables performance setting the tracesSampleRate to 1', () => {
@@ -57,6 +54,9 @@ describe('gcpfunctions onboarding docs', function () {
     expect(
       screen.getByText(textWithMarkupMatcher(/tracesSampleRate: 1\.0/))
     ).toBeInTheDocument();
+    expect(
+      screen.getByText(textWithMarkupMatcher(/profileSessionSampleRate: 1.0/))
+    ).toBeInTheDocument();
   });
 
   it('enables profiling by setting profiling samplerates', () => {
@@ -72,7 +72,7 @@ describe('gcpfunctions onboarding docs', function () {
       )
     ).toBeInTheDocument();
     expect(
-      screen.getByText(textWithMarkupMatcher(/profilesSampleRate: 1\.0/))
+      screen.getByText(textWithMarkupMatcher(/profileLifecycle: 'trace'/))
     ).toBeInTheDocument();
   });
 
@@ -99,7 +99,7 @@ describe('gcpfunctions onboarding docs', function () {
 
     // Profiles sample rate should not be set for continuous profiling
     expect(
-      screen.queryByText(textWithMarkupMatcher(/profilesSampleRate: 1\.0/))
+      screen.queryByText(textWithMarkupMatcher(/profileLifecycle: 'trace'/))
     ).not.toBeInTheDocument();
 
     // Should have start and stop profiling calls
diff --git a/static/app/gettingStartedDocs/node/hapi.spec.tsx b/static/app/gettingStartedDocs/node/hapi.spec.tsx
index aaef22d5c187..21c5e87d3168 100644
--- a/static/app/gettingStartedDocs/node/hapi.spec.tsx
+++ b/static/app/gettingStartedDocs/node/hapi.spec.tsx
@@ -47,9 +47,6 @@ describe('hapi onboarding docs', function () {
     expect(
       screen.getByText(textWithMarkupMatcher(/tracesSampleRate/))
     ).toBeInTheDocument();
-    expect(
-      screen.getByText(textWithMarkupMatcher(/profilesSampleRate/))
-    ).toBeInTheDocument();
   });
 
   it('enables performance setting the tracesSampleRate to 1', () => {
@@ -63,6 +60,9 @@ describe('hapi onboarding docs', function () {
     expect(
       screen.getByText(textWithMarkupMatcher(/tracesSampleRate: 1\.0/))
     ).toBeInTheDocument();
+    expect(
+      screen.getByText(textWithMarkupMatcher(/profileSessionSampleRate: 1.0/))
+    ).toBeInTheDocument();
   });
 
   it('enables profiling by setting profiling samplerates', () => {
@@ -78,7 +78,7 @@ describe('hapi onboarding docs', function () {
       )
     ).toBeInTheDocument();
     expect(
-      screen.getByText(textWithMarkupMatcher(/profilesSampleRate: 1\.0/))
+      screen.getByText(textWithMarkupMatcher(/profileLifecycle: 'trace'/))
     ).toBeInTheDocument();
   });
 
@@ -105,7 +105,7 @@ describe('hapi onboarding docs', function () {
 
     // Profiles sample rate should not be set for continuous profiling
     expect(
-      screen.queryByText(textWithMarkupMatcher(/profilesSampleRate: 1\.0/))
+      screen.queryByText(textWithMarkupMatcher(/profileLifecycle: 'trace'/))
     ).not.toBeInTheDocument();
 
     // Should have start and stop profiling calls
diff --git a/static/app/gettingStartedDocs/node/koa.spec.tsx b/static/app/gettingStartedDocs/node/koa.spec.tsx
index 63d5c4131a39..2e347f675dea 100644
--- a/static/app/gettingStartedDocs/node/koa.spec.tsx
+++ b/static/app/gettingStartedDocs/node/koa.spec.tsx
@@ -48,7 +48,7 @@ describe('koa onboarding docs', function () {
       screen.getByText(textWithMarkupMatcher(/tracesSampleRate/))
     ).toBeInTheDocument();
     expect(
-      screen.getByText(textWithMarkupMatcher(/profilesSampleRate/))
+      screen.getByText(textWithMarkupMatcher(/profileSessionSampleRate: 1.0/))
     ).toBeInTheDocument();
   });
 
@@ -78,7 +78,7 @@ describe('koa onboarding docs', function () {
       )
     ).toBeInTheDocument();
     expect(
-      screen.getByText(textWithMarkupMatcher(/profilesSampleRate: 1\.0/))
+      screen.getByText(textWithMarkupMatcher(/profileLifecycle: 'trace'/))
     ).toBeInTheDocument();
   });
 
@@ -105,7 +105,7 @@ describe('koa onboarding docs', function () {
 
     // Profiles sample rate should not be set for continuous profiling
     expect(
-      screen.queryByText(textWithMarkupMatcher(/profilesSampleRate: 1\.0/))
+      screen.queryByText(textWithMarkupMatcher(/profileLifecycle: 'trace'/))
     ).not.toBeInTheDocument();
 
     // Should have start and stop profiling calls
diff --git a/static/app/gettingStartedDocs/node/nestjs.spec.tsx b/static/app/gettingStartedDocs/node/nestjs.spec.tsx
index ec3b92575727..89a3d12e674b 100644
--- a/static/app/gettingStartedDocs/node/nestjs.spec.tsx
+++ b/static/app/gettingStartedDocs/node/nestjs.spec.tsx
@@ -48,7 +48,7 @@ describe('Nest.js onboarding docs', function () {
       screen.getByText(textWithMarkupMatcher(/tracesSampleRate/))
     ).toBeInTheDocument();
     expect(
-      screen.getByText(textWithMarkupMatcher(/profilesSampleRate/))
+      screen.getByText(textWithMarkupMatcher(/profileSessionSampleRate: 1.0/))
     ).toBeInTheDocument();
   });
 
@@ -78,7 +78,7 @@ describe('Nest.js onboarding docs', function () {
       )
     ).toBeInTheDocument();
     expect(
-      screen.getByText(textWithMarkupMatcher(/profilesSampleRate: 1\.0/))
+      screen.getByText(textWithMarkupMatcher(/profileLifecycle: 'trace'/))
     ).toBeInTheDocument();
   });
 
@@ -105,7 +105,7 @@ describe('Nest.js onboarding docs', function () {
 
     // Profiles sample rate should not be set for continuous profiling
     expect(
-      screen.queryByText(textWithMarkupMatcher(/profilesSampleRate: 1\.0/))
+      screen.queryByText(textWithMarkupMatcher(/profileLifecycle: 'trace'/))
     ).not.toBeInTheDocument();
 
     // Should have start and stop profiling calls
diff --git a/static/app/gettingStartedDocs/node/node.spec.tsx b/static/app/gettingStartedDocs/node/node.spec.tsx
index b50066153bc4..1094eaf5b239 100644
--- a/static/app/gettingStartedDocs/node/node.spec.tsx
+++ b/static/app/gettingStartedDocs/node/node.spec.tsx
@@ -40,7 +40,7 @@ describe('node onboarding docs', function () {
       screen.getByText(textWithMarkupMatcher(/tracesSampleRate/))
     ).toBeInTheDocument();
     expect(
-      screen.getByText(textWithMarkupMatcher(/profilesSampleRate/))
+      screen.getByText(textWithMarkupMatcher(/profileSessionSampleRate: 1.0/))
     ).toBeInTheDocument();
   });
 
@@ -70,7 +70,7 @@ describe('node onboarding docs', function () {
       )
     ).toBeInTheDocument();
     expect(
-      screen.getByText(textWithMarkupMatcher(/profilesSampleRate: 1\.0/))
+      screen.getByText(textWithMarkupMatcher(/profileLifecycle: 'trace'/))
     ).toBeInTheDocument();
   });
 
@@ -97,7 +97,7 @@ describe('node onboarding docs', function () {
 
     // Profiles sample rate should not be set for continuous profiling
     expect(
-      screen.queryByText(textWithMarkupMatcher(/profilesSampleRate: 1\.0/))
+      screen.queryByText(textWithMarkupMatcher(/profileLifecycle: 'trace'/))
     ).not.toBeInTheDocument();
 
     // Should have start and stop profiling calls
diff --git a/static/app/utils/gettingStartedDocs/node.ts b/static/app/utils/gettingStartedDocs/node.ts
index 1eebf7fb764d..9043e481073e 100644
--- a/static/app/utils/gettingStartedDocs/node.ts
+++ b/static/app/utils/gettingStartedDocs/node.ts
@@ -219,9 +219,14 @@ Sentry.init({
     params.isProfilingSelected &&
     params.profilingOptions?.defaultProfilingMode !== 'continuous'
       ? `
-    // Set sampling rate for profiling - this is relative to tracesSampleRate
-    profilesSampleRate: 1.0,`
-      : ''
+    // Set sampling rate for profiling - this is evaluated only once per SDK.init call
+    profileSessionSampleRate: 1.0,
+    // Trace lifecycle automatically enables profiling during active traces
+    profileLifecycle: 'trace',`
+      : `
+    // Set sampling rate for profiling - this is evaluated only once per SDK.init
+    profileSessionSampleRate: 1.0,
+    `
   }});${
     params.isProfilingSelected &&
     params.profilingOptions?.defaultProfilingMode === 'continuous'
@@ -241,8 +246,8 @@ Sentry.startSpan({
 `
     : '// this code will be profiled'
 }
-// Calls to stopProfiling are optional - if you don't stop the profiler, it will keep profiling
-// your application until the process exits or stopProfiling is called.
+// Calls to stopProfiler are optional - if you don't stop the profile session, it will keep profiling
+// your application until the process exits or stopProfiler is called.
 Sentry.profiler.stopProfiler();`
       : ''
   }`;


Reviews:
user: login: ArthurKnaus
state: APPROVED
author_association: MEMBER
submitted_at: 2025-03-13T13:41:39Z
user: login: constantinius
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-13T13:43:59Z
user: login: constantinius
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-13T13:44:18Z
user: login: constantinius
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-13T13:44:43Z

Review comments:
diff_hunk: @@ -228,7 +228,7 @@ Sentry.init({
       ? `
 // Manually call startProfiler and stopProfiler
 // to profile the code in between
path: static/app/utils/gettingStartedDocs/node.ts
user: login: constantinius
body: ```suggestion
// Manually call startProfileSession and stopProfileSession
// to profile the code in between
```
created_at: 2025-03-13T13:43:59Z
author_association: CONTRIBUTOR
diff_hunk: @@ -243,7 +243,7 @@ Sentry.startSpan({
 }
 // Calls to stopProfiling are optional - if you don't stop the profiler, it will keep profiling
 // your application until the process exits or stopProfiling is called.
path: static/app/utils/gettingStartedDocs/node.ts
user: login: constantinius
body: ```suggestion
// Calls to stopProfileSession are optional - if you don't stop the profiler, it will keep profiling
// your application until the process exits or stopProfiling is called.
```
created_at: 2025-03-13T13:44:18Z
author_association: CONTRIBUTOR
diff_hunk: @@ -228,7 +228,7 @@ Sentry.init({
       ? `
 // Manually call startProfiler and stopProfiler
 // to profile the code in between
path: static/app/utils/gettingStartedDocs/node.ts
user: login: constantinius
body: We should probably update the comments as well
created_at: 2025-03-13T13:44:43Z
author_association: CONTRIBUTOR

PR comments:
user: login: JonasBa
created_at: 2025-03-13T13:42:12Z
body: @ArthurKnaus just fyi, we need to wait for JS release before merging.
author_association: MEMBER
user: login: JonasBa
created_at: 2025-03-13T14:25:20Z
body: @ArthurKnaus @constantinius since you reviewed this, would you mind taking a look at the [docs change](https://github.com/getsentry/sentry-docs/pull/12998) as well?

author_association: MEMBER