Skip to content

Add W3C Baggage boundary tests and entry-counter comment (follow-up to #1975)#1976

Merged
bobstrecansky merged 1 commit into
open-telemetry:mainfrom
tonghuaroot:baggage-boundary-tests
May 28, 2026
Merged

Add W3C Baggage boundary tests and entry-counter comment (follow-up to #1975)#1976
bobstrecansky merged 1 commit into
open-telemetry:mainfrom
tonghuaroot:baggage-boundary-tests

Conversation

@tonghuaroot

Copy link
Copy Markdown
Contributor

Fast-follow to #1975, addressing @bobstrecansky's non-blocking review suggestions.

What's changed

1. Boundary tests (tests/Unit/API/Baggage/Propagation/ParserTest.php)

The existing caps tests fire well past the limits (1024 pairs / 500 pairs), which proves the caps engage but does not pin the > vs >= edge. These four cases lock the off-by-one against the actual implemented semantics:

  • test_parse_into_accepts_header_at_exactly_w3c_byte_limit — exactly 8192 bytes is accepted (the cap is inclusive: strlen() > MAX_BAGGAGE_BYTES).
  • test_parse_into_rejects_header_one_byte_over_w3c_byte_limit — 8193 bytes discards the whole header.
  • test_parse_into_accepts_exactly_w3c_list_member_limit — 180 valid list-members are all accepted.
  • test_parse_into_caps_at_w3c_list_member_limit_plus_one — the 181st valid member is dropped once $entries reaches 180 ($entries >= MAX_BAGGAGE_ENTRIES).

2. Intent comment (src/API/Baggage/Propagation/Parser.php)

One line documenting that $entries counts only accepted pairs (incremented at the bottom of the loop), not raw comma-separated list-members, so the counter isn't silently relocated in a future refactor.

The silent-drop observability idea is intentionally deferred — discarding an over-cap header matches the W3C spec ("MAY truncate or discard") and the behaviour of the sibling SDKs, so it's not wired in here.

Testing

vendor/bin/phpunit --filter ParserTest tests/Unit/API/Baggage/Propagation/ParserTest.php

OK (17 tests, 43 assertions)

Follow-up to open-telemetry#1975. Pins the exact off-by-one behaviour of the W3C
Baggage caps that the existing tests (1024 pairs / 500 pairs) only
exercised well past the limits:

- byte cap is inclusive: 8192 bytes accepted, 8193 bytes rejected
- list-member cap: 180 entries accepted, 181st dropped

Also documents that $entries counts only ACCEPTED pairs (incremented at
the bottom of the loop), not raw comma-separated list-members, so a
future change does not silently move the counter and alter semantics.

Signed-off-by: tonghuaroot <[email protected]>
@tonghuaroot
tonghuaroot requested a review from a team as a code owner May 28, 2026 14:18
@welcome

welcome Bot commented May 28, 2026

Copy link
Copy Markdown

Thanks for opening your first pull request! If you haven't yet signed our Contributor License Agreement (CLA), then please do so that we can accept your contribution. A link should appear shortly in this PR if you have not already signed one.

@codecov

codecov Bot commented May 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.86%. Comparing base (73d88a0) to head (f272918).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1976      +/-   ##
============================================
+ Coverage     67.81%   67.86%   +0.05%     
  Complexity     3046     3046              
============================================
  Files           459      459              
  Lines          8891     8891              
============================================
+ Hits           6029     6034       +5     
+ Misses         2862     2857       -5     
Flag Coverage Δ
8.1 67.55% <ø> (+0.02%) ⬆️
8.2 67.82% <ø> (+0.08%) ⬆️
8.3 67.74% <ø> (-0.02%) ⬇️
8.4 67.74% <ø> (-0.01%) ⬇️
8.5 67.73% <ø> (-0.05%) ⬇️

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

Files with missing lines Coverage Δ
src/API/Baggage/Propagation/Parser.php 100.00% <ø> (ø)

... and 6 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 73d88a0...f272918. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bobstrecansky

Copy link
Copy Markdown
Contributor

Fascinating that this failed just PHP 8.1. Did a quick copilot review:

The failing test test_storage_keeps_constant_memory_on_one_active_reader is asserting that memory usage should increase by less than 2000 bytes during 10,000 iterations, but it's actually increasing by 65,536 bytes.

Root Cause: The DeltaStorage class is not properly cleaning up or releasing memory for inactive readers. When only reader 0 is active (calling collect(0)), the storage should not accumulate data for reader 1 (which is never collected).

The Issue at Line 127:

PHP
$this->assertLessThan(2000, memory_get_usage() - $memory);
The test expects constant memory with only one active reader, but memory is growing by 65,536 bytes (approximately 64KB), suggesting that metrics data is being retained for the inactive reader instead of being released after collection.

Fix for DeltaStorage:

The DeltaStorage class needs to implement logic that removes metrics from readers that have collected them. When a reader collects a delta, if that reader is the only one who hasn't collected yet, the metric should be purged from storage.

Key changes needed in the DeltaStorage implementation:

Track which readers have collected each metric version
Remove metrics once all active readers have collected them
Ensure proper cleanup to prevent memory accumulation
The test validates that with only one active reader consistently collecting, the memory footprint remains stable. The current implementation is likely keeping historical metric data that should be discarded once a reader has accessed it.

Verification: After fixing the storage cleanup logic, the memory growth during 10,000 iterations with only one active reader should remain under 2000 bytes, confirming that old data is properly released.

Rerunning to test.

@bobstrecansky

Copy link
Copy Markdown
Contributor

Looks like it might have just been a GHA flake, merging.

@bobstrecansky
bobstrecansky merged commit 086ec77 into open-telemetry:main May 28, 2026
17 of 18 checks passed
@Devansh1093 Devansh1093 mentioned this pull request Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants