Skip to content

Commit 41d4511

Browse files
authored
fix: don't inline system env vars (#190)
My understanding is that all of this code runs only server-side In that case, there is no benefit to trying to fallback to `NEXT_PUBLIC_VERCEL_URL` (the only case where it's necessary is for client-side code, where there is obviously no `process.env` at runtime.) This means that the JS chunks in the serverless function are now deterministic as `NEXT_PUBLIC_` always inlined the value into the JS chunk
1 parent bce5ea2 commit 41d4511

3 files changed

Lines changed: 11 additions & 18 deletions

File tree

.changeset/spicy-dingos-speak.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vercel/otel": patch
3+
---
4+
5+
fix: don't inline system env vars

packages/otel/src/instrumentations/fetch.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,8 @@ export class FetchInstrumentation implements Instrumentation {
169169
}
170170

171171
private shouldPropagate(url: URL, init?: InternalRequestInit): boolean {
172-
const host =
173-
process.env.VERCEL_URL || process.env.NEXT_PUBLIC_VERCEL_URL || null;
174-
const branchHost =
175-
process.env.VERCEL_BRANCH_URL ||
176-
process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL ||
177-
null;
172+
const host = process.env.VERCEL_URL || null;
173+
const branchHost = process.env.VERCEL_BRANCH_URL || null;
178174
const propagateContextUrls = this.config.propagateContextUrls ?? [];
179175
const dontPropagateContextUrls = this.config.dontPropagateContextUrls ?? [];
180176
if (init?.opentelemetry?.propagateContext) {

packages/otel/src/sdk.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,12 @@ export class Sdk {
128128
// Vercel.
129129
// https://vercel.com/docs/projects/environment-variables/system-environment-variables
130130
// Vercel Env set as top level attribute for simplicity. One of 'production', 'preview' or 'development'.
131-
env: process.env.VERCEL_ENV || process.env.NEXT_PUBLIC_VERCEL_ENV,
131+
env: process.env.VERCEL_ENV,
132132
"vercel.region": process.env.VERCEL_REGION,
133133
"vercel.runtime": runtime,
134-
"vercel.sha":
135-
process.env.VERCEL_GIT_COMMIT_SHA ||
136-
process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA,
137-
"vercel.host":
138-
process.env.VERCEL_URL ||
139-
process.env.NEXT_PUBLIC_VERCEL_URL ||
140-
undefined,
141-
"vercel.branch_host":
142-
process.env.VERCEL_BRANCH_URL ||
143-
process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL ||
144-
undefined,
134+
"vercel.sha": process.env.VERCEL_GIT_COMMIT_SHA,
135+
"vercel.host": process.env.VERCEL_URL || undefined,
136+
"vercel.branch_host": process.env.VERCEL_BRANCH_URL || undefined,
145137
"vercel.deployment_id": process.env.VERCEL_DEPLOYMENT_ID || undefined,
146138
[SemanticResourceAttributes.SERVICE_VERSION]:
147139
process.env.VERCEL_DEPLOYMENT_ID,

0 commit comments

Comments
 (0)