Repository navigation
ref(core): Share the commit env var list used for release detection - #25478
mwarkentin wants to merge 2 commits into
Conversation
The Node SDK, the Vercel Edge SDK and the bundler plugins each kept their own copy of the commit environment variables they read to detect a release, along with their own placeholder check. The copies had already drifted: the bundler plugins did not read HEROKU_BUILD_COMMIT. The list and the placeholder check now live in @sentry/core/server as getReleaseFromCommitEnv() and readCommitEnvVar(). Node and Vercel Edge keep their SENTRY_RELEASE and injected-release checks, and the bundler plugins keep their git fallback and their own once-per-build warning. The bundler plugins now also read HEROKU_BUILD_COMMIT. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WgDm3ijhQZQUHGAFFqQzKQ
size-limit report 📦
|
isaacs
left a comment
There was a problem hiding this comment.
This looks good to me, but I'd lean towards giving the new exports the _INTERNAL_ tag so that they're not an ongoing SemVer commitment.
Some other little suggestions as well, nothing too major.
| onPlaceholder(name); | ||
| return undefined; | ||
| } | ||
| return value || undefined; |
There was a problem hiding this comment.
Hm, so, a value of "" will now become undefined, yes?
I think that's a good fix, actually, but should perhaps be mentioned in the commit message, since it's a subtle behavior change.
There was a problem hiding this comment.
Yes. Release detection already skipped empty values through the old || chains, so the only visible change is the Vercel setCommits default: VERCEL_GIT_PREVIOUS_SHA="" now leaves previousCommit unset instead of sending "". Called out in the 3c5b60d commit message and the PR description.
| name: string, | ||
| onPlaceholder: PlaceholderCommitEnvVarHandler = warnAboutPlaceholderCommitEnvVar, | ||
| ): string | undefined { | ||
| if (typeof process === 'undefined') { |
There was a problem hiding this comment.
May as well go all the way on this guard, and defend against a non-existent env on an existing process, since it's cheap anyway.
| if (typeof process === 'undefined') { | |
| if (!process?.env || typeof process.env !== 'object') { |
There was a problem hiding this comment.
Not sure on this one, but my clanker says:
I’d leave this one as is: every caller (Node and Vercel Edge getSentryRelease, the bundler plugins’ options mapping) reads process.env directly before calling this, so a process without env would already have thrown before reaching it. One more thing: process?.env still throws a ReferenceError when process isn’t declared, so the typeof process check needs to stay either way. Happy to add the env guard if you’d still like it.
Export getReleaseFromCommitEnv and readCommitEnvVar from @sentry/core/server with the _INTERNAL_ prefix, so they are not part of the public API, and drop the PlaceholderCommitEnvVarHandler type export, which nothing imports. Note a subtle behaviour change from the previous commit: readCommitEnvVar now returns undefined for an empty variable. Release detection already skipped empty values, so the only caller that sees it is the bundler plugins' Vercel setCommits default: VERCEL_GIT_PREVIOUS_SHA="" now leaves previousCommit unset instead of sending an empty string. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WgDm3ijhQZQUHGAFFqQzKQ
|
CI failures on 3c5b60d, which only renames two exports in
None of these is caused by this PR, and there is no fix to port. I have used my one re-run; Generated by Claude Code |
Follow-up to #25244, as suggested in review there.
The Node SDK, the Vercel Edge SDK and the bundler plugins each kept their own copy of the commit environment variables they read to detect a release, plus their own copy of the placeholder check added in #25244. The copies had already drifted: the bundler plugins did not read
HEROKU_BUILD_COMMIT.Changes
packages/core/src/utils/commitEnv.ts, exported from@sentry/core/serveras_INTERNAL_readCommitEnvVarand_INTERNAL_getReleaseFromCommitEnv, so they are not a public API commitment:readCommitEnvVar(name, onPlaceholder?)ignores a value that is its own name. By default it warns throughconsoleSandboxwith the[Sentry]prefix;getReleaseFromCommitEnv(onPlaceholder?)returns the first variable that is set. It reads in order and stops at the first match, so a placeholder is only reported when it would otherwise have become the release.getSentryRelease()keeps theSENTRY_RELEASEand injected-release checks, then callsgetReleaseFromCommitEnv().determineReleaseName()callsgetReleaseFromCommitEnv(), then falls back togit rev-parseas before. It passes its own handler, which keeps the[@sentry/bundler-plugins]prefix and warns once per variable per build.readCommitEnvVarkeeps its signature, sosetCommitsis unchanged.Behaviour changes
HEROKU_BUILD_COMMIT, ahead ofHEROKU_SLUG_COMMIT, as Node and Vercel Edge already do.readCommitEnvVarreturnsundefinedfor an empty variable. Release detection already skipped empty values, so the only caller that sees this is the bundler plugins' VercelsetCommitsdefault:VERCEL_GIT_PREVIOUS_SHA=""now leavespreviousCommitunset instead of sending an empty string.Nothing else changes order or meaning.
Testing
packages/core/test/lib/utils/commitEnv.test.tscovers:HEROKU_BUILD_COMMITbeforeHEROKU_SLUG_COMMIT;HEROKU_BUILD_COMMIT.Before submitting a pull request, please take a look at our
Contributing guidelines and verify:
yarn lint) & (yarn test).Generated by Claude Code