Skip to content

feat: added Get/Set Environment on Scope - #5772

Open
bitsandfoxes wants to merge 13 commits into
mainfrom
feat/scope-set-environment
Open

feat: added Get/Set Environment on Scope#5772
bitsandfoxes wants to merge 13 commits into
mainfrom
feat/scope-set-environment

Conversation

@bitsandfoxes

@bitsandfoxes bitsandfoxes commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

📜 Description

Adds a getter and setter to the scope that allows users to configure the Environment at runtime.

💡 Motivation and Context

See #5769

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

@github-actions

github-actions Bot commented Jul 16, 2026

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

Generated by 🚫 dangerJS against 3163e45

@sentry

sentry Bot commented Jul 16, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.50.0 (1) release

⚙️ sentry-android Build Distribution Settings

@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 315.91 ms 380.62 ms 64.71 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
6b019b7 319.84 ms 333.15 ms 13.31 ms
c3ee041 310.64 ms 361.90 ms 51.26 ms
d501a7e 348.06 ms 431.42 ms 83.36 ms
3998a95 415.94 ms 478.54 ms 62.60 ms
ed33deb 343.30 ms 362.41 ms 19.10 ms
5b1a06b 310.56 ms 362.79 ms 52.22 ms
91bb874 310.68 ms 359.24 ms 48.56 ms
0ee65e9 317.37 ms 366.50 ms 49.13 ms
6edfca2 305.52 ms 432.78 ms 127.26 ms
5e269de 292.83 ms 379.12 ms 86.29 ms

App size

Revision Plain With Sentry Diff
6b019b7 0 B 0 B 0 B
c3ee041 0 B 0 B 0 B
d501a7e 0 B 0 B 0 B
3998a95 1.58 MiB 2.10 MiB 532.96 KiB
ed33deb 1.58 MiB 2.13 MiB 559.52 KiB
5b1a06b 0 B 0 B 0 B
91bb874 1.58 MiB 2.13 MiB 559.07 KiB
0ee65e9 0 B 0 B 0 B
6edfca2 1.58 MiB 2.13 MiB 559.07 KiB
5e269de 0 B 0 B 0 B

Previous results on branch: feat/scope-set-environment

Startup times

Revision Plain With Sentry Diff
9f4de8c 324.54 ms 361.39 ms 36.85 ms
978ba7b 315.02 ms 355.28 ms 40.26 ms
62d5092 312.19 ms 327.22 ms 15.03 ms
284a8f9 319.11 ms 381.14 ms 62.03 ms
e9c4258 339.22 ms 436.33 ms 97.10 ms

App size

Revision Plain With Sentry Diff
9f4de8c 0 B 0 B 0 B
978ba7b 0 B 0 B 0 B
62d5092 0 B 0 B 0 B
284a8f9 0 B 0 B 0 B
e9c4258 0 B 0 B 0 B

…nment

# Conflicts:
#	sentry-android-core/src/main/java/io/sentry/android/core/ApplicationExitInfoEventProcessor.java
#	sentry-android-core/src/test/java/io/sentry/android/core/ApplicationExitInfoEventProcessorTest.kt
@bitsandfoxes
bitsandfoxes marked this pull request as ready for review July 17, 2026 13:17
Comment thread sentry/src/main/java/io/sentry/Scope.java
Comment thread sentry/src/main/java/io/sentry/Scope.java
Comment thread sentry/src/main/java/io/sentry/SentryClient.java
Comment thread sentry/src/main/java/io/sentry/Scope.java
Comment thread sentry/src/main/java/io/sentry/Sentry.java
scopeCache.resetCache();
final @Nullable String environment = globalScope.getEnvironment();
if (environment != null) {
scopeCache.setEnvironment(environment);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

l: can we maybe add a comment describing why we do this for environment now? Something like

// scope environment is configuration, not telemetry state: re-persist it after the reset like release/dist above

Comment thread CHANGELOG.md

@romtsn romtsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

overall looks good to me, nice job!

There's one place where I think we need to update the usage of environment too, and that is Baggage/DSC (Baggage.java:523, :560). That's the envelope header relay uses for dynamic-sampling rules and trace-level environment in the UI, so we should get it aligned with the rest of telemetry I believe?

Co-authored-by: Roman Zavarnitsyn <rom4ek93@gmail.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3163e45. Configure here.

Comment thread CHANGELOG.md
### Fixes

- Prevent concurrent PixelCopy access during Session Replay masking and bitmap cleanup ([#5808](https://github.com/getsentry/sentry-java/pull/5808))
- Release `MediaMuxer` when the replay video encoder fails to start to avoid a resource leak ([#5607](https://github.com/getsentry/sentry-java/pull/5607))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Duplicated changelog sections

Low Severity

The Unreleased notes now repeat ### Features, ### Improvements, and ### Fixes with the same entries. The feature line appears twice, and the existing improvements/fixes are duplicated instead of Features being moved above them.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3163e45. Configure here.

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.

2 participants