Skip to content

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

Closed
dmitryax wants to merge 1 commit intoopen-telemetry:mainfrom
dmitryax:context-marshaling-4
Closed

[exporterhelper] Preserve request span context in the persistent queue#13176
dmitryax wants to merge 1 commit intoopen-telemetry:mainfrom
dmitryax:context-marshaling-4

Conversation

@dmitryax
Copy link
Copy Markdown
Member

@dmitryax dmitryax commented Jun 7, 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

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 7, 2025

Codecov Report

Attention: Patch coverage is 60.51502% with 92 lines in your changes missing coverage. Please review.

Project coverage is 91.28%. Comparing base (d800ad3) to head (bf58132).
Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
...exporterhelper/internal/persistentqueue/meta.pb.go 21.00% 77 Missing and 2 partials ⚠️
...xporterhelper/internal/persistentqueue/encoding.go 89.28% 8 Missing and 4 partials ⚠️
...rterhelper/internal/queuebatch/persistent_queue.go 90.00% 0 Missing and 1 partial ⚠️

❌ Your patch status has failed because the patch coverage (60.51%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13176      +/-   ##
==========================================
- Coverage   91.28%   91.28%   -0.01%     
==========================================
  Files         510      512       +2     
  Lines       28725    28844     +119     
==========================================
+ Hits        26223    26330     +107     
- Misses       1988     1996       +8     
- Partials      514      518       +4     

☔ 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-4 branch from 7a8a355 to bf58132 Compare June 7, 2025 05:58
Copy link
Copy Markdown
Member Author

@dmitryax dmitryax Jun 7, 2025

Choose a reason for hiding this comment

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

I had to move the persistentqueue package to be able to call NewEncoder from exporterhelper

Copy link
Copy Markdown
Contributor

@jmacd jmacd left a comment

Choose a reason for hiding this comment

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

I'm glad we're adding this feature.

My only regret is to see a new bespoke encoding be crafted here--I would prefer to see a human-readable (e.g.., JSON) or a protobuf-readable structure as opposed to a new magic number.

featuregate.WithRegisterDescription("controls whether context should be stored alongside requests in the persistent queue"),
)

type Encoding[T any] interface {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Alternative to this (not sure if this is a good idea) is to rely on the transform function and save the incoming context?

Copy link
Copy Markdown
Member Author

@dmitryax dmitryax Jun 9, 2025

Choose a reason for hiding this comment

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

@bogdandrutu, do you mean putting this information in the signal payload itself? Like under a special attribute resource attribute?

Another option can be having another protobuf wrapper specifically for the persistent queue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think is better to pass context to encoding though, if we are ok with this breaking change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ah yes, I investigated this approach with my initial PR but it seemed to make more sense to store it downstream of the individual request types (would need to be added to each request type including future signals)

Copy link
Copy Markdown
Contributor

@jackgopack4 jackgopack4 left a comment

Choose a reason for hiding this comment

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

yes this makes sense especially using the libraries like otel/propagation

# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
Currently, it is behind the exporter.PersistRequestContext feature gate, which can be enabled by adding
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

since this one is the user chloggen, it may makes sense to add a comment as to what this enables (consistent internal telemetry/span links when using persistentqueue)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Makes sense. Submitted #13217

req, err := re.requestEncoding.Unmarshal(b)
return context.Background(), req, err
}
ctx := tracePropagator.Extract(context.Background(), &bytesMapCarrier{bytesMap: bm})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this propagation library is exactly what I should have used, will note going forward

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why separate file from encoding_test.go?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It provides test utilities, not tests

// Marshal is a function that can marshal a request into bytes.
Marshal(T) ([]byte, error)
// Marshal is a function that can marshal a request and its context into bytes.
Marshal(context.Context, T) ([]byte, error)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

since exporterhelper is still beta version, it's not a problem modifying the API like this, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. This interface is marked as experimental

Copy link
Copy Markdown
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.

LGTM, need a big rebase, but should get simpler this PR.

@dmitryax
Copy link
Copy Markdown
Member Author

dmitryax commented Jun 11, 2025

@bogdandrutu @jmacd here is another approach that doesn't involve the custom encoding but introduces new public module pdata/xpdata/request which provides access to the pdata protobuf to built a wrapper on top of it #13188

@dmitryax
Copy link
Copy Markdown
Member Author

Closing in favor of #13188

@dmitryax dmitryax closed this Jun 16, 2025
github-merge-queue Bot pushed a commit that referenced this pull request Jun 16, 2025
#13188)

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 deleted the context-marshaling-4 branch June 21, 2025 02:04
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

4 participants