Skip to content

socialbase/elastic-apm-php-agent

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Elastic APM: PHP Agent

Build Status

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.

Installation

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

Usage

Initialize the Agent with minimal Config

$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
  ]
] );

Capture Errors and Exceptions

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

Transaction without minimal Meta data and Context

$trxName = 'Demo Simple Transaction';
$agent->startTransaction( $trxName );
// Do some stuff you want to watch ...
$agent->stopTransaction( $trxName );

Transaction with Meta data and Contexts

$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' ] );  

Tests

vendor/bin/phpunit

About

PHP Agent for Elastic APM

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%