From 5c54bbe2999f4b46a9a72433090deb2c38205e0a Mon Sep 17 00:00:00 2001 From: Bruno Garcia Date: Tue, 1 Jun 2021 22:59:47 -0400 Subject: [PATCH 1/3] experimental wpf integration --- Sentry.sln | 7 ++ samples/Sentry.Samples.Wpf/App.xaml | 9 +++ samples/Sentry.Samples.Wpf/App.xaml.cs | 81 +++++++++++++++++++ samples/Sentry.Samples.Wpf/AssemblyInfo.cs | 10 +++ samples/Sentry.Samples.Wpf/MainWindow.xaml | 12 +++ samples/Sentry.Samples.Wpf/MainWindow.xaml.cs | 32 ++++++++ .../Sentry.Samples.Wpf.csproj | 13 +++ 7 files changed, 164 insertions(+) create mode 100644 samples/Sentry.Samples.Wpf/App.xaml create mode 100644 samples/Sentry.Samples.Wpf/App.xaml.cs create mode 100644 samples/Sentry.Samples.Wpf/AssemblyInfo.cs create mode 100644 samples/Sentry.Samples.Wpf/MainWindow.xaml create mode 100644 samples/Sentry.Samples.Wpf/MainWindow.xaml.cs create mode 100644 samples/Sentry.Samples.Wpf/Sentry.Samples.Wpf.csproj diff --git a/Sentry.sln b/Sentry.sln index d7aa0ae5bd..b09c7b45a2 100644 --- a/Sentry.sln +++ b/Sentry.sln @@ -125,6 +125,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.EntityFramework.Test EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Samples.EntityFramework", "samples\Sentry.Samples.EntityFramework\Sentry.Samples.EntityFramework.csproj", "{8E4BA4C7-413C-4668-8F41-32F484FFB7AA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Samples.Wpf", "samples\Sentry.Samples.Wpf\Sentry.Samples.Wpf.csproj", "{0A73AAD2-F705-4A64-8214-C49739E0FF07}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -271,6 +273,10 @@ Global {8E4BA4C7-413C-4668-8F41-32F484FFB7AA}.Debug|Any CPU.Build.0 = Debug|Any CPU {8E4BA4C7-413C-4668-8F41-32F484FFB7AA}.Release|Any CPU.ActiveCfg = Release|Any CPU {8E4BA4C7-413C-4668-8F41-32F484FFB7AA}.Release|Any CPU.Build.0 = Release|Any CPU + {0A73AAD2-F705-4A64-8214-C49739E0FF07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0A73AAD2-F705-4A64-8214-C49739E0FF07}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0A73AAD2-F705-4A64-8214-C49739E0FF07}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0A73AAD2-F705-4A64-8214-C49739E0FF07}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -314,6 +320,7 @@ Global {8B38F62E-0DD5-486F-96F5-2025AFB9B491} = {AF6AF4C7-8AA2-4D59-8064-2D79560904EB} {840B220E-68EC-4ECB-AEA1-67B0151F17FC} = {83263231-1A2A-4733-B759-EEFF14E8C5D5} {8E4BA4C7-413C-4668-8F41-32F484FFB7AA} = {77454495-55EE-4B40-A089-71B9E8F82E89} + {0A73AAD2-F705-4A64-8214-C49739E0FF07} = {77454495-55EE-4B40-A089-71B9E8F82E89} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {0C652B1A-DF72-4EE5-A98B-194FE2C054F6} diff --git a/samples/Sentry.Samples.Wpf/App.xaml b/samples/Sentry.Samples.Wpf/App.xaml new file mode 100644 index 0000000000..9577f99adf --- /dev/null +++ b/samples/Sentry.Samples.Wpf/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/samples/Sentry.Samples.Wpf/App.xaml.cs b/samples/Sentry.Samples.Wpf/App.xaml.cs new file mode 100644 index 0000000000..97491ca113 --- /dev/null +++ b/samples/Sentry.Samples.Wpf/App.xaml.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Windows; +using System.Windows.Navigation; +using Sentry.Protocol; + +namespace Sentry.Samples.Wpf +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + public App() + { + // TODO: Should be part of Sentry.Wpf and hook automatically + DispatcherUnhandledException += (sender, e) => + { + if (e.Exception is Exception ex) + { + ex.Data[Mechanism.HandledKey] = e.Handled; + ex.Data[Mechanism.MechanismKey] = "App.DispatcherUnhandledException"; + _ = SentrySdk.CaptureException(ex); + } + + if (!e.Handled) + { + // Unhandled will crash the app so flush the queue: + SentrySdk.FlushAsync(TimeSpan.FromSeconds(2)).GetAwaiter().GetResult(); + } + }; + + SentrySdk.Init(o => + { + o.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; + // TODO: Should print to VS debug window (similar to Sentry for ASP.NET) + o.Debug = true; + // TODO: Doesn't support multiple instances of the process on the same directory yet + o.CacheDirectoryPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); + // For testing, set to 100% transactions for performance monitoring. + o.TracesSampleRate = 1.0; + }); + } + + protected override void OnStartup(StartupEventArgs e) + { + SentrySdk.AddBreadcrumb("OnStartup", "app.lifecycle"); + SentrySdk.ConfigureScope(s => s.Transaction = SentrySdk.StartTransaction("Startup", "app.start")); + base.OnStartup(e); + } + + protected override void OnNavigating(NavigatingCancelEventArgs e) + { + SentrySdk.AddBreadcrumb("NavigatingCancelEventArgs", + "navigation", + data: new Dictionary + { + {"url", e.Uri.ToString()} + }); + base.OnNavigating(e); + } + + protected override void OnFragmentNavigation(FragmentNavigationEventArgs e) + { + SentrySdk.AddBreadcrumb("OnFragmentNavigation", + "navigation", + data: new Dictionary + { + {"fragment", e.Fragment}, + {"handled", e.Handled.ToString()} + }); + base.OnFragmentNavigation(e); + } + + protected override void OnExit(ExitEventArgs e) + { + base.OnExit(e); + SentrySdk.Close(); + } + } +} diff --git a/samples/Sentry.Samples.Wpf/AssemblyInfo.cs b/samples/Sentry.Samples.Wpf/AssemblyInfo.cs new file mode 100644 index 0000000000..b9d746b184 --- /dev/null +++ b/samples/Sentry.Samples.Wpf/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/samples/Sentry.Samples.Wpf/MainWindow.xaml b/samples/Sentry.Samples.Wpf/MainWindow.xaml new file mode 100644 index 0000000000..85722fdaa6 --- /dev/null +++ b/samples/Sentry.Samples.Wpf/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/samples/Sentry.Samples.Wpf/MainWindow.xaml.cs b/samples/Sentry.Samples.Wpf/MainWindow.xaml.cs new file mode 100644 index 0000000000..01ebd46f7a --- /dev/null +++ b/samples/Sentry.Samples.Wpf/MainWindow.xaml.cs @@ -0,0 +1,32 @@ +using System; +using System.Windows; + +namespace Sentry.Samples.Wpf +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() => InitializeComponent(); + + private ISpan _initSpan; + + public override void BeginInit() + { + _initSpan = SentrySdk.GetSpan()?.StartChild("BeginInit"); + base.BeginInit(); + } + + public override void EndInit() + { + base.EndInit(); + _initSpan?.Finish(); + // Is this the API to close the current transaction bound to the scope? Maybe we need to revisit this.. + SentrySdk.ConfigureScope(s => s.Transaction?.Finish()); + } + + private void ButtonBase_OnClick(object sender, RoutedEventArgs e) + => throw new InvalidOperationException("This button shall not be pressed!"); + } +} diff --git a/samples/Sentry.Samples.Wpf/Sentry.Samples.Wpf.csproj b/samples/Sentry.Samples.Wpf/Sentry.Samples.Wpf.csproj new file mode 100644 index 0000000000..93f0a3e71b --- /dev/null +++ b/samples/Sentry.Samples.Wpf/Sentry.Samples.Wpf.csproj @@ -0,0 +1,13 @@ + + + + WinExe + netcoreapp3.1-windows + true + + + + + + + From 0765af120f7dce44fea54aec81ede70d8262ca0d Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 6 Jan 2022 10:15:32 +1100 Subject: [PATCH 2/3] . --- Sentry.sln | 7 +++++++ samples/Sentry.Samples.Wpf/Sentry.Samples.Wpf.csproj | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Sentry.sln b/Sentry.sln index 2aaf62ed6d..4a71ff6a1d 100644 --- a/Sentry.sln +++ b/Sentry.sln @@ -138,6 +138,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.DiagnosticSource", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.DiagnosticSource.Tests", "test\Sentry.DiagnosticSource.Tests\Sentry.DiagnosticSource.Tests.csproj", "{D870B028-16ED-4551-8B0F-5529479D04C9}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.Samples.Wpf", "samples\Sentry.Samples.Wpf\Sentry.Samples.Wpf.csproj", "{84CEA08F-7D13-4C3F-853F-4B5F324586CF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -312,6 +314,10 @@ Global {D870B028-16ED-4551-8B0F-5529479D04C9}.Debug|Any CPU.Build.0 = Debug|Any CPU {D870B028-16ED-4551-8B0F-5529479D04C9}.Release|Any CPU.ActiveCfg = Release|Any CPU {D870B028-16ED-4551-8B0F-5529479D04C9}.Release|Any CPU.Build.0 = Release|Any CPU + {84CEA08F-7D13-4C3F-853F-4B5F324586CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {84CEA08F-7D13-4C3F-853F-4B5F324586CF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {84CEA08F-7D13-4C3F-853F-4B5F324586CF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {84CEA08F-7D13-4C3F-853F-4B5F324586CF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -362,6 +368,7 @@ Global {BB54EF08-2FA1-498B-827B-32D905FB0F9F} = {83263231-1A2A-4733-B759-EEFF14E8C5D5} {0BE821AB-88D4-4EB5-B012-C964FF58087A} = {AF6AF4C7-8AA2-4D59-8064-2D79560904EB} {D870B028-16ED-4551-8B0F-5529479D04C9} = {83263231-1A2A-4733-B759-EEFF14E8C5D5} + {84CEA08F-7D13-4C3F-853F-4B5F324586CF} = {77454495-55EE-4B40-A089-71B9E8F82E89} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {0C652B1A-DF72-4EE5-A98B-194FE2C054F6} diff --git a/samples/Sentry.Samples.Wpf/Sentry.Samples.Wpf.csproj b/samples/Sentry.Samples.Wpf/Sentry.Samples.Wpf.csproj index 93f0a3e71b..a6e5d7da84 100644 --- a/samples/Sentry.Samples.Wpf/Sentry.Samples.Wpf.csproj +++ b/samples/Sentry.Samples.Wpf/Sentry.Samples.Wpf.csproj @@ -2,7 +2,7 @@ WinExe - netcoreapp3.1-windows + net6.0-windows true From b481bec95627c3e25515307de93f38ff99eef32b Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Wed, 5 Jan 2022 23:16:32 +0000 Subject: [PATCH 3/3] Format code --- samples/Sentry.Samples.Wpf/App.xaml.cs | 2 +- samples/Sentry.Samples.Wpf/AssemblyInfo.cs | 8 ++++---- samples/Sentry.Samples.Wpf/MainWindow.xaml.cs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/Sentry.Samples.Wpf/App.xaml.cs b/samples/Sentry.Samples.Wpf/App.xaml.cs index 97491ca113..73a0acf78a 100644 --- a/samples/Sentry.Samples.Wpf/App.xaml.cs +++ b/samples/Sentry.Samples.Wpf/App.xaml.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Windows; using System.Windows.Navigation; diff --git a/samples/Sentry.Samples.Wpf/AssemblyInfo.cs b/samples/Sentry.Samples.Wpf/AssemblyInfo.cs index b9d746b184..8b5504ecfb 100644 --- a/samples/Sentry.Samples.Wpf/AssemblyInfo.cs +++ b/samples/Sentry.Samples.Wpf/AssemblyInfo.cs @@ -2,9 +2,9 @@ [assembly: ThemeInfo( ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located - //(used if a resource is not found in the page, - // or application resource dictionaries) + //(used if a resource is not found in the page, + // or application resource dictionaries) ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located - //(used if a resource is not found in the page, - // app, or any theme specific resource dictionaries) + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) )] diff --git a/samples/Sentry.Samples.Wpf/MainWindow.xaml.cs b/samples/Sentry.Samples.Wpf/MainWindow.xaml.cs index 01ebd46f7a..b7c2f9902b 100644 --- a/samples/Sentry.Samples.Wpf/MainWindow.xaml.cs +++ b/samples/Sentry.Samples.Wpf/MainWindow.xaml.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Windows; namespace Sentry.Samples.Wpf