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

feat: Minimal Blazor support #3386

Merged
merged 24 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6f19ac0
based blazor
bitsandfoxes May 24, 2024
e3fecbf
Format code
getsentry-bot May 24, 2024
521cb01
preview
bitsandfoxes May 27, 2024
762d78a
Merge branch 'feat/blazor-base' of https://github.com/getsentry/sentr…
bitsandfoxes May 27, 2024
695aecc
lower the tfw
bitsandfoxes May 28, 2024
d133933
removed unused dependency
bitsandfoxes May 28, 2024
407ba7c
Merge branch 'main' into feat/blazor-base
bitsandfoxes May 28, 2024
960c844
Updated CHANGELOG.md
bitsandfoxes May 28, 2024
caaae1b
Merge branch 'main' into feat/blazor-base
jamescrosswell May 29, 2024
50a60f2
Merge branch 'main' into feat/blazor-base
bitsandfoxes Jun 5, 2024
4959a6e
renamed to 'Senty.AspNetCore.Blazor.WebAssembly'
bitsandfoxes Jun 5, 2024
85f4618
fixed rename
bitsandfoxes Jun 5, 2024
0860efa
visiblity
bitsandfoxes Jun 5, 2024
c26c323
setting globalmode ootb
bitsandfoxes Jun 5, 2024
42f4ea9
Merge branch 'main' into feat/blazor-base
bitsandfoxes Jun 5, 2024
44e92c6
.
bitsandfoxes Jun 5, 2024
5924a40
Merge branch 'feat/blazor-base' of https://github.com/getsentry/sentr…
bitsandfoxes Jun 5, 2024
8b2d7cc
updated README.md
bitsandfoxes Jun 10, 2024
113310f
rename
bitsandfoxes Jun 10, 2024
c6ccc52
Identify unhandled WASM exceptions
jamescrosswell Jun 11, 2024
b3e8756
Merge branch 'main' into feat/blazor-base
bitsandfoxes Jun 18, 2024
77c840a
updated sample
bitsandfoxes Jun 18, 2024
b6834a5
Merge branch 'main' into feat/blazor-base
jamescrosswell Jun 18, 2024
1796464
Tweaked css styles
jamescrosswell Jun 19, 2024
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
7 changes: 7 additions & 0 deletions .generated.NoMobile.sln
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root", "root", "{233D34AB-9
CONTRIBUTING.md = CONTRIBUTING.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AspNetCore.Blazor", "src\Sentry.AspNetCore.Blazor\Sentry.AspNetCore.Blazor.csproj", "{7D797C46-EF23-40DD-A8AC-EB1DB3708EB0}"
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -502,6 +504,10 @@ Global
{46E40BE8-1AB0-4846-B0A2-A40AD0272C64}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46E40BE8-1AB0-4846-B0A2-A40AD0272C64}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46E40BE8-1AB0-4846-B0A2-A40AD0272C64}.Release|Any CPU.Build.0 = Release|Any CPU
{7D797C46-EF23-40DD-A8AC-EB1DB3708EB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D797C46-EF23-40DD-A8AC-EB1DB3708EB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D797C46-EF23-40DD-A8AC-EB1DB3708EB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D797C46-EF23-40DD-A8AC-EB1DB3708EB0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -587,5 +593,6 @@ Global
{407C477D-69C0-4B02-8A68-EE6B5A81C696} = {21B42F60-5802-404E-90F0-AEBCC56760C0}
{EADF25F5-8D02-4747-AB54-5F2BAA648471} = {230B9384-90FD-4551-A5DE-1A5C197F25B6}
{46E40BE8-1AB0-4846-B0A2-A40AD0272C64} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D}
{7D797C46-EF23-40DD-A8AC-EB1DB3708EB0} = {230B9384-90FD-4551-A5DE-1A5C197F25B6}
EndGlobalSection
EndGlobal
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

- Added a new package `Sentry.AspNetCore.Blazor`. This packages provides you with an extension to `WebAssemblyHostBuilder` to allow SDK configuration via the builder pattern. This package gives us an entry point and the ability to extend the SDKs support and out-of-the-box offering. You can follow the progress and leave feedback either ([here](https://github.com/getsentry/sentry-dotnet/issues/2329)) for extending the support for Blazor Server or ([here](https://github.com/getsentry/sentry-dotnet/issues/2021)) for Blazor WebAssembly support ([#3386](https://github.com/getsentry/sentry-dotnet/pull/3386))
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved

### Dependencies

- Bump Native SDK from v0.7.4 to v0.7.5 ([#3399](https://github.com/getsentry/sentry-dotnet/pull/3399))
Expand Down
1 change: 1 addition & 0 deletions Sentry-CI-Build-Linux.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"samples\\Sentry.Samples.OpenTelemetry.Console\\Sentry.Samples.OpenTelemetry.Console.csproj",
"samples\\Sentry.Samples.Serilog\\Sentry.Samples.Serilog.csproj",
"src\\Sentry.Android.AssemblyReader\\Sentry.Android.AssemblyReader.csproj",
"src\\Sentry.AspNetCore.Blazor\\Sentry.AspNetCore.Blazor.csproj",
"src\\Sentry.AspNetCore.Grpc\\Sentry.AspNetCore.Grpc.csproj",
"src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj",
"src\\Sentry.Azure.Functions.Worker\\Sentry.Azure.Functions.Worker.csproj",
Expand Down
1 change: 1 addition & 0 deletions Sentry-CI-Build-Windows.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"samples\\Sentry.Samples.Serilog\\Sentry.Samples.Serilog.csproj",
"src\\Sentry.Android.AssemblyReader\\Sentry.Android.AssemblyReader.csproj",
"src\\Sentry.AspNet\\Sentry.AspNet.csproj",
"src\\Sentry.AspNetCore.Blazor\\Sentry.AspNetCore.Blazor.csproj",
"src\\Sentry.AspNetCore.Grpc\\Sentry.AspNetCore.Grpc.csproj",
"src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj",
"src\\Sentry.Azure.Functions.Worker\\Sentry.Azure.Functions.Worker.csproj",
Expand Down
1 change: 1 addition & 0 deletions Sentry-CI-Build-macOS.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"samples\\Sentry.Samples.Serilog\\Sentry.Samples.Serilog.csproj",
"src\\Sentry.Android.AssemblyReader\\Sentry.Android.AssemblyReader.csproj",
"src\\Sentry.AspNet\\Sentry.AspNet.csproj",
"src\\Sentry.AspNetCore.Blazor\\Sentry.AspNetCore.Blazor.csproj",
"src\\Sentry.AspNetCore.Grpc\\Sentry.AspNetCore.Grpc.csproj",
"src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj",
"src\\Sentry.Azure.Functions.Worker\\Sentry.Azure.Functions.Worker.csproj",
Expand Down
1 change: 1 addition & 0 deletions Sentry-CI-CodeQL.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"projects": [
"src\\Sentry.Android.AssemblyReader\\Sentry.Android.AssemblyReader.csproj",
"src\\Sentry.AspNet\\Sentry.AspNet.csproj",
"src\\Sentry.AspNetCore.Blazor\\Sentry.AspNetCore.Blazor.csproj",
"src\\Sentry.AspNetCore.Grpc\\Sentry.AspNetCore.Grpc.csproj",
"src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj",
"src\\Sentry.Azure.Functions.Worker\\Sentry.Azure.Functions.Worker.csproj",
Expand Down
7 changes: 7 additions & 0 deletions Sentry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root", "root", "{233D34AB-9
CONTRIBUTING.md = CONTRIBUTING.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AspNetCore.Blazor", "src\Sentry.AspNetCore.Blazor\Sentry.AspNetCore.Blazor.csproj", "{7D797C46-EF23-40DD-A8AC-EB1DB3708EB0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -502,6 +504,10 @@ Global
{46E40BE8-1AB0-4846-B0A2-A40AD0272C64}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46E40BE8-1AB0-4846-B0A2-A40AD0272C64}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46E40BE8-1AB0-4846-B0A2-A40AD0272C64}.Release|Any CPU.Build.0 = Release|Any CPU
{7D797C46-EF23-40DD-A8AC-EB1DB3708EB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D797C46-EF23-40DD-A8AC-EB1DB3708EB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D797C46-EF23-40DD-A8AC-EB1DB3708EB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D797C46-EF23-40DD-A8AC-EB1DB3708EB0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -587,5 +593,6 @@ Global
{407C477D-69C0-4B02-8A68-EE6B5A81C696} = {21B42F60-5802-404E-90F0-AEBCC56760C0}
{EADF25F5-8D02-4747-AB54-5F2BAA648471} = {230B9384-90FD-4551-A5DE-1A5C197F25B6}
{46E40BE8-1AB0-4846-B0A2-A40AD0272C64} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D}
{7D797C46-EF23-40DD-A8AC-EB1DB3708EB0} = {230B9384-90FD-4551-A5DE-1A5C197F25B6}
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions SentryAspNetCore.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"samples\\Sentry.Samples.Aws.Lambda.AspNetCoreServer\\Sentry.Samples.Aws.Lambda.AspNetCoreServer.csproj",
"samples\\Sentry.Samples.Hangfire\\Sentry.Samples.Hangfire.csproj",
"samples\\Sentry.Samples.OpenTelemetry.AspNetCore\\Sentry.Samples.OpenTelemetry.AspNetCore.csproj",
"src\\Sentry.AspNetCore.Blazor\\Sentry.AspNetCore.Blazor.csproj",
"src\\Sentry.AspNetCore.Grpc\\Sentry.AspNetCore.Grpc.csproj",
"src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj",
"src\\Sentry.DiagnosticSource\\Sentry.DiagnosticSource.csproj",
Expand Down
1 change: 1 addition & 0 deletions SentryNoMobile.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"samples\\Sentry.Samples.OpenTelemetry.Console\\Sentry.Samples.OpenTelemetry.Console.csproj",
"samples\\Sentry.Samples.Serilog\\Sentry.Samples.Serilog.csproj",
"src\\Sentry.AspNet\\Sentry.AspNet.csproj",
"src\\Sentry.AspNetCore.Blazor\\Sentry.AspNetCore.Blazor.csproj",
"src\\Sentry.AspNetCore.Grpc\\Sentry.AspNetCore.Grpc.csproj",
"src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj",
"src\\Sentry.Azure.Functions.Worker\\Sentry.Azure.Functions.Worker.csproj",
Expand Down
1 change: 1 addition & 0 deletions SentryNoSamples.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"benchmarks\\Sentry.Benchmarks\\Sentry.Benchmarks.csproj",
"src\\Sentry.Android.AssemblyReader\\Sentry.Android.AssemblyReader.csproj",
"src\\Sentry.AspNet\\Sentry.AspNet.csproj",
"src\\Sentry.AspNetCore.Blazor\\Sentry.AspNetCore.Blazor.csproj",
"src\\Sentry.AspNetCore.Grpc\\Sentry.AspNetCore.Grpc.csproj",
"src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj",
"src\\Sentry.Azure.Functions.Worker\\Sentry.Azure.Functions.Worker.csproj",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Sentry.AspNetCore.Blazor\Sentry.AspNetCore.Blazor.csproj" />
<ProjectReference Include="..\..\src\Sentry.AspNetCore\Sentry.AspNetCore.csproj" />
</ItemGroup>

Expand Down
17 changes: 8 additions & 9 deletions samples/Sentry.Samples.AspNetCore.Blazor.Wasm/Program.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Sentry.Samples.AspNetCore.Blazor.Wasm;

// Capture blazor bootstrapping errors
using var sdk = SentrySdk.Init(o =>
{
o.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537";
o.Debug = true;
//IsGlobalModeEnabled will be true for Blazor WASM
Debug.Assert(o.IsGlobalModeEnabled);
});
try
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.UseSentry(options =>
{
options.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537";
options.Debug = true;
options.IsGlobalModeEnabled = true;
});
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved

builder.RootComponents.Add<App>("#app");
builder.Logging.SetMinimumLevel(LogLevel.Debug);

// Captures logError and higher as events
builder.Logging.AddSentry(o => o.InitializeSdk = false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.3"/>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.3" PrivateAssets="all"/>
<ProjectReference Include="..\..\src\Sentry\Sentry.csproj" />
<ProjectReference Include="..\..\src\Sentry.Extensions.Logging\Sentry.Extensions.Logging.csproj" />
<ProjectReference Include="..\..\src\Sentry.AspNetCore.Blazor\Sentry.AspNetCore.Blazor.csproj" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions src/Sentry.AspNetCore.Blazor/Sentry.AspNetCore.Blazor.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<VersionSuffix>-preview.1</VersionSuffix>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Sentry.Extensions.Logging\Sentry.Extensions.Logging.csproj" />
<ProjectReference Include="..\Sentry\Sentry.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.30" />
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>
</Project>
41 changes: 41 additions & 0 deletions src/Sentry.AspNetCore.Blazor/WebAssemblyHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Microsoft.Extensions.Logging;
using Sentry;
using Sentry.Extensions.Logging;

// ReSharper disable once CheckNamespace - Discoverability
namespace Microsoft.AspNetCore.Components.WebAssembly.Hosting;

/// <summary>
/// Extension methods for <see cref="WebAssemblyHostBuilder"/>
/// </summary>
public static class WebAssemblyHostBuilderExtensions
{
/// <summary>
/// Use Sentry Integration
/// </summary>
/// <param name="builder"></param>
/// <param name="configureOptions"></param>
/// <returns></returns>
public static WebAssemblyHostBuilder UseSentry(this WebAssemblyHostBuilder builder, Action<SentryBlazorOptions> configureOptions)
{
builder.Logging.AddSentry<SentryBlazorOptions>(blazorOptions =>
{
configureOptions(blazorOptions);

// System.PlatformNotSupportedException: System.Diagnostics.Process is not supported on this platform.
blazorOptions.DetectStartupTime = StartupTimeDetectionMode.Fast;
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved
// Warning: No response compression supported by HttpClientHandler.
blazorOptions.RequestBodyCompressionLevel = CompressionLevel.NoCompression;
});

return builder;
}
}

/// <summary>
/// Sentry Blazor Options
/// </summary>
public class SentryBlazorOptions : SentryLoggingOptions
{
// Awesome Blazor specific options go here
}
14 changes: 8 additions & 6 deletions src/Sentry.Extensions.Logging/LoggingBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ public static ILoggingBuilder AddSentry(this ILoggingBuilder builder, string dsn
/// </summary>
/// <param name="builder">The builder.</param>
/// <param name="optionsConfiguration">The options configuration.</param>
public static ILoggingBuilder AddSentry(
public static ILoggingBuilder AddSentry(this ILoggingBuilder builder, Action<SentryLoggingOptions>? optionsConfiguration)
=> builder.AddSentry<SentryLoggingOptions>(optionsConfiguration);

internal static ILoggingBuilder AddSentry<TOptions>(
this ILoggingBuilder builder,
Action<SentryLoggingOptions>? optionsConfiguration)
Action<TOptions>? optionsConfiguration)
where TOptions : SentryLoggingOptions, new()
{
builder.AddConfiguration();

Expand All @@ -45,11 +49,9 @@ public static ILoggingBuilder AddSentry(
builder.Services.Configure(optionsConfiguration);
}

builder.Services.AddSingleton<IConfigureOptions<SentryLoggingOptions>, SentryLoggingOptionsSetup>();

builder.Services.AddSingleton<IConfigureOptions<TOptions>, SentryLoggingOptionsSetup>();
builder.Services.AddSingleton<ILoggerProvider, SentryLoggerProvider>();

builder.Services.AddSentry<SentryLoggingOptions>();
builder.Services.AddSentry<TOptions>();

// All logs should flow to the SentryLogger, regardless of level.
// Filtering of events is handled in SentryLogger, using SentryOptions.MinimumEventLevel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

<ItemGroup>
<InternalsVisibleTo Include="Sentry.AspNetCore" PublicKey="$(SentryPublicKey)" />
<InternalsVisibleTo Include="Sentry.AspNetCore.Blazor" PublicKey="$(SentryPublicKey)" />
<InternalsVisibleTo Include="Sentry.AspNetCore.Tests" PublicKey="$(SentryPublicKey)" />
<InternalsVisibleTo Include="Sentry.AspNetCore.Grpc" PublicKey="$(SentryPublicKey)" />
<InternalsVisibleTo Include="Sentry.AspNetCore.Grpc.Tests" PublicKey="$(SentryPublicKey)" />
Expand Down
Loading