Skip to content

fix(core): Reset contexts when a scope is cleared - #5895

Open
limbonaut wants to merge 4 commits into
mainfrom
limbonaut/fix/scope-clear
Open

fix(core): Reset contexts when a scope is cleared#5895
limbonaut wants to merge 4 commits into
mainfrom
limbonaut/fix/scope-clear

Conversation

@limbonaut

@limbonautlimbonaut commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

📜 Description

Scope.clear() is documented as resetting the scope to its default state, but it never touched contexts, so anything set through setContexts survived a clear. Every other field the public API writes to was already being reset. This adds a clear() to Contexts and calls it from Scope.clear(); CombinedContextsView overrides it to delegate to the default scope, matching how it already handles put and remove. Other SDKs, such as JavaScript, Python, Cocoa and native all clear contexts as part of their scope clear. Surfaced while implementing per-capture scopes for the Godot SDK, where identical game code dropped the context on desktop but kept it on Android.

💡 Motivation and Context

Dev docs describe clear as

Reset scope to defaults, keeping event processors.

So this change brings implementation closer to spec.

💚 How did you test it?

📝 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

attributes.clear();
extra.clear();
contexts.clear();
eventProcessors.clear();

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Also worth mentioning another thing from Scopes spec: "keeping event processors". Currently, they are cleared. I'm not sure if it's an intentional deviation.

@sentry

sentryBot commented Aug 5, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App NameApp IDVersionConfiguration
SDK Sizeio.sentry.tests.size8.52.0 (1)release

⚙️ sentry-android Build Distribution Settings

@limbonaut
limbonaut marked this pull request as ready for review August 5, 2026 19:32
Sign up for freeto 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.

scope.clear() does not remove contexts

1 participant

@limbonaut