-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added B3Propagator for B3 Single Header (#691)
* Added B3Propagator Class to handle two configurations and storing debug flag in the returned context * Updated B3Propagator extract according to the clarification in the specs; updated test cases
- Loading branch information
1 parent
2457c76
commit 0f30849
Showing
14 changed files
with
1,502 additions
and
325 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\Extension\Propagator\B3; | ||
|
||
use OpenTelemetry\Context\Context; | ||
use OpenTelemetry\Context\ContextKey; | ||
|
||
/** | ||
* @psalm-internal \OpenTelemetry | ||
*/ | ||
final class B3DebugFlagContextKey | ||
{ | ||
private const KEY_NAME = 'OpenTelemetry Context Key B3 Debug Flag'; | ||
|
||
private static ?ContextKey $instance = null; | ||
|
||
public static function instance(): ContextKey | ||
{ | ||
if (self::$instance === null) { | ||
self::$instance = Context::createKey(self::KEY_NAME); | ||
} | ||
|
||
return self::$instance; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\Extension\Propagator\B3; | ||
|
||
use OpenTelemetry\Context\Context; | ||
use OpenTelemetry\Context\Propagation\ArrayAccessGetterSetter; | ||
use OpenTelemetry\Context\Propagation\PropagationGetterInterface; | ||
use OpenTelemetry\Context\Propagation\PropagationSetterInterface; | ||
use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface; | ||
|
||
/** | ||
* B3 is a propagator that supports the specification for the header | ||
* "b3" used for trace context propagation across service boundaries. | ||
* (https://github.com/openzipkin/b3-propagation) | ||
*/ | ||
final class B3Propagator implements TextMapPropagatorInterface | ||
{ | ||
private TextMapPropagatorInterface $propagator; | ||
|
||
private function __construct(TextMapPropagatorInterface $propagator) | ||
{ | ||
$this->propagator = $propagator; | ||
} | ||
|
||
public static function getB3SingleHeaderInstance(): self | ||
{ | ||
static $instance; | ||
|
||
return $instance ??= new self(B3SinglePropagator::getInstance()); | ||
} | ||
public static function getB3MultiHeaderInstance(): self | ||
{ | ||
static $instance; | ||
|
||
return $instance ??= new self(B3MultiPropagator::getInstance()); | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function fields(): array | ||
{ | ||
return $this->propagator->fields(); | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function inject(&$carrier, PropagationSetterInterface $setter = null, Context $context = null): void | ||
{ | ||
$this->propagator->inject($carrier, $setter, $context); | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function extract($carrier, PropagationGetterInterface $getter = null, Context $context = null): Context | ||
{ | ||
$getter ??= ArrayAccessGetterSetter::getInstance(); | ||
$context ??= Context::getCurrent(); | ||
|
||
$b3SingleHeaderContext = B3SinglePropagator::getInstance()->extract($carrier, $getter, $context); | ||
if ($b3SingleHeaderContext !== $context) { | ||
return $b3SingleHeaderContext; | ||
} | ||
|
||
return B3MultiPropagator::getInstance()->extract($carrier, $getter, $context); | ||
} | ||
} |
Oops, something went wrong.