0
PHP 使用 Zipkin 做调用链性能分析
先安装zipkin, 然后直接运行
docker pull openzipkin/zipkin
docker run -d -p 9411:9411 openzipkin/zipkin
$ composer require whitemerry/phpkin
运行下面的例子即可
<?php
namespace whitemerry\phpkin;
include './vendor/autoload.php';
$endpoint = new Endpoint(
'Passport', // Application name
'127.0.0.1', // Current application IP address
'80' // Current application port (default 80)
);
$logger = new Logger\SimpleHttpLogger([
'host' => 'http://127.0.0.1:9411' // Zipkin's API host with schema (http://) and without trailing slash
]);
$tracer = new Tracer(
'http://rpc/login', // Trace name
$endpoint, // Your application meta-information
$logger // Logger used to store/send traces
);
$tracer->setProfile(Tracer::FRONTEND);
$tracer->trace();
$requestStartTimestamp = zipkin_timestamp();
$spanIdentifier = new Identifier\SpanIdentifier();
/*
...
Request logic
Remember, you need to add B3 headers to your request:
X-B3-TraceId = TracerInfo::getTraceId();
X-B3-SpanId = $spanIdentifier;
X-B3-Sampled = TracerInfo::isSampled();
*/
sleep(1);
$endpoint = new Endpoint(
'rpc 1', // Name of service you're connecting with
'127.0.1.1', // This service Ip
'8000' // And port
);
$annotationBlock = new AnnotationBlock(
$endpoint,
$requestStartTimestamp
);
// 参数放到这里面
$metadata = new Metadata();
$metadata->set("file" , __FILE__);
$span = new Span(
$spanIdentifier,
'rpc 1',
$annotationBlock,
$metadata
);
$tracer->addSpan($span);
$tracer->trace();
$requestStartTimestamp = zipkin_timestamp();
$spanIdentifier = new Identifier\SpanIdentifier();
sleep(2);
/*
...
Request logic
Remember, you need to add B3 headers to your request:
X-B3-TraceId = TracerInfo::getTraceId();
X-B3-SpanId = $spanIdentifier;
X-B3-Sampled = TracerInfo::isSampled();
*/
$endpoint = new Endpoint(
'rpc 2', // Name of service you're connecting with
'127.0.1.1', // This service Ip
'8000' // And port
);
$annotationBlock = new AnnotationBlock(
$endpoint,
$requestStartTimestamp
);
$span = new Span(
$spanIdentifier,
'Rcp 2',
$annotationBlock
);
$tracer->addSpan($span);
$tracer->trace();
回复
Recommend
相关搜索关键词
- Top团队大牛带你玩转Android性能分析与优化
- 使用本地缓存优化微服务
- visa卡使用场景
- 图静态分析
- 静态分析
- @@dPXB7/blog/wp-admin/setup-config.php?step=0
- @@dPXB7/mirasvit_adminer_431.php
- @@dPXB7/mirasvit_adminer-4.2.3.php
- @@dPXB7/site/wp-admin/setup-config.php?step=0
- @@dPXB7/latest-mysql.php
- @@dPXB7/latest-mysql-en.php
- @@dPXB7/wp-admin/adminer.php
- @@dPXB7/adminer-4.3.0.php
- @@dPXB7/test/wp-admin/setup-config.php?step=0
- @@dPXB7/wp-login.php
- @@dPXB7/mirasvit_adminer_mysql.php
- @@dPXB7/adminer-4.7.0.php
- php and 5759=5759-- iuuq
- @@dPXB7/adminer1.php
- php and 9438=3142-- fruq
- @@dPXB7/wp/wp-admin/setup-config.php?step=0
- @@dPXB7/wp-includes/ID3/module.audio.ac3.php
- @@dPXB7/adminer/adminer.php
- PHP
- @@dPXB7/wp-content/uploads/2022/10/settings_auto.php
- @@dpxb7/wp-content/plugins/hd-webplayer/playlist.php
- @@dPXB7/latest.php
- PHP AND 7873=9865
- @@dPXB7/wp-admin/setup-config.php?step=0
- php
Recent search keywords
- DOVE加速器
- Graphcore
- n950f
- eb341820cd3a3485461a61b1e97d31b1
- onepiece
- Samsung gaming
- contact
- hindi
- golang9478590
- http\x3A\x2F\x2Fbestbuy.com
- 哥们
- 黑兽
- -4307" or 5781=5781 and "yvut"="yvut
- yiyo
- Inda
- -1" or 2+501-501-1=0+0+0+1 --
- upi
- 印度支付通道
- AC8227L+Android+head+unit+4gb/32gb
- xperia+5+v
- org+chart
- Iptv+2023
- san+francisco+web+development
- 8257+logo
- hacks+in+blooket
- 深入理解+Gem5
- xperia+5+v+kernel
- hacks in blooket
- Iptv 2023
- teligu
- Read.Me
- flip
- wrp android video player pro" and 8553=8553 and "fygz"="fygz
- -1 or 3+520-520-1=0+0+0+1
- abap
- 深入理解 Gem5
- xperia 5 v kernel
- xperia 5 v
- san francisco web development
- flutter内核源码剖析
- zepp
- m31s
- khmer
- iptv+smart+player
- JAC+8229B
- Savings+Account
- 4th+generation
- Personal+Loan+Account
- clash+tun
- Oneplus+8t
- galaxy+s24+ultra
- checking+system+health+gpt
- Indian+Rupee+Ngultrum
- Kuwaiti+Dinar
- PlayWright
- solid+state
- Slim+odan
- radio+setup
- mlc+llm
- junsun+v1+pro+c,+radio+setup
- AGGIORNAMENTO+ROM+AC8227L+-+Android+JCAC10003-OC2
- checking+system+health
- read+only
- Ergonomic+Frozen+Shirt
- unidoc+health
- tab+4
- YT9217b+firmware
- Northern+Mariana+Islands
- utunnel
- read only
- radio
- 著作權
- M3U8
- 鸿蒙
- Japan
- @@neb61
- Laptop Rental - All Major Brand Laptops For Rent in Mumbai
- yt9213aj
- galaxy s24 ultra
- alwinner
- nat geo
- AGGIORNAMENTO ROM AC8227L - Android JCAC10003-OC2
- wulu
- office
- offcie
- gospel americano
- junsun v1 pro c, radio setup
- radio setup
- AC8227L Android head unit 4gb/32gb
- K4811_NWD_S217206
- unidoc health
- 5ber
- YT9217b
- YT9217b firmware
- HW8227L
- tinystudio
- Slim odan
- Slim
- clash tun
- tun