11// PUBLIC APIS
22
33import { getCurrentScope } from '@sentry/core' ;
4- import type { Client } from '@sentry/types' ;
4+ import type { Client , StackParser } from '@sentry/types' ;
5+ import { GLOBAL_OBJ , createStackParser , nodeStackLineParser } from '@sentry/utils' ;
6+ import { createGetModuleFromFilename } from '../utils/module' ;
57
68/** Get the currently active client. */
79export function getClient < C extends Client > ( ) : C {
@@ -15,3 +17,40 @@ export function getClient<C extends Client>(): C {
1517 // TODO otherwise ensure we use a noop client
1618 return { } as C ;
1719}
20+
21+ /**
22+ * Returns a release dynamically from environment variables.
23+ */
24+ export function getSentryRelease ( fallback ?: string ) : string | undefined {
25+ // Always read first as Sentry takes this as precedence
26+ if ( process . env . SENTRY_RELEASE ) {
27+ return process . env . SENTRY_RELEASE ;
28+ }
29+
30+ // This supports the variable that sentry-webpack-plugin injects
31+ if ( GLOBAL_OBJ . SENTRY_RELEASE && GLOBAL_OBJ . SENTRY_RELEASE . id ) {
32+ return GLOBAL_OBJ . SENTRY_RELEASE . id ;
33+ }
34+
35+ return (
36+ // GitHub Actions - https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
37+ process . env . GITHUB_SHA ||
38+ // Netlify - https://docs.netlify.com/configure-builds/environment-variables/#build-metadata
39+ process . env . COMMIT_REF ||
40+ // Vercel - https://vercel.com/docs/v2/build-step#system-environment-variables
41+ process . env . VERCEL_GIT_COMMIT_SHA ||
42+ process . env . VERCEL_GITHUB_COMMIT_SHA ||
43+ process . env . VERCEL_GITLAB_COMMIT_SHA ||
44+ process . env . VERCEL_BITBUCKET_COMMIT_SHA ||
45+ // Zeit (now known as Vercel)
46+ process . env . ZEIT_GITHUB_COMMIT_SHA ||
47+ process . env . ZEIT_GITLAB_COMMIT_SHA ||
48+ process . env . ZEIT_BITBUCKET_COMMIT_SHA ||
49+ // Cloudflare Pages - https://developers.cloudflare.com/pages/platform/build-configuration/#environment-variables
50+ process . env . CF_PAGES_COMMIT_SHA ||
51+ fallback
52+ ) ;
53+ }
54+
55+ /** Node.js stack parser */
56+ export const defaultStackParser : StackParser = createStackParser ( nodeStackLineParser ( createGetModuleFromFilename ( ) ) ) ;
0 commit comments