Skip to content

Commit 8c325f3

Browse files
committed
profiling: rename api
1 parent 5ef0e8b commit 8c325f3

File tree

5 files changed

+40
-96
lines changed

5 files changed

+40
-96
lines changed

docs/migration/continuous-profiling.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Previously, the profiling mode was implicitly determined by initialization optio
1717

1818
The main profiling control methods have been renamed to better reflect their purpose:
1919

20-
- `Sentry.profiler.start()``Sentry.profiler.startProfileSession()`
21-
- `Sentry.profiler.stop()``Sentry.profiler.stopProfileSession()`
20+
- `Sentry.profiler.start()``Sentry.profiler.startProfiler()`
21+
- `Sentry.profiler.stop()``Sentry.profiler.stopProfiler()`
2222

2323
The new names emphasize that these methods control profiling sessions and are subject to session sampling.
2424

packages/core/src/profiling.ts

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ function isProfilingIntegrationWithProfiler(
1818
* Starts the Sentry continuous profiler.
1919
* This mode is exclusive with the transaction profiler and will only work if the profilesSampleRate is set to a falsy value.
2020
* In continuous profiling mode, the profiler will keep reporting profile chunks to Sentry until it is stopped, which allows for continuous profiling of the application.
21-
* @deprecated Use `startProfileSession()` instead.
2221
*/
2322
function startProfiler(): void {
2423
const client = getClient();
@@ -45,7 +44,6 @@ function startProfiler(): void {
4544
/**
4645
* Stops the Sentry continuous profiler.
4746
* Calls to stop will stop the profiler and flush the currently collected profile data to Sentry.
48-
* @deprecated Use `stopProfilerSession()` instead.
4947
*/
5048
function stopProfiler(): void {
5149
const client = getClient();
@@ -68,57 +66,7 @@ function stopProfiler(): void {
6866
integration._profiler.stop();
6967
}
7068

71-
/**
72-
* Starts a new profiler session.
73-
*/
74-
function startProfileSession(): void {
75-
const client = getClient();
76-
if (!client) {
77-
DEBUG_BUILD && logger.warn('No Sentry client available, profiling is not started');
78-
return;
79-
}
80-
81-
const integration = client.getIntegrationByName<ProfilingIntegration<any>>('ProfilingIntegration');
82-
if (!integration) {
83-
DEBUG_BUILD && logger.warn('ProfilingIntegration is not available');
84-
return;
85-
}
86-
87-
if (!isProfilingIntegrationWithProfiler(integration)) {
88-
DEBUG_BUILD && logger.warn('Profiler is not available on profiling integration.');
89-
return;
90-
}
91-
92-
integration._profiler.startProfileSession();
93-
}
94-
95-
/**
96-
* Stops the current profiler session.
97-
*/
98-
function stopProfileSession(): void {
99-
const client = getClient();
100-
if (!client) {
101-
DEBUG_BUILD && logger.warn('No Sentry client available, profiling is not started');
102-
return;
103-
}
104-
105-
const integration = client.getIntegrationByName<ProfilingIntegration<any>>('ProfilingIntegration');
106-
if (!integration) {
107-
DEBUG_BUILD && logger.warn('ProfilingIntegration is not available');
108-
return;
109-
}
110-
111-
if (!isProfilingIntegrationWithProfiler(integration)) {
112-
DEBUG_BUILD && logger.warn('Profiler is not available on profiling integration.');
113-
return;
114-
}
115-
116-
integration._profiler.stopProfileSession();
117-
}
118-
11969
export const profiler: Profiler = {
12070
startProfiler,
12171
stopProfiler,
122-
startProfileSession,
123-
stopProfileSession,
12472
};

packages/core/src/types-hoist/profiling.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ export interface ContinuousProfiler<T extends Client> {
77
initialize(client: T): void;
88
start(): void;
99
stop(): void;
10-
startProfileSession(): void;
11-
stopProfileSession(): void;
1210
}
1311

1412
export interface ProfilingIntegration<T extends Client> extends Integration {
@@ -18,25 +16,13 @@ export interface ProfilingIntegration<T extends Client> extends Integration {
1816
export interface Profiler {
1917
/**
2018
* Starts the profiler.
21-
* @deprecated Use `startProfileSession()` instead.
2219
*/
2320
startProfiler(): void;
2421

2522
/**
2623
* Stops the profiler.
27-
* @deprecated Use `stopProfilerSession()` instead.
2824
*/
2925
stopProfiler(): void;
30-
31-
/**
32-
* Starts a new profiler session.
33-
*/
34-
startProfileSession(): void;
35-
36-
/**
37-
* Stops the current profiler session.
38-
*/
39-
stopProfileSession(): void;
4026
}
4127

4228
export type ThreadId = string;

packages/profiling-node/src/integration.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class ContinuousProfiler {
108108
break;
109109
}
110110
case 'manual': {
111-
// Manual mode requires manual calls to profiler.startProfileSession() and profiler.stopProfileSession()
111+
// Manual mode requires manual calls to profiler.startProfiler() and profiler.stopProfiler()
112112
break;
113113
}
114114
default: {
@@ -136,6 +136,11 @@ class ContinuousProfiler {
136136
* @returns void
137137
*/
138138
public start(): void {
139+
if (this._mode === 'current') {
140+
this.startProfiler();
141+
return;
142+
}
143+
139144
if (!this._client) {
140145
DEBUG_BUILD && logger.log('[Profiling] Failed to start, sentry client was never attached to the profiler.');
141146
return;
@@ -165,6 +170,11 @@ class ContinuousProfiler {
165170
* @returns void
166171
*/
167172
public stop(): void {
173+
if (this._mode === 'current') {
174+
this.stopProfiler();
175+
return;
176+
}
177+
168178
if (!this._client) {
169179
DEBUG_BUILD && logger.log('[Profiling] Failed to stop, sentry client was never attached to the profiler.');
170180
return;
@@ -184,7 +194,7 @@ class ContinuousProfiler {
184194
this._teardownSpanChunkInstrumentation();
185195
}
186196

187-
public startProfileSession(): void {
197+
private startProfiler(): void {
188198
if (this._mode !== 'current') {
189199
DEBUG_BUILD && logger.log('[Profiling] Continuous profiling is not supported in the current mode.');
190200
return;
@@ -205,15 +215,15 @@ class ContinuousProfiler {
205215
if (this._profileLifecycle === 'trace') {
206216
DEBUG_BUILD &&
207217
logger.log(
208-
'[Profiling] You are using the trace profile lifecycle, manual calls to profiler.startProfileSession() and profiler.stopProfileSession() will be ignored.',
218+
'[Profiling] You are using the trace profile lifecycle, manual calls to profiler.startProfiler() and profiler.stopProfiler() will be ignored.',
209219
);
210220
return;
211221
}
212222

213223
this._startChunkProfiling();
214224
}
215225

216-
public stopProfileSession(): void {
226+
private stopProfiler(): void {
217227
if (this._mode !== 'current') {
218228
DEBUG_BUILD && logger.log('[Profiling] Continuous profiling is not supported in the current mode.');
219229
return;
@@ -222,7 +232,7 @@ class ContinuousProfiler {
222232
if (this._profileLifecycle === 'trace') {
223233
DEBUG_BUILD &&
224234
logger.log(
225-
'[Profiling] You are using the trace profile lifecycle, manual calls to profiler.startProfileSession() and profiler.stopProfileSession() will be ignored.',
235+
'[Profiling] You are using the trace profile lifecycle, manual calls to profiler.startProfiler() and profiler.stopProfiler() will be ignored.',
226236
);
227237
return;
228238
}

packages/profiling-node/test/integration.test.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,8 @@ describe('ProfilingIntegration', () => {
735735
const startProfilingSpy = vi.spyOn(CpuProfilerBindings, 'startProfiling');
736736
const stopProfilingSpy = vi.spyOn(CpuProfilerBindings, 'stopProfiling');
737737

738-
Sentry.profiler.startProfileSession();
739-
Sentry.profiler.stopProfileSession();
738+
Sentry.profiler.startProfiler();
739+
Sentry.profiler.stopProfiler();
740740

741741
expect(startProfilingSpy).toHaveBeenCalled();
742742
expect(stopProfilingSpy).toHaveBeenCalled();
@@ -753,13 +753,13 @@ describe('ProfilingIntegration', () => {
753753
const startProfilingSpy = vi.spyOn(CpuProfilerBindings, 'startProfiling');
754754
const stopProfilingSpy = vi.spyOn(CpuProfilerBindings, 'stopProfiling');
755755

756-
Sentry.profiler.startProfileSession();
757-
Sentry.profiler.startProfileSession();
756+
Sentry.profiler.startProfiler();
757+
Sentry.profiler.startProfiler();
758758

759759
expect(startProfilingSpy).toHaveBeenCalledTimes(1);
760760

761-
Sentry.profiler.stopProfileSession();
762-
Sentry.profiler.stopProfileSession();
761+
Sentry.profiler.stopProfiler();
762+
Sentry.profiler.stopProfiler();
763763

764764
expect(stopProfilingSpy).toHaveBeenCalledTimes(1);
765765
});
@@ -774,8 +774,8 @@ describe('ProfilingIntegration', () => {
774774
const startProfilingSpy = vi.spyOn(CpuProfilerBindings, 'startProfiling');
775775
const stopProfilingSpy = vi.spyOn(CpuProfilerBindings, 'stopProfiling');
776776

777-
Sentry.profiler.startProfileSession();
778-
Sentry.profiler.stopProfileSession();
777+
Sentry.profiler.startProfiler();
778+
Sentry.profiler.stopProfiler();
779779

780780
expect(startProfilingSpy).not.toHaveBeenCalled();
781781
expect(stopProfilingSpy).not.toHaveBeenCalled();
@@ -792,8 +792,8 @@ describe('ProfilingIntegration', () => {
792792
const startProfilingSpy = vi.spyOn(CpuProfilerBindings, 'startProfiling');
793793
const stopProfilingSpy = vi.spyOn(CpuProfilerBindings, 'stopProfiling');
794794

795-
Sentry.profiler.startProfileSession();
796-
Sentry.profiler.stopProfileSession();
795+
Sentry.profiler.startProfiler();
796+
Sentry.profiler.stopProfiler();
797797

798798
expect(startProfilingSpy).not.toHaveBeenCalled();
799799
expect(stopProfilingSpy).not.toHaveBeenCalled();
@@ -815,9 +815,9 @@ describe('ProfilingIntegration', () => {
815815

816816
const transportSpy = vi.spyOn(transport, 'send').mockReturnValue(Promise.resolve({}));
817817

818-
Sentry.profiler.startProfileSession();
818+
Sentry.profiler.startProfiler();
819819
await wait(1000);
820-
Sentry.profiler.stopProfileSession();
820+
Sentry.profiler.stopProfiler();
821821

822822
await Sentry.flush(1000);
823823

@@ -848,8 +848,8 @@ describe('ProfilingIntegration', () => {
848848
const startProfilingSpy = vi.spyOn(CpuProfilerBindings, 'startProfiling');
849849
const stopProfilingSpy = vi.spyOn(CpuProfilerBindings, 'stopProfiling');
850850

851-
Sentry.profiler.startProfileSession();
852-
Sentry.profiler.stopProfileSession();
851+
Sentry.profiler.startProfiler();
852+
Sentry.profiler.stopProfiler();
853853

854854
expect(startProfilingSpy).not.toHaveBeenCalled();
855855
expect(stopProfilingSpy).not.toHaveBeenCalled();
@@ -989,7 +989,7 @@ describe('ProfilingIntegration', () => {
989989
describe('Legacy vs Current API compat', () => {
990990
describe('legacy', () => {
991991
describe('span profiling', () => {
992-
it('profiler.start, profiler.stop, profiler.startProfileSession, profiler.stopProfileSession void in automated span profiling mode', () => {
992+
it('profiler.start, profiler.stop, profiler.startProfiler, profiler.stopProfiler void in automated span profiling mode', () => {
993993
const [client] = makeLegacySpanProfilingClient();
994994
Sentry.setCurrentClient(client);
995995
client.init();
@@ -1005,8 +1005,8 @@ describe('Legacy vs Current API compat', () => {
10051005
expect(stopProfilingSpy).not.toHaveBeenCalled();
10061006

10071007
// This API is not supported in legacy mode
1008-
Sentry.profiler.startProfileSession();
1009-
Sentry.profiler.stopProfileSession();
1008+
Sentry.profiler.startProfiler();
1009+
Sentry.profiler.stopProfiler();
10101010

10111011
expect(startProfilingSpy).not.toHaveBeenCalled();
10121012
expect(stopProfilingSpy).not.toHaveBeenCalled();
@@ -1021,7 +1021,7 @@ describe('Legacy vs Current API compat', () => {
10211021
});
10221022

10231023
describe('continuous profiling', () => {
1024-
it('profiler.start and profiler.stop start and stop the profiler, calls to profiler.startProfileSession and profiler.stopProfileSession are ignored', () => {
1024+
it('profiler.start and profiler.stop start and stop the profiler, calls to profiler.startProfiler and profiler.stopProfiler are ignored', () => {
10251025
const [client] = makeLegacyContinuousProfilingClient();
10261026
Sentry.setCurrentClient(client);
10271027
client.init();
@@ -1037,8 +1037,8 @@ describe('Legacy vs Current API compat', () => {
10371037
expect(stopProfilingSpy).not.toHaveBeenCalled();
10381038

10391039
// This API is not supported in legacy mode
1040-
Sentry.profiler.startProfileSession();
1041-
Sentry.profiler.stopProfileSession();
1040+
Sentry.profiler.startProfiler();
1041+
Sentry.profiler.stopProfiler();
10421042

10431043
expect(startProfilingSpy).not.toHaveBeenCalled();
10441044
expect(stopProfilingSpy).not.toHaveBeenCalled();
@@ -1055,7 +1055,7 @@ describe('Legacy vs Current API compat', () => {
10551055

10561056
describe('current', () => {
10571057
describe('span profiling', () => {
1058-
it('profiler.start, profiler.stop, profiler.startProfileSession, profiler.stopProfileSession void in automated span profiling mode', () => {
1058+
it('profiler.start, profiler.stop, profiler.startProfiler, profiler.stopProfiler void in automated span profiling mode', () => {
10591059
const [client] = makeCurrentSpanProfilingClient({
10601060
profileLifecycle: 'trace',
10611061
});
@@ -1073,8 +1073,8 @@ describe('Legacy vs Current API compat', () => {
10731073
expect(stopProfilingSpy).not.toHaveBeenCalled();
10741074

10751075
// This API is not supported in trace mode
1076-
Sentry.profiler.startProfileSession();
1077-
Sentry.profiler.stopProfileSession();
1076+
Sentry.profiler.startProfiler();
1077+
Sentry.profiler.stopProfiler();
10781078

10791079
expect(startProfilingSpy).not.toHaveBeenCalled();
10801080
expect(stopProfilingSpy).not.toHaveBeenCalled();

0 commit comments

Comments
 (0)