pccomponentes/apm-guzzle

Guzzle 的 Elastic APM

0.1.3 2021-04-15 12:51 UTC

This package is auto-updated.

Last update: 2024-09-15 20:01:34 UTC


README

这个库支持通过 Guzzle 进行 HTTP 调用的 Span 跟踪和分布式跟踪。

安装

  1. 通过 composer 安装

    composer require pccomponentes/apm-guzzle

用法

在所有情况下,假定已经创建了一个 ElasticApmTracer 实例。

原生 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);

服务容器(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.

许可证

MIT 许可证 下许可

阅读 LICENSE 了解更多信息