Tolerance\Bridge\Guzzle\Tracer\SpanFactory\GuzzleMessageSpanFactory::fromIncomingResponse PHP Метод

fromIncomingResponse() публичный Метод

public fromIncomingResponse ( GuzzleHttp\Message\RequestInterface $originalRequest, GuzzleHttp\Message\ResponseInterface $response = null ) : Span
$originalRequest GuzzleHttp\Message\RequestInterface
$response GuzzleHttp\Message\ResponseInterface
Результат Tolerance\Tracer\Span\Span
    public function fromIncomingResponse(RequestInterface $originalRequest, ResponseInterface $response = null)
    {
        $span = $originalRequest->getHeader('X-B3-SpanId');
        $trace = $originalRequest->getHeader('X-B3-TraceId');
        if (empty($span) || empty($trace)) {
            throw new \InvalidArgumentException('Unable to find the original request properties');
        }
        return new Span(Identifier::fromString($span), $this->getName($originalRequest), Identifier::fromString($trace), [new Annotation(Annotation::CLIENT_RECEIVE, $this->clock->microseconds(), $this->endpointResolver->resolve())], [new BinaryAnnotation('http.status', $response !== null ? $response->getStatusCode() : 0, BinaryAnnotation::TYPE_INTEGER_16)]);
    }

Usage Example

Пример #1
0
 /**
  * @param RequestInterface $request
  * @param ResponseInterface|null $response
  */
 public function onEnd(RequestInterface $request, ResponseInterface $response = null)
 {
     try {
         $span = $this->guzzleMessageSpanFactory->fromIncomingResponse($request, $response);
     } catch (\InvalidArgumentException $e) {
         return;
     }
     $this->tracer->trace([$span]);
 }