Skip to content

[Sampler.AWS] Limit the max size read for response body getting the sampling rules to 1MB.#4100

Merged
Kielek merged 4 commits intoopen-telemetry:mainfrom
normj:defensive-read
Apr 14, 2026
Merged

[Sampler.AWS] Limit the max size read for response body getting the sampling rules to 1MB.#4100
Kielek merged 4 commits intoopen-telemetry:mainfrom
normj:defensive-read

Conversation

@normj
Copy link
Copy Markdown
Contributor

@normj normj commented Apr 14, 2026

Fixes #

Changes

Makes the code reading X-Ray sampling rules more defensive reading the response back from the sampling endpoint. Limits the max read for sampling rules to 1 MB. Well beyond what sampling rules max should be as long as the code is receiving valid sampling rules.

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)

@normj normj requested a review from a team as a code owner April 14, 2026 06:34
@github-actions github-actions Bot requested a review from srprash April 14, 2026 06:34
@github-actions github-actions Bot added the comp:sampler.aws Things related to OpenTelemetry.Samplers.AWS label Apr 14, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 14, 2026

Codecov Report

❌ Patch coverage is 87.75510% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.96%. Comparing base (4785a16) to head (9380846).
⚠️ Report is 4 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/OpenTelemetry.Sampler.AWS/LimitedStream.cs 86.36% 6 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4100      +/-   ##
==========================================
+ Coverage   72.93%   72.96%   +0.03%     
==========================================
  Files         452      453       +1     
  Lines       17844    17890      +46     
==========================================
+ Hits        13014    13054      +40     
- Misses       4830     4836       +6     
Flag Coverage Δ
unittests-Sampler.AWS 93.72% <87.75%> (-0.56%) ⬇️

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

Files with missing lines Coverage Δ
.../OpenTelemetry.Sampler.AWS/AWSXRaySamplerClient.cs 97.26% <100.00%> (+0.07%) ⬆️
src/OpenTelemetry.Sampler.AWS/LimitedStream.cs 86.36% <86.36%> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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 defensive cap (1MB) when reading AWS X-Ray sampling rules/targets responses to reduce risk from unexpectedly large/untrusted HTTP payloads.

Changes:

  • Introduce LimitedStream stream wrapper enforcing a maximum number of bytes read.
  • Update AWSXRaySamplerClient.DoRequestAsync to read via stream + LimitedStream instead of ReadAsStringAsync.
  • Add unit tests for LimitedStream and update package changelog.

Reviewed changes

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

File Description
src/OpenTelemetry.Sampler.AWS/AWSXRaySamplerClient.cs Switch response reading to a streamed approach with a 1MB cap.
src/OpenTelemetry.Sampler.AWS/LimitedStream.cs New stream wrapper enforcing a max-bytes-read limit.
test/OpenTelemetry.Sampler.AWS.Tests/TestLimitedStreamReader.cs New tests validating LimitedStream behavior.
src/OpenTelemetry.Sampler.AWS/CHANGELOG.md Document the new 1MB response-size limit behavior.

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

Comment thread src/OpenTelemetry.Sampler.AWS/LimitedStream.cs
Comment thread src/OpenTelemetry.Sampler.AWS/LimitedStream.cs
Comment thread src/OpenTelemetry.Sampler.AWS/AWSXRaySamplerClient.cs Outdated
Comment thread src/OpenTelemetry.Sampler.AWS/AWSXRaySamplerClient.cs Outdated
Comment thread src/OpenTelemetry.Sampler.AWS/AWSXRaySamplerClient.cs
@Kielek Kielek enabled auto-merge April 14, 2026 07:43
@Kielek Kielek disabled auto-merge April 14, 2026 07:43
@Kielek Kielek changed the title Limit the max size read for response body getting the sampling rules to 1MB. [Sampler.AWS] Limit the max size read for response body getting the sampling rules to 1MB. Apr 14, 2026
@Kielek Kielek enabled auto-merge April 14, 2026 07:44
@Kielek Kielek added this pull request to the merge queue Apr 14, 2026
Merged via the queue into open-telemetry:main with commit 08e0ae2 Apr 14, 2026
74 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:sampler.aws Things related to OpenTelemetry.Samplers.AWS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants