jcchavezs / dd-opentracing
This package is abandoned and no longer maintained.
The author suggests using the https://github.com/dataDog/dd-trace-php package instead.
DataDog implementation for OpenTracing in PHP
0.3.1
2017-05-19 18:50 UTC
Requires
- php: ^5.6||^7.0
- guzzlehttp/guzzle: ^6.2
- jcchavezs/dd-trace: ^0.2.3
- jcchavezs/opentracing: ^0.3.1
- jcchavezs/tracing-context: ^0.1.0
Requires (Dev)
- phpunit/phpunit: ~5.7.19
README
DataDog implementation for OpenTracing in PHP
Installation
Execute:
composer require jcchavezs/dd-opentracing
Examples
use DdOpenTracing\Tracer; use OpenTracing\Carriers\HttpHeaders; use OpenTracing\GlobalTracer; use OpenTracing\Propagator; use OpenTracing\SpanContext; use OpenTracing\SpanReference\ChildOf; use OpenTracing\Tag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; $request = Request::createFromGlobals(); $client = new \GuzzleHttp\Client(); $logger = new \Monolog\Logger("log"); $encoderFactory = new \DdTrace\Encoders\JsonFactory; $transport = new \DdTrace\Transports\Http($client, $logger, $encoderFactory); $buffer = new \DdTrace\Buffer(); $ddTracer = new \DdTrace\Tracer($buffer, $logger, $transport); $tracer = new Tracer($ddTracer, $logger); $tracer->enableDebugLogging(); GlobalTracer::setGlobalTracer($tracer); $spanContext = GlobalTracer::globalTracer()->extract( Propagator::HTTP_HEADERS, HttpHeaders::fromRequest($request) ); usleep(200); readFromDB($spanContext); $response = Response::create("", 200); $response->send(); // This flushes the traces, if the buffer could be persisted, a worker could flush the traces from time to time. $tracer->tracer()->flushTraces(); function readFromDB(SpanContext $spanContext) { $tracer = GlobalTracer::globalTracer(); $component = Tag::create("component", "SELECT * FROM test_table"); $peerService = Tag::create("peer.service", "test_service"); $span = $tracer->startSpan("Db read", ChildOf::withContext($spanContext), null, $component, $peerService); usleep(3000); $span->finish(); }