public function notify(UrlEvent $event)
 {
     if (!$this->isEnabled() || !$event->getUrl() || !$this->producer) {
         return false;
     }
     try {
         $message = array_merge(['url' => $event->getUrl()->toArray(), 'type' => $event->getType(), 'created_on' => (new \DateTime())->format(\DateTime::ISO8601)], $event->getAdditional());
         $this->producer->publish(json_encode($message));
     } catch (\Exception $e) {
         // TODO: log message
     }
     return true;
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function publish($msgBody, $routingKey = '', $additionalProperties = array())
 {
     $message = new AMQPMessage((string) $msgBody, array_merge($additionalProperties, ['routing_key' => $routingKey]));
     $span = $this->amqpSpanFactory->fromProducedMessage($message);
     if (!array_key_exists('application_headers', $additionalProperties)) {
         $additionalProperties['application_headers'] = new AMQPTable();
     } elseif (!$additionalProperties['application_headers'] instanceof AMQPTable) {
         throw new \InvalidArgumentException('Your `application_headers` must be an `AMQPTable`');
     }
     $headers = $additionalProperties['application_headers'];
     $headers->set('X-B3-SpanId', (string) $span->getIdentifier());
     $headers->set('X-B3-TraceId', (string) $span->getTraceIdentifier());
     $headers->set('X-B3-ParentSpanId', (string) $span->getParentIdentifier());
     $headers->set('X-B3-Flags', $span->getDebug() ? '1' : '0');
     $result = $this->decoratedProducer->publish($msgBody, $routingKey, $additionalProperties);
     $this->tracer->trace([$span]);
     return $result;
 }
 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('', '');
 }
Exemple #4
0
 /**
  * @param Process $process
  */
 public function publish(Process $process)
 {
     $this->processProducer->publish($this->processSerializer->serialize($process));
 }
 public function dispatch(Event $event)
 {
     $this->producer->publish($event->getBody());
 }