v0.1.2 2018-08-01 20:10 UTC


CircleCI OpenTracing Badge Minimum PHP Version

Experimental PHP Tracer!

This project is experimental and under active development. Use it at your own risk.


composer require datadog/dd-trace


  • PHP 5.6 or later


In order to be familiar with tracing elements it is recommended to read the OpenTracing specification.

Using the tracer

To start using the DataDog Tracer with the OpenTracing API, you should first initialize the tracer:

use DDTrace\Tracer;
use OpenTracing\GlobalTracer;

// Creates a tracer with default transport and default propagators
$tracer = new Tracer();

// Sets a global tracer (singleton). Ideally tracer should be
// injected as a dependency


// Flushes traces to agent.
register_shutdown_function(function() {

PHP as a request scoped language has no simple means to pass the collected spans data to a background process without blocking the main request thread/process. It is mandatory to execute the Tracer::flush() after the response is served to the client by using register_shutdown_function.

Advanced configuration

Transport can be customized by the config parameters:

use DDTrace\Encoders\Json;
use DDTrace\Transport\Http;

$transport = new Http(
    new Json(),
        'endpoint' => 'http://localhost:8126/v0.3/traces', // Agent endpoint

Tracer can be customized by the config settings:

use DDTrace\Tracer;
use OpenTracing\Formats;

// Config for tracer
$config = [
    'service_name' => 'my_service', // The name of the service.
    'enabled' => true, // If tracer is not enabled, all spans will be created as noop.
    'global_tags' => ['host' => 'hostname'], // Set of tags being added to every span.

$tracer = new Tracer(
    [ Formats\TEXT_MAP => $textMap ],

Creating Spans

Propagation of context


Before contributing to this open source project, read our

Run tests

composer test

Fix lint

composer fix-lint


See RELEASING for more information on releasing new versions.