Push over OTLP
To send the metrics to an OTLP/HTTP endpoint, set the endpoint and schedule metrics:push.
1. Set the endpoint
Section titled “1. Set the endpoint”Set the base URL of the endpoint. The package appends /v1/metrics, so leave it out.
OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4318To send JSON instead of protobuf:
OTEL_EXPORTER_OTLP_PROTOCOL=http/jsonThe package reads these through config/metrics.php. After a change, run php artisan config:cache again if the configuration is cached.
2. Push once by hand
Section titled “2. Push once by hand”php artisan metrics:pushThe command prints Sent N metrics. on success. It prints The store holds no metrics. when there is nothing to send yet. Exit code 1 means the store cannot be read or the endpoint refused the push. See Troubleshoot.
3. Schedule the command
Section titled “3. Schedule the command”use Illuminate\Support\Facades\Schedule;
Schedule::command('metrics:push')->everyMinute();When several servers run the scheduler, push from one only:
Schedule::command('metrics:push')->everyMinute()->onOneServer();onOneServer() needs a cache store that every server shares, such as Redis or the database.
Push more often than the backend forgets a series. The Collector’s Prometheus exporter drops a series after metric_expiration, 5 minutes by default, without a push.
Send to an OpenTelemetry Collector
Section titled “Send to an OpenTelemetry Collector”A minimal Collector configuration that accepts the push:
receivers: otlp: protocols: http: endpoint: 0.0.0.0:4318
exporters: debug: verbosity: basic
service: pipelines: metrics: receivers: [otlp] exporters: [debug]Replace the debug exporter with the exporter of your backend.
Send to a backend that needs an API key
Section titled “Send to a backend that needs an API key”Put the headers in push.headers. Publish the configuration first:
php artisan vendor:publish --tag=metrics-configFor a backend that takes a bearer token:
'push' => [ // ... 'headers' => [ 'Authorization' => 'Bearer '.env('OTLP_TOKEN'), ],],For Grafana Cloud, the endpoint is the OTLP gateway of your stack, and the header is Basic authentication with the instance ID and an access policy token:
OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp-gateway-prod-eu-west-2.grafana.net/otlpGRAFANA_INSTANCE_ID=123456GRAFANA_OTLP_TOKEN=glc_...'headers' => [ 'Authorization' => 'Basic '.base64_encode(env('GRAFANA_INSTANCE_ID').':'.env('GRAFANA_OTLP_TOKEN')),],Copy the gateway URL and the instance ID from the OpenTelemetry tile of your Grafana Cloud stack. The region in the URL differs per stack.
Only string header values are sent.
Set the resource
Section titled “Set the resource”Each push carries service.name and deployment.environment.name:
service.nameisOTEL_SERVICE_NAME, elseAPP_NAME, elselaravel.deployment.environment.nameisAPP_ENV.
To add your own attributes:
'resource' => [ 'service.name' => env('OTEL_SERVICE_NAME', env('APP_NAME', 'laravel')), 'deployment.environment.name' => env('APP_ENV'), 'service.namespace' => 'shop',],Do not add host or process attributes. The store holds the totals of every process and host.
Change the timeout
Section titled “Change the timeout”The push times out after 10 seconds. To change it:
'timeout' => 5,