Skip to content

[exporterhelper] Preserve request span context in the persistent queue #13188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 16, 2025

Conversation

dmitryax
Copy link
Member

@dmitryax dmitryax commented Jun 11, 2025

This change makes it possible to propagate span context through the Collector with enable persistent queue.

Currently, it is behind the exporter.PersistRequestContext feature gate, which can be enabled by adding --feature-gates=exporter.PersistRequestContext to the collector command line. An exporter buffer stored by a previous version of the collector (or by a collector with the feature gate disabled) can be read by a newer collector with the feature enabled. However, the reverse is not supported: a buffer stored by a newer collector with the feature enabled cannot be read by an older collector (or by a collector with the feature gate disabled).

Resolves #11740

Alternative to #13176 that doesn't involve custom encoder but exposes new public module pdata/xpdata/request

The actual change set is pretty small. Most of the code is generated protobuf

@dmitryax dmitryax force-pushed the context-marshaling-5 branch 6 times, most recently from 45a9ea4 to 2a88aec Compare June 11, 2025 05:19
@dmitryax dmitryax force-pushed the context-marshaling-5 branch 2 times, most recently from e6a73fa to 2dab304 Compare June 11, 2025 05:37
Copy link

codecov bot commented Jun 11, 2025

Codecov Report

Attention: Patch coverage is 95.26316% with 9 lines in your changes missing coverage. Please review.

Project coverage is 91.53%. Comparing base (1921e21) to head (efcbe18).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
exporter/exporterhelper/logs.go 88.23% 2 Missing ⚠️
exporter/exporterhelper/metrics.go 88.23% 2 Missing ⚠️
exporter/exporterhelper/traces.go 88.23% 2 Missing ⚠️
...xporter/exporterhelper/xexporterhelper/profiles.go 88.23% 2 Missing ⚠️
.../exporterhelper/internal/queue/persistent_queue.go 90.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13188      +/-   ##
==========================================
+ Coverage   91.27%   91.53%   +0.26%     
==========================================
  Files         514      520       +6     
  Lines       28857    28918      +61     
==========================================
+ Hits        26340    26471     +131     
+ Misses       1998     1929      -69     
+ Partials      519      518       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@dmitryax dmitryax force-pushed the context-marshaling-5 branch 2 times, most recently from 82fe8ac to 864743e Compare June 11, 2025 16:50
@dmitryax dmitryax marked this pull request as draft June 12, 2025 01:03
@dmitryax dmitryax force-pushed the context-marshaling-5 branch 3 times, most recently from ff34a4c to 63bfbd1 Compare June 12, 2025 15:10
@dmitryax dmitryax marked this pull request as ready for review June 12, 2025 15:10
@dmitryax dmitryax force-pushed the context-marshaling-5 branch 2 times, most recently from c0525c3 to 3ab99cb Compare June 13, 2025 21:10
@dmitryax dmitryax force-pushed the context-marshaling-5 branch 4 times, most recently from 04af594 to 572e5c9 Compare June 13, 2025 22:49
@dmitryax dmitryax force-pushed the context-marshaling-5 branch from 572e5c9 to a057af0 Compare June 13, 2025 23:30
Copy link
Member

@bogdandrutu bogdandrutu left a comment

Choose a reason for hiding this comment

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

The only downside is that I don't see how to extend this to preserve other parts from the context (configured somehow).

Let's merge and iterate over a possible version to have instead of context a map[string]string? Or maybe add options to Marshal/Unmarshal and accept some helpers that will return "key/value" and accept "key/value" when re-constructing the context?

message RequestContext {
// Span context encoded using W3C trace context format.
// This map typically includes "traceparent" and optionally "tracestate" keys.
map<string, string> span_context_map = 1;
Copy link
Member

Choose a reason for hiding this comment

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

Map is pretty expensive, can keep a list of message {key, value} since this is not exposed to the users.

@github-actions github-actions bot requested a review from bogdandrutu June 16, 2025 03:35
@dmitryax dmitryax added this pull request to the merge queue Jun 16, 2025
Merged via the queue into open-telemetry:main with commit 3ef58fd Jun 16, 2025
59 checks passed
@dmitryax dmitryax deleted the context-marshaling-5 branch June 16, 2025 05:01
github-merge-queue bot pushed a commit that referenced this pull request Jun 17, 2025
…13216)

Resolves
#13188 (review)

This also required moving to gogoproto to reuse existing
opentelemetry.proto.common.v1.KeyValue message.

Benchmarks:
```
goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/collector/pdata/xpdata/request
cpu: Apple M1 Max

before:
BenchmarkEncodeDecodeContext-10    	  519790	      2278 ns/op	    1376 B/op	      22 allocs/op

after:
BenchmarkEncodeDecodeContext-10    	  747158	      1600 ns/op	     661 B/op	      18 allocs/op
```
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.

Context through persistent queue
3 participants