Skip to content

feat(options): Support SENTRY_DSN, SENTRY_RELEASE, and SENTRY_ENVIRONMENT env vars#548

Merged
limbonaut merged 12 commits intomainfrom
feat/environment-variables
Feb 27, 2026
Merged

feat(options): Support SENTRY_DSN, SENTRY_RELEASE, and SENTRY_ENVIRONMENT env vars#548
limbonaut merged 12 commits intomainfrom
feat/environment-variables

Conversation

@limbonaut
Copy link
Copy Markdown
Collaborator

@limbonaut limbonaut commented Feb 26, 2026

Support configuring DSN, release, and environment via environment variables, as specified in the SDK environment variables spec.

This enables deployment-time configuration — the same exported project can be configured differently per deployment without modifying project files or code.

Only string options are supported because for booleans and numbers there is no way to distinguish a default value from one intentionally set in project settings.

Precedence (highest to lowest):

  1. Code (SentrySDK.init() callback)
  2. Project Settings
  3. Environment variables
  4. Defaults

Environment variables only apply when the corresponding project setting is still at its default value. A fresh SentryOptions instance is used to obtain defaults, so changes to defaults are automatically reflected.

Note: SENTRY_DSN can provide the DSN without configuring it in project settings, but auto_init must still be enabled (which it is by default).

…MENT env vars

Read environment variables as a fallback when the corresponding project
setting is still at its default value. Explicit project settings take
precedence, and the init callback overrides everything.

Priority order (highest to lowest):
1. Code (SentrySDK.init() callback)
2. Project Settings
3. Environment variables
4. Defaults

Refs GH-174
Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 26, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (options) Support SENTRY_DSN, SENTRY_RELEASE, and SENTRY_ENVIRONMENT env vars by limbonaut in #548
  • Add shutdown_timeout_ms option by limbonaut in #539

Documentation 📚

  • Add README files for addon and demo project packages by limbonaut in #547
  • Update Web platform support information in README by limbonaut in #536

Internal Changes 🔧

Deps

  • Update Native SDK to v0.13.0 by github-actions in #533
  • Update Sentry Android to v8.33.0 by github-actions in #531
  • Update wasm-split to v26.2.1 by github-actions in #534
  • Update Sentry JavaScript to v10.40.0 by github-actions in #540

Other

  • (web) Optimize file attachment loading in WASM bridge by limbonaut in #538
  • Add GH_TOKEN and harden AssetLib workflow by limbonaut in #546
  • Automate AssetLib updates on release by limbonaut in #545
  • Generate a separate package with demo project by limbonaut in #542
  • Exclude MSVC linker byproducts from build artifact by limbonaut in #543
  • Run CI on all PRs regardless of changed paths by limbonaut in #541

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 26, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 8e9a741

limbonaut and others added 5 commits February 26, 2026 17:04
Co-Authored-By: Claude <noreply@anthropic.com>
Test the full precedence chain:
- Env vars fill in when project settings are at defaults
- Explicit project settings take precedence over env vars
- Init callback takes precedence over env vars

Co-Authored-By: Claude <noreply@anthropic.com>
Reorder so env vars are applied to a plain defaults instance before
project settings are loaded. This allows simple comparison against
raw defaults without re-reading from ProjectSettings. The load step
now conditionally skips dsn, release, and environment when the
project setting matches its default, preserving env var values.

Co-Authored-By: Claude <noreply@anthropic.com>
Remove the separate _apply_environment_variables method and inline
the env var checks directly into _load_project_settings. This makes
the precedence chain (project setting > env var > default) visible
in one place per option, eliminates the extra defaults allocation,
and removes the implicit ordering dependency between methods.

Co-Authored-By: Claude <noreply@anthropic.com>
The method now calls OS::get_singleton()->get_environment() for env
var support. Add a null guard for consistency with the existing
ProjectSettings guard and the defensive style used elsewhere.

Co-Authored-By: Claude <noreply@anthropic.com>
@limbonaut limbonaut marked this pull request as ready for review February 26, 2026 20:24
limbonaut and others added 6 commits February 26, 2026 21:31
Use a fresh SentryOptions instance to reset dsn, release, and
environment project settings to their defaults before testing env
vars. This prevents the test from breaking if someone configures
non-default values in project.godot.

Co-Authored-By: Claude <noreply@anthropic.com>
Use set_dsn() instead of direct member assignment to match the
pattern used for release and environment.

Co-Authored-By: Claude <noreply@anthropic.com>
DSN is not readable back through the API, so the env var test
verifies indirectly via is_enabled().

Co-Authored-By: Claude <noreply@anthropic.com>
Restore release and environment project settings to their defaults in
after() to prevent test pollution.

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@JoshuaMoelans JoshuaMoelans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noice, LGTM 🚀

@limbonaut limbonaut merged commit a900680 into main Feb 27, 2026
63 checks passed
@limbonaut limbonaut deleted the feat/environment-variables branch February 27, 2026 10: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.

Support passing some options via environment variables

2 participants