function it_do_not_trace_if_no_request_in_stack(Tracer $tracer, SpanStack $spanStack, Span $span, PostResponseEvent $event)
 {
     $event->isMasterRequest()->willReturn(true);
     $spanStack->pop()->willReturn(null);
     $tracer->trace(Argument::any())->shouldNotBeCalled();
     $this->onKernelTerminate($event);
 }
Example #2
0
 /**
  * Updates the record with the span identifiers.
  *
  * @param array $record
  *
  * @return array
  */
 public function __invoke(array $record)
 {
     if (null === ($span = $this->spanStack->current())) {
         return $record;
     }
     $record['context']['tags'] = ['span_id' => (string) $span->getIdentifier(), 'trace_id' => (string) $span->getTraceIdentifier()];
     return $record;
 }
Example #3
0
 function it_adds_the_span_in_the_stack_during_the_execution(ConsumerInterface $decoratedConsumer, SpanStack $spanStack)
 {
     $message = new AMQPMessage('');
     $spanStack->push(Argument::type(Span::class))->shouldBeCalled();
     $decoratedConsumer->execute($message)->shouldBeCalled();
     $spanStack->pop()->shouldBeCalled();
     $this->execute($message);
 }
 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $span = $this->httpFoundationSpanFactory->fromIncomingRequest($event->getRequest());
     $this->stack->push($span);
     $this->tracer->trace([$span]);
 }
 /**
  * @param PostResponseEvent $event
  */
 public function onKernelTerminate(PostResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     if ($span = $this->spanStack->pop()) {
         $this->tracer->trace([$this->httpFoundationSpanFactory->fromOutgoingResponse($event->getResponse(), $span)]);
     }
 }
 function it_traces_and_add_a_span_to_the_stack(SpanStack $spanStack, Tracer $tracer, HttpFoundationSpanFactory $httpFoundationSpanFactory, GetResponseEvent $event, Span $span)
 {
     $request = Request::create('/');
     $event->getRequest()->willReturn($request);
     $event->isMasterRequest()->willReturn(true);
     $httpFoundationSpanFactory->fromIncomingRequest($request)->willReturn($span);
     $spanStack->push($span)->shouldBeCalled();
     $tracer->trace([$span])->shouldBeCalled();
     $this->onKernelRequest($event);
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function execute(AMQPMessage $msg)
 {
     $span = $this->amqpSpanFactory->fromReceivedMessage($msg);
     $this->tracer->trace([$span]);
     $this->spanStack->push($span);
     $result = $this->decoratedConsumer->execute($msg);
     $this->tracer->trace([$this->amqpSpanFactory->fromConsumedMessage($msg)]);
     $this->spanStack->pop();
     return $result;
 }
Example #8
0
 /**
  * @param AMQPMessage $message
  *
  * @return Span
  */
 public function fromProducedMessage(AMQPMessage $message)
 {
     $currentSpan = $this->spanStack->current();
     return new Span($this->identifierGenerator->generate(), $this->getMessageName($message), null !== $currentSpan ? $currentSpan->getTraceIdentifier() : $this->identifierGenerator->generate(), [new Annotation(Annotation::CLIENT_SEND, $this->clock->microseconds(), $this->endpointResolver->resolve())], [], $currentSpan !== null ? $currentSpan->getIdentifier() : null, $currentSpan !== null ? $currentSpan->getDebug() : null, $this->clock->microseconds());
 }
Example #9
0
 /**
  * @param RequestInterface $request
  *
  * @return Span
  */
 public function fromOutgoingRequest(RequestInterface $request)
 {
     $currentSpan = $this->spanStack->current();
     return new Span($this->identifierGenerator->generate(), $this->getName($request), null !== $currentSpan ? $currentSpan->getTraceIdentifier() : $this->identifierGenerator->generate(), [new Annotation(Annotation::CLIENT_SEND, $this->clock->microseconds(), $this->endpointResolver->resolve())], [new BinaryAnnotation('http.host', $request->getUri()->getHost(), BinaryAnnotation::TYPE_STRING), new BinaryAnnotation('http.path', $request->getUri()->getPath(), BinaryAnnotation::TYPE_STRING), new BinaryAnnotation('http.method', $request->getMethod(), BinaryAnnotation::TYPE_STRING)], $currentSpan !== null ? $currentSpan->getIdentifier() : null, $currentSpan !== null ? $currentSpan->getDebug() : null);
 }