-
Notifications
You must be signed in to change notification settings - Fork 848
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
Now MultiTextMapPropagator
allows to select extractors and injectors separately
#3366
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...src/main/java/io/opentelemetry/context/propagation/CompositeTextMapPropagatorBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.context.propagation; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* A builder for configuring a {@link TextMapPropagator} specifying which propagators should be used | ||
* for extracting the context and which should be used for injecting the context. | ||
*/ | ||
public final class CompositeTextMapPropagatorBuilder { | ||
|
||
private final List<TextMapPropagator> extractors; | ||
private final List<TextMapPropagator> injectors; | ||
|
||
/** | ||
* Package protected to disallow direct initialization. | ||
* | ||
* @see TextMapPropagator#builder() | ||
*/ | ||
CompositeTextMapPropagatorBuilder() { | ||
this.extractors = new ArrayList<>(); | ||
this.injectors = new ArrayList<>(); | ||
} | ||
|
||
/** Adds a {@link TextMapPropagator} to be used only when extracting context. */ | ||
public CompositeTextMapPropagatorBuilder addExtractor(TextMapPropagator propagator) { | ||
Objects.requireNonNull(propagator, "propagator"); | ||
this.extractors.add(propagator); | ||
slinkydeveloper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return this; | ||
} | ||
|
||
/** Adds a {@link TextMapPropagator} to be used only when injecting context. */ | ||
public CompositeTextMapPropagatorBuilder addInjector(TextMapPropagator propagator) { | ||
Objects.requireNonNull(propagator, "propagator"); | ||
this.injectors.add(propagator); | ||
return this; | ||
} | ||
|
||
/** Adds a {@link TextMapPropagator} to be used both when extracting and injecting context. */ | ||
public CompositeTextMapPropagatorBuilder addPropagator(TextMapPropagator propagator) { | ||
Objects.requireNonNull(propagator, "propagator"); | ||
this.injectors.add(propagator); | ||
this.extractors.add(propagator); | ||
return this; | ||
} | ||
|
||
/** | ||
* Returns the built {@link TextMapPropagator}. | ||
* | ||
* @see CompositeTextMapPropagatorBuilder | ||
*/ | ||
public TextMapPropagator build() { | ||
if (this.injectors.isEmpty() && this.extractors.isEmpty()) { | ||
return NoopTextMapPropagator.getInstance(); | ||
} | ||
|
||
return new CompositeTextMapPropagator(this.extractors, this.injectors); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
Comparing source compatibility of against | ||
No changes. | ||
+++ NEW CLASS: PUBLIC(+) FINAL(+) io.opentelemetry.context.propagation.CompositeTextMapPropagatorBuilder (not serializable) | ||
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. | ||
+++ NEW SUPERCLASS: java.lang.Object | ||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.context.propagation.CompositeTextMapPropagatorBuilder addExtractor(io.opentelemetry.context.propagation.TextMapPropagator) | ||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.context.propagation.CompositeTextMapPropagatorBuilder addInjector(io.opentelemetry.context.propagation.TextMapPropagator) | ||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.context.propagation.CompositeTextMapPropagatorBuilder addPropagator(io.opentelemetry.context.propagation.TextMapPropagator) | ||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.context.propagation.TextMapPropagator build() | ||
***! MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.context.propagation.TextMapPropagator (not serializable) | ||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0 | ||
+++! NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.context.propagation.CompositeTextMapPropagatorBuilder builder() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is this right? The fields are only from the injectors? I think this might need to be the union of the extractors and injectors, rather than just the injectors.
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.
That's not what I understood from the
fields()
javadoc, it rather seems to me that method is used only when writing the context back to the wire, and not while extracting it...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 think the javadoc provides that as a usage (to clear out headers if the header implementation is re-used), but I think
fields()
could also be used by extraction in some cases. I'm honestly not 100% sure what the behavior should be in this case when injection doesn't necessarily match extraction.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 created a spec issue for this, since I don't think I know what the answer should be: open-telemetry/opentelemetry-specification#1809
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 second @jkwatson with this - I know at least one case in instrumentation where
fields
are considered during extraction (seeio.opentelemetry.instrumentation.awslambda.v1_0.TracingRequestStreamHandler
)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.
Please comment on the spec issue. :)
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.
Weighting issues - sub-optimal performance vs actual bug I'd say that keeping all fields still wins. But yeah, spec issue is the proper place to discuss 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.
@kubawach please provide a permalink to your example of TracingRequestStreamHandler, I couldn't find it.
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.
@yurishkuro here you go: https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/ApiGatewayProxyRequest.java
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.
@kubawach thanks. If I am reading this correctly, I wouldn't classify this usage as "on the extract path", and I probably would've implemented that check differently in the first place, the use of fields() to determine "noHttpPropagationNeeded" seems a bit round-about. Here's the exact usage link, for reference:
https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/1b5df6d78a6877dab38f573b44d0358927d1ab3d/instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/ApiGatewayProxyRequest.java#L27