[Api] Optimize TraceContextPropagator#7060
[Api] Optimize TraceContextPropagator#7060martincostello wants to merge 7 commits intoopen-telemetry:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7060 +/- ##
==========================================
- Coverage 89.04% 89.02% -0.02%
==========================================
Files 271 271
Lines 12935 13068 +133
==========================================
+ Hits 11518 11634 +116
- Misses 1417 1434 +17
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Pull request overview
Optimizes TraceContextPropagator.Extract() to reduce overhead during context extraction (particularly avoiding LINQ and using span-based parsing), and expands test coverage around carrier value shapes.
Changes:
- Reworked
TraceContextPropagator.Extract()to avoid LINQ and add helper paths for “single value” extraction. - Reimplemented tracestate extraction to support
IEnumerable<string>directly, including an optimized single-header parsing path. - Added/updated unit tests to cover
IReadOnlyList<string>and generalIEnumerable<string>carrier values, plus new tracestate parsing cases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/OpenTelemetry.Api/Context/Propagation/TraceContextPropagator.cs | Removes LINQ from extraction, adds helpers, and introduces span-based tracestate parsing with an IEnumerable<string> overload. |
| test/OpenTelemetry.Tests/Trace/Propagation/TraceContextPropagatorTests.cs | Updates getters/assertions and adds new tests validating extraction/parsing behavior for additional carrier value types. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Need to cross-check this against #6161/GHSA-8785-wc3w-h8q6 as well to make sure the issues there aren't re-introduced. |
Prompt
Response
Test code
|
This comment was marked as resolved.
This comment was marked as resolved.
Refactor based on suggestions from Copilot to improve throughput and reduce allocations by avoiding LINQ.
Extend test coverage for `TraceContextPropagator`.
Address Copilot code review feedback.
Add test that appears to relate to GHSA-8785-wc3w-h8q6, although it passes before and after that change was reverted.
Fix-up the regression test so it actually detects the issue caused by open-telemetry#5749.
Add missing field.
c509aa3 to
d32ff17
Compare
Changes
While looking at some profiles for an OTel instrumented application of mine, I noticed that
TraceContextPropagator.Extract()came up in the top 5 OTel-related samples.This makes some improvements, mostly written by Copilot, by:
Benchmark results
Copilot Summary
For the 6
TraceContextPropagatorBenchmarks.Extractcases, this PR is better in every case: lower mean execution time and lower allocations.mainMeanpr-7060MeanmainAllocpr-7060AllocTakeaway
The benchmark suite:
99.8%
The largest wins are in the
MembersCount = 4scenarios and in theLongListMember = Truecases with previously high allocations.Expand to see
mainThis PR
Merge requirement checklist
Unit tests added/updatedAppropriateCHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)