Skip to content

[AspNet] Use Http*Base classes in public API - #3110

Merged
Kielek merged 6 commits into
open-telemetry:mainfrom
Kielek:aspnet-base-classes
Sep 17, 2025
Merged

[AspNet] Use Http*Base classes in public API#3110
Kielek merged 6 commits into
open-telemetry:mainfrom
Kielek:aspnet-base-classes

Conversation

@Kielek

@Kielek Kielek commented Sep 11, 2025

Copy link
Copy Markdown
Member

Fixes #1438

Changes

All usages of HttpRequest, HttpResponse and HttpContext replaced by HttpRequestBase, HttpResponseBase and HttpContextBase respectively.

Added simple test to utilize new (internal) API.

The only drawback I see is src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/TelemetryHttpModule.cs where there is couple of calls of (new HttpContextWrapper(realContextHere).

It is the last moment where we can consider such breaking change without rising major version.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@github-actions github-actions Bot added comp:instrumentation.aspnet.telemetryhttpmodule Things related to OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule comp:instrumentation.aspnet Things related to OpenTelemetry.Instrumentation.AspNet labels Sep 11, 2025
@Kielek
Kielek force-pushed the aspnet-base-classes branch from 80148cd to a07569f Compare September 11, 2025 06:54
@codecov

codecov Bot commented Sep 11, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 63.63636% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.76%. Comparing base (d22fdd9) to head (5df1a73).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
....AspNet.TelemetryHttpModule/TelemetryHttpModule.cs 0.00% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3110      +/-   ##
==========================================
- Coverage   70.20%   69.76%   -0.44%     
==========================================
  Files         429      410      -19     
  Lines       16820    16235     -585     
==========================================
- Hits        11808    11327     -481     
+ Misses       5012     4908     -104     
Flag Coverage Δ
unittests-Extensions.Enrichment.Http ?
unittests-Instrumentation.AspNet 75.18% <63.63%> (+0.24%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ation.AspNet.TelemetryHttpModule/ActivityHelper.cs 85.71% <100.00%> (ø)
....TelemetryHttpModule/TelemetryHttpModuleOptions.cs 90.00% <100.00%> (ø)
...tion.AspNet/AspNetMetricsInstrumentationOptions.cs 100.00% <ø> (ø)
...tation.AspNet/AspNetTraceInstrumentationOptions.cs 100.00% <100.00%> (ø)
...umentation.AspNet/Implementation/HttpInListener.cs 80.41% <ø> (ø)
...on.AspNet/Implementation/HttpRequestRouteHelper.cs 100.00% <ø> (ø)
...pNet/Implementation/RequestDataHelperExtensions.cs 100.00% <ø> (ø)
....AspNet.TelemetryHttpModule/TelemetryHttpModule.cs 5.26% <0.00%> (ø)

... and 40 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Kielek
Kielek force-pushed the aspnet-base-classes branch from a07569f to 4249f04 Compare September 11, 2025 06:58
@Kielek

Kielek commented Sep 11, 2025

Copy link
Copy Markdown
Member Author

@qhris, it will be great if you can check this PR. You have requested these changes long time ago.

@Kielek
Kielek marked this pull request as ready for review September 11, 2025 07:01
@Kielek
Kielek requested a review from a team as a code owner September 11, 2025 07:01

@alanwest alanwest left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a little odd to make this change solely for the purpose of testability. I'm approving, but there's a fair amount of history here I'm not familiar with, so I do not fully understand the reasons why we should make this change.

@rajkumar-rangaraj rajkumar-rangaraj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I acknowledge Alan's point. I see that we've made it testable. Do you know what benefits or drawbacks this change might bring?

@qhris

qhris commented Sep 12, 2025

Copy link
Copy Markdown
Contributor

I'm not in a situation to check this out in much detail at the moment, but it looks good to me.

From what I can remember, setting ServerVariables was especially hard without this PR.

Last time I looked into this, I found it very hard to actually test functionality without having to spin up a local server each time which led to very slow development and testing. But it has been almost 2 years since I made the issue and my memory is a bit fuzzy at this point. 😄 @alanwest

@Kielek

Kielek commented Sep 16, 2025

Copy link
Copy Markdown
Member Author

The main drawback I see is src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/TelemetryHttpModule.cs where there is couple of calls of (new HttpContextWrapper(realContextHere).

Based on additional research, the HttpContext classes was introduced into the framework in 1.0 version. There were no possibility to add Based classes to the inheritance without introducing breaking changes. Ref: thttps://stackoverflow.com/a/1973727

As Base classes are modern, I would go with this implementation.

@Kielek
Kielek merged commit 5d2da78 into open-telemetry:main Sep 17, 2025
61 checks passed
@Kielek
Kielek deleted the aspnet-base-classes branch September 17, 2025 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:instrumentation.aspnet.telemetryhttpmodule Things related to OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule comp:instrumentation.aspnet Things related to OpenTelemetry.Instrumentation.AspNet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rework HTTP telemetry modules to enable easier testing

5 participants