Capture Errors and Exceptions
October 2, 2020 ยท View on GitHub
The agent can capture all types or errors and exceptions that are implemented from the interface Throwable. When capturing an error, you can a context and highly recommended a parent transaction as illustrated in the following snippet.
By doing so you increase the tracability of the error.
// Setup Agent
$config = [
'serviceName' => 'examples',
'serviceVersion' => '1.0.0-beta',
];
$agent = (new \Nipwaayoni\AgentBuilder())
->withConfig(new Nipwaayoni\Config($config))
->build();
// start a new transaction or use an existing one
$transaction = $agent->startTransaction('Failing-Transaction');
try {
//
// do stuff that generates an Exception
//
}
catch(Exception $e) {
$agent->captureThrowable($e, [], $transaction);
// handle Exception ..
}
// do some more stuff ..
$agent->stopTransaction($transaction->getTransactionName());