The LaraOTel OpenTelemetry package for Laravel provides a simple way to incorporate OpenTelemetry in your Laravel application. This package can measure performance across jobs, services, database queries, events, and more.
OpenTelemetry (OTel) is a "vendor-neutral open source observability framework for instrumenting, generating, collecting, and exporting telemetry data such as traces, metrics, and logs."
To start using this package, you'll enable the package's global middleware used to measure requests, and you can configure watchers via the package's configuration file to trace specific parts of your application:
AuthenticateWatcherto trace authentications.CacheWatcherto trace cache operations.DatabaseQueryWatcherto trace database queries.QueueWatcherto trace job execution.RedisWatcherto trace redis operations.EventWatcherto trace event opearations.HtttpClientWatcherto trace http client requests.LogWatcherto trace log operations.
You can also create custom spans to measure the performance of specific parts of your application:
use LaraOTel\OpenTelemetryLaravel\Facades\Measure; Measure::span('my-web-request')->measure(function() { // ...}); // Or manually start and end a spanMeasure::start('my-web-request'); // ... Measure::end(); // Modify span attributesMeasure::start('my-web-request', function($span) { $span->setAttribute('key', 'value'); // ...}); // ...Measure::end();
This package also supports open-source tracing applications (Zipkin and Jaeger) for visualizing traces if you want to try it out locally. You'll need to install and enable the PHP PHP OpenTelemetry extension to use this package.
You can learn more about this package, get full installation instructions, and view the source code on GitHub. You can install this package in your Laravel application with Composer:
composer require laraotel/opentelemetry-laravel:2.0.3