forked from getsentry/sentry-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(profiling): Expose profiler as top level primitive (getsentry#13512
) We are about to enter a public beta for continuous profiling, which means it is time to expose this from under the wraps of the integration and align it with how the profiler is exposed in python and iOS SDKs --------- Co-authored-by: Luca Forstner <luca.forstner@sentry.io>
- Loading branch information
Showing
12 changed files
with
153 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import type { Profiler, ProfilingIntegration } from '@sentry/types'; | ||
import { logger } from '@sentry/utils'; | ||
|
||
import { getClient } from './currentScopes'; | ||
import { DEBUG_BUILD } from './debug-build'; | ||
|
||
function isProfilingIntegrationWithProfiler( | ||
integration: ProfilingIntegration<any> | undefined, | ||
): integration is ProfilingIntegration<any> { | ||
return ( | ||
!!integration && | ||
typeof integration['_profiler'] !== 'undefined' && | ||
typeof integration['_profiler']['start'] === 'function' && | ||
typeof integration['_profiler']['stop'] === 'function' | ||
); | ||
} | ||
/** | ||
* 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. | ||
*/ | ||
function startProfiler(): 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.start(); | ||
} | ||
|
||
/** | ||
* Stops the Sentry continuous profiler. | ||
* Calls to stop will stop the profiler and flush the currently collected profile data to Sentry. | ||
*/ | ||
function stopProfiler(): 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.stop(); | ||
} | ||
|
||
export const profiler: Profiler = { | ||
startProfiler, | ||
stopProfiler, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.