Skip to content

Commit e33b254

Browse files
authored
chore(reporting): adds b3:0 header to the reporting call to avoid tracing from mesh sidecars. (#179)
1 parent 26a217b commit e33b254

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/Zipkin/Reporters/Http/ClientFactory.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@
77
interface ClientFactory
88
{
99
/**
10-
* @param array $options
10+
* @param array $options the options for HTTP call:
11+
*
12+
* <code>
13+
* $options = [
14+
* 'endpoint_url' => 'http://myzipkin:9411/api/v2/spans', // the reporting url for zipkin server
15+
* 'headers' => ['X-API-Key' => 'abc123'] // the additional headers to be included in the request
16+
* 'timeout' => 10, // the timeout for the request in seconds
17+
* ];
18+
* </code>
19+
*
1120
* @return callable(string):void
1221
*/
1322
public function build(array $options): callable;

src/Zipkin/Reporters/Http/CurlFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static function create(): self
2929
/**
3030
* {@inheritdoc}
3131
*/
32-
public function build(array $options = []): callable
32+
public function build(array $options): callable
3333
{
3434
/**
3535
* @param string $payload
@@ -50,6 +50,7 @@ public function build(array $options = []): callable
5050
$requiredHeaders = [
5151
'Content-Type' => 'application/json',
5252
'Content-Length' => \strlen($payload),
53+
'b3' => '0',
5354
];
5455
$additionalHeaders = $options['headers'] ?? [];
5556
$headers = \array_merge($additionalHeaders, $requiredHeaders);

tests/Integration/Reporters/Http/CurlFactoryTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace ZipkinTests\Integration\Reporters\Http;
44

5-
use HttpTest\HttpTestServer;
6-
use Psr\Http\Message\RequestInterface;
7-
use Psr\Http\Message\ResponseInterface;
8-
use RuntimeException;
95
use Zipkin\Reporters\Http\CurlFactory;
6+
use RuntimeException;
7+
use Psr\Http\Message\ResponseInterface;
8+
use Psr\Http\Message\RequestInterface;
109
use PHPUnit\Framework\TestCase;
10+
use HttpTest\HttpTestServer;
1111

1212
/**
1313
* @group ignore-windows
@@ -22,6 +22,7 @@ public function testHttpReportingSuccess()
2222
function (RequestInterface $request, ResponseInterface &$response) use ($t) {
2323
$t->assertEquals('POST', $request->getMethod());
2424
$t->assertEquals('application/json', $request->getHeader('Content-Type')[0]);
25+
$t->assertEquals('0', $request->getHeader('b3')[0]);
2526
$response = $response->withStatus(202);
2627
}
2728
);

0 commit comments

Comments
 (0)