Skip to content

profiling: implement new profiling API spec #15636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions packages/core/src/profiling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function isProfilingIntegrationWithProfiler(
* Starts the Sentry continuous profiler.
* This mode is exclusive with the transaction profiler and will only work if the profilesSampleRate is set to a falsy value.
* 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.
* @deprecated Use `startProfilerSession()` instead.
* @deprecated Use `startProfileSession()` instead.
*/
function startProfiler(): void {
const client = getClient();
Expand Down Expand Up @@ -71,16 +71,54 @@ function stopProfiler(): void {
/**
* Starts a new profiler session.
*/
function startProfilerSession(): void {}
function startProfileSession(): void {
const client = getClient();
if (!client) {
DEBUG_BUILD && logger.warn('No Sentry client available, profiling is not started');
return;
}

const integration = client.getIntegrationByName<ProfilingIntegration<any>>('ProfilingIntegration');
if (!integration) {
DEBUG_BUILD && logger.warn('ProfilingIntegration is not available');
return;
}

if (!isProfilingIntegrationWithProfiler(integration)) {
DEBUG_BUILD && logger.warn('Profiler is not available on profiling integration.');
return;
}

integration._profiler.startProfileSession();
}

/**
* Stops the current profiler session.
*/
function stopProfilerSession(): void {}
function stopProfileSession(): void {
const client = getClient();
if (!client) {
DEBUG_BUILD && logger.warn('No Sentry client available, profiling is not started');
return;
}

const integration = client.getIntegrationByName<ProfilingIntegration<any>>('ProfilingIntegration');
if (!integration) {
DEBUG_BUILD && logger.warn('ProfilingIntegration is not available');
return;
}

if (!isProfilingIntegrationWithProfiler(integration)) {
DEBUG_BUILD && logger.warn('Profiler is not available on profiling integration.');
return;
}

integration._profiler.stopProfileSession();
}

export const profiler: Profiler = {
startProfiler,
stopProfiler,
startProfilerSession,
stopProfilerSession,
startProfileSession,
stopProfileSession,
};
8 changes: 5 additions & 3 deletions packages/core/src/types-hoist/profiling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export interface ContinuousProfiler<T extends Client> {
initialize(client: T): void;
start(): void;
stop(): void;
startProfileSession(): void;
stopProfileSession(): void;
}

export interface ProfilingIntegration<T extends Client> extends Integration {
Expand All @@ -16,7 +18,7 @@ export interface ProfilingIntegration<T extends Client> extends Integration {
export interface Profiler {
/**
* Starts the profiler.
* @deprecated Use `startProfilerSession()` instead.
* @deprecated Use `startProfileSession()` instead.
*/
startProfiler(): void;

Expand All @@ -29,12 +31,12 @@ export interface Profiler {
/**
* Starts a new profiler session.
*/
startProfilerSession(): void;
startProfileSession(): void;

/**
* Stops the current profiler session.
*/
stopProfilerSession(): void;
stopProfileSession(): void;
}

export type ThreadId = string;
Expand Down
Loading
Loading