Skip to content

fix(cli): inject Sentry DSN and PostHog credentials into Go binary#5314

Merged
Coly010 merged 2 commits into
developfrom
fix/inject-posthog-sentry
May 20, 2026
Merged

fix(cli): inject Sentry DSN and PostHog credentials into Go binary#5314
Coly010 merged 2 commits into
developfrom
fix/inject-posthog-sentry

Conversation

@Coly010
Copy link
Copy Markdown
Contributor

@Coly010 Coly010 commented May 20, 2026

What changed

  • apps/cli/scripts/build.tsbuildGoTarget now reads SENTRY_DSN, POSTHOG_API_KEY, and POSTHOG_ENDPOINT from process.env and appends a matching -X github.com/supabase/cli/internal/utils.{SentryDsn,PostHogAPIKey,PostHogEndpoint}=... segment to the Go linker flags when the value is set.
  • .github/workflows/release-shared.yml — the build job's env: block now exposes the three repo secrets so release builds get the values populated.

Why

Companion fix to #5313. The legacy CLI shell forwards telemetry through the bundled supabase-go binary, which reads its Sentry DSN and PostHog credentials from -ldflags -X-injected vars. The bun build script only injected utils.Version, so every release after the goreleaser → bun-script migration shipped with empty credentials:

  • apps/cli-go/internal/telemetry/service.go:61 constructs the PostHog client with an empty key and host → the client returns a no-op (internal/telemetry/client.go:32-56).
  • apps/cli-go/cmd/root.go:78 initializes Sentry with an empty DSN → no-op client.

PostHog event flow stopped on 2026-05-18 with v2.98.2 (the last build produced by the prior pipeline). Restoring these injections matches the historical .goreleaser.yml behavior using the same three repo secrets, which already exist (gh secret list --repo supabase/cli).

Reviewer notes

  • The TS shells don't need build-time injection. The next shell carries hardcoded PostHog defaults with runtime env overrides (apps/cli/src/next/config/cli-config.layer.ts), and legacy delegates everything to the Go binary via LegacyGoProxy.
  • The env vars are conditionally appended in the build script, so local builds and PR smoke builds (which don't expose the secrets) produce binaries with empty telemetry credentials and the existing safe no-op runtime behavior — no leakage and no test breakage.
  • Verified locally: SENTRY_DSN=… POSTHOG_API_KEY=… POSTHOG_ENDPOINT=… pnpm exec bun apps/cli/scripts/build.ts --version 2.100.1 --shell legacy produces a supabase-go whose strings output contains the three sentinel values; running the same command with the envs unset produces a binary with none of them.

Fixes CLI-1506

The legacy CLI shell forwards telemetry through the bundled `supabase-go`
binary. `utils.SentryDsn`, `utils.PostHogAPIKey`, and `utils.PostHogEndpoint`
are assigned at compile time via `-ldflags -X`, but the Bun build script
only injected `utils.Version`. As a result the released binary ran with
empty credentials: the PostHog client became a no-op and Sentry's crash
reporting was disabled. PostHog events stopped flowing on 2026-05-18 after
v2.98.2 — the last build produced by the previous goreleaser pipeline.

Read `SENTRY_DSN`, `POSTHOG_API_KEY`, and `POSTHOG_ENDPOINT` from
`process.env` inside `buildGoTarget` and append a corresponding `-X` flag
only when the value is set, so local and PR smoke builds remain
credential-free. Expose the three repo secrets to the build step in
`release-shared.yml` so release builds get them populated.

Fixes CLI-1506
@Coly010 Coly010 requested a review from a team as a code owner May 20, 2026 10:46
@Coly010 Coly010 self-assigned this May 20, 2026
@Coly010 Coly010 merged commit aa2b0f2 into develop May 20, 2026
8 checks passed
@Coly010 Coly010 deleted the fix/inject-posthog-sentry branch May 20, 2026 13:10
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.

2 participants