forked from open-telemetry/opentelemetry-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Francesco Guardiani <[email protected]>
- Loading branch information
1 parent
fffc831
commit 4267202
Showing
4 changed files
with
123 additions
and
6 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
...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,69 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.context.propagation; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* A builder for configuring an {@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<>(); | ||
} | ||
|
||
/** | ||
* Add a {@link TextMapPropagator} to be used only to extract the context. | ||
*/ | ||
public CompositeTextMapPropagatorBuilder extractor(TextMapPropagator propagator) { | ||
this.extractors.add(propagator); | ||
return this; | ||
} | ||
|
||
/** | ||
* Add a {@link TextMapPropagator} to be used only to inject the context. | ||
*/ | ||
public CompositeTextMapPropagatorBuilder injector(TextMapPropagator propagator) { | ||
this.injectors.add(propagator); | ||
return this; | ||
} | ||
|
||
/** | ||
* Add a {@link TextMapPropagator} to be used both to extract and inject the context. | ||
*/ | ||
public CompositeTextMapPropagatorBuilder propagator(TextMapPropagator 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.injectors.add(TextMapPropagator.noop()); | ||
} | ||
if (this.extractors.isEmpty()) { | ||
this.extractors.add(TextMapPropagator.noop()); | ||
} | ||
|
||
return new MultiTextMapPropagator(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