@@ -93,14 +93,9 @@ export function init(options: NodeOptions = {}): void {
9393 }
9494
9595 if ( options . release === undefined ) {
96- const global = getGlobalObject < Window > ( ) ;
97- // Prefer env var over global
98- if ( process . env . SENTRY_RELEASE ) {
99- options . release = process . env . SENTRY_RELEASE ;
100- }
101- // This supports the variable that sentry-webpack-plugin injects
102- else if ( global . SENTRY_RELEASE && global . SENTRY_RELEASE . id ) {
103- options . release = global . SENTRY_RELEASE . id ;
96+ const detectedRelease = getSentryRelease ( ) ;
97+ if ( detectedRelease !== undefined ) {
98+ options . release = detectedRelease ;
10499 }
105100
106101 // If release is not provided, then we should disable autoSessionTracking
@@ -161,7 +156,7 @@ export async function close(timeout?: number): Promise<boolean> {
161156}
162157
163158/**
164- * Function that checks if autoSessionTracking option is enabled
159+ * Function that checks if autoSessionTracking option is enabled
165160 */
166161export function isAutosessionTrackingEnabled ( ) : boolean {
167162 // Also add the checks that makes sure in case when you stop session tracking or resume
@@ -171,4 +166,32 @@ export function isAutosessionTrackingEnabled(): boolean {
171166 return clientOptions . autoSessionTracking ;
172167 }
173168 return false ;
169+
170+ /**
171+ * Function that returns a Sentry release string dynamically from env variables
172+ */
173+ function getSentryRelease ( ) : string | undefined {
174+ // Always read first as Sentry takes this as precedence
175+ if ( process . env . SENTRY_RELEASE ) {
176+ return process . env . SENTRY_RELEASE ;
177+ }
178+
179+ // This supports the variable that sentry-webpack-plugin injects
180+ const global = getGlobalObject ( ) ;
181+ if ( global . SENTRY_RELEASE && global . SENTRY_RELEASE . id ) {
182+ return global . SENTRY_RELEASE . id ;
183+ }
184+
185+ return (
186+ // GitHub Actions - https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
187+ process . env . GITHUB_SHA ||
188+ // Netlify - https://docs.netlify.com/configure-builds/environment-variables/#build-metadata
189+ process . env . COMMIT_REF ||
190+ // Vercel - https://vercel.com/docs/v2/build-step#system-environment-variables
191+ process . env . VERCEL_GIT_COMMIT_SHA ||
192+ // Zeit (now known as Vercel)
193+ process . env . ZEIT_GITHUB_COMMIT_SHA ||
194+ process . env . ZEIT_GITLAB_COMMIT_SHA ||
195+ process . env . ZEIT_BITBUCKET_COMMIT_SHA
196+ ) ;
174197}
0 commit comments