Skip to content

Instantly share code, notes, and snippets.

@jaytaph
Created March 6, 2018 10:05
Show Gist options
  • Save jaytaph/1aebce583d657df284dccf7afd38ea3f to your computer and use it in GitHub Desktop.
Save jaytaph/1aebce583d657df284dccf7afd38ea3f to your computer and use it in GitHub Desktop.
<?php
namespace App\Services;
use Psr\Http\Message\RequestInterface;
use Zipkin\Propagation\RequestHeaders;
use Zipkin\Tracing;
class ZipkinGuzzleMiddleware {
/**
* ZipkinGuzzleMiddleware constructor.
*/
public function __construct(Tracing $tracing)
{
$this->tracing = $tracing;
}
/**
* @param callable $handler
* @return \Closure
*/
function __invoke(callable $handler)
{
return function (RequestInterface $request, array $options) use ($handler) {
$injector = $this->tracing->getPropagation()->getInjector(new RequestHeaders());
$context = $this->tracing->getTracer()->getCurrentSpan()->getContext();
$injector($context, $request);
return $handler($request, $options);
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment