This library supports Span traces of HTTP calls and distributed traces with Guzzle.
-
Install via composer
composer require pccomponentes/apm-guzzle
In all cases, an already created instance of ElasticApmTracer is assumed.
<?php
declare(strict_types=1);
$apmMiddleware = PcComponentes\ElasticAPM\GuzzleHttp\ElasticApmMiddleware::trace(
$apmTracer, /** \ZoiloMora\ElasticAPM\ElasticApmTracer instance. */
);
$handler = GuzzleHttp\HandlerStack::create();
$handler->push($apmMiddleware);
$config = [
'handler' => $handler,
];
$client = new GuzzleHttp\Client($config);
http.client:
class: GuzzleHttp\Client
arguments:
$config:
handler: '@guzzle.handler'
guzzle.handler:
class: GuzzleHttp\HandlerStack
factory: 'GuzzleHttp\HandlerStack::create'
calls:
- method: push
arguments: ['@guzzle.middleware.apm', 'trace']
guzzle.middleware.apm:
class: Closure
factory: 'PcComponentes\ElasticAPM\GuzzleHttp\ElasticApmMiddleware::trace'
arguments:
$elasticApmTracer: '@apm.tracer' # \ZoiloMora\ElasticAPM\ElasticApmTracer instance.
Licensed under the MIT license
Read LICENSE for more information