Skip to content
Latchkey

Sentry SDK "Invalid Sentry Dsn" during init in CI

Sentrys SDK parses the DSN at init`. An empty or malformed DSN (a missing secret, a truncated value, or a placeholder) raises "Invalid Sentry Dsn". Note that an empty DSN normally disables the SDK quietly; a non-empty but malformed one throws.

What this error means

App or test startup logs "Sentry Logger [error]: Invalid Sentry Dsn: ..." (JS) or BadDsn: Invalid DSN (Python) from Sentry.init / sentry_sdk.init.

text
Sentry Logger [error]: Invalid Sentry Dsn: https://<key>@
# Python:
sentry_sdk.utils.BadDsn: Invalid DSN: missing public key and project id

Common causes

The DSN secret is not injected into CI

The workflow references SENTRY_DSN but the secret is unset for the job, so the SDK receives an empty or half-substituted value.

A placeholder or truncated DSN

A committed placeholder like https://<key>@sentry.io/<project> or a value cut off by shell quoting is not a valid DSN and fails to parse.

How to fix it

Skip Sentry.init when the DSN is absent

  1. In tests, do not initialize Sentry, or pass no DSN so the SDK is a no-op.
  2. Only call init with a DSN when the secret is actually present.
  3. Never commit a placeholder DSN that will parse as invalid.
instrument.js
if (process.env.SENTRY_DSN) {
  Sentry.init({ dsn: process.env.SENTRY_DSN });
}

Inject the DSN from a secret for jobs that need it

Expose the DSN via a secret so the value reaching init is complete and valid.

.github/workflows/ci.yml
env:
  SENTRY_DSN: ${{ secrets.SENTRY_DSN }}

How to prevent it

  • Guard Sentry.init behind a present, non-empty DSN.
  • Do not initialize Sentry in unit tests.
  • Keep the DSN in a secret, never a committed placeholder.

Frequently asked questions

What causes ""Invalid Sentry Dsn""?
The workflow references SENTRY_DSN but the secret is unset for the job, so the SDK receives an empty or half-substituted value.
How do I fix "Invalid Sentry Dsn"?
Skip Sentry.init when the DSN is absent

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card