Skip to content

runtime-node: detect the running commit and default the release to it; report test under test runners - #55

Merged
sagnik11 merged 3 commits into
mainfrom
feat/node-test-env-and-commit
Nov 15, 2026
Merged

sagnik11 merged 3 commits into
mainfrom
feat/node-test-env-and-commit

Conversation

@sagnik11

@sagnik11 sagnik11 commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

What users saw

  • A Node service that set no release sent errors with no release at all, so Autter could not say "broke in release X", resolve the deploy's commit and pull request, or pick the right source maps. Most hosting platforms already put the commit in the environment (VERCEL_GIT_COMMIT_SHA, RENDER_GIT_COMMIT, GITHUB_SHA, ...), but the SDK only read it in the optional enrichDeployment() enricher, and never put it on the resource.
  • Errors thrown while running the app's own test suite (Jest, Vitest, node --test) were reported as production, mixed in with real traffic, because the environment fell back to production whenever NODE_ENV was unset.
  • Three separate lists of commit variables (the enricher, verify, and the source-map CLI) disagreed on names and order, and none of them checked the value was a commit.

What changes

One commit list (packages/runtime-node/src/deployment.ts, COMMIT_ENV_VARS): AUTTER_COMMIT, GITHUB_SHA, VERCEL_GIT_COMMIT_SHA, CF_PAGES_COMMIT_SHA, GIT_SHA, GIT_COMMIT, COMMIT_SHA, SOURCE_COMMIT, RENDER_GIT_COMMIT, RAILWAY_GIT_COMMIT_SHA, HEROKU_SLUG_COMMIT, SOURCE_VERSION, tried in that order: Autter's own, then the four the source-map CLI has always read, in its order, so the SDK's default release is the release the CLI uploads maps under. Only 7 to 40 hexadecimal characters count as a commit; a variable holding anything else (a branch, refs/heads/main, a tag) is skipped and the next one is tried. The SDK reads environment variables only and never runs git or any subprocess.

Used by initAutterServer, initAutterLogging, enrichDeployment(), npx @autter/runtime-node verify, and @autter/runtime-cli's release resolution. runtime-core could not hold it: it is a private package runtime-cli does not depend on, and making it one would change the CLI's build and package.json. Instead the file is dependency-free and runtime-cli/src/release.ts imports it by path, so tsup bundles it into the CLI (the same pattern as runtime-node/src/verify.ts importing otlp-ingester/src/compat.ts). The published CLI gains no dependency; there is one definition, not a copy.

Commit on the resource: initAutterServer sets deployment.commit on the resource (spans and metrics) whenever a commit is found, whatever the release.

Release default (behaviour change): when release is not passed, the release is AUTTER_RELEASE, else the detected commit as the full value. An explicit release always wins. release: false, or AUTTER_DETECT_RELEASE=false, reports no release, as before. Same for initAutterLogging. verify uses the same default and now sends and reports the commit (commit in --json).

Environment default: the environment option, else NODE_ENV, else test when a test runner is detected (JEST_WORKER_ID, VITEST or NODE_TEST_CONTEXT set), else production. Explicit values always win. One helper for initAutterServer and initAutterLogging.

Source-map CLI (unchanged for existing builds): the default upload release is --release, else AUTTER_RELEASE (new), else exactly the old rule (the first of GITHUB_SHA, VERCEL_GIT_COMMIT_SHA, CF_PAGES_COMMIT_SHA, GIT_SHA that is set, any value, in that order), else (new) the first commit among the SDK's other commit variables, else git rev-parse HEAD (build time only). A build with GITHUB_SHA and GIT_SHA both set, or with GIT_SHA=v1.2.3, uploads under the same release as before, which is also what the browser snippets autter-runtime setup prints report. The --release help, the plugins' doc comment and the CLI README describe the rule. A test checks that for a commit in any single commit variable the SDK's default release equals the CLI's default release.

Places that read the release, checked with a 40-character SHA

  • Source maps: server frames without debug ids are now looked up by (release, path suffix) because a release is set; a miss is cached for 5 minutes by the ingester (symbolicate.ts), and the frame stays as parsed. Browser releases are separate and unchanged.
  • Compatibility handshake (compat.ts) and doctor do not read the release.
  • Request summaries and log records carry the release as service.version on the logs resource; the ingester keeps up to 200 characters.
  • verify: release step passes with a detected SHA (tested).
  • @autter/runtime-next passes options through to initAutterServer; its tests pass unchanged, also with GITHUB_SHA set. No change there.

Tests

  • New packages/runtime-node/test/environment.test.mjs: the helpers (environment order, hex-only commits and the shared order, release order and opt-outs, enrichDeployment), and end to end in child processes against a local collector: what initAutterServer puts on its span and log resources and what initAutterLogging puts on its log resource, for each rule. The children get an environment with every variable these rules read removed, because this suite itself runs under node --test (which sets NODE_TEST_CONTEXT) and CI sets GITHUB_SHA.
  • verify.test.mjs: clears every commit variable in its children; new case for the default release, the commit and the opt-out.
  • runtime-cli upload.test.mjs: release order with AUTTER_RELEASE; GITHUB_SHA still wins over a different GIT_SHA; GIT_SHA=v1.2.3 is still the release; other commit variables only when they hold a commit.
  • Locally: the whole runtime-node suite (292 tests) passes, also with GITHUB_SHA/CI set; runtime-cli, runtime-next and runtime-edge suites pass.

Docs and the changelog are written separately for this batch of Runtime changes; this PR does not edit CHANGELOG.md or docs/.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

sagnik11 and others added 3 commits November 15, 2026 10:45
…; report test under test runners

- One list of commit variables (packages/runtime-node/src/deployment.ts),
  used by initAutterServer, initAutterLogging, enrichDeployment,
  `autter-runtime verify` and @autter/runtime-cli's release resolution
  (bundled into the CLI by path; no new dependency). Only 7-40 hexadecimal
  characters count as a commit. Never runs git at runtime.
- initAutterServer sets the resource attribute deployment.commit whenever a
  commit is found.
- Release default when `release` is unset: AUTTER_RELEASE, else the full
  detected commit. `release: false` or AUTTER_DETECT_RELEASE=false: none.
- Environment default: the option, else NODE_ENV, else `test` when
  JEST_WORKER_ID, VITEST or NODE_TEST_CONTEXT is set, else `production`.
- The CLI's upload release now follows the same order (AUTTER_RELEASE, then
  the shared commit list, then git rev-parse HEAD) so uploaded maps match
  the SDK's default release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…variables first in the shared list

- The source-map CLI's default release is --release, else AUTTER_RELEASE,
  else exactly the old rule (first non-empty of GITHUB_SHA,
  VERCEL_GIT_COMMIT_SHA, CF_PAGES_COMMIT_SHA, GIT_SHA, any value), else the
  first commit among the SDK's other commit variables, else git HEAD. A
  build with GITHUB_SHA and GIT_SHA both set, or GIT_SHA=v1.2.3, uploads
  under the same release as before (and as the browser snippets report).
  RELEASE_ENV_VARS is the old four again.
- The shared commit list puts the CLI's four first, after AUTTER_COMMIT, so
  the SDK's default release matches the CLI's upload release for a commit
  in any one variable (tested).
- cli.ts --release help, build.ts doc comment and the README describe the
  rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sagnik11
sagnik11 merged commit e178eb8 into main Nov 15, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant