2017 © Pedro Peláez
 

library dd-trace

PHP APM Client

image

datadog/dd-trace

PHP APM Client

  • Thursday, July 26, 2018
  • by DataDog
  • Repository
  • 95 Watchers
  • 20 Stars
  • 909 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 6 Versions
  • 45350 % Grown

The README.md

DD Trace PHP

CircleCI OpenTracing Badge Minimum PHP Version License Packagist Version Total Downloads, (*1)

PHP Tracer, (*2)

This is Beta software. We do not recommend using it in production yet., (*3)

Getting Started

The Datadog PHP Tracer brings APM and distributed tracing to PHP., (*4)

Prerequisites

If you haven't already, sign up for a free Datadog account and download and install the Datadog agent., (*5)

Make sure that APM is enabled. The agent does not have APM enabled by default so make sure to enable it., (*6)

Installation

The PHP tracer is composed of a PHP extension and a Composer package. You'll need to install both in order to start tracing your PHP projects., (*7)

Composer installation

First we'll install the Composer package., (*8)

$ composer require datadog/dd-trace opentracing/opentracing:@dev

Note: Since the OpenTracing dependency is still in beta, adding the opentracing/opentracing:@dev argument to the composer require command will ensure the library is installed without changing your Composer minimum stability settings., (*9)

Installing the extension (from a package)

Next we'll install the ddtrace extension., (*10)

First download the appropriate package from the releases page. Then install the package with one of the commands below., (*11)

# using RPM package (RHEL/Centos 6+, Fedora 20+)
$ rpm -ivh datadog-php-tracer.rpm

# using DEB package (Debian Jessie+ , Ubuntu 14.04+)
$ deb -i datadog-php-tracer.deb

# using APK package (Alpine)
$ apk add datadog-php-tracer.apk --allow-untrusted

# using tar.gz archive (Other distributions using libc6)
$ tar -xf datadog-php-tracer.tar.gz -C /
  /opt/datadog-php/bin/post-install.sh

Installing the extension (manually)

The extension can also be installed manually from source. First download the source code from the releases page. Then compile and install the extension with the commands below., (*12)

$ cd /path/to/dd-trace-php
$ phpize
$ ./configure --enable-ddtrace
$ make
$ sudo make install

Usage

Once the ddtrace extension and Composer package is installed, you can start tracing your PHP project by wrapping your application code with a root span from the tracer., (*13)

use DDTrace\Tracer;
use OpenTracing\GlobalTracer;
use DDTrace\Integrations\IntegrationsLoader;

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

// Sets a global tracer (singleton)
GlobalTracer::set($tracer);
// Flushes traces to agent on script shutdown
register_shutdown_function(function() {
    GlobalTracer::get()->flush();
});

// Enable the built-in integrations
IntegrationsLoader::load();

// Start a root span
$scope = $tracer->startSpan('my_base_trace');

// Run your application here
// $myApplication->run();

// Close the root span after the application code has finished
$scope->close();

Notice we didn't specify an API key or any web endpoints. That's because the API key is set at the agent layer, so the PHP code just needs to know the hostname and port of the agent to send traces to Datadog. By default the PHP tracer will assume the agent hostname is localhost and the port is 8126. If you need to change these values, check out the configuration documentation., (*14)

Viewing the trace

Assuming the agent is running with APM enabled and it is configured with our API key, and assuming we successfully installed the ddtrace extension and the datadog/dd-trace package with Composer, we should be able to head over to the APM UI to see our trace., (*15)

Note: It might take a few minutes before your trace appears in the UI. Just refresh the page a few times until you see the screen change., (*16)

Digging deeper

For more information about configuration and specific framework integrations, check out the getting started docs., (*17)

Advanced configuration

In order to be familiar with tracing elements it is recommended to read the OpenTracing specification., (*18)

The transport can be customized by the config parameters:, (*19)

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

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

The tracer can be customized by the config settings:, (*20)

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(
    $transport,
    [ Formats\TEXT_MAP => $textMap ],
    $config
);

Creating Spans

Propagation of context

Contributing

Before contributing to this open source project, read our CONTRIBUTING.md., (*21)

Releasing

See RELEASING for more information on releasing new versions., (*22)

Security Vulnerabilities

If you have found a security issue, please contact the security team directly at security@datadoghq.com., (*23)

The Versions

26/07 2018

dev-master

9999999-dev

PHP APM Client

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Avatar DataDog

php datadog tracing

26/07 2018

dev-chuck.hagenbuch/stdout-transport

dev-chuck.hagenbuch/stdout-transport

PHP APM Client

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Avatar DataDog

php datadog tracing

25/07 2018

dev-feature/add_error_handling_to_set_tag_and_logs

dev-feature/add_error_handling_to_set_tag_and_logs

PHP APM Client

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Avatar DataDog

php datadog tracing

24/07 2018

dev-editor_config_linting

dev-editor_config_linting

PHP APM Client

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Avatar DataDog

php datadog tracing

23/07 2018

dev-phpcs_use_local_configuraiton_file_remove_unused_zend_sniffs_use_psr12

dev-phpcs_use_local_configuraiton_file_remove_unused_zend_sniffs_use_psr12

PHP APM Client

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Avatar DataDog

php datadog tracing

17/04 2018

0.1.0

0.1.0.0

PHP APM Client

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Avatar DataDog

php datadog tracing