Describe the bug
With adapter-node and the experimental observability flag enabled:
Importing $env/dynamic/public in the src/instrumentation.server.ts file will work when running with vite dev but not when running the build in production with node ./build.
I was unable to verify it with vite preview as the instrumentation.server.ts is not used in this mode (#14275)
Reproduction
Additional information is presented in the README of this reproduction repo:
https://github.com/jorisguffens/sveltekit-otel-env-var-not-available
Short snippet of instrumentation.server.js
import { dev } from "$app/environment";
import { env } from "$env/dynamic/public";
console.log("dev", dev);
console.log("process.env", process.env.PUBLIC_APPINSIGHTS_CONNECTION_STRING);
console.log("$env/dynamic/public", env.PUBLIC_APPINSIGHTS_CONNECTION_STRING);
Console output of vite dev
dev true
process.env undefined
$env/dynamic/public InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://applicationinsights.azure.com/;LiveEndpoint=https://livediagnostics.monitor.azure.com/;ApplicationId= 00000000-0000-0000-0000-000000000000
Console output of node --env-file=.env ./build
dev false
process.env InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://applicationinsights.azure.com/;LiveEndpoint=https://livediagnostics.monitor.azure.com/;ApplicationId= 00000000-0000-0000-0000-000000000000
$env/dynamic/public undefined
Logs
System Info
@sveltejs/adapter-node: ^5.3.1 => 5.3.1
@sveltejs/kit: ^2.22.0 => 2.36.1
@sveltejs/vite-plugin-svelte: ^6.0.0 => 6.1.3
svelte: ^5.0.0 => 5.38.2
vite: ^7.0.4 => 7.1.3
Severity
annoyance
Additional Information
As a workaround I had to use process.env which was available in the production build but not when running with vite dev. This discrepancy can be confusing.
Describe the bug
With adapter-node and the experimental observability flag enabled:
Importing
$env/dynamic/publicin thesrc/instrumentation.server.tsfile will work when running withvite devbut not when running the build in production withnode ./build.I was unable to verify it with
vite previewas theinstrumentation.server.tsis not used in this mode (#14275)Reproduction
Additional information is presented in the README of this reproduction repo:
https://github.com/jorisguffens/sveltekit-otel-env-var-not-available
Short snippet of
instrumentation.server.jsConsole output of
vite devConsole output of
node --env-file=.env ./buildLogs
System Info
Severity
annoyance
Additional Information
As a workaround I had to use
process.envwhich was available in the production build but not when running withvite dev. This discrepancy can be confusing.