Skip to content

[OpenTelemetry.Api] Avoid Baggage params enumeration - #7697

Merged
martincostello merged 5 commits into
open-telemetry:mainfrom
thomhurst:perf/baggage-params-span
Aug 26, 2026
Merged

martincostello merged 5 commits into
open-telemetry:mainfrom
thomhurst:perf/baggage-params-span

Conversation

@thomhurst

@thomhurst thomhurst commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Changes

Route the existing Baggage.SetBaggage(params KeyValuePair<...>[]) overload
through a private ReadOnlySpan<T> implementation. This avoids boxing the
array enumerator while preserving the arbitrary IEnumerable<T> overload and
public API.

Benchmark

BaggageBenchmarks was run before and after this change using BenchmarkDotNet
0.15.8 on .NET 10.0.11, Windows 11, Intel Core i7-12700K.

Method Items Before After Change Allocated before Allocated after
SetBaggageNoOp 1 8.421 ns 3.425 ns -59.3% 32 B 0 B
SetBaggageNoOp 5 26.470 ns 17.457 ns -34.1% 32 B 0 B
SetBaggageNoOp 20 100.349 ns 73.172 ns -27.1% 32 B 0 B
SetBaggageSingleUpdate 1 36.729 ns 28.870 ns -21.4% 248 B 216 B
SetBaggageSingleUpdate 5 78.342 ns 72.137 ns -7.9% 360 B 328 B
SetBaggageSingleUpdate 20 230.981 ns 209.6 ns -9.3% 808 B 776 B

The 20-item update case was rerun independently because the first post-change
run was noisy (250.342 ns, 33.943 ns standard deviation). The independent
run measured 209.6 ns with 5.21 ns standard deviation.

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • All 17 BaggageTests pass
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • No public API changes

@thomhurst
thomhurst requested a review from a team as a code owner August 25, 2026 19:25
@github-actions

Copy link
Copy Markdown
Contributor

Welcome, contributor! Thank you for your contribution to opentelemetry-dotnet.

Important reminders:

  • Read our Contributing Guidelines.
  • Sign the CLA if you haven't already.
  • Follow the OpenTelemetry Generative AI policy: disclose any AI use in your contribution, and communicate (PR descriptions, review replies) in your own words rather than AI-generated text.
  • Give reviewers at least a few days before pinging them for feedback.
  • If you need help with general setup, development process, or contributor etiquette, ask in #opentelemetry-new-contributors.

@github-actions github-actions Bot added the pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package label Aug 25, 2026
@codecov

codecov Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.55%. Comparing base (0bb4087) to head (8ce2c99).
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #7697   +/-   ##
=======================================
  Coverage   91.55%   91.55%           
=======================================
  Files         321      321           
  Lines       17982    17997   +15     
=======================================
+ Hits        16463    16478   +15     
  Misses       1519     1519           
Flag Coverage Δ
unittests-Project-Experimental 91.62% <100.00%> (-0.02%) ⬇️
unittests-Project-Stable 91.58% <100.00%> (-0.03%) ⬇️

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

Files with missing lines Coverage Δ
src/OpenTelemetry.Api/Baggage.cs 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-08-26 19:02 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Comment thread src/OpenTelemetry.Api/Baggage.cs Resolved
@martincostello
martincostello added this pull request to the merge queue Aug 26, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 26, 2026
@martincostello
martincostello added this pull request to the merge queue Aug 26, 2026
Merged via the queue into open-telemetry:main with commit c059ef6 Aug 26, 2026
79 checks passed
@otelbot

otelbot Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution @thomhurst! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

This was referenced Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants