Skip to content

Commit 7e6d797

Browse files
authored
Sample Blazor Wasm (#574)
1 parent 594edae commit 7e6d797

File tree

12 files changed

+207
-4
lines changed

12 files changed

+207
-4
lines changed

Sentry.sln

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
108108
.github\workflows\changelog.yaml = .github\workflows\changelog.yaml
109109
EndProjectSection
110110
EndProject
111-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AspNetCore.Grpc", "src\Sentry.AspNetCore.Grpc\Sentry.AspNetCore.Grpc.csproj", "{720811C8-29C7-4368-86F2-D61DF415AC2A}"
111+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.AspNetCore.Grpc", "src\Sentry.AspNetCore.Grpc\Sentry.AspNetCore.Grpc.csproj", "{720811C8-29C7-4368-86F2-D61DF415AC2A}"
112112
EndProject
113-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AspNetCore.Grpc.Tests", "test\Sentry.AspNetCore.Grpc.Tests\Sentry.AspNetCore.Grpc.Tests.csproj", "{3818FA5C-8649-427D-8E68-0C44558CA0DD}"
113+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.AspNetCore.Grpc.Tests", "test\Sentry.AspNetCore.Grpc.Tests\Sentry.AspNetCore.Grpc.Tests.csproj", "{3818FA5C-8649-427D-8E68-0C44558CA0DD}"
114114
EndProject
115-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Samples.AspNetCore.Grpc", "samples\Sentry.Samples.AspNetCore.Grpc\Sentry.Samples.AspNetCore.Grpc.csproj", "{21599C29-C3D4-4DAC-A2D6-6C194600478F}"
115+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.Samples.AspNetCore.Grpc", "samples\Sentry.Samples.AspNetCore.Grpc\Sentry.Samples.AspNetCore.Grpc.csproj", "{21599C29-C3D4-4DAC-A2D6-6C194600478F}"
116+
EndProject
117+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Samples.AspNetCore.Blazor.Wasm", "samples\Sentry.Samples.AspNetCore.Blazor.Wasm\Sentry.Samples.AspNetCore.Blazor.Wasm.csproj", "{73FDCE53-75D1-4DCC-933A-8AB93A0E86EA}"
116118
EndProject
117119
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Samples.Aws.Lambda.AspNetCoreServer", "samples\Sentry.Samples.Aws.Lambda.AspNetCoreServer\Sentry.Samples.Aws.Lambda.AspNetCoreServer.csproj", "{274CEDC2-2129-469D-B269-649EFA2EF5E0}"
118120
EndProject
@@ -242,6 +244,10 @@ Global
242244
{21599C29-C3D4-4DAC-A2D6-6C194600478F}.Debug|Any CPU.Build.0 = Debug|Any CPU
243245
{21599C29-C3D4-4DAC-A2D6-6C194600478F}.Release|Any CPU.ActiveCfg = Release|Any CPU
244246
{21599C29-C3D4-4DAC-A2D6-6C194600478F}.Release|Any CPU.Build.0 = Release|Any CPU
247+
{73FDCE53-75D1-4DCC-933A-8AB93A0E86EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
248+
{73FDCE53-75D1-4DCC-933A-8AB93A0E86EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
249+
{73FDCE53-75D1-4DCC-933A-8AB93A0E86EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
250+
{73FDCE53-75D1-4DCC-933A-8AB93A0E86EA}.Release|Any CPU.Build.0 = Release|Any CPU
245251
{274CEDC2-2129-469D-B269-649EFA2EF5E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
246252
{274CEDC2-2129-469D-B269-649EFA2EF5E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
247253
{274CEDC2-2129-469D-B269-649EFA2EF5E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -284,6 +290,7 @@ Global
284290
{720811C8-29C7-4368-86F2-D61DF415AC2A} = {AF6AF4C7-8AA2-4D59-8064-2D79560904EB}
285291
{3818FA5C-8649-427D-8E68-0C44558CA0DD} = {83263231-1A2A-4733-B759-EEFF14E8C5D5}
286292
{21599C29-C3D4-4DAC-A2D6-6C194600478F} = {77454495-55EE-4B40-A089-71B9E8F82E89}
293+
{73FDCE53-75D1-4DCC-933A-8AB93A0E86EA} = {77454495-55EE-4B40-A089-71B9E8F82E89}
287294
{274CEDC2-2129-469D-B269-649EFA2EF5E0} = {77454495-55EE-4B40-A089-71B9E8F82E89}
288295
EndGlobalSection
289296
GlobalSection(ExtensibilityGlobals) = postSolution

build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ dotnet test -c Release -l $testLogger `
88
/p:Exclude='"""[Sentry.Protocol.Test*]*,[xunit.*]*,[Sentry.Test*]*\"""'
99
if ($LASTEXITCODE -ne 0) { exit 1 }
1010

11-
dotnet pack -c Release --no-build /p:ContinuousIntegrationBuild=true
11+
dotnet pack -c Release /p:ContinuousIntegrationBuild=true
1212
if ($LASTEXITCODE -ne 0) { exit 1 }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Router AppAssembly="@typeof(Program).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
6+
<LayoutView Layout="@typeof(MainLayout)">
7+
<p>Sorry, there's nothing at this address.</p>
8+
</LayoutView>
9+
</NotFound>
10+
</Router>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@page "/"
2+
3+
<h1>Sentry on Blazor WebAssembly</h1>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page "/thrower"
2+
@using Microsoft.Extensions.Logging
3+
@inject ILogger<Thrower> Logger
4+
5+
<h1>Throw Exception</h1>
6+
7+
<button class="btn btn-primary" @onclick="Throw">Throw</button>
8+
9+
@if (SentrySdk.LastEventId != SentryId.Empty)
10+
{
11+
<p>Event Id: @SentrySdk.LastEventId</p>
12+
}
13+
14+
@code {
15+
private void Throw()
16+
{
17+
Logger.LogInformation("Doing something ... ");
18+
Stuff.DoSomething();
19+
}
20+
21+
private static class Stuff
22+
{
23+
public static void DoSomething() => Thrower();
24+
private static void Thrower() => throw null;
25+
}
26+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Net.Http;
3+
using System.Threading.Tasks;
4+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.Extensions.Logging;
7+
8+
namespace Sentry.Samples.AspNetCore.Blazor.Wasm
9+
{
10+
public static class Program
11+
{
12+
#pragma warning disable IDE1006 // Naming Styles
13+
public static async Task Main(string[] args)
14+
{
15+
// Capture blazor bootstrapping errors
16+
using var sdk = SentrySdk.Init(o =>
17+
{
18+
o.Dsn = "https://[email protected]/5428537";
19+
o.Debug = true;
20+
});
21+
try
22+
{
23+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
24+
builder.RootComponents.Add<App>("#app");
25+
builder.Logging.SetMinimumLevel(LogLevel.Debug);
26+
// Captures logError and higher as events
27+
builder.Logging.AddSentry(o => o.InitializeSdk = false);
28+
29+
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
30+
31+
await builder.Build().RunAsync();
32+
}
33+
catch (Exception e)
34+
{
35+
SentrySdk.CaptureException(e);
36+
await SentrySdk.FlushAsync(TimeSpan.FromSeconds(2));
37+
throw;
38+
}
39+
}
40+
}
41+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:65188",
7+
"sslPort": 44354
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
15+
"environmentVariables": {
16+
"ASPNETCORE_ENVIRONMENT": "Development"
17+
}
18+
},
19+
"Sentry.Samples.AspNetCore.Blazor.Wasm": {
20+
"commandName": "Project",
21+
"dotnetRunMessages": "true",
22+
"launchBrowser": true,
23+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
24+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
25+
"environmentVariables": {
26+
"ASPNETCORE_ENVIRONMENT": "Development"
27+
}
28+
}
29+
}
30+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0" />
9+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.0" PrivateAssets="all" />
10+
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\..\src\Sentry\Sentry.csproj" />
15+
<ProjectReference Include="..\..\src\Sentry.Extensions.Logging\Sentry.Extensions.Logging.csproj" />
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@inherits LayoutComponentBase
2+
3+
<div>
4+
<div>
5+
@Body
6+
</div>
7+
8+
<div>
9+
<NavMenu />
10+
</div>
11+
</div>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@using Microsoft.Extensions.Logging
2+
@inject ILogger<NavMenu> Logger
3+
4+
<div @onclick="ToggleNavMenu">
5+
<ul>
6+
<li>
7+
<NavLink href="thrower">
8+
Throw, Catch and Capture
9+
</NavLink>
10+
</li>
11+
</ul>
12+
</div>
13+
14+
@code {
15+
private bool _collapseNavMenu = true;
16+
17+
private string NavMenuCssClass => _collapseNavMenu ? "collapse" : null;
18+
19+
private void ToggleNavMenu()
20+
{
21+
Logger.LogInformation("ToggleNavMenu {_collapseNavMenu}", _collapseNavMenu);
22+
_collapseNavMenu = !_collapseNavMenu;
23+
}
24+
25+
}

0 commit comments

Comments
 (0)