Skip to content

feat: sync environment to the native layers#5365

Merged
jamescrosswell merged 15 commits into
mainfrom
feat/sync-scope-environment
Jul 15, 2026
Merged

feat: sync environment to the native layers#5365
jamescrosswell merged 15 commits into
mainfrom
feat/sync-scope-environment

Conversation

@bitsandfoxes

@bitsandfoxes bitsandfoxes commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Closes #5385

The scope exposes Environment to be overwritten after initialization by the user. This needs to be propagated to the respective native layers. API available on

  • sentry-native
  • sentry-cocoa
  • sentry-java needs to be followed up on.

We need to make sure that whatever it is that the SDK will end up setting on an event is also available on the native layer. The Enricher lazily guarantees that the context is getting populated, so clearing the Scope needs to restore the native scope to the fallback.

Initially, I thought we needed to have the Scope fetch and set the Environment from the options on the backing field in the constructor. The idea was that we'd avoid any duplicate scope sync. But this would only be an issue on non-global-mobe platforms, and those don't have scope sync in the first place.
So we can "get away" with simply having Environment be a smarter property.

Changelog Entry

The Environment set on the Scope now gets synchronized to the native layers (sentry-cocoa and sentry-native)

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Jul 9, 2026
Comment thread src/Sentry/Scope.cs
Comment thread src/Sentry/Platforms/Native/CFunctions.cs
@bitsandfoxes
bitsandfoxes marked this pull request as draft July 9, 2026 17:41
Comment thread src/Sentry/IScopeObserver.cs
Comment thread src/Sentry/IScopeObserver.cs
Comment thread src/Sentry/Scope.cs Outdated
@github-actions github-actions Bot added the public API Additions/modifications to, or removals from, the public API surface area. label Jul 10, 2026
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.75000% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.23%. Comparing base (b302e47) to head (b7dd7fb).

Files with missing lines Patch % Lines
src/Sentry/Internal/ScopeObserver.cs 0.00% 4 Missing ⚠️
src/Sentry/Platforms/Native/NativeScopeObserver.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5365      +/-   ##
==========================================
- Coverage   74.25%   74.23%   -0.02%     
==========================================
  Files         509      509              
  Lines       18420    18435      +15     
  Branches     3606     3610       +4     
==========================================
+ Hits        13677    13685       +8     
- Misses       3869     3875       +6     
- Partials      874      875       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bitsandfoxes
bitsandfoxes marked this pull request as ready for review July 13, 2026 08:01
Comment thread src/Sentry/Scope.cs Outdated
@github-actions github-actions Bot added risk: high PR risk score: high and removed risk: medium PR risk score: medium labels Jul 13, 2026
@bitsandfoxes
bitsandfoxes requested a review from Flash0ver July 13, 2026 13:50
Comment thread src/Sentry/Scope.cs

@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 2 potential issues.

Fix All in Cursor

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

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 490cc8f. Configure here.

Comment thread src/Sentry/Scope.cs
Comment thread src/Sentry/Scope.cs
Comment thread CHANGELOG.md Outdated
Comment thread src/Sentry/SentrySdk.cs
Comment thread src/Sentry/Scope.cs Outdated
Comment thread src/Sentry/Scope.cs Outdated
Comment thread src/Sentry/Scope.cs
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: high PR risk score: high labels Jul 13, 2026
Comment thread src/Sentry/Platforms/Native/NativeScopeObserver.cs

@jamescrosswell jamescrosswell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM - thanks @bitsandfoxes !

@jamescrosswell
jamescrosswell merged commit c679be2 into main Jul 15, 2026
51 checks passed
@jamescrosswell
jamescrosswell deleted the feat/sync-scope-environment branch July 15, 2026 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

public API Additions/modifications to, or removals from, the public API surface area. risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sync Environment via IScopeObserver in Hybrid SDK scenarios

4 participants