This package provides a simple way to add OpenTelemetry to your Laravel application.
You can install the package via composer:
composer require overtrue/laravel-open-telemetry
Publish the configuration file:
php artisan vendor:publish --provider="Overtrue\LaravelOpenTelemetry\OpenTelemetryServiceProvider" --tag="config"
You can refer to OpenTelemetry SDK Configuration Instructions
OTEL_ENABLED=true
OTEL_AUTO_TRACE_REQUESTS=true
OTEL_PHP_AUTOLOAD_ENABLED=true
OTEL_PHP_TRACE_CLI_ENABLED=true
OTEL_SERVICE_NAME=my-app
OTEL_TRACES_EXPORTER=otlp
#OTEL_EXPORTER_OTLP_PROTOCOL=grpc
OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4318
OTEL_PROPAGATORS=baggage,tracecontext
and other environment variables, you can find them in the configuration file: config/otle.php
.
you can register the middleware in the app/Http/Kernel.php
:
protected $middleware = [
\Overtrue\LaravelOpenTelemetry\Middlewares\MeasureRequest::class,
// ...
];
or you can set the env variable OTEL_AUTO_TRACE_REQUESTS
to true
to enable it automatically.
You can create a custom span by using the Overtrue\LaravelOpenTelemetry\Facades\Measure
facade:
use Overtrue\LaravelOpenTelemetry\Facades\Measure;
Measure::span('your-span-name')->measure(function() {
// ...
});
or manually start and end a span:
Measure::start('your-span-name');
// ...
Measure::end();
and you can modify the span attributes by using a closure:
Measure::start('your-span-name', function($span) {
$span->setAttribute('key', 'value');
// ...
});
// ...
Measure::end();
of course, you can get the span instance by using the Measure::span()
method:
$span = Measure::span('your-span-name');
$span->setAttribute('key', 'value');
$scope = $span->activate();
// ...
$span->end();
$scope->detach();
You can contribute in one of three ways:
- File bug reports using the issue tracker.
- Answer questions or fix bugs on the issue tracker.
- Contribute new features or update the wiki.
The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.
如果你喜欢我的项目并想支持它,点击这里 ❤️
Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.
MIT