-
-
Notifications
You must be signed in to change notification settings - Fork 226
Add new .NET 10 Blazor telemetry features example #4769
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
Merged
+460
−0
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
80b4bac
Add new .NET 10 Blazor telemetry features example
msuddaby 55b2d35
Add SentryCircuitHandler.cs and add a cleanup timer to prevent memory…
msuddaby 9ae1589
Remove `ConfigureScope` since the tags add this context anyways.
msuddaby 68bb4fd
Remove double call to dispose
msuddaby 9f28352
Remove unused metrics
msuddaby 98740c6
Remove unused `using` statements and fix / expand upon `BlazorEventPr…
msuddaby e8563ad
Dispose timer nicely
msuddaby e56ed60
Use Interlocked.Exchange for thread-safe disposal of timer
msuddaby a92cdb3
Dispose of everything else in StopAsync
msuddaby 7b63b2c
dotnet format
jamescrosswell 2f2788e
Merge remote-tracking branch 'upstream/main'
jamescrosswell 1cb8630
Update Sentry.Samples.AspNetCore.Blazor.Server.csproj
jamescrosswell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
samples/Sentry.Samples.AspNetCore.Blazor.Server/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
samples/Sentry.Samples.AspNetCore.Blazor.Server/Services/BlazorEventProcessor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| using Sentry.Extensibility; | ||
|
|
||
| namespace Sentry.Samples.AspNetCore.Blazor.Server.Services; | ||
|
|
||
| /// <summary> | ||
| /// This event processor adds Blazor-specific context to Sentry events | ||
| /// and improves transaction naming for Blazor SignalR requests. | ||
| /// </summary> | ||
| public class BlazorEventProcessor : ISentryEventProcessor | ||
| { | ||
| public SentryEvent Process(SentryEvent @event) | ||
| { | ||
| // Add Blazor-specific context to the event | ||
| if (@event.Tags.ContainsKey("blazor.circuit_id")) | ||
| { | ||
| @event.SetExtra("blazor", new | ||
| { | ||
| Route = @event.Tags.GetValueOrDefault("blazor.route"), | ||
| Component = @event.Tags.GetValueOrDefault("blazor.component"), | ||
| CircuitId = @event.Tags.GetValueOrDefault("blazor.circuit_id") | ||
| }); | ||
| } | ||
|
|
||
| // For transaction name, we need to set it through Contexts | ||
| var transactionName = @event.Contexts.Trace?.Operation; | ||
| if (!IsBlazorSignalRTransaction(transactionName)) | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| return @event; | ||
| } | ||
|
|
||
| var betterName = GetBetterTransactionName(@event); | ||
| @event.SetTag("transaction.original", transactionName ?? "unknown"); | ||
| @event.SetTag("transaction.name", betterName); | ||
msuddaby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return @event; | ||
| } | ||
|
|
||
| private static bool IsBlazorSignalRTransaction(string? transaction) | ||
| { | ||
| if (string.IsNullOrEmpty(transaction)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| return transaction.Contains("_blazor", StringComparison.OrdinalIgnoreCase) || | ||
| transaction.Contains("negotiate", StringComparison.OrdinalIgnoreCase); | ||
| } | ||
|
|
||
| private static string GetBetterTransactionName(SentryEvent @event) | ||
| { | ||
| if (@event.Tags.TryGetValue("blazor.route", out var route) && | ||
| !string.IsNullOrEmpty(route)) | ||
| { | ||
| return route; | ||
| } | ||
|
|
||
| if (@event.Tags.TryGetValue("blazor.component", out var component) && | ||
| !string.IsNullOrEmpty(component)) | ||
| { | ||
| var lastDot = component.LastIndexOf('.'); | ||
| var shortName = lastDot >= 0 ? component[(lastDot + 1)..] : component; | ||
| return $"Blazor/{shortName}"; | ||
| } | ||
|
|
||
| return "Blazor/Unknown"; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.