Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 573d5fd

Browse files
authored
Propagator is responsible for injecting, not the RequestHandler (#108)
1 parent fb8bfc8 commit 573d5fd

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/Trace/Propagator/HttpHeaderPropagator.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,13 @@ public function extract($headers)
7676
public function inject(SpanContext $context, $container)
7777
{
7878
$header = str_replace('_', '-', preg_replace('/^HTTP_/', '', $this->header));
79-
$container[$header] = $this->formatter->serialize($context);
80-
return $container;
79+
$value = $this->formatter->serialize($context);
80+
if (!headers_sent()) {
81+
header("$header: $value");
82+
}
83+
return [
84+
$header => $value
85+
];
8186
}
8287

8388
/**

src/Trace/RequestHandler.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@ public function __construct(
9393
// If the request was provided with a trace context header, we need to send it back with the response
9494
// including whether the request was sampled or not.
9595
if ($spanContext->fromHeader()) {
96-
if (!headers_sent()) {
97-
foreach ($propagator->inject($spanContext, $headers) as $header => $value) {
98-
header("$header: $value");
99-
}
100-
}
96+
$propagator->inject($spanContext, []);
10197
}
10298

10399
$this->tracer = $spanContext->enabled()

0 commit comments

Comments
 (0)