Skip to content

Commit

Permalink
chore(reporting): adds b3:0 header to the reporting call to avoid tra…
Browse files Browse the repository at this point in the history
…cing from mesh sidecars. (#179)
  • Loading branch information
jcchavezs authored Sep 15, 2020
1 parent 26a217b commit e33b254
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
11 changes: 10 additions & 1 deletion src/Zipkin/Reporters/Http/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@
interface ClientFactory
{
/**
* @param array $options
* @param array $options the options for HTTP call:
*
* <code>
* $options = [
* 'endpoint_url' => 'http://myzipkin:9411/api/v2/spans', // the reporting url for zipkin server
* 'headers' => ['X-API-Key' => 'abc123'] // the additional headers to be included in the request
* 'timeout' => 10, // the timeout for the request in seconds
* ];
* </code>
*
* @return callable(string):void
*/
public function build(array $options): callable;
Expand Down
3 changes: 2 additions & 1 deletion src/Zipkin/Reporters/Http/CurlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function create(): self
/**
* {@inheritdoc}
*/
public function build(array $options = []): callable
public function build(array $options): callable
{
/**
* @param string $payload
Expand All @@ -50,6 +50,7 @@ public function build(array $options = []): callable
$requiredHeaders = [
'Content-Type' => 'application/json',
'Content-Length' => \strlen($payload),
'b3' => '0',
];
$additionalHeaders = $options['headers'] ?? [];
$headers = \array_merge($additionalHeaders, $requiredHeaders);
Expand Down
9 changes: 5 additions & 4 deletions tests/Integration/Reporters/Http/CurlFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace ZipkinTests\Integration\Reporters\Http;

use HttpTest\HttpTestServer;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use RuntimeException;
use Zipkin\Reporters\Http\CurlFactory;
use RuntimeException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\RequestInterface;
use PHPUnit\Framework\TestCase;
use HttpTest\HttpTestServer;

/**
* @group ignore-windows
Expand All @@ -22,6 +22,7 @@ public function testHttpReportingSuccess()
function (RequestInterface $request, ResponseInterface &$response) use ($t) {
$t->assertEquals('POST', $request->getMethod());
$t->assertEquals('application/json', $request->getHeader('Content-Type')[0]);
$t->assertEquals('0', $request->getHeader('b3')[0]);
$response = $response->withStatus(202);
}
);
Expand Down

0 comments on commit e33b254

Please sign in to comment.