forked from open-telemetry/opentelemetry-php
-
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.
Add
TextMapPropagator
to instrumentation context (open-telemetry#1401)
- Loading branch information
Showing
6 changed files
with
96 additions
and
5 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,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Propagation; | ||
|
||
use Closure; | ||
use OpenTelemetry\Context\ContextInterface; | ||
use OpenTelemetry\Context\Propagation\PropagationGetterInterface; | ||
use OpenTelemetry\Context\Propagation\PropagationSetterInterface; | ||
use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class LateBindingTextMapPropagator implements TextMapPropagatorInterface | ||
{ | ||
|
||
/** | ||
* @param TextMapPropagatorInterface|Closure(): TextMapPropagatorInterface $propagator | ||
*/ | ||
public function __construct( | ||
private TextMapPropagatorInterface|Closure $propagator, | ||
) { | ||
} | ||
|
||
public function fields(): array | ||
{ | ||
if (!$this->propagator instanceof TextMapPropagatorInterface) { | ||
$this->propagator = ($this->propagator)(); | ||
} | ||
|
||
return $this->propagator->fields(); | ||
} | ||
|
||
public function inject(mixed &$carrier, ?PropagationSetterInterface $setter = null, ?ContextInterface $context = null): void | ||
{ | ||
if (!$this->propagator instanceof TextMapPropagatorInterface) { | ||
$this->propagator = ($this->propagator)(); | ||
} | ||
|
||
$this->propagator->inject($carrier, $setter, $context); | ||
} | ||
|
||
public function extract($carrier, ?PropagationGetterInterface $getter = null, ?ContextInterface $context = null): ContextInterface | ||
{ | ||
if (!$this->propagator instanceof TextMapPropagatorInterface) { | ||
$this->propagator = ($this->propagator)(); | ||
} | ||
|
||
return $this->propagator->extract($carrier, $getter, $context); | ||
} | ||
} |
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