This is a PHP agent for Elastic.co's APM product: https://www.elastic.co/solutions/apm. Please note that this agent is still experimental and not ready for any production usage.
The recommended way to install the agent is through Composer.
Run the following composer command
php composer.phar require philkra/elastic-apm-php-agent
After installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';
$agent = new \PhilKra\Agent( [ 'appName' => 'demo' ] );
When creating the agent, you can directly inject shared contexts such as user, tags and custom.
$agent = new \PhilKra\Agent( [ 'appName' => 'with-custom-context' ], [
'user' => [
'id' => 12345,
'email' => 'email@acme.com',
],
'tags' => [
// ... more key-values
],
'custom' => [
// ... more key-values
]
] );
The agent can capture all types or errors and exceptions that are implemented from the interface Throwable
(http://php.net/manual/en/class.throwable.php).
$agent->captureThrowable( new Exception() );
$trxName = 'Demo Simple Transaction';
$agent->startTransaction( $trxName );
// Do some stuff you want to watch ...
$agent->stopTransaction( $trxName );
$trxName = 'Demo Transaction with more Data';
$agent->startTransaction( $trxName );
// Do some stuff you want to watch ...
$agent->stopTransaction( $trxName, [
'result' => '200',
'type' => 'demo'
] );
$agent->getTransaction( $trxName )->setUserContext( [
'id' => 12345,
'email' => "hello@acme.com",
] );
$agent->getTransaction( $trxName )->setCustomContext( [
'foo' => 'bar',
'bar' => [ 'foo1' => 'bar1', 'foo2' => 'bar2' ]
] );
$agent->getTransaction( $trxName )->setTags( [ 'k1' => 'v1', 'k2' => 'v2' ] );
vendor/bin/phpunit