Accessing and ensuring global/shared scope in .NET

We solved “Global Mode” on version 3.8.1 of the .NET SDK.

It makes it so that any call to SentrySdk.SetTag or AddBreadcrumb or anything else that you do through SentrySdk.ConfigureScope mutates a single, static Scope object that affects all threads of the app. This is useful for Desktop and Mobile apps when you have a single user session and you add context to Sentry anywhere in the app and want that to be included if it crashes in any other thread.

You can opt-in to this mode through:

options.IsGlobalModeEnabled = true

To clarify: This options doesn’t make sense in any sort of web server where each individual request takes a separate scope (You want each SetTag("url", ...) to take a different request URL, headers etc). Nothing needs to be done for server apps, it continues to work as it did in the past.

Next release of Sentry.Xamarin and Sentry.Xamarin.Forms will include this option already opt-ed in.

We plan to ship Sentry.Wpf and Sentry.WinForms in the future that would already flip IsGlobalModeEnabled = true for you. Until then we’ll add to the docs that you can do that if you prefer to have a single mutable state.