Fix missing http.status_code tag on ASP.NET Core spans with errors#2458
Merged
Conversation
…status code is set Shows that the tests are failing for the "legacy" (feature-flag disabled) use case.
andrewlock
force-pushed
the
andrew/fix-aspnetcore-errors
branch
from
February 17, 2022 14:10
770908f to
e22e610
Compare
kevingosse
approved these changes
Feb 17, 2022
pierotibou
approved these changes
Feb 17, 2022
Member
Author
Code Coverage Report 📊✔️ Merging #2458 into master will not change line coverage
View the full report for further details: Datadog.Trace Breakdown ✔️
The following classes have significant coverage changes.
The following classes were added in #2458:
View the full reports for further details: |
Member
Author
Benchmarks Report 🐌Benchmarks for #2458 compared to master:
The following thresholds were used for comparing the benchmark speeds:
Allocation changes below 0.5% are ignored. Benchmark detailsBenchmarks.Trace.AgentWriterBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.AspNetCoreBenchmark - Unknown 🤷 Same allocations ✔️Raw results
Benchmarks.Trace.DbCommandBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.ElasticsearchBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.GraphQLBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.HttpClientBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.ILoggerBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.Log4netBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.NLogBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.RedisBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.SerilogBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.SpanBenchmark - Same speed ✔️ Same allocations ✔️Raw results
|
andrewlock
added a commit
that referenced
this pull request
Feb 21, 2022
…2458) * Add tests for case where an exception is set on a span and a non-200 status code is set Shows that the tests are failing for the "legacy" (feature-flag disabled) use case. * Fix missing HTTP status code tag when span is manually marked as an error
andrewlock
added a commit
that referenced
this pull request
Feb 21, 2022
…2458) * Add tests for case where an exception is set on a span and a non-200 status code is set Shows that the tests are failing for the "legacy" (feature-flag disabled) use case. * Fix missing HTTP status code tag when span is manually marked as an error
andrewlock
added a commit
that referenced
this pull request
Feb 21, 2022
…2458) * Add tests for case where an exception is set on a span and a non-200 status code is set Shows that the tests are failing for the "legacy" (feature-flag disabled) use case. * Fix missing HTTP status code tag when span is manually marked as an error
andrewlock
added a commit
that referenced
this pull request
Feb 21, 2022
…2458) * Add tests for case where an exception is set on a span and a non-200 status code is set Shows that the tests are failing for the "legacy" (feature-flag disabled) use case. * Fix missing HTTP status code tag when span is manually marked as an error
This was referenced Feb 21, 2022
Merged
andrewlock
added a commit
that referenced
this pull request
Feb 21, 2022
* Fix missing `http.status_code` tag on ASP.NET Core spans with errors (#2458) * Add tests for case where an exception is set on a span and a non-200 status code is set Shows that the tests are failing for the "legacy" (feature-flag disabled) use case. * Fix missing HTTP status code tag when span is manually marked as an error * Support cleaning filenames in http-client + aspnet (#2471) The HttpClient integration (and the ASP.NET/ASP.NET Core integration when the feature flag is disabled) all do "cleaning" of URLs to try and reduce the cardinality introduced by number/guid route parameters. This works by examining each "segment" in a URL, and using heuristics to see if we should replace it with `?`. This works as expected for the following paths: - `/some/value/123` => `/some/value/?` - `/some/value/123/123-456 => `/some/value/?/?` - `/some/value/123/example.png => `/some/value/?/example.png` However, it treats the whole final segment as a single unit, which means filenames with extensions will never be obfuscated, e.g. - `/some-filevalue/123.png` - `/some-filevalue/123.456` - `/some-filevalue/123.c` That can lead to high cardinality, which in turn can cause problems for customers with too many endpoints in their account. To work around it, we treat the filename as a separate segment from the file extension, and don't try and obfuscate the extension * Always set response header tags in ASP.NET Core (#2480) * Fix sample helpers and update snapshots Thes changes were necessary because of the significant differences between master and release/1.x
Merged
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary of changes
http.status_codeflag on ASP.NET Core spansReason for change
If the customer marks the root aspnetcore request
Spanas an error (e.g. usingTracer.ActiveScope.Span.SetException(ex)), currently we don't record the HTTP status code on response end. As a 200 response is assumed in these cases, we have error spans with the wrong status code.This is especially likely to occur when the customer is not using
DD_TRACE_ROUTE_TEMPLATE_RESOURCE_NAMES_ENABLED(i.e. the default in v1.x), as in these cases we only create a single aspnetcore span. When the feature flag is enabled (the default in v2.x), callingTracer.ActiveScope.Span.SetException(ex)sets the error on the inner span, and so we record the final status code correctly.Implementation details
If an exception occurs in the pipeline and isn't handled, the
OnHostingUnhandledExceptionhandler will record an appropriate status code. It needs to do some inferring of the final status code, as Kestrel may change the result after the pipeline has finished. Previously, we were using the presence of an error on the span to control whether to set the HTTP status code, to avoid overwriting with the wrong value.Instead, we now check to see if the status code has been set at all. If it hasn't, we set it. This fixes the bug, without requiring any significant changes.
Test coverage
Added an additional endpoint for testing this situation. Created snapshots for the expected results, confirmed they were missing the status code, then made the fix and confirmed it resolved.
Other details
Fixes APMS-6804
@DataDog/apm-dotnet