From 414678ef0335e5d1b531fcf98ca1abd3f44bce36 Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Tue, 22 Oct 2024 09:22:12 +0200 Subject: [PATCH 1/5] WIP --- src/Raygun.Blazor/Models/BreadcrumbDetails.cs | 12 ++++++- src/Raygun.Blazor/Models/BreadcrumbLevel.cs | 33 +++++++++++++++++++ src/Raygun.Blazor/RaygunBlazorClient.cs | 6 ++-- src/Raygun.Blazor/RaygunBrowserInterop.cs | 9 ++--- .../appsettings.json | 3 +- 5 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 src/Raygun.Blazor/Models/BreadcrumbLevel.cs diff --git a/src/Raygun.Blazor/Models/BreadcrumbDetails.cs b/src/Raygun.Blazor/Models/BreadcrumbDetails.cs index 9a32de9..9c844bf 100644 --- a/src/Raygun.Blazor/Models/BreadcrumbDetails.cs +++ b/src/Raygun.Blazor/Models/BreadcrumbDetails.cs @@ -73,6 +73,14 @@ public record BreadcrumbDetails /// [JsonInclude] public BreadcrumbType Type { get; set; } + + /// + /// The level of the breadcrumb. + /// + /// + /// Defaults to . + /// + public BreadcrumbLevel Level { get; set; } = BreadcrumbLevel.Info; #endregion @@ -98,7 +106,8 @@ private BreadcrumbDetails() /// A custom value used to arbitrarily group this Breadcrumb. /// Any custom data you want to record about application state when the breadcrumb was recorded. /// Specifies the platform that the breadcrumb was recorded on. Possible values are "DotNet", and "JavaScript. - public BreadcrumbDetails(string? message, BreadcrumbType type = BreadcrumbType.Manual, string? category = null, Dictionary? customData = null, string? platform = "DotNet") + /// Set the severity level of this breadcrumb. Defaults to . + public BreadcrumbDetails(string? message, BreadcrumbType type = BreadcrumbType.Manual, string? category = null, Dictionary? customData = null, string? platform = "DotNet", BreadcrumbLevel level = BreadcrumbLevel.Info) { Message = message; Type = type; @@ -114,6 +123,7 @@ public BreadcrumbDetails(string? message, BreadcrumbType type = BreadcrumbType.M ClassName = names.ClassName; MethodName = names.MethodName; LineNumber = stackFrame.GetFileLineNumber(); + Level = level; } #endregion diff --git a/src/Raygun.Blazor/Models/BreadcrumbLevel.cs b/src/Raygun.Blazor/Models/BreadcrumbLevel.cs new file mode 100644 index 0000000..51e6e80 --- /dev/null +++ b/src/Raygun.Blazor/Models/BreadcrumbLevel.cs @@ -0,0 +1,33 @@ +using System.Text.Json.Serialization; +using Raygun.Blazor.Converters; + +namespace Raygun.Blazor.Models +{ + + /// + /// Specifies the different types of that are currently supported by the Raygun API. + /// + [JsonConverter(typeof(KebabCaseJsonStringEnumConverter))] + public enum BreadcrumbLevel + { + /// + /// Debug level breadcrumb. + /// + Debug, + + /// + /// Info level breadcrumb. + /// + Info, + + /// + /// Warning level breadcrumb. + /// + Warning, + + /// + /// Error level breadcrumb. + /// + Error + } +} \ No newline at end of file diff --git a/src/Raygun.Blazor/RaygunBlazorClient.cs b/src/Raygun.Blazor/RaygunBlazorClient.cs index 5cd36e8..de420b0 100644 --- a/src/Raygun.Blazor/RaygunBlazorClient.cs +++ b/src/Raygun.Blazor/RaygunBlazorClient.cs @@ -166,6 +166,7 @@ public async Task InitializeAsync() /// The for the message. Defaults to . /// A custom value used to arbitrarily group this Breadcrumb. /// Any custom data you want to record about application state when the Breadcrumb was recorded. + /// Set the severity level of this breadcrumb. Defaults to . /// /// Breadcrumbs will be queued internally by the and sent with the next Exception report. /// @@ -173,9 +174,10 @@ public async Task InitializeAsync() /// TBD /// public void RecordBreadcrumb(string? message, BreadcrumbType breadcrumbType = BreadcrumbType.Manual, - string? category = null, Dictionary? customData = null, string? platform = "DotNet") + string? category = null, Dictionary? customData = null, string? platform = "DotNet", + BreadcrumbLevel level = BreadcrumbLevel.Info) { - _breadcrumbs.Add(new BreadcrumbDetails(message, breadcrumbType, category, customData, platform)); + _breadcrumbs.Add(new BreadcrumbDetails(message, breadcrumbType, category, customData, platform, level)); _raygunLogger?.Verbose("[RaygunBlazorClient] Breadcrumb recorded: " + message); } diff --git a/src/Raygun.Blazor/RaygunBrowserInterop.cs b/src/Raygun.Blazor/RaygunBrowserInterop.cs index 879f5db..a631777 100644 --- a/src/Raygun.Blazor/RaygunBrowserInterop.cs +++ b/src/Raygun.Blazor/RaygunBrowserInterop.cs @@ -27,7 +27,7 @@ public class RaygunBrowserInterop : IAsyncDisposable private readonly RaygunSettings _raygunSettings; private readonly IRaygunLogger? _raygunLogger; private readonly IWindowService _windowService; - private Action?, string?>? _breadcrumbAction; + private Action?, string?, BreadcrumbLevel>? _breadcrumbAction; private Func?, Dictionary?, CancellationToken, Task>? _exceptionAction; #endregion @@ -101,13 +101,14 @@ public RaygunBrowserInterop(IJSRuntime jsRuntime, IWindowService windowService, /// /// /// + /// /// [JSInvokable] public ValueTask RecordJsBreadcrumb(string message, BreadcrumbType breadcrumbType = BreadcrumbType.Manual, - string? category = null, Dictionary? customData = null) + string? category = null, Dictionary? customData = null, BreadcrumbLevel level = BreadcrumbLevel.Info) { _raygunLogger?.Verbose("[RaygunBrowserInterop] Recording breadcrumb: " + message); - _breadcrumbAction!.Invoke(message, breadcrumbType, category, customData, "JavaScript"); + _breadcrumbAction!.Invoke(message, breadcrumbType, category, customData, "JavaScript", level); return ValueTask.CompletedTask; } @@ -154,7 +155,7 @@ internal async Task GetBrowserEnvironment() /// /// internal async Task InitializeAsync(Func onUnhandledJsException, - Action?, string?>? breadcrumbAction, + Action?, string?, BreadcrumbLevel>? breadcrumbAction, Func?, Dictionary?, CancellationToken, Task>? exceptionAction) { _breadcrumbAction = breadcrumbAction; diff --git a/src/Raygun.Samples.Blazor.Server/appsettings.json b/src/Raygun.Samples.Blazor.Server/appsettings.json index 48cf4ec..bf5d62b 100644 --- a/src/Raygun.Samples.Blazor.Server/appsettings.json +++ b/src/Raygun.Samples.Blazor.Server/appsettings.json @@ -7,6 +7,7 @@ }, "AllowedHosts": "*", "Raygun": { - "LogLevel": "Verbose" + "LogLevel": "Verbose", + "ApiKey": "ZUxcKZEcZM6QbPttf0A3fw" } } From af63f26b314e9e083613583a8f7b1174e3f94957 Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Tue, 22 Oct 2024 09:25:10 +0200 Subject: [PATCH 2/5] test passing --- src/Raygun.Tests.Blazor/RaygunBlazorClientTests.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Raygun.Tests.Blazor/RaygunBlazorClientTests.cs b/src/Raygun.Tests.Blazor/RaygunBlazorClientTests.cs index a683f88..c6b3a1b 100644 --- a/src/Raygun.Tests.Blazor/RaygunBlazorClientTests.cs +++ b/src/Raygun.Tests.Blazor/RaygunBlazorClientTests.cs @@ -188,7 +188,8 @@ public async Task RaygunBlazorClient_BasicException_WithBreadcrumbs_ShouldSend() var raygunClient = TestHost.Services.GetService(); raygunClient.Should().NotBeNull(); - raygunClient.RecordBreadcrumb("About to send the test exception", BreadcrumbType.Manual, "Unit Tests"); + raygunClient.RecordBreadcrumb("About to send the test exception", BreadcrumbType.Manual, + "Unit Tests", new Dictionary(), "DotNet", BreadcrumbLevel.Error); Func recordException = async () => await raygunClient.RecordExceptionAsync(new Exception("Test")); await recordException.Should().NotThrowAsync(); @@ -206,6 +207,7 @@ public async Task RaygunBlazorClient_BasicException_WithBreadcrumbs_ShouldSend() raygunMsg.Details.Breadcrumbs[0].Message.Should().Be("About to send the test exception"); raygunMsg.Details.Breadcrumbs[0].Type.Should().Be(BreadcrumbType.Manual); raygunMsg.Details.Breadcrumbs[0].Category.Should().Be("Unit Tests"); + raygunMsg.Details.Breadcrumbs[0].Level.Should().Be(BreadcrumbLevel.Error); } /// From c77012b05a52c93ef8151dfe1a9e2dbe4b8e2f24 Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Tue, 22 Oct 2024 09:50:23 +0200 Subject: [PATCH 3/5] add level to webassembly example --- src/Raygun.Blazor/RaygunBlazorClient.cs | 10 ++++++++++ src/Raygun.Blazor/RaygunBrowserInterop.cs | 7 ++++--- src/Raygun.Blazor/wwwroot/Raygun.Blazor.js | 4 ++-- src/Raygun.Blazor/wwwroot/Raygun.Blazor.ts | 4 ++-- .../Pages/Counter.razor | 10 +++++++++- .../ViewModels/CounterViewModel.cs | 6 ++++++ .../wwwroot/index.html | 15 +++++++++++++++ 7 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/Raygun.Blazor/RaygunBlazorClient.cs b/src/Raygun.Blazor/RaygunBlazorClient.cs index de420b0..74d5137 100644 --- a/src/Raygun.Blazor/RaygunBlazorClient.cs +++ b/src/Raygun.Blazor/RaygunBlazorClient.cs @@ -180,6 +180,16 @@ public void RecordBreadcrumb(string? message, BreadcrumbType breadcrumbType = Br _breadcrumbs.Add(new BreadcrumbDetails(message, breadcrumbType, category, customData, platform, level)); _raygunLogger?.Verbose("[RaygunBlazorClient] Breadcrumb recorded: " + message); } + + /// + /// Records a Breadcrumb to help you track what was going on in your application before an error occurred. + /// + /// Breadcrumb details object + public void RecordBreadcrumb(BreadcrumbDetails breadcrumb) + { + _breadcrumbs.Add(breadcrumb); + _raygunLogger?.Verbose("[RaygunBlazorClient] Breadcrumb recorded: " + breadcrumb.Message); + } /// diff --git a/src/Raygun.Blazor/RaygunBrowserInterop.cs b/src/Raygun.Blazor/RaygunBrowserInterop.cs index a631777..45de28a 100644 --- a/src/Raygun.Blazor/RaygunBrowserInterop.cs +++ b/src/Raygun.Blazor/RaygunBrowserInterop.cs @@ -95,17 +95,18 @@ public RaygunBrowserInterop(IJSRuntime jsRuntime, IWindowService windowService, #region Public Methods /// - /// + /// Method invoked by JavaScript to record a breadcrumb. + /// See Raygun.Blazor.ts for more information. /// /// /// /// - /// /// + /// /// [JSInvokable] public ValueTask RecordJsBreadcrumb(string message, BreadcrumbType breadcrumbType = BreadcrumbType.Manual, - string? category = null, Dictionary? customData = null, BreadcrumbLevel level = BreadcrumbLevel.Info) + string? category = null, BreadcrumbLevel level = Models.BreadcrumbLevel.Info, Dictionary? customData = null) { _raygunLogger?.Verbose("[RaygunBrowserInterop] Recording breadcrumb: " + message); _breadcrumbAction!.Invoke(message, breadcrumbType, category, customData, "JavaScript", level); diff --git a/src/Raygun.Blazor/wwwroot/Raygun.Blazor.js b/src/Raygun.Blazor/wwwroot/Raygun.Blazor.js index 7b4d029..039676a 100644 --- a/src/Raygun.Blazor/wwwroot/Raygun.Blazor.js +++ b/src/Raygun.Blazor/wwwroot/Raygun.Blazor.js @@ -18,9 +18,9 @@ window.raygunBlazor = { /** * */ - recordBreadcrumb: function (message, category, level, customData) { + recordBreadcrumb: function (message, type, category, level, customData) { return __awaiter(this, void 0, void 0, function* () { - yield this._raygunInterop.invokeMethodAsync('RecordJsBreadcrumb', message, category, level, customData); + yield this._raygunInterop.invokeMethodAsync('RecordJsBreadcrumb', message, type, category, level, customData); }); }, /** diff --git a/src/Raygun.Blazor/wwwroot/Raygun.Blazor.ts b/src/Raygun.Blazor/wwwroot/Raygun.Blazor.ts index d3a1561..3ae529e 100644 --- a/src/Raygun.Blazor/wwwroot/Raygun.Blazor.ts +++ b/src/Raygun.Blazor/wwwroot/Raygun.Blazor.ts @@ -11,8 +11,8 @@ /** * */ - recordBreadcrumb: async function(message: string, category: string, level: string, customData: Record) { - await this._raygunInterop.invokeMethodAsync('RecordJsBreadcrumb', message, category, level, customData); + recordBreadcrumb: async function(message: string, type: string, category: string, level: string, customData: Record) { + await this._raygunInterop.invokeMethodAsync('RecordJsBreadcrumb', message, type, category, level, customData); }, /** diff --git a/src/Raygun.Samples.Blazor.WebAssembly/Pages/Counter.razor b/src/Raygun.Samples.Blazor.WebAssembly/Pages/Counter.razor index e3715bd..47315ba 100644 --- a/src/Raygun.Samples.Blazor.WebAssembly/Pages/Counter.razor +++ b/src/Raygun.Samples.Blazor.WebAssembly/Pages/Counter.razor @@ -14,8 +14,9 @@ - + + @code { @@ -63,4 +64,11 @@ await ViewModel.SendCustomJsException(); } + protected async Task SendCustomJsBreadcrumb() + { + RaygunClient.RecordBreadcrumb(new BreadcrumbDetails(message: "Send Custom JS Breadcrumb", + type: BreadcrumbType.ClickEvent, level: BreadcrumbLevel.Debug)); + await ViewModel.SendCustomJsBreadcrumb(); + } + } \ No newline at end of file diff --git a/src/Raygun.Samples.Blazor.WebAssembly/ViewModels/CounterViewModel.cs b/src/Raygun.Samples.Blazor.WebAssembly/ViewModels/CounterViewModel.cs index 0f2abb1..dc2e8d6 100644 --- a/src/Raygun.Samples.Blazor.WebAssembly/ViewModels/CounterViewModel.cs +++ b/src/Raygun.Samples.Blazor.WebAssembly/ViewModels/CounterViewModel.cs @@ -62,5 +62,11 @@ public async Task SendCustomJsException() var window = await _windowService.GetWindowAsync(); await window.PostMessageAsync("recordException"); } + + public async Task SendCustomJsBreadcrumb() + { + var window = await _windowService.GetWindowAsync(); + await window.PostMessageAsync("recordBreadcrumb"); + } } } diff --git a/src/Raygun.Samples.Blazor.WebAssembly/wwwroot/index.html b/src/Raygun.Samples.Blazor.WebAssembly/wwwroot/index.html index 7c9aae6..398ca58 100644 --- a/src/Raygun.Samples.Blazor.WebAssembly/wwwroot/index.html +++ b/src/Raygun.Samples.Blazor.WebAssembly/wwwroot/index.html @@ -20,6 +20,21 @@ if (e.data == "causeError") { causeErrors(); } + + if (e.data === "recordBreadcrumb") { + window.raygunBlazor.recordBreadcrumb( + // message + 'Custom JS Breadcrumb Message', + // type + 'console', + // category + 'manual', + // level + 'debug', + // custom data + {custom: 'data'} + ); + } if (e.data == "recordException") { let error = new Error(); From f4bed1f81f0b9812ac60b60c21fdad6fa4404631 Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Tue, 22 Oct 2024 09:50:57 +0200 Subject: [PATCH 4/5] code format --- src/Raygun.Blazor/Models/BreadcrumbDetails.cs | 2 +- src/Raygun.Blazor/Models/BreadcrumbLevel.cs | 6 +++--- src/Raygun.Blazor/RaygunBlazorClient.cs | 4 ++-- .../ViewModels/CounterViewModel.cs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Raygun.Blazor/Models/BreadcrumbDetails.cs b/src/Raygun.Blazor/Models/BreadcrumbDetails.cs index 9c844bf..1f78036 100644 --- a/src/Raygun.Blazor/Models/BreadcrumbDetails.cs +++ b/src/Raygun.Blazor/Models/BreadcrumbDetails.cs @@ -73,7 +73,7 @@ public record BreadcrumbDetails /// [JsonInclude] public BreadcrumbType Type { get; set; } - + /// /// The level of the breadcrumb. /// diff --git a/src/Raygun.Blazor/Models/BreadcrumbLevel.cs b/src/Raygun.Blazor/Models/BreadcrumbLevel.cs index 51e6e80..cc9489d 100644 --- a/src/Raygun.Blazor/Models/BreadcrumbLevel.cs +++ b/src/Raygun.Blazor/Models/BreadcrumbLevel.cs @@ -14,17 +14,17 @@ public enum BreadcrumbLevel /// Debug level breadcrumb. /// Debug, - + /// /// Info level breadcrumb. /// Info, - + /// /// Warning level breadcrumb. /// Warning, - + /// /// Error level breadcrumb. /// diff --git a/src/Raygun.Blazor/RaygunBlazorClient.cs b/src/Raygun.Blazor/RaygunBlazorClient.cs index 74d5137..6d03302 100644 --- a/src/Raygun.Blazor/RaygunBlazorClient.cs +++ b/src/Raygun.Blazor/RaygunBlazorClient.cs @@ -174,13 +174,13 @@ public async Task InitializeAsync() /// TBD /// public void RecordBreadcrumb(string? message, BreadcrumbType breadcrumbType = BreadcrumbType.Manual, - string? category = null, Dictionary? customData = null, string? platform = "DotNet", + string? category = null, Dictionary? customData = null, string? platform = "DotNet", BreadcrumbLevel level = BreadcrumbLevel.Info) { _breadcrumbs.Add(new BreadcrumbDetails(message, breadcrumbType, category, customData, platform, level)); _raygunLogger?.Verbose("[RaygunBlazorClient] Breadcrumb recorded: " + message); } - + /// /// Records a Breadcrumb to help you track what was going on in your application before an error occurred. /// diff --git a/src/Raygun.Samples.Blazor.WebAssembly/ViewModels/CounterViewModel.cs b/src/Raygun.Samples.Blazor.WebAssembly/ViewModels/CounterViewModel.cs index dc2e8d6..0cb3ead 100644 --- a/src/Raygun.Samples.Blazor.WebAssembly/ViewModels/CounterViewModel.cs +++ b/src/Raygun.Samples.Blazor.WebAssembly/ViewModels/CounterViewModel.cs @@ -62,7 +62,7 @@ public async Task SendCustomJsException() var window = await _windowService.GetWindowAsync(); await window.PostMessageAsync("recordException"); } - + public async Task SendCustomJsBreadcrumb() { var window = await _windowService.GetWindowAsync(); From 416066c874f4a4e7eb86b3df294f45e24a2d479e Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Tue, 22 Oct 2024 10:17:33 +0200 Subject: [PATCH 5/5] remove api key --- src/Raygun.Samples.Blazor.Server/appsettings.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Raygun.Samples.Blazor.Server/appsettings.json b/src/Raygun.Samples.Blazor.Server/appsettings.json index bf5d62b..48cf4ec 100644 --- a/src/Raygun.Samples.Blazor.Server/appsettings.json +++ b/src/Raygun.Samples.Blazor.Server/appsettings.json @@ -7,7 +7,6 @@ }, "AllowedHosts": "*", "Raygun": { - "LogLevel": "Verbose", - "ApiKey": "ZUxcKZEcZM6QbPttf0A3fw" + "LogLevel": "Verbose" } }