-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[exporterhelper][queuebatcher] Context value propagation during batching - approach #2 #13460
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
Conversation
5e60afe
to
a492600
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #13460 +/- ##
==========================================
- Coverage 92.52% 92.50% -0.03%
==========================================
Files 630 630
Lines 35535 35542 +7
==========================================
- Hits 32878 32877 -1
- Misses 2113 2119 +6
- Partials 544 546 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to be a good low-level interface allowing future customization. Would you develop this feature into an extension interface, or a configurable feature in the exporterhelper settings, somehow?
In the scenario I remember wanting this feature, we would copy all the partition metadata key:values as context keys for the batch. Maybe that's overly simple, but I would expect users to get something in a .yaml
they can configure to make an access token both the partition key and an export key (the way include_metadata
does for receivers).
Thanks! I’ve just updated the PR so that |
2eac887
to
710bbe7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. It would help me understand this a bit more to work through an example. I believe we are aiming to complete the replacement of batchprocessor implied by #8122, and it means implementing the metadata_keys
feature one way or another. I see that this PR is half of what we need. I think I want to see an option in the config that replaces metadata_keys
, basically.
The reason I mention extension interfaces (see also #13263), is that probably metadata_keys
functionality can be implemented as a "PartitionerExtension", it would have the legacy configuration from the batch processor https://github.com/open-telemetry/opentelemetry-collector/blob/main/processor/batchprocessor/README.md#batching-and-client-metadata and be configured as in
extensions:
batchpartitioner:
metadata_keys:
- tenant_id
metadata_cardinality_limit: 10
and in the exporter batcher:
exporters:
otlp:
sending_queue:
batch:
// ...
partitioner: batchpartitioner # refers to extension
In the exporterhelper setup code, you'll inspect for a partitioner
setting and probe the Host
for the extension. The extension will provide a MergeCtx
interface.
ItemsSizer request.Sizer[T] | ||
BytesSizer request.Sizer[T] | ||
Partitioner Partitioner[T] | ||
MergeCtx func(context.Context, context.Context) context.Context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting -- I agree this is a good place for programmable configuration. I expect there is a default implementation that mostly just works for most exporters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am leaning towards the most conservative default behavior — dropping everything — which also aligns with the current behavior. I’d love to hear your thoughts on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I assume that without the batcher, context otherwise passes through the exporterhelper path so that extensions like https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/extension/headerssetterextension work.
@jmacd Thanks for the input — this helps clarify a lot of things. I do think there’s still more to figure out around how to expose both When I designed the partitioning and merge context, I started with the assumption that users might want to pull arbitrary data out of the pdata or context — not just metadata. Under this assumption, Of course, this is all based on the assumption that users will want to work with more than just metadata. From use cases I’ve seen, the assumptions holds true, as people are interested in:
So I am yet not confident that metadata is unique enough to be the default behavior. That said, you likely have more insight into these patterns, so if you have suggestions for a better approach, I’m open to hearing them. |
244c305
to
0b80e40
Compare
qb.currentBatch.done = append(qb.currentBatch.done, done) | ||
qb.currentBatch.ctx = contextWithMergedLinks(qb.currentBatch.ctx, ctx) | ||
|
||
mergedCtx := context.Background() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't understand the check failure. 👎
ItemsSizer request.Sizer[T] | ||
BytesSizer request.Sizer[T] | ||
Partitioner Partitioner[T] | ||
MergeCtx func(context.Context, context.Context) context.Context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I assume that without the batcher, context otherwise passes through the exporterhelper path so that extensions like https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/extension/headerssetterextension work.
LGTM @sfc-gh-sili please resolve the CI failures |
c8ead13
to
e754f81
Compare
e754f81
to
2011f89
Compare
After some offline discussions, I propose we aim at providing the following in OTLP exporter
All these features should be configurable with a yaml file so OTLP exporter can be used out-of-the-box. In alignment with this goal, we will make a couple of adjustments to the programmatic API
Thanks @jmacd and @bogdandrutu for the great input! |
@sfc-gh-sili Shouldn't |
@sfc-gh-sili I have created #13742 PR to expose the |
Description
This PR provides a solution to propagate context values across batching. This is particularly useful in scenarios where context carries important metadata—such as authentication tokens.
New API
A new API has been added to support this functionality:
By supplying a custom mergeCtx function, users can control how context values are preserved or combined—for example, by selectively copying specific keys, merging metadata, or keeping the larger value.
Note:
context.Context
returned from the above function should not overrideValue()
function.Default Behavior
If mergeCtx is not provided (i.e., left as nil), the batching system defaults to a conservative behavior: no context values are retained from the original incoming contexts. Users who need context propagation must explicitly opt in by defining and supplying a mergeCtx function.
Link to tracking issue
#13320
Testing
batch_context_test.go
checks themergeCtx
does not interfere with span linkpartition_batcher_test.go
checksmergeCtx=nil
works properlyDocumentation