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';
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();
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)