function it_uses_the_span_name_when_only_one_is_traced(Tracer $decoratedTracer, Stopwatch $stopwatch) { $spans = [new Span(Identifier::fromString('1234'), 'name', Identifier::fromString('1234'))]; $stopwatch->start('trace (name)')->shouldBeCalled(); $stopwatch->stop('trace (name)')->shouldBeCalled(); $this->trace($spans); }
function let(ConsumerInterface $decoratedConsumer, Tracer $tracer, SpanStack $spanStack, AmqpSpanFactory $amqpSpanFactory) { $span = new Span(Identifier::fromString('1234'), 'name', Identifier::fromString('1234')); $amqpSpanFactory->fromReceivedMessage(Argument::type(AMQPMessage::class))->willReturn($span); $amqpSpanFactory->fromConsumedMessage(Argument::type(AMQPMessage::class))->willReturn($span); $this->beConstructedWith($decoratedConsumer, $tracer, $spanStack, $amqpSpanFactory); }
/** * @param RequestInterface $originalRequest * @param ResponseInterface|null $response * * @return 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)]); }
function it_should_add_the_trace_headers(ProducerInterface $decoratedProducer, AmqpSpanFactory $amqpSpanFactory, Tracer $tracer) { $span = new Span(Identifier::fromString('1234'), 'name', Identifier::fromString('trace')); $amqpSpanFactory->fromProducedMessage(Argument::type(AMQPMessage::class))->willReturn($span); $decoratedProducer->publish('', '', Argument::that(function (array $properties) { if (!array_key_exists('application_headers', $properties)) { return false; } $headers = $properties['application_headers']->getNativeData(); return isset($headers['X-B3-SpanId']) && isset($headers['X-B3-TraceId']); }))->shouldBeCalled(); $tracer->trace([$span])->shouldBeCalled(); $this->publish('', ''); }
/** * @param AMQPMessage $message * @param string $header * * @return null|Identifier */ private function getIdentifier(AMQPMessage $message, $header) { if (null !== ($header = $this->getMessageHeader($message, $header))) { return Identifier::fromString($header); } return null; }
function it_uses_the_information_from_headers_if_found() { $span = $this->fromReceivedMessage(new AMQPMessage('', ['application_headers' => ['X-B3-TraceId' => '1234', 'X-B3-SpanId' => '9876']])); $span->getIdentifier()->shouldBeLike(Identifier::fromString('9876')); $span->getTraceIdentifier()->shouldBeLike(Identifier::fromString('1234')); }
/** * {@inheritdoc} */ public function generate() { return Identifier::fromString((string) (rand() << 32 | rand())); }
/** * @param Request $request * @param string $header * * @return null|Identifier */ private function getIdentifier(Request $request, $header) { if (null !== ($value = $request->headers->get($header))) { return Identifier::fromString($value); } return null; }