dipenduroy/lumenzipkin
Composer 安装命令:
composer require dipenduroy/lumenzipkin
包简介
Distributed tracing for lumen using Zipkin
README 文档
README
Distributed Tracing of Guzzle HTTP Client (Micro Services internal calls) and dynamic profiling in Lumen
Contents
Prerequisites
Install
composer require dipenduroy/lumenzipkin
Register LumenZipkinServiceProvider
To enable Lumen Zipkin library, add below in bootstrap/app.php
$app->register(DipenduRoy\LumenZipkin\LumenZipkinServiceProvider::class);
Register ZipkinTraceMiddleware
To automatically flush all the traces to zipkin server while script ends. This is required to push trace info to zipkin server.
Add DipenduRoy\LumenZipkin\ZipkinTraceMiddleware::class in middleware's list of bootstrap/app.php, If no middleware
$app->middleware([
DipenduRoy\LumenZipkin\ZipkinTraceMiddleware::class
]);
Start Zipkin Server
Use Docker to start Zipkin Server
composer run-zipkin
Usage
Below example traces all guzzle calls between microservices. Similarly refer zipkin-php for more customized tracing
//Set your application variables below
$baseUri='http://local.app/';
$method='POST';
$requestUrl='example/url';
$queryString='?filter=category';
$formParams=[];
//Get Zipkin Trace Object
$ZipkinTrace=app('Trace\ZipkinTrace');
/* Creates the span for getting the guzzle client call */
$childSpan = $ZipkinTrace->createChildClientSpan($baseUri);
//Tags can be configured as per your requirement for filtering the requests from zipkin dashboard
$childSpan->tag(\Zipkin\Tags\HTTP_HOST, $baseUri);
$childSpan->tag(\Zipkin\Tags\HTTP_URL, $baseUri.$requestUrl);
$childSpan->tag(\Zipkin\Tags\HTTP_PATH, $requestUrl);
$childSpan->tag(\Zipkin\Tags\HTTP_METHOD, strtoupper($method));
$childSpan->annotate('request_started', \Zipkin\Timestamp\now());
$client = new \GuzzleHttp\Client([
'base_uri' => $baseUri,
]);
$headers['accept'] = "application/json";
$headers=array_merge($headers,$ZipkinTrace->getHeaders());
$params=[
'form_params' => $formParams,
'headers' => $headers,
'query' => $queryString,
];
try {
$response = $client->request($method, $requestUrl, $params);
} catch (\GuzzleHttp\Exception\TransferException $e) {
$response = $e->getResponse();
if ($e->hasResponse()) {
$responseString = $e->getResponse()->getBody(true);
} else {
$childSpan->tag(\Zipkin\Tags\HTTP_STATUS_CODE, 503);
$childSpan->tag(\Zipkin\Tags\ERROR, 'Guzzle Transfer Exception');
$childSpan->annotate('request_failed', \Zipkin\Timestamp\now());
}
}
$childSpan->tag(\Zipkin\Tags\HTTP_STATUS_CODE, $response->getStatusCode());
$childSpan->annotate('request_finished', \Zipkin\Timestamp\now());
Configuration
Set below environment variable as required
APP_NAME Environment variable is used for root trace name
LUMEN_ZIPKIN_ENABLE_SERVER_ADDRESS Environment variable is used to enable server address if available
Running with a custom zipkin location
If you need to pass the zipkin endpoint, just pass the reporter
url as HTTP_REPORTER_URL env variable. Default zipkin location is - http://localhost:9411/api/v2/spans
HTTP_REPORTER_URL=http://myzipkin:9411/api/v2/span composer run-frontend
References
Thanks to the below contributors
- This library uses Zipkin PHP Library, refer for more details
- Know Zipkin in detail
- Zipkin PHP Example
dipenduroy/lumenzipkin 适用场景与选型建议
dipenduroy/lumenzipkin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 12 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「distributed」 「lumen」 「zipkin」 「tracing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dipenduroy/lumenzipkin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dipenduroy/lumenzipkin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dipenduroy/lumenzipkin 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Testing Suite For Lumen like Laravel does.
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
Class to generate a standard structure for api json responses
A Symfony to process jobs from AbcJobServerBundle
A symfony bundle to manage asynchronous distributed processing of stateful jobs
Amqp classes
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-12-01