Skip to content

[OneCollector] Limit response body size read#4117

Merged
rajkumar-rangaraj merged 10 commits intoopen-telemetry:mainfrom
martincostello:onecollector-limit-response-size-read
Apr 16, 2026
Merged

[OneCollector] Limit response body size read#4117
rajkumar-rangaraj merged 10 commits intoopen-telemetry:mainfrom
martincostello:onecollector-limit-response-size-read

Conversation

@martincostello
Copy link
Copy Markdown
Member

Changes

Limit the length of the HTTP response body that is read by HttpJsonPostTransport.

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)

Comment thread src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md Outdated
@github-actions github-actions Bot added the comp:exporter.onecollector Things related to OpenTelemetry.Exporter.OneCollector label Apr 15, 2026
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is just a small refactor to use an expression body method I saw while I was looking for usages of GetAwaiter().GetResult().

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've put this into a shared helper with the intention to do some refactoring after the next release to centralise all the logic for this sort of thing into one place.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

See #4121 and #4122.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 15, 2026

Codecov Report

❌ Patch coverage is 96.36364% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.67%. Comparing base (1718625) to head (ae12cff).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/Shared/HttpClientHelpers.cs 95.65% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4117      +/-   ##
==========================================
- Coverage   72.79%   71.67%   -1.13%     
==========================================
  Files         459      461       +2     
  Lines       18103    17997     -106     
==========================================
- Hits        13178    12899     -279     
- Misses       4925     5098     +173     
Flag Coverage Δ
unittests-Contrib.Shared.Tests 89.93% <95.65%> (+0.28%) ⬆️
unittests-Exporter.Geneva 54.70% <ø> (-0.14%) ⬇️
unittests-Exporter.InfluxDB 94.67% <ø> (-1.15%) ⬇️
unittests-Exporter.Instana 74.86% <ø> (ø)
unittests-Exporter.OneCollector 94.61% <100.00%> (-0.01%) ⬇️
unittests-Extensions 90.65% <ø> (ø)
unittests-Extensions.Enrichment 100.00% <ø> (ø)
unittests-Extensions.Enrichment.AspNetCore 86.27% <ø> (ø)
unittests-Extensions.Enrichment.Http 94.33% <ø> (ø)
unittests-Instrumentation.AWS 83.54% <ø> (ø)
unittests-Instrumentation.AspNet 76.61% <ø> (ø)
unittests-Instrumentation.AspNetCore 70.44% <ø> (ø)
unittests-Instrumentation.Cassandra 23.52% <ø> (?)
unittests-Instrumentation.ConfluentKafka 39.83% <ø> (ø)
unittests-Instrumentation.ElasticsearchClient 80.60% <ø> (ø)
unittests-Instrumentation.EntityFrameworkCore 80.80% <ø> (ø)
unittests-Instrumentation.EventCounters 77.27% <ø> (ø)
unittests-Instrumentation.GrpcCore 91.42% <ø> (ø)
unittests-Instrumentation.GrpcNetClient 73.78% <ø> (ø)
unittests-Instrumentation.Hangfire 86.05% <ø> (ø)
unittests-Instrumentation.Http 74.62% <ø> (ø)
unittests-Instrumentation.Owin 88.62% <ø> (ø)
unittests-Instrumentation.Process 100.00% <ø> (ø)
unittests-Instrumentation.Quartz 78.76% <ø> (ø)
unittests-Instrumentation.Remoting 64.28% <ø> (ø)
unittests-Instrumentation.Runtime 100.00% <ø> (ø)
unittests-Instrumentation.ServiceFabricRemoting 34.68% <ø> (ø)
unittests-Instrumentation.SqlClient 85.21% <ø> (ø)
unittests-Instrumentation.StackExchangeRedis 71.98% <ø> (ø)
unittests-Instrumentation.Wcf 50.00% <ø> (-29.69%) ⬇️
unittests-OpAmp.Client 78.28% <ø> (-0.50%) ⬇️
unittests-PersistentStorage 71.47% <ø> (+1.63%) ⬆️
unittests-Resources.AWS 74.67% <ø> (ø)
unittests-Resources.Azure 85.31% <ø> (ø)
unittests-Resources.Container 67.34% <ø> (ø)
unittests-Resources.Gcp 71.42% <ø> (ø)
unittests-Resources.Host 72.26% <ø> (ø)
unittests-Resources.OperatingSystem 76.98% <ø> (ø)
unittests-Resources.Process 100.00% <ø> (ø)
unittests-Resources.ProcessRuntime 79.59% <ø> (ø)
unittests-Sampler.AWS 93.72% <ø> (ø)

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

Files with missing lines Coverage Δ
...ector/Internal/Transports/HttpJsonPostTransport.cs 95.55% <100.00%> (-0.04%) ⬇️
...er.OneCollector/Internal/Transports/IHttpClient.cs 100.00% <100.00%> (ø)
src/Shared/HttpClientHelpers.cs 95.65% <95.65%> (ø)

... and 33 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.

Limit the length of the HTTP response body that is read by `HttpJsonPostTransport`.
@martincostello martincostello force-pushed the onecollector-limit-response-size-read branch from 34752e0 to c2dd244 Compare April 15, 2026 13:36
@martincostello martincostello marked this pull request as ready for review April 15, 2026 13:51
@martincostello martincostello requested a review from a team as a code owner April 15, 2026 13:51
Copilot AI review requested due to automatic review settings April 15, 2026 13:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a shared helper to cap how much HTTP response body is read (primarily for OneCollector HTTP JSON transport failures) and introduces unit tests to validate truncation/charset/stream behaviors.

Changes:

  • Introduce HttpClientHelpers.TryGetResponseBodyAsString with a default 4MiB read limit and truncation behavior.
  • Use the new helper in HttpJsonPostTransport when informational logging is enabled.
  • Add unit tests and wire the shared helper into the relevant test/exporter projects.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/OpenTelemetry.Contrib.Shared.Tests/OpenTelemetry.Contrib.Shared.Tests.csproj Links the shared HttpClientHelpers source into the shared test project.
test/OpenTelemetry.Contrib.Shared.Tests/HttpClientHelperTests.cs Adds coverage for empty content, truncation, decompression, exceptions, cancellation, non-seekable streams, and charset handling.
src/Shared/HttpClientHelpers.cs Implements bounded response-body-to-string reading with charset decoding.
src/OpenTelemetry.Exporter.OneCollector/OpenTelemetry.Exporter.OneCollector.csproj Links the shared HttpClientHelpers into the OneCollector exporter build.
src/OpenTelemetry.Exporter.OneCollector/Internal/Transports/IHttpClient.cs Refactors Send to an expression-bodied implementation (no logic change intended).
src/OpenTelemetry.Exporter.OneCollector/Internal/Transports/HttpJsonPostTransport.cs Uses HttpClientHelpers to read error details with a size limit when info logging is enabled.
src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md Documents the behavior change.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Shared/HttpClientHelpers.cs
Comment thread src/Shared/HttpClientHelpers.cs Outdated
Comment thread src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md Outdated
- Update changelog link.
- Return null if cancelled.
- Always use `HttpCompletionOption.ResponseHeadersRead`.
- Ensure truncation is flagged correctly.
- Update code for future re-use with OpAMP.
- Support future usage that does not allow truncation.
- Handle `HttpContent` being null.
Remove unused `using`.
Comment thread src/Shared/HttpClientHelpers.cs Outdated
Method no longer used after refactoring.
martincostello added a commit to martincostello/opentelemetry-dotnet that referenced this pull request Apr 15, 2026
Move code to read a string from an `HttpResponseMessage` into a shared helper for future re-use.

See open-telemetry/opentelemetry-dotnet-contrib#4117.
- Allow nulls.
- Remove redundant guards.
- Throw if cancelled before reading string to avoid truncated content.
- Clear the rented buffer when returned.
@rajkumar-rangaraj rajkumar-rangaraj added this pull request to the merge queue Apr 16, 2026
Merged via the queue into open-telemetry:main with commit 77dc5d1 Apr 16, 2026
328 of 329 checks passed
@martincostello martincostello deleted the onecollector-limit-response-size-read branch April 16, 2026 06:44
martincostello added a commit to martincostello/opentelemetry-dotnet that referenced this pull request Apr 16, 2026
Move code to read a string from an `HttpResponseMessage` into a shared helper for future re-use.

See open-telemetry/opentelemetry-dotnet-contrib#4117.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:exporter.onecollector Things related to OpenTelemetry.Exporter.OneCollector

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants