PHP code example of shifudeen / elastic-apm-laravel
1. Go to this page and download the library: Download shifudeen/elastic-apm-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
shifudeen / elastic-apm-laravel example snippets
'providers' => [
// ... more providers
\AG\ElasticApmLaravel\ServiceProvider::class,
],
use AG\ElasticApmLaravel\Facades\ApmCollector;
ApmCollector::startMeasure('my-custom-span', 'custom', 'measure', 'My custom span');
// do something amazing
ApmCollector::stopMeasure('my-custom-span');
public function middleware()
{
return [
app(\AG\ElasticApmLaravel\Jobs\Middleware\RecordTransaction::class),
];
}
// app/Collectors/MailMessageCollector.php
namespace YourApp\Collectors;
use AG\ElasticApmLaravel\Contracts\DataCollector;
use AG\ElasticApmLaravel\Collectors\EventDataCollector;
use Illuminate\Mail\Events\MessageSending;
use Illuminate\Mail\Events\MessageSent;
class MailMessageCollector extends EventDataCollector implements DataCollector
{
public function getName(): string
{
return 'mail-message-collector';
}
protected function registerEventListeners(): void
{
$this->app->events->listen(MessageSending::class, function (\Swift_Message $message) {
$this->startMeasure(
'mail #' . $message->getId(),
'mail.delivery',
);
});
$this->app->events->listen(MessageSent::class, function (\Swift_Message $message) {
$this->stopMeasure('mail #' . $message->getId());
});
}
}
// app/Providers/AppServiceProvider.php
use AG\ElasticApmLaravel\Facades\ApmCollector;
use YourApp\Collectors\MailMessageCollector;
public function boot()
{
// ...
ApmCollector::addCollector(MailMessageCollector::class);
}