auxmoney / jaeger-php
php client for jaeger
Requires
- php: >=7.1
- ext-json: *
- opentracing/opentracing: ^1.0.1
- packaged/thrift: ~0.13.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^v3.1
- php-coveralls/php-coveralls: ^v2.4
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^8.5
- roave/security-advisories: dev-latest
- dev-master
- 3.0.2
- 3.0.1
- 3.0.0
- v2.1.3
- v2.1.3-beta
- v2.1.2-beta
- v2.1.1-beta
- v2.1.0-beta
- v2.0.9-beta
- v2.0.8-beta
- v2.0.7-beta
- v2.0.6-beta
- v2.0.5-beta
- v2.0.4-beta
- v2.0.3-beta
- v2.0.2-beta
- v2.0.1-beta
- v2.0.0-beta
- v1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-stable
- dev-hotfix/psr7
- dev-copy_baggage
- dev-fix_bug
- dev-active
- dev-del_setTags
- dev-phpunit
- dev-travis
- dev-imp_op_b5
- dev-apache_2_license
- dev-revert-34-support-unit-testing-autoloading
- dev-for_better_english
- dev-add_zipkin_header
- dev-fix_traceid_len
- dev-require
- dev-refactor
- dev-semantic_conventions
- dev-fix_add_tags
- dev-gen128bit
This package is auto-updated.
Last update: 2024-11-22 17:53:49 UTC
README
ATTENTION: this is a fork and republication of jukylin/jaeger-php
We opted into forking and publishing the original library in order to maintain our set of opentracing related symfony bundles. The original library seems to be unmaintained currently.
jaeger-php is a library implementing the OpenTracing specification for PHP to connect with the Jaeger Distributed Tracing Platform. It can be used to instrument PHP code to generate tracing data and send it to Jaeger.
Installation
composer require auxmoney/jaeger-php
Usage
First, you need to create a Config
object, which serves as the factory to create your Tracer
:
// create a config instance $config = \Jaeger\Config::getInstance(); // create a tracer $tracer = $config->initTracer('example service name', '0.0.0.0:6831');
To make the distributed tracing work, you need to extract your SpanContext
from somewhere, e.g. $_SERVER
:
$spanContext = $tracer->extract(\Opentracing\Formats\TEXT_MAP, $_SERVER);
You can then start tracing by using the common Opentracing interface:
$tracer->startActiveSpan("example operation name", ['child_of' => $spanContext]);
To add metadata to your span, you need to retrieve it first (be sure to check the semantic conventions first):
$span = $tracer->getActiveSpan(); $span->addBaggageItem("user_id", "12345"); $span->setTag("http.url", "http://localhost"); $span->log(["message" => "responded successfully"]); $span->finish();
Finally, at the end of your script, you should flush the original Config
. This will flush all created Tracer
s and all created Span
s:
$config->flush();
optional configuration
// optional: generate 128 bit trace ids (default: false) $config->gen128bit(); // optional: disable tracing (default: false) $config->setDisabled(true); // optional: inject custom transport (default: TransportUdp) $config->setTransport($transport); // optional: inject custom reporter (default: RemoteReporter) $config->setReporter($reporter); // optional: inject custom sampler (default: ConstSampler) $config->setSampler($sampler);
Special thanks
Thank you, @jukylin, for creating this library!