Skip to content

Always set response header tags in ASP.NET Core#2480

Merged
andrewlock merged 1 commit into
masterfrom
andrew/always-apply-headers
Feb 21, 2022
Merged

Always set response header tags in ASP.NET Core#2480
andrewlock merged 1 commit into
masterfrom
andrew/always-apply-headers

Conversation

@andrewlock

Copy link
Copy Markdown
Member

Summary of changes

  • Ensure we always add response header tags when an exception occurs in the middleware pipeline

Reason for change

Initially Discovered while investigating #2458, but also spotted when preparing a hotfix. We noticed that we were not calling SetHeaderTags() to record response headers when an unhandled exception occurs in the middleware/mvc pipeline, and in the latter case, if the status code was already set on the span.

Other details

Supersedes #2460

@andrewlock andrewlock added type:bug area:automatic-instrumentation Automatic instrumentation managed C# code (Datadog.Trace.ClrProfiler.Managed) labels Feb 21, 2022
@andrewlock
andrewlock requested a review from a team as a code owner February 21, 2022 11:24
@andrewlock
andrewlock force-pushed the andrew/always-apply-headers branch from 446f11f to 2afc19e Compare February 21, 2022 12:30
@andrewlock

Copy link
Copy Markdown
Member Author

Code Coverage Report 📊

✔️ Merging #2480 into master will not change line coverage
✔️ Merging #2480 into master will not change branch coverage
✔️ Merging #2480 into master will not change complexity

master #2480 Change
Lines 11635 / 15979 11629 / 15979
Lines % 73% 73% 0% ✔️
Branches 6259 / 9348 6252 / 9348
Branches % 67% 67% 0% ✔️
Complexity 10558 10558 0 ✔️

View the full report for further details:

Datadog.Trace Breakdown ✔️

master #2480 Change
Lines % 73% 73% 0% ✔️
Branches % 67% 67% 0% ✔️
Complexity 10558 10558 0 ✔️

The following classes have significant coverage changes.

File Line coverage change Branch coverage change Complexity change
Datadog.Trace.Telemetry.JsonWebRequestTelemetryTransport -28% -57% 0 ✔️
Datadog.Trace.ClrProfiler.AutoInstrumentation.MongoDb.MongoDbIntegration -7% 0% ✔️ 0 ✔️
Datadog.Trace.Telemetry.JsonHttpClientTelemetryTransport 26% ✔️ 38% ✔️ 0 ✔️

View the full reports for further details:

@andrewlock
andrewlock merged commit 7fa5de3 into master Feb 21, 2022
@andrewlock
andrewlock deleted the andrew/always-apply-headers branch February 21, 2022 14:13
@github-actions github-actions Bot added this to the vNext milestone Feb 21, 2022
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:automatic-instrumentation Automatic instrumentation managed C# code (Datadog.Trace.ClrProfiler.Managed) type:bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants