-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Migrate to ActivitySource #30089
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
Migrate to ActivitySource #30089
Conversation
src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs
Outdated
Show resolved
Hide resolved
src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs
Outdated
Show resolved
Hide resolved
src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs
Outdated
Show resolved
Hide resolved
CC @noahfalk |
src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs
Outdated
Show resolved
Hide resolved
src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs
Outdated
Show resolved
Hide resolved
src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs
Outdated
Show resolved
Hide resolved
src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs
Outdated
Show resolved
Hide resolved
src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs
Outdated
Show resolved
Hide resolved
FYI @pakrym |
|
||
var headers = httpContext.Request.Headers; | ||
if (!headers.TryGetValue(HeaderNames.TraceParent, out var requestId)) | ||
{ | ||
headers.TryGetValue(HeaderNames.RequestId, out requestId); | ||
} | ||
|
||
if (!StringValues.IsNullOrEmpty(requestId)) | ||
var activity = _activitySource.StartActivity(ActivityName, ActivityKind.Server, requestId); |
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.
@tarekgh/@noahfalk, what's the expected format of the activity name when used with the ActivitySource?
I thought that considering the ActivitySource
name is Microsoft.AspNetCore.Hosting
the activity name should be HttpRequestIn
and not Microsoft.AspNetCore.Hosting.HttpRequestIn
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.
You are correct @pakrym, the Activity names should be only the instrumented operation name (i.e. HttpRequestIn
for this specific code). And ActivitySource name should reflect the company name, component name, and the whole instrumented area (i.e. Microsoft.AspNetCore.Hosting
).
As this code existed for a while, do you think there will be any issue changing the Activity name?
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.
I think that's another area where reusing the same activity doesn't work well. We can't change existing activity names and ActivitySource-activity should have a different one.
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.
We spoke about this earlier today, the Activity name would have to be Microsoft.AspNetCore.Hosting.HttpRequestIn
to preserve compat. Instrumentation libraries can set Activity.DisplayName if they would prefer something more concise.
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.
Should we say there is no guidance around Activity.Name
then? If none of the Microsoft libraries would support it.
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.
The guidelines for Activity.Name still hold we only relax it for the sake of the compatibility. Any new written code with no compatibility concern should apply the guidelines.
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.
But if all the consuming code (OT) would forever have to check for legacy behavior. What's the point of the guideline?
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.
I am hoping the OTel will get rid of listening to the legacy behavior. My understanding is after this change, they are listening to the legacy for the payload and not the Activity itself. This may be the next step to look at that and try help OTel to get rid of this legacy listening.
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.
I am hoping the OTel will get rid of listening to the legacy behavior
After this change, all ASP.NET Core ActivitySource activities would forever have legacy Activity.Name.
Same for Azure SDKs if we try to reuse the same activity for both.
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.
As I mentioned we relaxed the guidelines for the Activity.Name for the sake of compatibility. If anyone writing any new code with no compatibility concern, would better to follow the guidelines. For aspnet case, I suggest setting the display name too.
Waiting on dotnet/runtime#48374 for the next update |
b1faee7
to
224912b
Compare
src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs
Outdated
Show resolved
Hide resolved
Before:
After:
@Tratcher @sebastienros Is there a better benchmark? I remember y'all mentioning there is a YARP benchmark for which Activity creation in hosting was on the hot path? |
In the scenarios page, look for yarp. Beware that the sample command is for httpclient though. |
Before:
After:
|
|
Another tip. You can save the results with |
Old:
New:
|
{ | ||
var activity = new Activity(ActivityName); | ||
var activity = _activitySource.CreateActivity(ActivityName, ActivityKind.Server); |
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.
var [](start = 12, length = 3)
does it make sense to check _activitySource.HasListeners() before calling _activitySource.CreateActivity if you want save some cycles when there is no listeners?
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.
I don't think it'll make a difference. You already do the check in ActivitySource.CreateActivity- https://github.com/dotnet/runtime/blob/master/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/ActivitySource.cs#L172
allocation profile plz 😄 |
Hello @shirhatti! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
Current behavior:
New behavior:
if (activity is not null)
{
}
Questions: