Skip to content

Psr7HeaderSetter

The outbound counterpart to Psr7HeaderGetter: adapts a PSR-7 request to OpenTelemetry’s propagation setter so TraceContextPropagator::inject() can write traceparent/tracestate onto an outgoing request.

This was previously unbuilt for want of an HTTP client to inject into.

The carrier is passed and reassigned by reference because PSR-7 messages are immutable — withHeader() returns a new instance — so inject()’s &$carrier contract is exactly what lets the mutated request propagate back to the caller.

Like Psr7HeaderGetter, this implements an open-telemetry/context interface directly, so it is only ever referenced behind a Trace::enabled() gate (in HttpClient), at which point the SDK is installed and the interface exists.

final class Psr7HeaderSetter implements PropagationSetterInterface

ImplementsPropagationSetterInterface
SourcePsr7HeaderSetter.php
MethodDescription
set(MessageInterface &$carrier, string $key, string $value): voidSet the value for a given key on the associated carrier.

public function set(MessageInterface &$carrier, string $key, string $value): void

Set the value for a given key on the associated carrier.

ParameterTypeDescription
$carrierMessageInterface
$keystring
$valuestring