Created
March 6, 2018 10:05
-
-
Save jaytaph/1aebce583d657df284dccf7afd38ea3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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