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

Add Blazor WASM detection to set IsGlobalModeEnabled to true #1931

Merged
merged 7 commits into from
Sep 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Dont send transaction for OPTIONS web request ([#1921](https://github.com/getsentry/sentry-dotnet/pull/1921))
- Fix missing details when aggregate exception is filtered out ([#1922](https://github.com/getsentry/sentry-dotnet/pull/1922))
- Exception filters should consider child exceptions of an `AggregateException` ([#1924](https://github.com/getsentry/sentry-dotnet/pull/1924))
- Add Blazor WASM detection to set IsGlobalModeEnabled to true ([#1931](https://github.com/getsentry/sentry-dotnet/pull/1931))

## 3.21.0

Expand Down
10 changes: 8 additions & 2 deletions samples/Sentry.Samples.AspNetCore.Blazor.Wasm/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net.Http;
using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Sentry.Samples.AspNetCore.Blazor.Wasm;

Expand All @@ -7,6 +8,8 @@
{
o.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537";
o.Debug = true;
//IsGlobalModeEnabled will be true for Blazor WASM
Debug.Assert(o.IsGlobalModeEnabled);
});
try
{
Expand All @@ -16,8 +19,11 @@
// Captures logError and higher as events
builder.Logging.AddSentry(o => o.InitializeSdk = false);

builder.Services.AddScoped(_ => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

builder.Services.AddScoped(_ =>
new HttpClient
{
BaseAddress = new(builder.HostEnvironment.BaseAddress)
});
await builder.Build().RunAsync();
}
catch (Exception e)
Expand Down
7 changes: 7 additions & 0 deletions src/Sentry/PlatformAbstractions/RuntimeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ public static bool IsNetCore(this Runtime runtime) =>
/// <returns>True if it's Mono, otherwise false.</returns>
public static bool IsMono(this Runtime runtime) => runtime.StartsWith("Mono");

/// <summary>
/// Is the runtime instance Browser Web Assembly.
/// </summary>
/// <param name="runtime">The runtime instance to check.</param>
/// <returns>True if it's Browser WASM, otherwise false.</returns>
internal static bool IsBrowserWasm(this Runtime runtime) => runtime.Identifier == "browser-wasm";

private static bool StartsWith(this Runtime? runtime, string runtimeName) =>
runtime?.Name?.StartsWith(runtimeName, StringComparison.OrdinalIgnoreCase) == true ||
runtime?.Raw?.StartsWith(runtimeName, StringComparison.OrdinalIgnoreCase) == true;
Expand Down
4 changes: 2 additions & 2 deletions src/Sentry/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public bool IsGlobalModeEnabled
/// <summary>
/// Specifies whether to use global scope management mode.
/// Should be <c>true</c> for client applications and <c>false</c> for server applications.
/// The default is <c>false</c>.
/// The default is <c>false</c>. The default for Blazor WASM, MAUI, and Mobile apps is <c>true</c>.
/// </summary>
public bool IsGlobalModeEnabled { get; set; }
public bool IsGlobalModeEnabled { get; set; } = Runtime.Current.IsBrowserWasm();
#endif

/// <summary>
Expand Down