-
Notifications
You must be signed in to change notification settings - Fork 146
[Tracer] Fix resource-based sampling for ASP.NET
spans in IIS
#6936
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,22 @@ public void Dispose() | |
{ | ||
} | ||
|
||
private static string BuildResourceName(Tracer tracer, HttpRequest httpRequest) | ||
{ | ||
var url = tracer.Settings.BypassHttpRequestUrlCachingEnabled | ||
? RequestDataHelper.BuildUrl(httpRequest) | ||
: RequestDataHelper.GetUrl(httpRequest); | ||
if (url is not null) | ||
{ | ||
var path = UriHelpers.GetCleanUriPath(url, httpRequest.ApplicationPath); | ||
return $"{httpRequest.HttpMethod.ToUpperInvariant()} {path.ToLowerInvariant()}"; | ||
} | ||
else | ||
{ | ||
return $"{httpRequest.HttpMethod.ToUpperInvariant()}"; | ||
} | ||
} | ||
|
||
internal static void AddHeaderTagsFromHttpResponse(HttpContext httpContext, Scope scope) | ||
{ | ||
if (!Tracer.Instance.Settings.HeaderTags.IsNullOrEmpty() && | ||
|
@@ -174,7 +190,12 @@ private void OnBeginRequest(object sender, EventArgs eventArgs) | |
var tags = new WebTags(); | ||
scope = tracer.StartActiveInternal(_requestOperationName, extractedContext.SpanContext, tags: tags); | ||
// Leave resourceName blank for now - we'll update it in OnEndRequest | ||
scope.Span.DecorateWebServerSpan(resourceName: null, httpMethod, host, url, userAgent, tags); | ||
|
||
// Attempt to set Resource Name to something that will be close to what is expected | ||
// Note: we will go and re-do it in OnEndRequest, but doing it here will allow for resource-based sampling | ||
// this likely won't be perfect - but we need something to try and allow resource-based sampling to function | ||
var resourceName = BuildResourceName(tracer, httpRequest); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This resource name won't include MVC route templates, right? Since we get those later when we instrument the MVC middleware. If the issue keep happening because the resource name doesn't match what the user's see in the UI, we may need to make a note that users should use what's in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, exactly, this is always going to be a problem 🙁 I think the proposed solution is a reasonable trade off though. We explicitly don't do this currently, to avoid extra allocation (as we're almost always going to create the resource name and then throw it away). But this is almost certainly preferable to the alternative. Seems like another example where Doug's proposed "lazy evaluation of properties based on span facts" would be a net win, as we would only perform this calculation if we need it (e.g. if we need to make a sampling decision based on the resource name). But that's a long way off right now 😄 |
||
scope.Span.DecorateWebServerSpan(resourceName: resourceName, httpMethod, host, url, userAgent, tags); | ||
tracer.TracerManager.SpanContextPropagator.AddHeadersToSpanAsTags(scope.Span, headers, tracer.Settings.HeaderTags, defaultTagPrefix: SpanContextPropagator.HttpRequestHeadersTagPrefix); | ||
|
||
if (tracer.Settings.IpHeaderEnabled || Security.Instance.AppsecEnabled) | ||
|
@@ -386,18 +407,7 @@ private void OnEndRequest(object sender, EventArgs eventArgs) | |
} | ||
else | ||
{ | ||
var url = tracer.Settings.BypassHttpRequestUrlCachingEnabled | ||
? RequestDataHelper.BuildUrl(app.Request) | ||
: RequestDataHelper.GetUrl(app.Request); | ||
if (url is not null) | ||
{ | ||
string path = UriHelpers.GetCleanUriPath(url, app.Request.ApplicationPath); | ||
currentSpan.ResourceName = $"{app.Request.HttpMethod.ToUpperInvariant()} {path.ToLowerInvariant()}"; | ||
} | ||
else | ||
{ | ||
currentSpan.ResourceName = $"{app.Request.HttpMethod.ToUpperInvariant()}"; | ||
} | ||
currentSpan.ResourceName = BuildResourceName(tracer, app.Request); | ||
} | ||
} | ||
finally | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
[ | ||
{ | ||
TraceId: Id_1, | ||
SpanId: Id_2, | ||
Name: aspnet-mvc.request, | ||
Resource: GET /home/pleasesamplemeout/?, | ||
Service: sample, | ||
Type: web, | ||
ParentId: Id_3, | ||
Tags: { | ||
aspnet.action: pleasesamplemeout, | ||
aspnet.controller: home, | ||
aspnet.route: {controller}/{action}/{id}, | ||
env: integration_tests, | ||
http.method: GET, | ||
http.request.headers.host: localhost:00000, | ||
http.status_code: 200, | ||
http.url: http://localhost:00000/Home/PleaseSampleMeOut/5555, | ||
http.useragent: testhelper, | ||
language: dotnet, | ||
span.kind: server, | ||
version: 1.0.0 | ||
} | ||
}, | ||
{ | ||
TraceId: Id_1, | ||
SpanId: Id_3, | ||
Name: aspnet.request, | ||
Resource: GET /home/pleasesamplemeout/?, | ||
Service: sample, | ||
Type: web, | ||
Tags: { | ||
env: integration_tests, | ||
http.method: GET, | ||
http.request.headers.host: localhost:00000, | ||
http.route: {controller}/{action}/{id}, | ||
http.status_code: 200, | ||
http.url: http://localhost:00000/Home/PleaseSampleMeOut/5555, | ||
http.useragent: testhelper, | ||
language: dotnet, | ||
runtime-id: Guid_1, | ||
span.kind: server, | ||
version: 1.0.0 | ||
}, | ||
Metrics: { | ||
process_id: 0, | ||
_dd.rule_psr: 0.0, | ||
_dd.top_level: 1.0, | ||
_dd.tracer_kr: 1.0, | ||
_sampling_priority_v1: -1.0 | ||
} | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
[ | ||
{ | ||
TraceId: Id_1, | ||
SpanId: Id_2, | ||
Name: aspnet-mvc.request, | ||
Resource: GET /home/pleasesamplemeout/{id}, | ||
Service: sample, | ||
Type: web, | ||
ParentId: Id_3, | ||
Tags: { | ||
aspnet.action: pleasesamplemeout, | ||
aspnet.controller: home, | ||
aspnet.route: {controller}/{action}/{id}, | ||
env: integration_tests, | ||
http.method: GET, | ||
http.request.headers.host: localhost:00000, | ||
http.status_code: 200, | ||
http.url: http://localhost:00000/Home/PleaseSampleMeOut/5555, | ||
http.useragent: testhelper, | ||
language: dotnet, | ||
span.kind: server, | ||
version: 1.0.0 | ||
} | ||
}, | ||
{ | ||
TraceId: Id_1, | ||
SpanId: Id_3, | ||
Name: aspnet.request, | ||
Resource: GET /home/pleasesamplemeout/{id}, | ||
Service: sample, | ||
Type: web, | ||
Tags: { | ||
env: integration_tests, | ||
http.method: GET, | ||
http.request.headers.host: localhost:00000, | ||
http.route: {controller}/{action}/{id}, | ||
http.status_code: 200, | ||
http.url: http://localhost:00000/Home/PleaseSampleMeOut/5555, | ||
http.useragent: testhelper, | ||
language: dotnet, | ||
runtime-id: Guid_1, | ||
span.kind: server, | ||
version: 1.0.0 | ||
}, | ||
Metrics: { | ||
process_id: 0, | ||
_dd.top_level: 1.0, | ||
_dd.tracer_kr: 1.0, | ||
_sampling_priority_v1: 1.0 | ||
} | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
[ | ||
{ | ||
TraceId: Id_1, | ||
SpanId: Id_2, | ||
Name: aspnet-mvc.request, | ||
Resource: GET /home/pleasesamplemeout/?, | ||
Service: sample, | ||
Type: web, | ||
ParentId: Id_3, | ||
Tags: { | ||
aspnet.action: pleasesamplemeout, | ||
aspnet.controller: home, | ||
aspnet.route: {controller}/{action}/{id}, | ||
env: integration_tests, | ||
http.method: GET, | ||
http.request.headers.host: localhost:00000, | ||
http.status_code: 200, | ||
http.url: http://localhost:00000/Home/PleaseSampleMeOut/5555, | ||
http.useragent: testhelper, | ||
language: dotnet, | ||
span.kind: server, | ||
version: 1.0.0 | ||
} | ||
}, | ||
{ | ||
TraceId: Id_1, | ||
SpanId: Id_3, | ||
Name: aspnet.request, | ||
Resource: GET /home/pleasesamplemeout/?, | ||
Service: sample, | ||
Type: web, | ||
Tags: { | ||
env: integration_tests, | ||
http.method: GET, | ||
http.request.headers.host: localhost:00000, | ||
http.route: {controller}/{action}/{id}, | ||
http.status_code: 200, | ||
http.url: http://localhost:00000/Home/PleaseSampleMeOut/5555, | ||
http.useragent: testhelper, | ||
language: dotnet, | ||
runtime-id: Guid_1, | ||
span.kind: server, | ||
version: 1.0.0 | ||
}, | ||
Metrics: { | ||
process_id: 0, | ||
_dd.rule_psr: 0.0, | ||
_dd.top_level: 1.0, | ||
_dd.tracer_kr: 1.0, | ||
_sampling_priority_v1: -1.0 | ||
} | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
[ | ||
{ | ||
TraceId: Id_1, | ||
SpanId: Id_2, | ||
Name: aspnet-mvc.request, | ||
Resource: GET /home/pleasesamplemeout/{id}, | ||
Service: sample, | ||
Type: web, | ||
ParentId: Id_3, | ||
Tags: { | ||
aspnet.action: pleasesamplemeout, | ||
aspnet.controller: home, | ||
aspnet.route: {controller}/{action}/{id}, | ||
env: integration_tests, | ||
http.method: GET, | ||
http.request.headers.host: localhost:00000, | ||
http.status_code: 200, | ||
http.url: http://localhost:00000/Home/PleaseSampleMeOut/5555, | ||
http.useragent: testhelper, | ||
language: dotnet, | ||
span.kind: server, | ||
version: 1.0.0 | ||
} | ||
}, | ||
{ | ||
TraceId: Id_1, | ||
SpanId: Id_3, | ||
Name: aspnet.request, | ||
Resource: GET /home/pleasesamplemeout/{id}, | ||
Service: sample, | ||
Type: web, | ||
Tags: { | ||
env: integration_tests, | ||
http.method: GET, | ||
http.request.headers.host: localhost:00000, | ||
http.route: {controller}/{action}/{id}, | ||
http.status_code: 200, | ||
http.url: http://localhost:00000/Home/PleaseSampleMeOut/5555, | ||
http.useragent: testhelper, | ||
language: dotnet, | ||
runtime-id: Guid_1, | ||
span.kind: server, | ||
version: 1.0.0 | ||
}, | ||
Metrics: { | ||
process_id: 0, | ||
_dd.rule_psr: 0.0, | ||
_dd.top_level: 1.0, | ||
_dd.tracer_kr: 1.0, | ||
_sampling_priority_v1: -1.0 | ||
} | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
[ | ||
{ | ||
TraceId: Id_1, | ||
SpanId: Id_2, | ||
Name: aspnet-mvc.request, | ||
Resource: GET /home/pleasesamplemeout/{id}, | ||
Service: sample, | ||
Type: web, | ||
ParentId: Id_3, | ||
Tags: { | ||
aspnet.action: pleasesamplemeout, | ||
aspnet.controller: home, | ||
aspnet.route: {controller}/{action}/{id}, | ||
env: integration_tests, | ||
http.method: GET, | ||
http.request.headers.host: localhost:00000, | ||
http.status_code: 200, | ||
http.url: http://localhost:00000/Home/PleaseSampleMeOut/5555, | ||
http.useragent: testhelper, | ||
language: dotnet, | ||
span.kind: server, | ||
version: 1.0.0 | ||
} | ||
}, | ||
{ | ||
TraceId: Id_1, | ||
SpanId: Id_3, | ||
Name: aspnet.request, | ||
Resource: GET /home/pleasesamplemeout/{id}, | ||
Service: sample, | ||
Type: web, | ||
Tags: { | ||
env: integration_tests, | ||
http.method: GET, | ||
http.request.headers.host: localhost:00000, | ||
http.route: {controller}/{action}/{id}, | ||
http.status_code: 200, | ||
http.url: http://localhost:00000/Home/PleaseSampleMeOut/5555, | ||
http.useragent: testhelper, | ||
language: dotnet, | ||
runtime-id: Guid_1, | ||
span.kind: server, | ||
version: 1.0.0 | ||
}, | ||
Metrics: { | ||
process_id: 0, | ||
_dd.rule_psr: 0.0, | ||
_dd.top_level: 1.0, | ||
_dd.tracer_kr: 1.0, | ||
_sampling_priority_v1: -1.0 | ||
} | ||
} | ||
] |
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.
nit