René's URL Explorer Experiment


Title: Add `scope.SetEnvironment` · Issue #5769 · getsentry/sentry-java · GitHub

Open Graph Title: Add `scope.SetEnvironment` · Issue #5769 · getsentry/sentry-java

X Title: Add `scope.SetEnvironment` · Issue #5769 · getsentry/sentry-java

Description: Proposal: Allow setting Environment on the Scope Unblocks getsentry/sentry-dotnet#5387 getsentry/sentry-unity#2764 Summary Add getEnvironment() / setEnvironment(String) to sentry-java's IScope, so other SDKs (hybrid SDKs like .NET, Godot...

Open Graph Description: Proposal: Allow setting Environment on the Scope Unblocks getsentry/sentry-dotnet#5387 getsentry/sentry-unity#2764 Summary Add getEnvironment() / setEnvironment(String) to sentry-java's IScope, so ...

X Description: Proposal: Allow setting Environment on the Scope Unblocks getsentry/sentry-dotnet#5387 getsentry/sentry-unity#2764 Summary Add getEnvironment() / setEnvironment(String) to sentry-java's IScope,...

Opengraph URL: https://github.com/getsentry/sentry-java/issues/5769

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.114.4


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add `scope.SetEnvironment`","articleBody":"# Proposal: Allow setting `Environment` on the Scope\n\nUnblocks\n- https://github.com/getsentry/sentry-dotnet/issues/5387\n- https://github.com/getsentry/sentry-unity/pull/2764\n\n## Summary\n\nAdd `getEnvironment()` / `setEnvironment(String)` to sentry-java's `IScope`, so other SDKs (hybrid SDKs like .NET, Godot, Unity, Unreal, React Native?) and end users can set the `Environment` on the scope at runtime. This lifts the restriction of having to provide it strictly at init via `SentryOptions.setEnvironment(...)`.\n\nThis brings `sentry-java` to parity with `sentry-cocoa` and `sentry-native`. These already expose a scope-/runtime-level environment setter.\n\n## Motivation\n\nToday `environment` in sentry-java lives only on `SentryOptions`, fixed at init time. Any hybrid SDKs layered on top either manage their own `environment` or provide a way for users to modify it at runtime. This creates the  need to sync it into the Java layer at runtime. That way events, and persisted (background/ANR/NDK) events, carry the correct value. \n\nBoth reference SDKs already support this:\n\n| SDK    | API                                                          | Level        | Getter? |\n|--------|--------------------------------------------------------------|--------------|---------|\n| cocoa  | `- (void)setEnvironment:(NSString *)environment` on `Scope`  | scope        | no      |\n| native | `sentry_set_environment(const char *environment)` (+ `_n`)   | global scope | no      |\n| java   | **(proposed)** `IScope.setEnvironment(String)` + `getEnvironment()` | scope  | yes     |\n\n## Proposed API (sentry-java)\n\n```java\npublic interface IScope {\n  // ...\n  @Nullable String getEnvironment();\n\n  /**\n   * Sets the Scope's environment. Takes precedence over SentryOptions#getEnvironment()\n   * when applied to events. Mainly used by hybrid SDKs to sync their environment.\n   */\n  void setEnvironment(@Nullable String environment);\n}\n```\n\nReached by users/hybrid SDKs the same way as other scope mutations:\n\n```java\nSentry.configureScope(scope -> scope.setEnvironment(\"staging\"));\n```\n\nUnlike cocoa, we could also add a **getter**, consistent with other Java scope fields like `getTransactionName`, and `getUser` e.t.c. and required by the combined-scope view.\n\n### API References\n\n**sentry-cocoa**\n- [`SentryScope.h`](https://github.com/getsentry/sentry-cocoa/blob/8693a8f07525287fcc3714cdbc505cf0b73b4d84/Sources/Sentry/Public/SentryScope.h#L99) - `(void)setEnvironment:(NSString *_Nullable)environment;`\n- [`SentryScope.m`](https://github.com/getsentry/sentry-cocoa/blob/8693a8f07525287fcc3714cdbc505cf0b73b4d84/Sources/Sentry/SentryScope.m#L385) - sets `environmentString`, then notifies scope observers.\n- [`SentryScope::applyToEvent`](https://github.com/getsentry/sentry-cocoa/blob/8693a8f07525287fcc3714cdbc505cf0b73b4d84/Sources/Sentry/SentryScope.m#L638-L643) - odering & backfill\n- Usage: `SentrySDK.configureScope { $0.setEnvironment(\"staging\") }`\n\n**sentry-native**\n- [`sentry.h`](https://github.com/getsentry/sentry-native/blob/2723a0fb5707ae8596e90ae041d397d8ce4e9ceb/include/sentry.h#L2272-L2278) - `SENTRY_API void sentry_set_environment(const char *environment);`\n- [`sentry_core.c`](https://github.com/getsentry/sentry-native/blob/2723a0fb5707ae8596e90ae041d397d8ce4e9ceb/src/sentry_core.c#L935-L951) - overwrites `scope->environment`\n- [`sentry__scope_apply_to_event`](https://github.com/getsentry/sentry-native/blob/2723a0fb5707ae8596e90ae041d397d8ce4e9ceb/src/sentry_scope.c#L449) \n- Usage: `sentry_set_environment(\"staging\");`\n\n## Precedence of application\n\nEffective order from top to bottom: \"environment set on the event itself\" > scope > options**\n\n- `SentryClient.applyScope`: applies scope environment to the event only when the event has none.\n- [`MainEventProcessor.setEnvironment`](https://github.com/getsentry/sentry-java/blob/20be537e26bae44a7ffdb1b207ea3f631a711a15/sentry/src/main/java/io/sentry/MainEventProcessor.java#L154-L158): later fallback to `options.getEnvironment()` when still unset\n\nThis matches the precedence used by `cocoa` and `native`.\n\n## Known gap / suggested follow-up\n\nThe Android **AEI/ANR backfill** processor reads environment only from the *options* cache, not the *scope* cache:\n\n- [`ApplicationExitInfoEventProcessor.setEnvironment`](https://github.com/getsentry/sentry-java/blob/20be537e26bae44a7ffdb1b207ea3f631a711a15/sentry-android-core/src/main/java/io/sentry/android/core/ApplicationExitInfoEventProcessor.java#L461-L466) reads `PersistingOptionsObserver.ENVIRONMENT_FILENAME`, falling back to `options.getEnvironment()`:\n\nSo a scope-set environment is persisted (via the new `PersistingScopeObserver` file) but is **not** picked up when backfilling exit-info events. \nThis could be resolved by reading the scope file first?","author":{"url":"https://github.com/bitsandfoxes","@type":"Person","name":"bitsandfoxes"},"datePublished":"2026-07-16T11:15:48Z","url":"https://github.com/getsentry/sentry-java/issues/5769"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:e73675bd-406a-c37f-6df2-838d20b28e01
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC602:347215:42B2F2:5BB4AD:6B0451B0
html-safe-nonce0a0d5c04c6e653f0da1c812985e75c8c816c2832ebbdc4dc3e4d1bced3b0b972
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNjAyOjM0NzIxNTo0MkIyRjI6NUJCNEFEOjZCMDQ1MUIwIiwidmlzaXRvcl9pZCI6Ijg5NTE1ODQ2ODI3OTgyNDAxNzYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacb9e8b2b503de595e8bc5d85f0305516f685dc4ced250a7045ce0dd7ee073dcc2
hovercard-subject-tagissue:4901434810
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-java/5769/issue_layout
twitter:imagehttps://opengraph.githubassets.com/781b30fc14494052a8daefc17a4658a5dd81ddb7c69b8f0a4b65e01bb8d61999/getsentry/sentry-java/issues/5769
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/781b30fc14494052a8daefc17a4658a5dd81ddb7c69b8f0a4b65e01bb8d61999/getsentry/sentry-java/issues/5769
og:image:altProposal: Allow setting Environment on the Scope Unblocks getsentry/sentry-dotnet#5387 getsentry/sentry-unity#2764 Summary Add getEnvironment() / setEnvironment(String) to sentry-java's IScope, so ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamebitsandfoxes
hostnamegithub.com
expected-hostnamegithub.com
None910ca0e260cfec6aff11407d8dc6a0d3a4cd381a2ec9ada56627b063426892a0
turbo-cache-controlno-preview
go-importgithub.com/getsentry/sentry-java git https://github.com/getsentry/sentry-java.git
octolytics-dimension-user_id1396951
octolytics-dimension-user_logingetsentry
octolytics-dimension-repository_id3368190
octolytics-dimension-repository_nwogetsentry/sentry-java
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id3368190
octolytics-dimension-repository_network_root_nwogetsentry/sentry-java
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasee086f9b7e88322eb2b41885a6ad425b215737fa5
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/getsentry/sentry-java/issues/5769#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-java%2Fissues%2F5769
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-java%2Fissues%2F5769
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=getsentry%2Fsentry-java
Reloadhttps://github.com/getsentry/sentry-java/issues/5769
Reloadhttps://github.com/getsentry/sentry-java/issues/5769
Reloadhttps://github.com/getsentry/sentry-java/issues/5769
getsentryhttps://github.com/getsentry
sentry-javahttps://github.com/getsentry/sentry-java
Codehttps://github.com/getsentry/sentry-java
Issues266 (266)https://github.com/getsentry/sentry-java/issues
Pull requests58 (58)https://github.com/getsentry/sentry-java/pulls
Discussionshttps://github.com/getsentry/sentry-java/discussions
Actionshttps://github.com/getsentry/sentry-java/actions
Projectshttps://github.com/getsentry/sentry-java/projects
Security and quality2 (2)https://github.com/getsentry/sentry-java/security
Insightshttps://github.com/getsentry/sentry-java/insights
https://github.com/getsentry/sentry-java
New issuehttps://github.com/login?return_to=https://github.com/getsentry/sentry-java/issues/5769
New issuehttps://github.com/login?return_to=https://github.com/getsentry/sentry-java/issues/5769
Add scope.SetEnvironmenthttps://github.com/getsentry/sentry-java/issues/5769#top
https://github.com/bitsandfoxes
FeatureIssue typehttps://github.com/getsentry/sentry-java/issues?q=state%3Aopen%20label%3A%22Feature%22
JavaSDKhttps://github.com/getsentry/sentry-java/issues?q=state%3Aopen%20label%3A%22Java%22
Platform: Javahttps://github.com/getsentry/sentry-java/issues?q=state%3Aopen%20label%3A%22Platform%3A%20Java%22
https://github.com/bitsandfoxes
bitsandfoxeshttps://github.com/bitsandfoxes
on Jul 16, 2026https://github.com/getsentry/sentry-java/issues/5769#issue-4901434810
Sync Environment via IScopeObserver in Hybrid SDK scenarios (sentry-java) sentry-dotnet#5387https://github.com/getsentry/sentry-dotnet/issues/5387
fix: sync environment to native SDKs sentry-unity#2764https://github.com/getsentry/sentry-unity/pull/2764
SentryScope.hhttps://github.com/getsentry/sentry-cocoa/blob/8693a8f07525287fcc3714cdbc505cf0b73b4d84/Sources/Sentry/Public/SentryScope.h#L99
SentryScope.mhttps://github.com/getsentry/sentry-cocoa/blob/8693a8f07525287fcc3714cdbc505cf0b73b4d84/Sources/Sentry/SentryScope.m#L385
SentryScope::applyToEventhttps://github.com/getsentry/sentry-cocoa/blob/8693a8f07525287fcc3714cdbc505cf0b73b4d84/Sources/Sentry/SentryScope.m#L638-L643
sentry.hhttps://github.com/getsentry/sentry-native/blob/2723a0fb5707ae8596e90ae041d397d8ce4e9ceb/include/sentry.h#L2272-L2278
sentry_core.chttps://github.com/getsentry/sentry-native/blob/2723a0fb5707ae8596e90ae041d397d8ce4e9ceb/src/sentry_core.c#L935-L951
sentry__scope_apply_to_eventhttps://github.com/getsentry/sentry-native/blob/2723a0fb5707ae8596e90ae041d397d8ce4e9ceb/src/sentry_scope.c#L449
MainEventProcessor.setEnvironmenthttps://github.com/getsentry/sentry-java/blob/20be537e26bae44a7ffdb1b207ea3f631a711a15/sentry/src/main/java/io/sentry/MainEventProcessor.java#L154-L158
ApplicationExitInfoEventProcessor.setEnvironmenthttps://github.com/getsentry/sentry-java/blob/20be537e26bae44a7ffdb1b207ea3f631a711a15/sentry-android-core/src/main/java/io/sentry/android/core/ApplicationExitInfoEventProcessor.java#L461-L466
https://github.com/apps/linear-code
linear-codehttps://github.com/apps/linear-code
on Jul 16, 2026https://github.com/getsentry/sentry-java/issues/5769#issuecomment-4991182418
Linear Codehttps://linear.app
JAVA-644https://linear.app/getsentry/issue/JAVA-644
github-actionshttps://github.com/apps/github-actions
Platform: Javahttps://github.com/getsentry/sentry-java/issues?q=state%3Aopen%20label%3A%22Platform%3A%20Java%22
on Jul 16, 2026https://github.com/getsentry/sentry-java/issues/5769#event-28065798046
linear-codehttps://github.com/apps/linear-code
FeatureIssue typehttps://github.com/getsentry/sentry-java/issues?q=state%3Aopen%20label%3A%22Feature%22
JavaSDKhttps://github.com/getsentry/sentry-java/issues?q=state%3Aopen%20label%3A%22Java%22
on Jul 16, 2026https://github.com/getsentry/sentry-java/issues/5769#event-28065832364
runningcodehttps://github.com/runningcode
bitsandfoxeshttps://github.com/bitsandfoxes
on Jul 20, 2026https://github.com/getsentry/sentry-java/issues/5769#event-28212168391
https://github.com/romtsn
romtsnhttps://github.com/romtsn
on Nov 18, 2026https://github.com/getsentry/sentry-java/issues/5769#issuecomment-6981864323
#5772https://github.com/getsentry/sentry-java/pull/5772
romtsnhttps://github.com/romtsn
completedhttps://github.com/getsentry/sentry-java/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Nov 18, 2026https://github.com/getsentry/sentry-java/issues/5769#event-36539968846
Sign up for freehttps://github.com/signup?return_to=https://github.com/getsentry/sentry-java/issues/5769
Sign in to commenthttps://github.com/login?return_to=https://github.com/getsentry/sentry-java/issues/5769
bitsandfoxeshttps://github.com/bitsandfoxes
FeatureIssue typehttps://github.com/getsentry/sentry-java/issues?q=state%3Aopen%20label%3A%22Feature%22
JavaSDKhttps://github.com/getsentry/sentry-java/issues?q=state%3Aopen%20label%3A%22Java%22
Platform: Javahttps://github.com/getsentry/sentry-java/issues?q=state%3Aopen%20label%3A%22Platform%3A%20Java%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.