[OneCollector] Limit response body size read#4117
[OneCollector] Limit response body size read#4117rajkumar-rangaraj merged 10 commits intoopen-telemetry:mainfrom
Conversation
There was a problem hiding this comment.
This is just a small refactor to use an expression body method I saw while I was looking for usages of GetAwaiter().GetResult().
There was a problem hiding this comment.
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.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ 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 Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Limit the length of the HTTP response body that is read by `HttpJsonPostTransport`.
Add PR number.
34752e0 to
c2dd244
Compare
There was a problem hiding this comment.
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.TryGetResponseBodyAsStringwith a default 4MiB read limit and truncation behavior. - Use the new helper in
HttpJsonPostTransportwhen 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.
- 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`.
Fix class name.
Method no longer used after refactoring.
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.
77dc5d1
Move code to read a string from an `HttpResponseMessage` into a shared helper for future re-use. See open-telemetry/opentelemetry-dotnet-contrib#4117.
Changes
Limit the length of the HTTP response body that is read by
HttpJsonPostTransport.Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)