pccomponentes/apm-symfony-messenger

Elastic APM for Symfony Messenger

0.1.2 2021-05-14 10:06 UTC

This package is auto-updated.

Last update: 2024-04-14 16:09:50 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