Skip to content

Commit f7452ce

Browse files
authored
feat(v9/meta): Unify detection of serverless environments and add Cloud Run (#17204)
Backport of this PR: #17168 Adds Google Cloud Run environment variable to serverless detection to wait until flushing. Documented here: https://cloud.google.com/run/docs/configuring/services/environment-variables#reserved related to this: #17165
1 parent 20cc8ac commit f7452ce

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

packages/nuxt/src/runtime/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export async function flushIfServerless(): Promise<void> {
103103
const isServerless =
104104
!!process.env.FUNCTIONS_WORKER_RUNTIME || // Azure Functions
105105
!!process.env.LAMBDA_TASK_ROOT || // AWS Lambda
106+
!!process.env.K_SERVICE || // Google Cloud Run
106107
!!process.env.CF_PAGES || // Cloudflare
107108
!!process.env.VERCEL ||
108109
!!process.env.NETLIFY;

packages/solidstart/src/server/utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import { DEBUG_BUILD } from '../common/debug-build';
55

66
/** Flush the event queue to ensure that events get sent to Sentry before the response is finished and the lambda ends */
77
export async function flushIfServerless(): Promise<void> {
8-
const isServerless = !!process.env.LAMBDA_TASK_ROOT || !!process.env.VERCEL;
8+
const isServerless =
9+
!!process.env.FUNCTIONS_WORKER_RUNTIME || // Azure Functions
10+
!!process.env.LAMBDA_TASK_ROOT || // AWS Lambda
11+
!!process.env.K_SERVICE || // Google Cloud Run
12+
!!process.env.CF_PAGES || // Cloudflare
13+
!!process.env.VERCEL ||
14+
!!process.env.NETLIFY;
915

1016
if (isServerless) {
1117
try {

packages/sveltekit/src/server-common/utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ export async function flushIfServerless(): Promise<void> {
2222
return;
2323
}
2424

25-
const platformSupportsStreaming = !process.env.LAMBDA_TASK_ROOT && !process.env.VERCEL;
25+
const isServerless =
26+
!!process.env.FUNCTIONS_WORKER_RUNTIME || // Azure Functions
27+
!!process.env.LAMBDA_TASK_ROOT || // AWS Lambda
28+
!!process.env.K_SERVICE || // Google Cloud Run
29+
!!process.env.CF_PAGES || // Cloudflare
30+
!!process.env.VERCEL ||
31+
!!process.env.NETLIFY;
2632

27-
if (!platformSupportsStreaming) {
33+
if (isServerless) {
2834
try {
2935
DEBUG_BUILD && debug.log('Flushing events...');
3036
await flush(2000);

0 commit comments

Comments
 (0)