feat(options): Support SENTRY_DSN, SENTRY_RELEASE, and SENTRY_ENVIRONMENT env vars#548
Merged
feat(options): Support SENTRY_DSN, SENTRY_RELEASE, and SENTRY_ENVIRONMENT env vars#548
Conversation
…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>
Contributor
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Documentation 📚
Internal Changes 🔧Deps
Other
🤖 This preview updates automatically when you update the PR. |
Contributor
|
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>
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>
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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):
SentrySDK.init()callback)Environment variables only apply when the corresponding project setting is still at its default value. A fresh
SentryOptionsinstance is used to obtain defaults, so changes to defaults are automatically reflected.Note:
SENTRY_DSNcan provide the DSN without configuring it in project settings, butauto_initmust still be enabled (which it is by default).