Repository navigation
fix: inline the public Sentry DSN into the client bundle - #95
Conversation
PR #94 read the DSN through a helper that indexes process.env dynamically. Next only substitutes literal `process.env.NEXT_PUBLIC_*` expressions when building the client bundle, so the dynamic read survived into the browser as undefined and Sentry disabled itself with no error. Verified against the deployed site: the SDK shipped but the DSN string was absent, while PostHog's token was inlined because it is referenced literally. Server and edge runtimes were unaffected — they read process.env at runtime. The client now passes literal references explicitly, and a guard test asserts the literal is present and that the no-argument form is not used, since a unit test cannot observe bundler substitution. Confirmed with a real build: a probe DSN now appears in a client chunk.
Strix Security ReviewNo security issues found. Review summaryReviewed both changed files: Updated for Reviewed by Strix |
Follow-up to #94, which shipped broken client-side error reporting.
What went wrong
buildSentryOptionsreads env values throughenv[key]. Next only substitutes literalprocess.env.NEXT_PUBLIC_*expressions into the client bundle, so a dynamic read is left as-is and evaluates toundefinedin the browser. Sentry then disables itself silently — no error, no warning.Verified against the deployed site after #94: the Sentry SDK was present in two chunks, the DSN string in none, while PostHog's
phc_…token was inlined becauseinstrumentation-client.tsreferences it literally.Server and edge runtimes were never affected: they read
process.envat runtime, where dynamic access is fine.Fix
The client now passes its values as literal
process.env.Xexpressions. Client-side environment and release come fromNEXT_PUBLIC_-prefixed names, sinceSOURCE_COMMITis not available in the browser.Test
A unit test cannot observe bundler substitution, so the guard is a static one: it asserts
instrumentation-client.tscontains the literal reference and does not use the no-argumentbuildSentryOptions('client')form. Both tests fail against the code as merged in #94.Also confirmed the real way — built with
NEXT_PUBLIC_SENTRY_DSNset to a probe value and grepped the output: the probe now appears in a client chunk, where before it appeared in none.Verification
yarn lintcleanyarn test:run— 304 tests, 70 files, all passingyarn buildpasses