Skip to content

Add lazy-transformer to KeyClassifier for deferred header decoding#11466

Open
amarziali wants to merge 1 commit into
masterfrom
andrea.marziali/propagators-transform
Open

Add lazy-transformer to KeyClassifier for deferred header decoding#11466
amarziali wants to merge 1 commit into
masterfrom
andrea.marziali/propagators-transform

Conversation

@amarziali
Copy link
Copy Markdown
Contributor

What does this do

Adds a default generic method to AgentPropagation.KeyClassifier:

default <T> boolean accept(String key, T value, Function<T, String> transformer)

The default applies the transformer eagerly and delegates to accept(String, String), so existing classifiers need no changes.

Motivation

Some carriers store header values in raw form (e.g. byte[]) and have to convert them to strings before calling accept. Right now that conversion happens for every header, including the ones the classifier immediately ignores.

An example is kafka that's decoding into base64 all the headers without knowing if it's needed.

This overload lets callers pass the raw value and a conversion function. A classifier that rejects unknown keys early never pays for the conversion at all.

The concrete follow-up is the Kafka TextMapExtractAdapter, where Base64-decoding all message headers is wasteful and currently throws IllegalArgumentException on non-Base64 input. That fix comes in a separate PR.

Additional Notes

Contributor Checklist

  • Format the title according to the contribution guidelines
  • Assign the type: and (comp: or inst:) labels in addition to any other useful labels
  • Avoid using close, fix, or any linking keywords when referencing an issue
    Use solves instead, and assign the PR milestone to the issue
  • Update the CODEOWNERS file on source file addition, migration, or deletion
  • Update public documentation with any new configuration flags or behaviors
  • Add your completed PR to the merge queue by commenting /merge. You can also:
    • Customize the commit message associated with the merge with /merge --commit-message "..."
    • Remove your PR from the merge queue with /merge -c
    • Skip all merge queue checks with /merge -f --reason "reason"; please use this judiciously, as some checks do not run at the PR-level
    • Get more information in this doc

Jira ticket: [PROJ-IDENT]

@amarziali amarziali requested review from a team as code owners May 27, 2026 09:52
@amarziali amarziali requested review from mcculls and mtoffl01 and removed request for a team May 27, 2026 09:52
@amarziali amarziali added type: enhancement Enhancements and improvements comp: context propagation Trace context propagation labels May 27, 2026
Copy link
Copy Markdown
Contributor

@sarahchen6 sarahchen6 left a comment

Choose a reason for hiding this comment

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

Cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: context propagation Trace context propagation type: enhancement Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants