OpenTelemetry for Laravel

The keepsuit/laravel-opentelemetry package hooks OpenTelemetry into Laravel's HTTP kernel, database, queue, cache and logging. Install it, set a few variables in .env, and requests, queries and jobs reach Maple as traces.

GET /orders/{order} 5 spans · 81ms
DurationStatus
/orders/{order}store-app
81.0msOk
SELECT orders
9.0msOk
HTTP GET
34.0msOk
/ratesshipping-api
29.0msOk
orders.show
18.0msOk

Example: a Laravel request with a query and an Http call

Quick start

Set up Laravel

1

Install the package and publish its config

bash
composer require keepsuit/laravel-opentelemetry

php artisan vendor:publish \
  --provider="Keepsuit\LaravelOpenTelemetry\LaravelOpenTelemetryServiceProvider" \
  --tag="opentelemetry-config"
2

Point the exporters at Maple

bash
# .env
OTEL_SERVICE_NAME=my-laravel-app

OTEL_TRACES_EXPORTER=otlp
OTEL_METRICS_EXPORTER=otlp
OTEL_LOGS_EXPORTER=otlp

OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.maple.dev
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer YOUR_INGEST_KEY"

OTEL_RESOURCE_ATTRIBUTES="deployment.environment.name=production"
3

Send logs to the otlp channel

php
// config/logging.php
'channels' => [
    'stack' => [
        'driver' => 'stack',
        'channels' => ['single', 'otlp'],
    ],
],

This is the short path. The full Laravel guide covers the rest.

Organization in the EU region? Send to https://ingest.eu.maple.dev instead of https://ingest.maple.dev. An ingest key only works in its own region.

What you get

What a Laravel app sends to Maple

HTTP requests

A server span per request, named after its method and route, and the http.server.request.duration metric.

Eloquent and the query builder

A span per statement with the standard db.* attributes, which draw the database node on the service map.

Queue jobs

Producer and consumer spans, with the trace context carried across the queue to the worker.

Http facade calls

A client span per outgoing request, with traceparent sent to the service you call.

Redis, cache and views

Redis commands as spans, cache hits and misses as span events, and a span per view or Livewire render.

Logs on the otlp channel

Log records go to Maple with the active trace id attached, so each line links to its request.

What is different in Laravel

Protobuf needs an extension

http/protobuf falls back to the slow pure-PHP protobuf library. Install the protobuf C extension for production, or set the protocol to http/json, which Maple also accepts.

Cached config hides changes

After editing .env, run php artisan config:clear. A cached config keeps exporting with the old values, or not at all.

Switch off what you do not need

Each instrumentation has its own OTEL_INSTRUMENTATION_* variable, such as OTEL_INSTRUMENTATION_QUERY=false. Keep queries on: they feed the service map.

통합

다른 통합

오늘 첫 트레이스를 확인하세요.

SDK를 추가하고 OTLP 익스포터를 Maple로 향하게 하면 트레이스가 도착합니다.

maple.dev: OpenTelemetry 위의 옵저버빌리티