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

Commit 2bbf046

Browse files
authored
Fix Guzzle SpanContext propagation (#170)
* Guzzle headers that are set should be dasherized versions * Inject http headers with dasherized version
1 parent 5f7021f commit 2bbf046

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/Trace/Propagator/HttpHeaderPropagator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function extract($headers)
7575
*/
7676
public function inject(SpanContext $context, $container)
7777
{
78-
$header = str_replace('_', '-', preg_replace('/^HTTP_/', '', $this->header));
78+
$header = $this->key();
7979
$value = $this->formatter->serialize($context);
8080
if (!headers_sent()) {
8181
header("$header: $value");
@@ -102,6 +102,6 @@ public function formatter()
102102
*/
103103
public function key()
104104
{
105-
return $this->header;
105+
return str_replace('_', '-', preg_replace('/^HTTP_/', '', $this->header));
106106
}
107107
}

tests/unit/Trace/Integrations/Guzzle/EventSubscriberTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public function testAddsSpanContextHeader()
7272

7373
$request = $history->getLastRequest();
7474
$headers = $request->getHeaders();
75-
$this->assertArrayHasKey('HTTP_X_CLOUD_TRACE_CONTEXT', $headers);
76-
$this->assertRegExp('/[0-9a-f]+\/4660;o=1/', $headers['HTTP_X_CLOUD_TRACE_CONTEXT'][0]);
75+
$this->assertArrayHasKey('X-CLOUD-TRACE-CONTEXT', $headers);
76+
$this->assertRegExp('/[0-9a-f]+\/4660;o=1/', $headers['X-CLOUD-TRACE-CONTEXT'][0]);
7777

7878
$rt->onExit();
7979
}

tests/unit/Trace/Integrations/Guzzle/MiddlewareTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testAddsSpanContextHeader()
6363
$req = $this->prophesize(RequestInterface::class);
6464
$req->getMethod()->willReturn('GET')->shouldBeCalled();
6565
$req->getUri()->willReturn('/')->shouldBeCalled();
66-
$req->withHeader('HTTP_X_CLOUD_TRACE_CONTEXT', Argument::that(function ($val) {
66+
$req->withHeader('X-CLOUD-TRACE-CONTEXT', Argument::that(function ($val) {
6767
return preg_match('/[0-9a-f]+\/4660;o=1/', $val);
6868
}))->willReturn($req->reveal())->shouldBeCalled();
6969
$request = $req->reveal();

0 commit comments

Comments
 (0)