-
-
Notifications
You must be signed in to change notification settings - Fork 220
Replace BaseScope with IScope #590
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
Conversation
Codecov Report
@@ Coverage Diff @@
## main #590 +/- ##
==========================================
- Coverage 81.58% 81.58% -0.01%
==========================================
Files 151 149 -2
Lines 3986 4023 +37
Branches 879 885 +6
==========================================
+ Hits 3252 3282 +30
- Misses 490 494 +4
- Partials 244 247 +3
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few notes
src/Sentry/Scope.cs
Outdated
/// <inheritdoc /> | ||
[DataMember(Name = "breadcrumbs", EmitDefaultValue = false)] | ||
[DontSerializeEmpty] | ||
public ICollection<Breadcrumb> Breadcrumbs { get; } = new SynchronizedList<Breadcrumb>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of this custom "synchronized list". Doesnt' ConcurrentBag and List both implement IEnumerable?
The extension method is internal and can type cast to the type we know we support in both implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IEnumerable doesn't have .Add().
ConcurrentBag implements ICollection but doesn't guarantee order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want Add
exposed to the user. We need Add
ourselves on the AddBreadcrumb
method (before we just typecast to the right type)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right about the order. I don't see the reason to change the way this was done before tbqh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to avoid leaky abstraction from IScope
, because then AddBreadcrumb
would be coupled to both SentryEvent
and Scope
at runtime without a way to validate its assumptions statically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another approach is to add AddBreadcrumb
directly to IScope
, which would eliminate the abstraction issues and would probably be the cleanest solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway, I don't really care about this too much and I guess it's safer to just keep things how they were. Reverted it back to ConcurrentQueue
on Scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK adding to the interface sounds OK
src/Sentry/Scope.cs
Outdated
/// <inheritdoc /> | ||
[DataMember(Name = "extra", EmitDefaultValue = false)] | ||
[DontSerializeEmpty] | ||
public IDictionary<string, object?> Extra { get; } = new ConcurrentDictionary<string, object?>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the old implementation these lists were not allocated at all. Now we get these two lists instatiated for each new Scope pushed/poped even if nothing is ever added
Rearranging scope data and cleaning up the code. Required for implementing transactions.
Some side effects of the changes:
Breadcrumbs
fromConcurrentQueue<T>
to a lock-synchronizedList<T>
. This is becauseConcurrentQueue<T>
doesn't implementICollection<T>
or any other common abstraction that could be used inIScope
. Synchronized list is less efficient, but for small collections that don't get updated on a hot path it's actually really good.null
defaults for collections. As I understand it, this was only used to avoid serializing additional properties if they are unset. Replaced this behavior with a special attribute and a custom contract resolver instead. Previous workaround was also inefficient (serializer still dynamically read those properties, forcing them to initialize) and lead to unnecessarynull
s appearing in the code base. After this change, the collections are now null-safe as an additional benefit. I didn't extend this on objects likeContexts
andRequest
because it's more difficult and probably not worth it. Ultimately, manual serialization fixes all those problems in a much more elegant way.