From d6cf611a4b9149a1a9029a5483433afa1d1ed250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliv=C3=A9r=20Kecskem=C3=A9ty?= Date: Sat, 21 Nov 2026 02:01:13 +0100 Subject: [PATCH 1/2] ci: publish through the shared workflow and version builds from the tag --- .github/workflows/docker-publish.yml | 124 +++------------------------ AGENTS.md | 2 +- Dockerfile | 9 +- components/app-sidebar.tsx | 13 ++- docker-compose.yml | 3 +- docs/observability.md | 4 +- docs/releases.md | 4 +- lib/release-link.ts | 11 +++ next.config.ts | 54 +----------- tests/lib/release-link.test.ts | 25 ++++++ 10 files changed, 63 insertions(+), 186 deletions(-) create mode 100644 lib/release-link.ts create mode 100644 tests/lib/release-link.test.ts diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 830dc98..f21e7b3 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -18,122 +18,20 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} -defaults: - run: - shell: bash - -env: - REGISTRY: ghcr.io - jobs: - build-and-push: - name: Build and push - runs-on: ubuntu-latest - timeout-minutes: 30 - # Pull requests build without logging in, pushing or attesting, so the write scopes are never used there. + docker: + name: Docker + uses: BSStudio/.github/.github/workflows/shared-publish.yml@14e6deaf34d65dd4db67c19f146449c1cf99c1cc # v1.3.0 permissions: contents: read packages: write - # Mint the OIDC token and write the build provenance attestation. id-token: write attestations: write - steps: - - name: Check out - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - # The version is counted from the last release tag. - fetch-depth: 0 - persist-credentials: false - - - name: Resolve build metadata - id: build-meta - env: - REF_TYPE: ${{ github.ref_type }} - REF_NAME: ${{ github.ref_name }} - SHA: ${{ github.event.pull_request.head.sha || github.sha }} - run: | - echo "hash=${SHA:0:7}" >> "$GITHUB_OUTPUT" - - if [ "$REF_TYPE" = "tag" ]; then - echo "version=${REF_NAME#v}" >> "$GITHUB_OUTPUT" - else - # Mirrors `appVersion` in next.config.ts, which versions local builds. - describe=$(git describe --tags --first-parent --long --abbrev=7 --match 'v[0-9]*.[0-9]*.[0-9]*' --exclude '*-*') - [[ $describe =~ ^v([0-9]+\.[0-9]+\.[0-9]+)-([0-9]+)-g([0-9a-f]+)$ ]] - tag=${BASH_REMATCH[1]} - distance=${BASH_REMATCH[2]} - hash=${BASH_REMATCH[3]} - branch=${REF_NAME//[^0-9A-Za-z-]/-} - - # Later commits must sort higher in Sentry, which compares the revision numerically and prereleases as text. - if [ "$distance" = 0 ]; then - echo "version=$tag" >> "$GITHUB_OUTPUT" - elif [ "$branch" = main ]; then - echo "version=$tag.$distance+$hash" >> "$GITHUB_OUTPUT" - else - echo "version=$tag.$distance+$branch.$hash" >> "$GITHUB_OUTPUT" - fi - fi - - # ghcr has no uppercase in image names. metadata-action lowercases its own - # input, the attest step does not, so both read this one. - echo "image=$REGISTRY/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT" - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 - - - name: Log into registry ${{ env.REGISTRY }} - if: github.event_name != 'pull_request' - uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract Docker metadata - id: meta - uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0 - with: - images: ${{ steps.build-meta.outputs.image }} - tags: | - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - - - name: Build and push Docker image - id: build-and-push - uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 - with: - context: . - build-args: | - NEXT_PUBLIC_SENTRY_DSN=${{ vars.NEXT_PUBLIC_SENTRY_DSN }} - NEXT_PUBLIC_SENTRY_ENVIRONMENT=${{ vars.NEXT_PUBLIC_SENTRY_ENVIRONMENT }} - NEXT_PUBLIC_APP_VERSION=${{ steps.build-meta.outputs.version }} - NEXT_PUBLIC_COMMIT_HASH=${{ steps.build-meta.outputs.hash }} - SENTRY_ORG=${{ vars.SENTRY_ORG }} - SENTRY_PROJECT=${{ vars.SENTRY_PROJECT }} - # Empty on pull requests, which switches source map upload off rather than - # minting a Sentry release for every PR build. - secrets: | - sentry_auth_token=${{ github.event_name != 'pull_request' && secrets.SENTRY_AUTH_TOKEN || '' }} - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max - # Provenance handled by the attest step below; buildkit's own - # attestations would push untagged "unknown/unknown" manifests to ghcr. - provenance: false - sbom: false - - - name: Attest build provenance - if: github.event_name != 'pull_request' - uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2 - with: - subject-name: ${{ steps.build-meta.outputs.image }} - subject-digest: ${{ steps.build-and-push.outputs.digest }} - # Keep the attestation in GitHub's store only; pushing to ghcr would add - # an untagged referrer artifact. Verify with: - # gh attestation verify oci:// --owner BSStudio - push-to-registry: false + with: + build-args: | + NEXT_PUBLIC_SENTRY_DSN=${{ vars.NEXT_PUBLIC_SENTRY_DSN }} + NEXT_PUBLIC_SENTRY_ENVIRONMENT=${{ vars.NEXT_PUBLIC_SENTRY_ENVIRONMENT }} + SENTRY_ORG=${{ vars.SENTRY_ORG }} + SENTRY_PROJECT=${{ vars.SENTRY_PROJECT }} + secrets: + sentry-auth-token: ${{ github.ref_type == 'tag' && secrets.SENTRY_AUTH_TOKEN || '' }} diff --git a/AGENTS.md b/AGENTS.md index 643577d..af3b7c8 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,6 +1,6 @@ -# This is NOT the Next.js you know +## This is NOT the Next.js you know This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` (resolved from this file's directory; in monorepos the `next` package may not be visible from the repo root) before writing any code. Heed deprecation notices. diff --git a/Dockerfile b/Dockerfile index aefa16c..ad51631 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,20 +42,17 @@ COPY . . ARG NEXT_PUBLIC_SENTRY_DSN="" # Empty falls back to NODE_ENV, i.e. production. ARG NEXT_PUBLIC_SENTRY_ENVIRONMENT="" -ARG NEXT_PUBLIC_APP_VERSION="dev" -# No `.git` or git binary here, so CI passes what next.config.ts derives locally. -ARG NEXT_PUBLIC_COMMIT_HASH="" +ARG VERSION="dev" ARG SENTRY_ORG="" ARG SENTRY_PROJECT="" ENV NEXT_PUBLIC_SENTRY_DSN=$NEXT_PUBLIC_SENTRY_DSN ENV NEXT_PUBLIC_SENTRY_ENVIRONMENT=$NEXT_PUBLIC_SENTRY_ENVIRONMENT -ENV NEXT_PUBLIC_APP_VERSION=$NEXT_PUBLIC_APP_VERSION -ENV NEXT_PUBLIC_COMMIT_HASH=$NEXT_PUBLIC_COMMIT_HASH +ENV NEXT_PUBLIC_APP_VERSION=$VERSION ENV SENTRY_ORG=$SENTRY_ORG ENV SENTRY_PROJECT=$SENTRY_PROJECT # Without the token `withSentryConfig` skips source map upload and the build still passes. -RUN --mount=type=secret,id=sentry_auth_token,env=SENTRY_AUTH_TOKEN \ +RUN --mount=type=secret,id=SENTRY_AUTH_TOKEN,env=SENTRY_AUTH_TOKEN \ --mount=type=cache,id=next,target=/app/.next/cache \ pnpm build diff --git a/components/app-sidebar.tsx b/components/app-sidebar.tsx index d645ce3..647c151 100644 --- a/components/app-sidebar.tsx +++ b/components/app-sidebar.tsx @@ -32,8 +32,11 @@ import { } from "@/components/ui/sidebar"; import { NAV_LABELS } from "@/lib/nav-labels"; import { canViewAdminArea } from "@/lib/permissions"; +import { releaseLink } from "@/lib/release-link"; import type { UserRole } from "@/types"; +const release = releaseLink(process.env.NEXT_PUBLIC_APP_VERSION ?? "dev"); + type NavItem = { title: string; url: string; @@ -192,18 +195,12 @@ export function AppSidebar({ role }: { role: UserRole }) { - {process.env.NEXT_PUBLIC_APP_VERSION} + {release.label} diff --git a/docker-compose.yml b/docker-compose.yml index 0900b09..f0a0bfa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,8 +6,7 @@ services: args: NEXT_PUBLIC_SENTRY_DSN: ${NEXT_PUBLIC_SENTRY_DSN:-} NEXT_PUBLIC_SENTRY_ENVIRONMENT: ${NEXT_PUBLIC_SENTRY_ENVIRONMENT:-} - NEXT_PUBLIC_APP_VERSION: ${NEXT_PUBLIC_APP_VERSION:-dev} - NEXT_PUBLIC_COMMIT_HASH: ${NEXT_PUBLIC_COMMIT_HASH:-} + VERSION: ${VERSION:-dev} SENTRY_ORG: ${SENTRY_ORG:-} SENTRY_PROJECT: ${SENTRY_PROJECT:-} restart: unless-stopped diff --git a/docs/observability.md b/docs/observability.md index 8524970..63b0620 100644 --- a/docs/observability.md +++ b/docs/observability.md @@ -27,9 +27,9 @@ A sync failure is tagged `sync.target`, `sync.operation`, `sync.job_id` and `mem **And nothing is collected that the scrubber would only have to drop.** The SDK collects every `dataCollection` category by default, so the restrictive baseline is spelled out rather than inherited — `scrub.ts` is the second line of defence, not the only one. `userInfo`, `cookies` and `httpHeaders` are off and `httpBodies` is none; `urlQueryParams` keeps the query string but denies any key containing `name`, which is how a member's own name arrives at `/api/usernames/suggest?firstName=…&lastName=…` — deny terms match as case-insensitive substrings, so the one term covers every spelling. `databaseQueryData` is pinned for a different reason: it reaches nothing while tracing is off, and the pin is what keeps enabling tracing from shipping the values Prisma binds. The remaining span-scoped categories (`queues`, `genAI`, `graphQL`) have no integration behind them at all and are left alone. -**Release tagging.** Every version string has to parse as semver in Sentry, or the release gets no ordering, no `release.version` filter and no regression detection. Release tags stay `vX.Y.Z`, but the version drops the `v`, which Sentry's parser refuses. A commit carrying a release tag builds as `X.Y.Z`; anything else as `X.Y.Z.+`, or `…+.` off `main`, the branch reduced to `[0-9A-Za-z-]`. The distance goes in the fourth, *revision* number because Sentry compares that numerically but a prerelease as plain text, where `dev.10` sorts below `dev.9`; the build code after `+` takes no part in the ordering. Only `vX.Y.Z` tags count, so a prerelease tag never resets the count, and only along the first-parent line, so neither does a tag on a merged branch. A working tree with uncommitted changes never builds as the bare tag. `next.config.ts` derives this locally and the publish workflow in CI, which passes it in as `NEXT_PUBLIC_APP_VERSION` — the two are written to match and nothing ties them together. +**Release tagging.** Every version string has to parse as semver in Sentry, or the release gets no ordering, no `release.version` filter and no regression detection. Release tags stay `vX.Y.Z`, but the version drops the `v`, which Sentry's parser refuses. A tag build is versioned `X.Y.Z`; every other image `0.0.0+`, with the commit's first seven characters, and creates no release, because production runs tagged releases only. The shared publish workflow passes the version in as `VERSION`, which the Dockerfile hands to `next build` as `NEXT_PUBLIC_APP_VERSION`; a build without it, such as a local `pnpm build`, reports `dev`. -The release name is `backstage@`: release names are shared across the whole Sentry organization, so the project slug keeps them apart. `next.config.ts` builds it once into `NEXT_PUBLIC_SENTRY_RELEASE`, which `sentryInitOptions` sets on every runtime and `withSentryConfig` uploads source maps under, so the two cannot name different releases. Source map upload switches itself off unless `SENTRY_AUTH_TOKEN` is present — that secret belongs to the Docker build, not to a local `pnpm build`. +The release name is `backstage@`: release names are shared across the whole Sentry organization, so the project slug keeps them apart. `next.config.ts` builds it once into `NEXT_PUBLIC_SENTRY_RELEASE`, which `sentryInitOptions` sets on every runtime and `withSentryConfig` uploads source maps under, so the two cannot name different releases. Source map upload and the release switch themselves off unless `SENTRY_AUTH_TOKEN` is present — the publish workflow passes that secret to tag builds only, and a local `pnpm build` has none. **Client events tunnel through `/monitoring`.** `tunnelRoute` in `next.config.ts` makes the browser POST envelopes to our own origin instead of `sentry.io`, which ad blockers filter by hostname. The route is generated by the Sentry plugin, so it exists only in a real build — and it is in `publicPaths` in `proxy.ts`, because an error on the login page has no session cookie yet and a redirect would drop the POST body. diff --git a/docs/releases.md b/docs/releases.md index 7f28d3e..21d9dcc 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -4,7 +4,7 @@ **Migrations run from the entrypoint**, not a separate Job — one replica, one deploy. `RUN_MIGRATIONS=false` opts a container out. The standalone bundle contains only what the server traced, so the image carries its own copy of the Prisma CLI, npm-installed at build time from the versions in `package.json` so it cannot drift from the generated client. `prisma.config.ts` is copied next to that `node_modules` tree because its `dotenv` and `prisma/config` imports have to resolve somewhere, and the config's relative migrations path then points at the copy beside it. Do not try to shrink that tree by deleting `@prisma/studio-core` or `@prisma/dev`: `build/cli.js` requires both eagerly and the CLI stops loading at all. -**Build args vs secrets.** Every `NEXT_PUBLIC_*` value is a plain build arg — `NEXT_PUBLIC_SENTRY_DSN`, `NEXT_PUBLIC_SENTRY_ENVIRONMENT`, `NEXT_PUBLIC_APP_VERSION` and `NEXT_PUBLIC_COMMIT_HASH`. A DSN is public, the rest name the build or the environment, and `next build` freezes all of them into the bundle, so setting any of them on the running container reports nothing at all. `NEXT_PUBLIC_SENTRY_RELEASE` is the exception: `next.config.ts` derives it from the version and it is not an input. An empty `NEXT_PUBLIC_SENTRY_ENVIRONMENT` falls back to `NODE_ENV`, which is what an unconfigured image reports as. `SENTRY_ORG` and `SENTRY_PROJECT` are build args too: they only address the upload target, and without them `withSentryConfig` has nowhere to send source maps. `SENTRY_AUTH_TOKEN` is the only real secret and comes in as a BuildKit secret mount; a build arg would land in the image history. The publish workflow derives the version from the ref it is building and its distance to the last release tag — hence the full-history checkout — and the hash from the commit, and reads `NEXT_PUBLIC_SENTRY_DSN`, `NEXT_PUBLIC_SENTRY_ENVIRONMENT`, `SENTRY_ORG` and `SENTRY_PROJECT` from repository *variables*, the token from a repository *secret*. +**Build args vs secrets.** Every `NEXT_PUBLIC_*` value comes from a plain build arg — `NEXT_PUBLIC_SENTRY_DSN` and `NEXT_PUBLIC_SENTRY_ENVIRONMENT` under their own names, `NEXT_PUBLIC_APP_VERSION` from `VERSION`. A DSN is public, the rest name the build or the environment, and `next build` freezes all of them into the bundle, so setting any of them on the running container reports nothing at all. `NEXT_PUBLIC_SENTRY_RELEASE` is the exception: `next.config.ts` derives it from the version and it is not an input. An empty `NEXT_PUBLIC_SENTRY_ENVIRONMENT` falls back to `NODE_ENV`, which is what an unconfigured image reports as. `SENTRY_ORG` and `SENTRY_PROJECT` are build args too: they only address the upload target, and without them `withSentryConfig` has nowhere to send source maps. `SENTRY_AUTH_TOKEN` is the only real secret and comes in as a BuildKit secret mount; a build arg would land in the image history. The image is built by the [shared publish workflow](https://github.com/BSStudio/.github/blob/main/docs/workflows.md#calling-the-shared-publish-workflow) of `BSStudio/.github`, which passes `VERSION` (see [Observability](observability.md)); `docker-publish.yml` adds `NEXT_PUBLIC_SENTRY_DSN`, `NEXT_PUBLIC_SENTRY_ENVIRONMENT`, `SENTRY_ORG` and `SENTRY_PROJECT` from repository *variables*, and the token from a repository *secret* on tag builds only. **Workflows** (`.github/workflows/`), actions pinned to a commit SHA with the version in a comment, mirroring [BSStudio/request-manager](https://github.com/BSStudio/request-manager): @@ -12,7 +12,7 @@ | --- | --- | --- | | `ci.yml` | PR, push to `main` | Biome + tsc, Vitest with coverage → Codecov, commitlint over the PR range | | `checks.yml` | PR, push to `main` | BSStudio/.github's shared checks: actionlint and zizmor over the workflows, dependency review on PRs | -| `docker-publish.yml` | PR (build only), push to `main`, `v*.*.*` tags | Buildx → `ghcr.io/bsstudio/backstage`, provenance attestation | +| `docker-publish.yml` | PR (build only), push to `main`, `v*.*.*` tags | BSStudio/.github's shared publish workflow: Buildx → `ghcr.io/bsstudio/backstage`, provenance attestation | | `authentik-contract.yml` | Weekly cron, dispatch, PRs touching `lib/authentik/**` | Diffs Authentik's published spec against `scripts/authentik-contract.json` | `ci.yml` and `checks.yml` carry no `paths` filter on purpose: they are what `main` is protected on, and a required check that never runs on a docs-only PR blocks that PR instead of passing it. `ci.yml`'s `Lint and typecheck` and `Test` run `prisma generate` first — `app/generated/prisma/` is gitignored and `tsc` resolves through it. diff --git a/lib/release-link.ts b/lib/release-link.ts new file mode 100644 index 0000000..793f282 --- /dev/null +++ b/lib/release-link.ts @@ -0,0 +1,11 @@ +const repoUrl = "https://github.com/BSStudio/backstage"; + +// Tag builds are versioned X.Y.Z, other images 0.0.0+, local builds dev. +export function releaseLink(version: string): { label: string; url: string } { + if (/^\d+\.\d+\.\d+$/.test(version)) { + return { label: `v${version}`, url: `${repoUrl}/releases/tag/v${version}` }; + } + const commit = version.split("+")[1]; + if (commit) return { label: commit, url: `${repoUrl}/commit/${commit}` }; + return { label: version, url: repoUrl }; +} diff --git a/next.config.ts b/next.config.ts index 90554ea..d2397ca 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,57 +1,8 @@ -import { execFileSync } from "node:child_process"; import { withSentryConfig } from "@sentry/nextjs/config"; import type { NextConfig } from "next"; -function git(...args: string[]) { - return execFileSync("git", args, { stdio: ["ignore", "pipe", "ignore"] }) - .toString() - .trim(); -} - -const commitHash = (() => { - if (process.env.NEXT_PUBLIC_COMMIT_HASH) - return process.env.NEXT_PUBLIC_COMMIT_HASH; - try { - return git("rev-parse", "--short", "HEAD"); - } catch { - return ""; - } -})(); - -// Mirrors the "Resolve build metadata" step of .github/workflows/docker-publish.yml, which -// versions image builds. -const appVersion = (() => { - if (process.env.NEXT_PUBLIC_APP_VERSION) - return process.env.NEXT_PUBLIC_APP_VERSION; - try { - const describe = git( - "describe", - "--tags", - "--first-parent", - "--long", - "--abbrev=7", - "--match=v[0-9]*.[0-9]*.[0-9]*", - "--exclude=*-*", - ); - const match = /^v(\d+\.\d+\.\d+)-(\d+)-g([0-9a-f]+)$/.exec(describe); - if (!match) return "dev"; - const [, tag, distance, hash] = match; - - if (distance === "0" && git("status", "--porcelain") === "") return tag; - - // Later commits must sort higher in Sentry, which compares the revision numerically and - // prereleases as text. - const branch = git("branch", "--show-current").replace( - /[^0-9A-Za-z-]/g, - "-", - ); - return branch === "" || branch === "main" - ? `${tag}.${distance}+${hash}` - : `${tag}.${distance}+${branch}.${hash}`; - } catch { - return "dev"; - } -})(); +// The Dockerfile sets it from its VERSION build arg. +const appVersion = process.env.NEXT_PUBLIC_APP_VERSION || "dev"; // Release names are shared across the Sentry organization, hence the project slug. const sentryRelease = `backstage@${appVersion}`; @@ -63,7 +14,6 @@ const nextConfig: NextConfig = { skipTrailingSlashRedirect: true, env: { NEXT_PUBLIC_APP_VERSION: appVersion, - NEXT_PUBLIC_COMMIT_HASH: commitHash, NEXT_PUBLIC_SENTRY_RELEASE: sentryRelease, }, images: { diff --git a/tests/lib/release-link.test.ts b/tests/lib/release-link.test.ts new file mode 100644 index 0000000..67cd79d --- /dev/null +++ b/tests/lib/release-link.test.ts @@ -0,0 +1,25 @@ +import { describe, expect, it } from "vitest"; +import { releaseLink } from "@/lib/release-link"; + +describe("releaseLink", () => { + it("links a tag build to its release", () => { + expect(releaseLink("1.4.0")).toEqual({ + label: "v1.4.0", + url: "https://github.com/BSStudio/backstage/releases/tag/v1.4.0", + }); + }); + + it("links any other image to its commit", () => { + expect(releaseLink("0.0.0+abc1234")).toEqual({ + label: "abc1234", + url: "https://github.com/BSStudio/backstage/commit/abc1234", + }); + }); + + it("links a local build to the repository", () => { + expect(releaseLink("dev")).toEqual({ + label: "dev", + url: "https://github.com/BSStudio/backstage", + }); + }); +}); From 361b89f740259160131a90e465450e29f4c8b887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliv=C3=A9r=20Kecskem=C3=A9ty?= Date: Sat, 21 Nov 2026 02:26:09 +0100 Subject: [PATCH 2/2] fix: keep local dev builds from creating a sentry release --- docs/observability.md | 4 ++-- next.config.ts | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/observability.md b/docs/observability.md index 63b0620..71ee1a2 100644 --- a/docs/observability.md +++ b/docs/observability.md @@ -27,9 +27,9 @@ A sync failure is tagged `sync.target`, `sync.operation`, `sync.job_id` and `mem **And nothing is collected that the scrubber would only have to drop.** The SDK collects every `dataCollection` category by default, so the restrictive baseline is spelled out rather than inherited — `scrub.ts` is the second line of defence, not the only one. `userInfo`, `cookies` and `httpHeaders` are off and `httpBodies` is none; `urlQueryParams` keeps the query string but denies any key containing `name`, which is how a member's own name arrives at `/api/usernames/suggest?firstName=…&lastName=…` — deny terms match as case-insensitive substrings, so the one term covers every spelling. `databaseQueryData` is pinned for a different reason: it reaches nothing while tracing is off, and the pin is what keeps enabling tracing from shipping the values Prisma binds. The remaining span-scoped categories (`queues`, `genAI`, `graphQL`) have no integration behind them at all and are left alone. -**Release tagging.** Every version string has to parse as semver in Sentry, or the release gets no ordering, no `release.version` filter and no regression detection. Release tags stay `vX.Y.Z`, but the version drops the `v`, which Sentry's parser refuses. A tag build is versioned `X.Y.Z`; every other image `0.0.0+`, with the commit's first seven characters, and creates no release, because production runs tagged releases only. The shared publish workflow passes the version in as `VERSION`, which the Dockerfile hands to `next build` as `NEXT_PUBLIC_APP_VERSION`; a build without it, such as a local `pnpm build`, reports `dev`. +**Release tagging.** Every image's version has to parse as semver in Sentry, or the release gets no ordering, no `release.version` filter and no regression detection. Release tags stay `vX.Y.Z`, but the version drops the `v`, which Sentry's parser refuses. A tag build is versioned `X.Y.Z`; every other image `0.0.0+`, with the commit's first seven characters, and creates no release, because production runs tagged releases only. The shared publish workflow passes the version in as `VERSION`, which the Dockerfile hands to `next build` as `NEXT_PUBLIC_APP_VERSION`; a build without it, such as a local `pnpm build`, is versioned `dev`, which is not semver, so it never creates a release or uploads source maps, even with a token. -The release name is `backstage@`: release names are shared across the whole Sentry organization, so the project slug keeps them apart. `next.config.ts` builds it once into `NEXT_PUBLIC_SENTRY_RELEASE`, which `sentryInitOptions` sets on every runtime and `withSentryConfig` uploads source maps under, so the two cannot name different releases. Source map upload and the release switch themselves off unless `SENTRY_AUTH_TOKEN` is present — the publish workflow passes that secret to tag builds only, and a local `pnpm build` has none. +The release name is `backstage@`: release names are shared across the whole Sentry organization, so the project slug keeps them apart. `next.config.ts` builds it once into `NEXT_PUBLIC_SENTRY_RELEASE`, which `sentryInitOptions` sets on every runtime and `withSentryConfig` uploads source maps under, so the two cannot name different releases. Source map upload and the release switch themselves off unless `SENTRY_AUTH_TOKEN` is present and the version is not `dev` — the publish workflow passes that secret to tag builds only. **Client events tunnel through `/monitoring`.** `tunnelRoute` in `next.config.ts` makes the browser POST envelopes to our own origin instead of `sentry.io`, which ad blockers filter by hostname. The route is generated by the Sentry plugin, so it exists only in a real build — and it is in `publicPaths` in `proxy.ts`, because an error on the login page has no session cookie yet and a redirect would drop the POST body. diff --git a/next.config.ts b/next.config.ts index d2397ca..c473b5f 100644 --- a/next.config.ts +++ b/next.config.ts @@ -29,8 +29,10 @@ const nextConfig: NextConfig = { }, }; -// Upload is off without the build secret, so a local `pnpm build` still succeeds. +// Upload is off without the build secret, so a local `pnpm build` still succeeds, and for +// `dev`, so a local token cannot publish a build as `backstage@dev`. const sentryAuthToken = process.env.SENTRY_AUTH_TOKEN; +const upload = Boolean(sentryAuthToken) && appVersion !== "dev"; export default withSentryConfig(nextConfig, { org: process.env.SENTRY_ORG, @@ -42,11 +44,12 @@ export default withSentryConfig(nextConfig, { // Proxy events through our own origin so ad blockers cannot drop them by hostname. tunnelRoute: "/monitoring", sourcemaps: { - disable: !sentryAuthToken, + disable: !upload, deleteSourcemapsAfterUpload: true, }, release: { name: sentryRelease, - create: Boolean(sentryAuthToken), + create: upload, + finalize: upload, }, });