Add `scope.SetEnvironment`
@bitsandfoxes đang làm issue này rồi.
Từ ngày 20/7/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Proposal: Allow setting Environment on the Scope
Unblocks
- https://github.com/getsentry/sentry-dotnet/issues/5387
- https://github.com/getsentry/sentry-unity/pull/2764
Summary
Add 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(...).
This brings sentry-java to parity with sentry-cocoa and sentry-native. These already expose a scope-/runtime-level environment setter.
Motivation
Today 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.
Both reference SDKs already support this:
| SDK | API | Level | Getter? |
|---|---|---|---|
| cocoa | - (void)setEnvironment:(NSString *)environment on Scope |
scope | no |
| native | sentry_set_environment(const char *environment) (+ _n) |
global scope | no |
| java | (proposed) IScope.setEnvironment(String) + getEnvironment() |
scope | yes |
Proposed API (sentry-java)
public interface IScope {
// ...
@Nullable String getEnvironment();
/**
* Sets the Scope's environment. Takes precedence over SentryOptions#getEnvironment()
* when applied to events. Mainly used by hybrid SDKs to sync their environment.
*/
void setEnvironment(@Nullable String environment);
}
Reached by users/hybrid SDKs the same way as other scope mutations:
Sentry.configureScope(scope -> scope.setEnvironment("staging"));
Unlike 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.
API References
sentry-cocoa
SentryScope.h-(void)setEnvironment:(NSString *_Nullable)environment;SentryScope.m- setsenvironmentString, then notifies scope observers.SentryScope::applyToEvent- odering & backfill- Usage:
SentrySDK.configureScope { $0.setEnvironment("staging") }
sentry-native
sentry.h-SENTRY_API void sentry_set_environment(const char *environment);sentry_core.c- overwritesscope->environmentsentry__scope_apply_to_event- Usage:
sentry_set_environment("staging");
Precedence of application
Effective order from top to bottom: "environment set on the event itself" > scope > options**
SentryClient.applyScope: applies scope environment to the event only when the event has none.MainEventProcessor.setEnvironment: later fallback tooptions.getEnvironment()when still unset
This matches the precedence used by cocoa and native.
Known gap / suggested follow-up
The Android AEI/ANR backfill processor reads environment only from the options cache, not the scope cache:
ApplicationExitInfoEventProcessor.setEnvironmentreadsPersistingOptionsObserver.ENVIRONMENT_FILENAME, falling back tooptions.getEnvironment():
So a scope-set environment is persisted (via the new PersistingScopeObserver file) but is not picked up when backfilling exit-info events.
This could be resolved by reading the scope file first?
- Ngôn ngữ chính
- Kotlin
- Star
- 1.4k
- Fork
- 478
- Merge trung bình
- 3 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 70
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của getsentry/sentry-java
-
Bug Java Platform: Java
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
getsentry/sentry-java#6138 · 1 bình luận ·
-
Feature Java Platform: Java Spans
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
getsentry/sentry-java#5984 · 1 bình luận ·
-
Android Task Traces
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
getsentry/sentry-java#5376 · 1 bình luận ·
-
Android Docs Errors
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
getsentry/sentry-java#5375 · 1 bình luận ·
-
Android good first issue Task User Feedbacks
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 68/100
getsentry/sentry-java#5354 · 1 bình luận ·
Tất cả issue của getsentry/sentry-java
Issue tương tự
-
Icon Requests Đang mởsupported
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
LawnchairLauncher/lawnicons#4100 ·
-
cr:missing-repro cr:platform:android platform:android repro-provided
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
software-mansion/react-native-screens#4699 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Good First Issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
ankidroid/Anki-Android#21942 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
libre-tube/LibreTube#8781 · 1 bình luận ·