Documentation is still in progress and subject to change.

PHP Getting Started

NOTE: If you're using the Laravel framework, please see the documentation for integrating with Laravel specifically.

1. Install

Use composer to install the taildev/php library.

composer require taildev/php

Make sure that the composer autoloader is being required somewhere in your project:

require __DIR__ . '/vendor/autoload.php';

2. Setup APM

Initialize and start the APM tracking as early as possible in the code process. You'll need an auth token (see Quickstart). You can provide any service-name you'd like to identify which app this APM is tracking.

use Tail\Apm;

Apm::init('...some-token', 'service-name');
Apm::startRequest(); 

register_shutdown_function(function () {
    Apm::finish();
});

Alternatively you can use startJob($name) for background jobs, CLI commands, etc. or startCustom($name)

The shutdown function will ensure that after the process is finished tail.dev is sent the APM tracking request. You may call finish manually at any time to send the APM trace to tail.dev, just keep in mind it will mark the trace completed from that point. For best performance this should happen AFTER any HTTP response or other user feedback has been provided.

To track a custom span during the transaction:

$span = Apm::newSpan('fetch-config');
// ... code fetching config
$span->finish();

3. Logs

Initialize the logger with your auth token (see Quickstart). You may optionally provide a service name and environment to attach to the logs.

use Tail\Log;

Log::init('my-token', 'optional-service-name', 'optional-service-environment');

Now you can use Log::get() from anywhere to log a new message

use Apm\Log;

Log::get()->debug('My debug message');

Log::get()->alert('Something went wrong', ['custom_tag' => 'more info']);

The available log levels are:

->debug($message)
->info($message)
->notice($message)
->warning($message)
->error($message)
->critical($message)
->alert($message)
->emergency($message)

4. Dive deeper

© 2020 tail.dev