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

[Hackweek] Blazor Wasm SDK #2569

Draft
wants to merge 31 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e8aefbb
birth
bruno-garcia Aug 21, 2023
4376b55
yarn and bridge
bruno-garcia Aug 21, 2023
e9e3d5d
wasm lib
bruno-garcia Aug 21, 2023
0d70ac3
blazor component
bruno-garcia Aug 21, 2023
254a5d0
download sentry - no yarn
bruno-garcia Aug 21, 2023
d55ec36
UseSentry
bruno-garcia Aug 21, 2023
56e318c
init with logging
bruno-garcia Aug 21, 2023
0b8a37f
attempt to load js
bruno-garcia Aug 21, 2023
bad7351
net7
bruno-garcia Aug 21, 2023
cc1ff4c
load from component
bruno-garcia Aug 21, 2023
307b2bf
init via C#
bruno-garcia Aug 21, 2023
14618d9
clean
bruno-garcia Aug 21, 2023
18ae935
add js sdk via C# if not available
bruno-garcia Aug 21, 2023
b387cc5
single compo
bruno-garcia Aug 22, 2023
8d0e488
javascript scope observer
bruno-garcia Aug 22, 2023
d737660
sync some scope
bruno-garcia Aug 22, 2023
1b001b6
sample complete
bruno-garcia Aug 22, 2023
c4334b8
fail without C#
bruno-garcia Aug 22, 2023
eb9fc8f
Merge remote-tracking branch 'origin' into feat/blazor
bruno-garcia Aug 22, 2023
857497f
fix
bruno-garcia Aug 22, 2023
282f790
download sourcemaps
bruno-garcia Aug 22, 2023
7d2e5b3
navigation crumb, error component
bruno-garcia Aug 23, 2023
ca12e5d
clean
bruno-garcia Aug 23, 2023
38adc54
get wasm url with stack trace hack
bruno-garcia Aug 23, 2023
1d508f9
simplify regex
bruno-garcia Aug 23, 2023
d7cb3cc
disable wasm integrity check
bruno-garcia Aug 23, 2023
6d9cc37
test proj
bruno-garcia Aug 23, 2023
ca07eef
symbolicates
bruno-garcia Aug 24, 2023
0e1ebd6
add files to download
bruno-garcia Aug 24, 2023
8836785
compile with wasm debug info
bruno-garcia Aug 24, 2023
43bb7ea
examples in nuget
bruno-garcia Aug 25, 2023
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 Sentry.Full.sln
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.Samples.OpenTelemetr
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.Samples.OpenTelemetry.Console", "samples\Sentry.Samples.OpenTelemetry.Console\Sentry.Samples.OpenTelemetry.Console.csproj", "{A9176F5B-0CA6-4479-BE64-A3C3CEA632D4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AspNetCore.Blazor", "src\Sentry.AspNetCore.Blazor\Sentry.AspNetCore.Blazor.csproj", "{D7BF7C07-4C77-478C-92E5-D623AEBAD11F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -475,6 +477,10 @@ Global
{A9176F5B-0CA6-4479-BE64-A3C3CEA632D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A9176F5B-0CA6-4479-BE64-A3C3CEA632D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A9176F5B-0CA6-4479-BE64-A3C3CEA632D4}.Release|Any CPU.Build.0 = Release|Any CPU
{D7BF7C07-4C77-478C-92E5-D623AEBAD11F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D7BF7C07-4C77-478C-92E5-D623AEBAD11F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7BF7C07-4C77-478C-92E5-D623AEBAD11F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7BF7C07-4C77-478C-92E5-D623AEBAD11F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -551,6 +557,7 @@ Global
{C51A781A-C568-4E1A-834C-8E4EFA3C5B54} = {83263231-1A2A-4733-B759-EEFF14E8C5D5}
{2502D3A0-7628-4768-A430-0854BEB1E7A5} = {77454495-55EE-4B40-A089-71B9E8F82E89}
{A9176F5B-0CA6-4479-BE64-A3C3CEA632D4} = {77454495-55EE-4B40-A089-71B9E8F82E89}
{D7BF7C07-4C77-478C-92E5-D623AEBAD11F} = {AF6AF4C7-8AA2-4D59-8064-2D79560904EB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0C652B1A-DF72-4EE5-A98B-194FE2C054F6}
Expand Down
14 changes: 14 additions & 0 deletions Sentry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Samples.GraphQL.Serv
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Samples.GraphQL.Client.Http", "samples\Sentry.Samples.GraphQL.Client.Http\Sentry.Samples.GraphQL.Client.Http.csproj", "{B01C5D8F-62EE-4E63-AE96-745BA1D2E175}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AspNetCore.Blazor", "src\Sentry.AspNetCore.Blazor\Sentry.AspNetCore.Blazor.csproj", "{22411837-A0DB-4E3F-91A0-DA88CCFA0AC2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AspNetCore.Blazor.Tests", "test\Sentry.AspNetCore.Blazor.Tests\Sentry.AspNetCore.Blazor.Tests.csproj", "{CAE3B0FA-3D75-49E0-B1CC-55B2588C8E66}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -416,6 +420,14 @@ Global
{B01C5D8F-62EE-4E63-AE96-745BA1D2E175}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B01C5D8F-62EE-4E63-AE96-745BA1D2E175}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B01C5D8F-62EE-4E63-AE96-745BA1D2E175}.Release|Any CPU.Build.0 = Release|Any CPU
{22411837-A0DB-4E3F-91A0-DA88CCFA0AC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{22411837-A0DB-4E3F-91A0-DA88CCFA0AC2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{22411837-A0DB-4E3F-91A0-DA88CCFA0AC2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{22411837-A0DB-4E3F-91A0-DA88CCFA0AC2}.Release|Any CPU.Build.0 = Release|Any CPU
{CAE3B0FA-3D75-49E0-B1CC-55B2588C8E66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CAE3B0FA-3D75-49E0-B1CC-55B2588C8E66}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CAE3B0FA-3D75-49E0-B1CC-55B2588C8E66}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CAE3B0FA-3D75-49E0-B1CC-55B2588C8E66}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -483,6 +495,8 @@ Global
{D62E79F4-FC3C-4D75-ABFE-CDE76EF46DDE} = {77454495-55EE-4B40-A089-71B9E8F82E89}
{B3BFB7BA-1A5E-468F-8C47-F0841AA75848} = {77454495-55EE-4B40-A089-71B9E8F82E89}
{B01C5D8F-62EE-4E63-AE96-745BA1D2E175} = {77454495-55EE-4B40-A089-71B9E8F82E89}
{22411837-A0DB-4E3F-91A0-DA88CCFA0AC2} = {AF6AF4C7-8AA2-4D59-8064-2D79560904EB}
{CAE3B0FA-3D75-49E0-B1CC-55B2588C8E66} = {83263231-1A2A-4733-B759-EEFF14E8C5D5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0C652B1A-DF72-4EE5-A98B-194FE2C054F6}
Expand Down
18 changes: 18 additions & 0 deletions SentryBlazor.slnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"solution": {
"path": "Sentry.sln",
"projects": [
"samples\\Sentry.Samples.AspNetCore.Blazor.Server\\Sentry.Samples.AspNetCore.Blazor.Server.csproj",
"samples\\Sentry.Samples.AspNetCore.Blazor.Wasm\\Sentry.Samples.AspNetCore.Blazor.Wasm.csproj",
"src\\Sentry.AspNetCore.Blazor\\Sentry.AspNetCore.Blazor.csproj",
"src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj",
"src\\Sentry.Extensions.Logging\\Sentry.Extensions.Logging.csproj",
"src\\Sentry\\Sentry.csproj",
"test\\Sentry.AspNetCore.Blazor.Tests\\Sentry.AspNetCore.Blazor.Tests.csproj",
"test\\Sentry.AspNetCore.Tests\\Sentry.AspNetCore.Tests.csproj",
"test\\Sentry.Extensions.Logging.Tests\\Sentry.Extensions.Logging.Tests.csproj",
"test\\Sentry.Testing\\Sentry.Testing.csproj",
"test\\Sentry.Tests\\Sentry.Tests.csproj"
]
}
}
10 changes: 5 additions & 5 deletions samples/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
Note - The below works because SentryAttributes is already being converted to
actual attributes in src/Sentry/buildTransitive/Sentry.targets.
-->
<ItemGroup>
<SentryAttributes Include="Sentry.DsnAttribute">
<_Parameter1>https://[email protected]/5428537</_Parameter1>
</SentryAttributes>
</ItemGroup>
<!-- <ItemGroup>-->
<!-- <SentryAttributes Include="Sentry.DsnAttribute">-->
<!-- <_Parameter1>https://[email protected]/5428537</_Parameter1>-->
<!-- </SentryAttributes>-->
<!-- </ItemGroup>-->

<!-- Workaround for hang on compile issue. See https://github.com/xamarin/xamarin-macios/issues/17825#issuecomment-1478568270. -->
<PropertyGroup Condition="'$(Configuration)' == 'Release' And '$(TargetFramework)' == 'net7.0-ios' And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<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
33 changes: 23 additions & 10 deletions samples/Sentry.Samples.AspNetCore.Blazor.Wasm/App.razor
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
@using Sentry.AspNetCore.Blazor
<SentryBlazor>
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</SentryBlazor>

@code{

[JSInvokable]
public static void CrashMe()
{
throw new Exception("crash me");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@page "/nowhere"
36 changes: 25 additions & 11 deletions samples/Sentry.Samples.AspNetCore.Blazor.Wasm/Pages/Thrower.razor
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
@page "/thrower"
@using Microsoft.Extensions.Logging
@inject ILogger<Thrower> Logger
@using Sentry.AspNetCore.Blazor

<h1>Throw Exception</h1>

<button class="btn btn-primary" @onclick="Throw">Throw</button>
<div>
<button @onclock=IncrementCount>Click twice to capture error.</button>
<Sentry.ExampleErrors/>
</div>

@if (SentrySdk.LastEventId != SentryId.Empty)
{
<p>Event Id: @SentrySdk.LastEventId</p>
}

@code {
private void Throw()
{
Logger.LogInformation("Doing something ... ");
Stuff.DoSomething();
}

private static class Stuff
// https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/handle-errors?view=aspnetcore-7.0#alternative-global-exception-handling
[CascadingParameter]
public SentryBlazor SentryBlazor { get; set; }

private int _currentCount = 0;

private void IncrementCount()
{
public static void DoSomething() => Thrower();
private static void Thrower() => throw null;
try
{
_currentCount++;

if (_currentCount > 2)
{
throw new InvalidOperationException("Current count is over five!");
}
}
catch (Exception ex)
{
SentryBlazor?.ProcessError(ex);
}
}
}
38 changes: 12 additions & 26 deletions samples/Sentry.Samples.AspNetCore.Blazor.Wasm/Program.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Sentry;
using Sentry.Samples.AspNetCore.Blazor.Wasm;

// Capture blazor bootstrapping errors
using var sdk = SentrySdk.Init(o =>
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.UseSentry(o =>
{
o.Dsn = "https://[email protected]/5428537";
o.Debug = true;
//IsGlobalModeEnabled will be true for Blazor WASM
Debug.Assert(o.IsGlobalModeEnabled);
o.TracesSampleRate = 1.0;

});
try
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.Logging.SetMinimumLevel(LogLevel.Debug);
// Captures logError and higher as events
builder.Logging.AddSentry(o => o.InitializeSdk = false);
builder.RootComponents.Add<App>("#app");
builder.Logging.SetMinimumLevel(LogLevel.Debug);

builder.Services.AddScoped(_ =>
new HttpClient
{
BaseAddress = new(builder.HostEnvironment.BaseAddress)
});
await builder.Build().RunAsync();
}
catch (Exception e)
{
SentrySdk.CaptureException(e);
await SentrySdk.FlushAsync();
throw;
}
builder.Services.AddScoped(_ =>
new HttpClient
{
BaseAddress = new(builder.HostEnvironment.BaseAddress)
});
await builder.Build().RunAsync();
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<!-- https://learn.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/webassembly?view=aspnetcore-7.0#disable-integrity-checking-for-non-pwa-apps-->
<!-- Patching the wasm file to get debug_id fails the integrity check. But disabling it have it load via URL so the hack with calling a func to get a stack trace isn't needed-->
<BlazorCacheBootResources>false</BlazorCacheBootResources>

<!-- https://github.com/dotnet/runtime/blob/ba6a4adb228567a6bb3f4a9e5789fb74c47c8c94/src/mono/wasm/build/WasmApp.targets#L23-L26-->
<WasmNativeDebugSymbols>true</WasmNativeDebugSymbols>
<WasmNativeStrip>true</WasmNativeStrip>

<WasmEmitSymbolMap>true</WasmEmitSymbolMap>
<WasmEmitSourceMap>true</WasmEmitSourceMap>
<!-- https://stackoverflow.com/questions/73651974/how-do-i-make-the-wasmemitsymbolmap-and-or-wasmnativestrip-properties-take-effec-->
<!-- <RunAOTCompilation>true</RunAOTCompilation>-->
<!-- <RunAOTCompilationAfterBuild>true</RunAOTCompilationAfterBuild>-->
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.19" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.0" PrivateAssets="all" />
<ProjectReference Include="..\..\src\Sentry\Sentry.csproj" />
<ProjectReference Include="..\..\src\Sentry.Extensions.Logging\Sentry.Extensions.Logging.csproj" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.10" PrivateAssets="all" />
<ProjectReference Include="..\..\src\Sentry.AspNetCore.Blazor\Sentry.AspNetCore.Blazor.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
@using Microsoft.Extensions.Logging
@using Sentry.AspNetCore.Blazor
@inject ILogger<NavMenu> Logger

<div @onclick="ToggleNavMenu">
<ul>
<li>
<NavLink href="/">
Home!
</NavLink>
<NavLink href="thrower">
Throw, Catch and Capture
</NavLink>
<NavLink href="nowhere">
Navigate nowhere
</NavLink>
</li>
</ul>
</div>
Expand All @@ -21,5 +28,4 @@
Logger.LogInformation("ToggleNavMenu {_collapseNavMenu}", _collapseNavMenu);
_collapseNavMenu = !_collapseNavMenu;
}

}
Loading