Repository navigation
Description
Problem Statement
The SentryEvent is generally allowed to be mutated. Most properties have setters, or other mechanisms for modification. This is useful when creating a new event to capture manually, and also when modifying an event via BeforeSend.
However, we have some inconsistencies with regards to treatment of dictionaries.
Specifically:
Breadcrumbscan only have items added viaAddBreadcrumb. The API doesn't provide a direct way to modify or remove breadcrumbs once they are on the event. (Breadcrumbobjects are immutable.)BeforeBreadcrumbcan be used to keep them off the event, but there may be need to modify inBeforeSendas well, based on other criteria specific to the event.- One could cast to
List<Breadcrumb>orIList<Breadcrumb>manually, but that is brittle and shouldn't be required.
Extracan only have items added viaSetExtra.- You can set
nullto overwrite an existing item, but the null will still end up in the data. - One could cast to
Dictionary<string, object?>orIDictionary<string, object?>manually, but that is brittle and shouldn't be required.
- You can set
Tagshas bothSetTagandUnsetTagmethods, so it is mutable for all practical reasons. However, it's not clear why these methods are needed, rather than just exposingIDictionary<string, string>. It also makes it cumbersome to clear all entries at once.- One can cast to
Dictionary<string, string>orIDictionary<string, string>manually, but that is brittle and shouldn't be required.
- One can cast to
Solution Brainstorm
In next major release (4.0.0), change the public API of SentryEvent to expose all collection and dictionary properties on SentryEvent as IList<T> or IDictionary<TKey, TValue>.
We can then remove the AddBreadcrumb, SetExtra, SetTag, and UnsetTag methods.
The only other non-mutable properties would be:
EventId,Timestamp, andSdk- which should probably remain immutable.Exception, which we might consider adding a setter for.
Investigation
On the Scope, Breadcrumbs are stored internally in a ConcurrentQueue<Breadcrumb>... presumably because once we hit SentryOptions.MaxBreadcrumbs we start throwing away the old ones. For this reason, I think it makes sense to leave Breadcrumbs as they are.
Tags is feasible. The only complication is that we have an IScopeObserver to sync the scope to iOS. So I've had to wrap the ConcurrentDictionary that was being used to store tags internally in an InterceptingDictionary class that let's us intercept the settter/getter on the index property.
Activity