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.
Sentry Logger [error]: Invalid Sentry Dsn: https://<key>@
# Python:
sentry_sdk.utils.BadDsn: Invalid DSN: missing public key and project idCommon 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
- In tests, do not initialize Sentry, or pass no DSN so the SDK is a no-op.
- Only call init with a DSN when the secret is actually present.
- Never commit a placeholder DSN that will parse as invalid.
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.
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.