-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Blazor - rendering metrics and tracing #61609
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
Open
pavelsavara
wants to merge
21
commits into
dotnet:main
Choose a base branch
from
pavelsavara:blazor_metrics_feedback
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,183
−405
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
cebb68e
rebase
pavelsavara 6664645
Merge branch 'main' into blazor_metrics_feedback
pavelsavara 0bcd459
more
pavelsavara 2557f08
- remove FeatureSwitchDefinition for now
pavelsavara 4c75495
whitespace
pavelsavara 0f3d48a
navigation draft
pavelsavara cf15c8d
cleanup
pavelsavara 550f633
cleanup
pavelsavara 9ab8a84
more
pavelsavara 0a4d488
IsAllDataRequested
pavelsavara cf2ab99
- ComponentsActivitySourceTest
pavelsavara 44fa207
Update src/Components/Components/src/ComponentsMetrics.cs
pavelsavara 105b02f
Update src/Components/Components/src/ComponentsMetrics.cs
pavelsavara 63f8a69
Update src/Components/Components/src/ComponentsMetrics.cs
pavelsavara 860931d
feedback
pavelsavara de22914
fix tests
pavelsavara 5ca497d
update_parameters feedback
pavelsavara 2ae95e0
Update src/Components/Components/src/ComponentsActivitySource.cs
pavelsavara b9331d9
Update src/Components/Components/src/ComponentsActivitySource.cs
pavelsavara 96f1d6a
Update src/Components/Components/src/ComponentsActivitySource.cs
pavelsavara 1c61f50
feedback
pavelsavara 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
177 changes: 177 additions & 0 deletions
177
src/Components/Components/src/ComponentsActivitySource.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,177 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics; | ||
|
||
namespace Microsoft.AspNetCore.Components; | ||
|
||
/// <summary> | ||
/// This is instance scoped per renderer | ||
/// </summary> | ||
internal class ComponentsActivitySource | ||
{ | ||
internal const string Name = "Microsoft.AspNetCore.Components"; | ||
internal const string OnCircuitName = $"{Name}.CircuitStart"; | ||
internal const string OnRouteName = $"{Name}.RouteChange"; | ||
internal const string OnEventName = $"{Name}.Event"; | ||
|
||
private ActivityContext _httpContext; | ||
private ActivityContext _circuitContext; | ||
private string? _circuitId; | ||
private ActivityContext _routeContext; | ||
|
||
private ActivitySource ActivitySource { get; } = new ActivitySource(Name); | ||
|
||
public static ActivityContext CaptureHttpContext() | ||
{ | ||
var parentActivity = Activity.Current; | ||
if (parentActivity is not null && parentActivity.OperationName == "Microsoft.AspNetCore.Hosting.HttpRequestIn" && parentActivity.Recorded) | ||
{ | ||
return parentActivity.Context; | ||
} | ||
return default; | ||
} | ||
|
||
public Activity? StartCircuitActivity(string circuitId, ActivityContext httpContext) | ||
{ | ||
_circuitId = circuitId; | ||
|
||
var activity = ActivitySource.CreateActivity(OnCircuitName, ActivityKind.Server, parentId: null, null, null); | ||
if (activity is not null) | ||
{ | ||
if (activity.IsAllDataRequested) | ||
{ | ||
if (_circuitId != null) | ||
{ | ||
activity.SetTag("circuit.id", _circuitId); | ||
} | ||
if (httpContext != default) | ||
{ | ||
activity.AddLink(new ActivityLink(httpContext)); | ||
} | ||
} | ||
activity.DisplayName = $"Circuit {circuitId ?? ""}"; | ||
activity.Start(); | ||
_circuitContext = activity.Context; | ||
} | ||
return activity; | ||
} | ||
|
||
public void FailCircuitActivity(Activity? activity, Exception ex) | ||
{ | ||
_circuitContext = default; | ||
if (activity != null && !activity.IsStopped) | ||
{ | ||
activity.SetTag("error.type", ex.GetType().FullName); | ||
activity.SetStatus(ActivityStatusCode.Error); | ||
activity.Stop(); | ||
} | ||
} | ||
|
||
public Activity? StartRouteActivity(string componentType, string route) | ||
{ | ||
if (_httpContext == default) | ||
{ | ||
_httpContext = CaptureHttpContext(); | ||
} | ||
|
||
var activity = ActivitySource.CreateActivity(OnRouteName, ActivityKind.Server, parentId: null, null, null); | ||
if (activity is not null) | ||
{ | ||
if (activity.IsAllDataRequested) | ||
{ | ||
if (_circuitId != null) | ||
{ | ||
activity.SetTag("circuit.id", _circuitId); | ||
} | ||
if (componentType != null) | ||
{ | ||
activity.SetTag("component.type", componentType); | ||
} | ||
if (route != null) | ||
{ | ||
activity.SetTag("route", route); | ||
} | ||
if (_httpContext != default) | ||
{ | ||
activity.AddLink(new ActivityLink(_httpContext)); | ||
} | ||
if (_circuitContext != default) | ||
{ | ||
activity.AddLink(new ActivityLink(_circuitContext)); | ||
} | ||
} | ||
|
||
activity.DisplayName = $"Route {route ?? "[unknown path]"} -> {componentType ?? "[unknown component]"}"; | ||
activity.Start(); | ||
_routeContext = activity.Context; | ||
} | ||
return activity; | ||
} | ||
|
||
public Activity? StartEventActivity(string? componentType, string? methodName, string? attributeName) | ||
{ | ||
var activity = ActivitySource.CreateActivity(OnEventName, ActivityKind.Server, parentId: null, null, null); | ||
if (activity is not null) | ||
{ | ||
if (activity.IsAllDataRequested) | ||
{ | ||
if (_circuitId != null) | ||
{ | ||
activity.SetTag("circuit.id", _circuitId); | ||
} | ||
if (componentType != null) | ||
{ | ||
activity.SetTag("component.type", componentType); | ||
} | ||
if (methodName != null) | ||
{ | ||
activity.SetTag("component.method", methodName); | ||
} | ||
if (attributeName != null) | ||
{ | ||
activity.SetTag("attribute.name", attributeName); | ||
} | ||
if (_httpContext != default) | ||
{ | ||
activity.AddLink(new ActivityLink(_httpContext)); | ||
} | ||
if (_circuitContext != default) | ||
{ | ||
activity.AddLink(new ActivityLink(_circuitContext)); | ||
} | ||
if (_routeContext != default) | ||
{ | ||
activity.AddLink(new ActivityLink(_routeContext)); | ||
} | ||
} | ||
|
||
activity.DisplayName = $"Event {attributeName ?? "[unknown attribute]"} -> {componentType ?? "[unknown component]"}.{methodName ?? "[unknown method]"}"; | ||
activity.Start(); | ||
} | ||
return activity; | ||
} | ||
|
||
public static void FailEventActivity(Activity? activity, Exception ex) | ||
{ | ||
if (activity != null && !activity.IsStopped) | ||
{ | ||
activity.SetTag("error.type", ex.GetType().FullName); | ||
activity.SetStatus(ActivityStatusCode.Error); | ||
activity.Stop(); | ||
} | ||
} | ||
|
||
public static async Task CaptureEventStopAsync(Task task, Activity? activity) | ||
{ | ||
try | ||
{ | ||
await task; | ||
activity?.Stop(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
FailEventActivity(activity, ex); | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In talking with Dan Roth, the ActivityKind should probably be Internal when running in WASM. Its neither really client nor server in that case.