Skip to content

jcchavezs/dd-trace-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DataDog Trace PHP

Build Status Total Downloads License

This library contains Datadog's tracing client. It is used to trace requests as they flow across web servers, databases and microservices so that developers have visibility into bottlenecks and troublesome requests.

Tracer has two core objects: Tracers and Spans. Spans represent a chunk of computation time. They have names, durations, timestamps and other metadata. Tracers are used to create hierarchies of spans in a request, buffer and submit them to the server.

The tracing client can perform trace sampling. While the trace agent already samples traces to reduce bandwidth usage, client sampling reduces performance overhead.

Installation

DD Trace can be installed by composer:

composer require jcchavezs/dd-trace

Example

use DdTrace\Tracer;
use GuzzleHttp\Exception\RequestException;

$tracer = Tracer::noop();
$client = new GuzzleHttp\Client();

$span = $tracer->createRootSpan("http.client.request", "example.com", "/user/{id}");

$url = "http://example.com/user/123";

try {
    $response = $client->get($url);

    $span->setMeta("http.status", $response->getStatusCode());
    $span->setMeta("http.url", $url);
} catch (RequestException $e) {
    $span->setError($e);
}

$span->finish();

Unit testing

Run in the source folder:

make test