philkra/elastic-apm-php-agent
PHP agent for Elastic APM that instruments your application to capture transactions, spans, errors, and performance metrics. Sends telemetry to Elastic APM Server for tracing and monitoring, with support for web and CLI workloads and configurable sampling.
$transaction = $agent->startTransaction('Simple Transaction');
// Do some stuff you want to watch ...
$agent->stopTransaction($transaction->getTransactionName());
$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' => "[email protected]",
] );
$agent->getTransaction( $trxName )->setCustomContext( [
'foo' => 'bar',
'bar' => [ 'foo1' => 'bar1', 'foo2' => 'bar2' ]
] );
$agent->getTransaction( $trxName )->setTags( [ 'k1' => 'v1', 'k2' => 'v2' ] );
This example illustrates how you can monitor a call to another web service.
$agent = new \PhilKra\Agent([ 'appName' => 'examples' ]);
$endpoint = 'https://acme.com/api/';
$payload = [ 'foo' => 'bar' ];
$client = new GuzzleHttp\Client();
// Start the Transaction
$transaction = $agent->startTransaction('POST https://acme.com/api/');
// Do the call via curl/Guzzle e.g.
$response = $client->request('POST', $endpoint, [
'json' => $payload
]);
// Stop the Transaction tracing, attach the Status and the sent Payload
$agent->stopTransaction($transaction->getTransactionName(), [
'status' => $response->getStatusCode(),
'payload' => $payload,
]);
// The collected traces will be send to the APM server as soon as
// the Agent object is destroyed. But, you can manually flush the
// playload queue with $agent->send();
How can I help you explore Laravel packages today?