Skip to content

[Resources.AWS] Limit response body size read#4122

Merged
martincostello merged 4 commits into
open-telemetry:mainfrom
martincostello:limit-aws-detector-response-limit
Apr 16, 2026
Merged

[Resources.AWS] Limit response body size read#4122
martincostello merged 4 commits into
open-telemetry:mainfrom
martincostello:limit-aws-detector-response-limit

Conversation

@martincostello

@martincostello martincostello commented Apr 15, 2026

Copy link
Copy Markdown
Member

Changes

  • 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.

Builds on top of #4117.

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:exporter.onecollector Things related to OpenTelemetry.Exporter.OneCollector comp:resources.aws Things related to OpenTelemetry.Resources.AWS labels Apr 15, 2026
@codecov

codecov Bot commented Apr 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.80488% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.86%. Comparing base (9d8a364) to head (9af5375).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/OpenTelemetry.Resources.AWS/AWSEC2Detector.cs 60.00% 2 Missing ⚠️
src/OpenTelemetry.Resources.AWS/AWSEKSDetector.cs 75.00% 2 Missing ⚠️
...enTelemetry.Resources.AWS/ResourceDetectorUtils.cs 94.73% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
unittests-Instrumentation.Cassandra ?
unittests-Instrumentation.Remoting ?
unittests-Resources.AWS 73.88% <87.80%> (-0.80%) ⬇️

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

Files with missing lines Coverage Δ
src/OpenTelemetry.Resources.AWS/AWSECSDetector.cs 91.75% <100.00%> (+2.86%) ⬆️
...enTelemetry.Resources.AWS/ResourceDetectorUtils.cs 95.83% <94.73%> (-4.17%) ⬇️
src/OpenTelemetry.Resources.AWS/AWSEC2Detector.cs 73.52% <60.00%> (ø)
src/OpenTelemetry.Resources.AWS/AWSEKSDetector.cs 62.29% <75.00%> (ø)

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

Comment thread src/OpenTelemetry.Resources.AWS/CHANGELOG.md Outdated
- 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.
@martincostello
martincostello force-pushed the limit-aws-detector-response-limit branch from 797031c to 6078209 Compare April 16, 2026 07:42
@github-actions github-actions Bot removed the comp:exporter.onecollector Things related to OpenTelemetry.Exporter.OneCollector label Apr 16, 2026
@martincostello
martincostello marked this pull request as ready for review April 16, 2026 07:44
@martincostello
martincostello requested a review from a team as a code owner April 16, 2026 07:44
Copilot AI review requested due to automatic review settings April 16, 2026 07:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 synchronous SendOutRequest path that uses shared HttpClientHelpers to cap response body reads.
  • Simplify file/stream reading in ECS/EKS container-id and credential parsing.
  • Wire HttpClientHelpers into 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.

Comment thread src/OpenTelemetry.Resources.AWS/ResourceDetectorUtils.cs Outdated
Comment thread src/OpenTelemetry.Resources.AWS/ResourceDetectorUtils.cs
Comment thread src/OpenTelemetry.Resources.AWS/ResourceDetectorUtils.cs
Comment thread src/OpenTelemetry.Resources.AWS/AWSECSDetector.cs Outdated
Comment thread src/OpenTelemetry.Resources.AWS/AWSECSDetector.cs
- Use `HttpCompletionOption.ResponseHeadersRead`.
- Add test.
@github-actions
github-actions Bot requested review from normj and srprash April 16, 2026 08:50
Remove redundant variable.
@martincostello
martincostello added this pull request to the merge queue Apr 16, 2026
Merged via the queue into open-telemetry:main with commit 304b93c Apr 16, 2026
74 checks passed
@martincostello
martincostello deleted the limit-aws-detector-response-limit branch April 16, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:resources.aws Things related to OpenTelemetry.Resources.AWS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants