Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hubs/Scopes Merge 15 - Replace ThreadLocal with scope storage #3317

Merged
merged 19 commits into from
Apr 19, 2024

Conversation

adinauer
Copy link
Member

@adinauer adinauer commented Apr 4, 2024

#skip-changelog

📜 Description

Replace ThreadLocal in Sentry with scopes storage.

💡 Motivation and Context

Can use token to clean up forked Scopes. Can configure store to use OpenTelemetry Context under the hood (in a follow up PR).

💚 How did you test it?

📝 Checklist

  • I reviewed the submitted code.
  • 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.
  • 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.

🔮 Next steps

@adinauer adinauer changed the title Replace ThreadLocal with scope storage Hubs/Scopes Merge 15 - Replace ThreadLocal with scope storage Apr 4, 2024
Copy link
Contributor

github-actions bot commented Apr 4, 2024

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

Generated by 🚫 dangerJS against 07545e7

sentry/src/main/java/io/sentry/Sentry.java Show resolved Hide resolved
@@ -508,7 +516,7 @@ public static synchronized void close() {
final IScopes scopes = getCurrentScopes();
mainScopes = NoOpScopes.getInstance();
// remove thread local to avoid memory leak
currentScopes.remove();
getScopesStorage().close();
Copy link
Collaborator

Choose a reason for hiding this comment

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

If not in globalHubMode, is it enough to clean the ThreadLocal in the calling thread?
What about scopes stored in other long-living threads, like worker threads or threads in ThreadPools that are reused, wouldn't the scopes in there live on? Would have been the same for Hub before the Hubs/Scopes merge.

If one would re-init Sentry, the ThreadLocal on the calling thread is cleaned, if, however there were long-living threads that had a reference to the initial Scopes instance, they would still use the initial version of Scopes when calling Sentry.captureX for example.

Not sure about the implications, just wanted to point out a potential issue.

Please correct me if I'm wrong :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, maybe we can give https://github.com/getsentry/sentry-java/pull/2711/files a try once we're done with most changes for the major.

Base automatically changed from feat/hubs-scopes-merge-2-add-scopes to 8.x.x April 19, 2024 11:57
@adinauer adinauer merged commit edb4be2 into 8.x.x Apr 19, 2024
3 of 20 checks passed
@adinauer adinauer deleted the feat/hsm-15-scope-storage branch April 19, 2024 12:00
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.

3 participants