Inspector logo

Legacy PHP app monitoring

Build Status Latest Stable Version

Install the latest version by:

composer require logengine/logengine-php

Use

To start sending data to LOG Engine you need to provide the API KEY when create a configuration instance:

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

use LogEngine\ApmAgent;
use LogEngine\Configuration;

$configuration = new Configuration('API_KEY');
$apm = new ApmAgent($configuration);
$apm->startTransaction($_SERVER['PATH_INFO'])

$span = $apm->startSpan('Process Exception');
try {

    throw new UnauthorizedException("You don't have permission to access.");

} catch(UnauthorizedException $exception) {
    $apm->reportException($exception);
} fianlly {
    $span->end();
}

You can obtain LOGENGINE_API_KEY creating a new project in your LOG Engine dashboard.

Start a transaction

Everything in LOG Engine start with a transaction. Without starting a transaction at the origin of your script execution you could maintain a non-real visibility of your application performance.

// Start a transaction
$apm->startTransaction($_SERVER['PATH_INFO']);

By default the transaction will closed automatically after your application has sent the response to the user. You can close the transaction manually if you want.

// Close a transaction
$apm->end();

Spans

After a transaction is started you can segmenting your script execution with multiple spans, and object that measure the timing needed to every task to be executed.

// Monitor the execution of a part of your script
$span = $apm->startSpan('Process Exception');
try {

    throw new UnauthorizedException("You don't have permission to access.");

} catch(UnauthorizedException $exception) {
    $apm->reportException($exception);
} fianlly {
    $span->end();
}

Remember to close every span opened, so use finally keyword in a try/catch code block.

Options

Proxy

LOG Engine library supports data delivery through proxy. Specify proxy using libcurl format: [protocol://][user:password@]proxyhost[:port]

$configuration = new LogEngine\Configuration(
    'API_KEY', 
    ['proxy' => 'https://55.88.22.11:3128']
);

Curl path

It can be useful to specify curl destination path for AsyncTransport. This option is set to 'curl' by default.

$configuration = new LogEngine\Configuration(
    'API_KEY', 
    ['curlPath' => '/usr/bin/curl']
);