cyberclick-os/apm-symfony-messenger

Elastic APM for Symfony Messenger

1.2.1 2023-12-12 15:17 UTC

README

This library supports Span traces of Symfony Messenger messages.

Installation

  1. Install via composer

    composer require pccomponentes/apm-symfony-messenger

Usage

In all cases, an already created instance of ElasticApmTracer is assumed.

Native PHP

<?php
declare(strict_types=1);

class TextNameExtractor implements PcComponentes\ElasticAPM\Symfony\Component\Messenger\NameExtractor
{
    public function execute($message): string
    {
        if (false === is_string($message)) {
            throw new InvalidArgumentException('The parameter must be of type string');
        }

        return $message;
    }
}

$apmMiddleware = new PcComponentes\ElasticAPM\Symfony\Component\Messenger\ApmMiddleware(
    $apmTracer, /** \ZoiloMora\ElasticAPM\ElasticApmTracer instance. */
    new TextNameExtractor(),
);

$bus = new Symfony\Component\Messenger\MessageBus([
    $apmMiddleware
]);

Service Container (Symfony)

app.bus:
  class: Symfony\Component\Messenger\MessageBus
  arguments:
    $middlewareHandlers:
      - '@app.bus.middleware.apm'

app.bus.middleware.apm:
  class: PcComponentes\ElasticAPM\Symfony\Component\Messenger\ApmMiddleware
  arguments:
    $elasticApmTracer: '@apm.tracer' # \ZoiloMora\ElasticAPM\ElasticApmTracer instance.
    $nameExtractor: '@app.bus.middleware.apm.name_extractor'

app.bus.middleware.apm.name_extractor:
  class: ExampleTextNameExtractor

License

Licensed under the MIT license

Read LICENSE for more information