-
-
Notifications
You must be signed in to change notification settings - Fork 222
Add overload to prevent delegate allocation for ConfigureScope #4228
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
Comments
@bruno-garcia maybe you've got some context around this. In the Hub we have this internally: sentry-dotnet/src/Sentry/Internal/Hub.cs Line 34 in 34d8490
Why is it we only expose that via a ConfigureScope callback (instead of surfacing it directly via the IHub interface or some public extension method)? |
The idea is that once you return the reference explicitly you've lost ownership over it. One can hold it in a static field, access it concurrently etc. So having that state be accessed only behind our public API (SetTag, AddBreadcrumb, etc) allows us to control access, including having it be threadlocal, or asynclocal, or keep it per HTTP request (aspnet classic) etc. |
We should start with adding Also not against adding overloads that allow for 0 allocations of course, but I do think we can add some stuff to our public API like SetTag and other common things. |
That would be even better, as you wouldn't have to go through the hassle of using a callback. Would you be open to PRs for adding both (i.e. |
That'd be awesome. Would you start with SetTag please? Think that's slam dunk. The other one we might want to discuss further (just want to hear from @james.crosswell and @bitsandfoxes before we go ahead) |
In principle, the overloads leveraging static lambdas are really nice as well. Having them there relies on people using them appropriately though. I think if we have methods like On the other hand, having the overloads would provide ultimate flexibility. Maybe we do both then - maybe we add |
Problem Statement
I use the following code to configure a scope, capturing a value to be set as a tag on the scope. Unfortunately, this always results in a delegate allocation because of the capture.
Solution Brainstorm
Perhaps there already is a better way to set a tag on the current scope, but otherwise I'd propose adding the following methods:
These methods could then be used like this:
I'd be happy to provide the implementation if this is something you're interested in.
The text was updated successfully, but these errors were encountered: