[Resources.AWS] Limit response body size read#4122
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4122 +/- ##
==========================================
+ Coverage 72.77% 72.86% +0.08%
==========================================
Files 469 452 -17
Lines 18272 17846 -426
==========================================
- Hits 13298 13003 -295
+ Misses 4974 4843 -131
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 from the AWS EC2/ECS/EKS instance metadata service. - Simplify stream reading. - Remove redundant sync-over-async calls.
797031c to
6078209
Compare
There was a problem hiding this comment.
Pull request overview
Updates the AWS resource detectors to reduce risk from unexpectedly large metadata service responses by limiting how much response body is consumed, while simplifying stream-reading code and removing sync-over-async helper usage.
Changes:
- Replace async HTTP metadata reads (and
AsyncHelper) with a synchronousSendOutRequestpath that uses sharedHttpClientHelpersto cap response body reads. - Simplify file/stream reading in ECS/EKS container-id and credential parsing.
- Wire
HttpClientHelpersinto the AWS project and document the change in the AWS changelog.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| test/OpenTelemetry.Resources.AWS.Tests/AsyncHelperTests.cs | Removes tests for AsyncHelper (helper is removed from production code). |
| src/OpenTelemetry.Resources.AWS/AsyncHelper.cs | Removes the sync-over-async helper now that call sites no longer need it. |
| src/OpenTelemetry.Resources.AWS/ResourceDetectorUtils.cs | Introduces synchronous metadata HTTP request helper and uses HttpClientHelpers for bounded response reads; stream/file helper simplifications. |
| src/OpenTelemetry.Resources.AWS/AWSEKSDetector.cs | Simplifies token/container-id file reads; switches to new synchronous request helper. |
| src/OpenTelemetry.Resources.AWS/AWSECSDetector.cs | Fixes/simplifies container-id file parsing; switches ECS metadata v4 fetches to new synchronous request helper. |
| src/OpenTelemetry.Resources.AWS/AWSEC2Detector.cs | Switches EC2 IMDS calls to new synchronous request helper and simplifies small helpers. |
| src/OpenTelemetry.Resources.AWS/OpenTelemetry.Resources.AWS.csproj | Links in src/Shared/HttpClientHelpers.cs for bounded response reading. |
| src/OpenTelemetry.Resources.AWS/CHANGELOG.md | Adds an Unreleased entry for limiting metadata HTTP response body consumption. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Use `HttpCompletionOption.ResponseHeadersRead`. - Add test.
Remove redundant variable.
Changes
Builds on top of #4117.
Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)