pccomponentes/apm-guzzle

Elastic APM for Guzzle

0.1.3 2021-04-15 12:51 UTC

This package is auto-updated.

Last update: 2024-04-15 19:13:39 UTC


README

This library supports Span traces of HTTP calls and distributed traces with Guzzle.

Installation

  1. Install via composer

    composer require pccomponentes/apm-guzzle

Usage

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

Native PHP

<?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);

Service Container (Symfony)

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.

License

Licensed under the MIT license

Read LICENSE for more information