Skip to main content

What is OpenTelemetry?

OpenTelemetry is a vendor-neutral, open-source observability framework that provides a unified set of APIs, SDKs, and tools for generating, collecting, and exporting telemetry data. It is maintained by the Cloud Native Computing Foundation (CNCF) and is the industry standard for instrumenting cloud-native applications. Telemetry data comes in three signals:
  • Traces — distributed call graphs that show exactly what happened during a request, including cross-service hops.
  • Metrics — numerical measurements over time (request counts, latency histograms, error rates, etc.).
  • Logs — structured log records correlated with the active trace context.

What this package does

keepsuit/laravel-opentelemetry integrates the OpenTelemetry PHP SDK into Laravel with zero boilerplate. After installing the package and setting a couple of environment variables, your application automatically emits traces, metrics, and logs for the most common Laravel operations. The package handles the full SDK lifecycle — building providers, registering propagators, managing exporters, and flushing telemetry on shutdown — so you can focus on your application.

Supported instrumentations

All instrumentations are enabled by default and configurable via environment variables or config/opentelemetry.php.
InstrumentationWhat it tracesEnv variable
HTTP ServerIncoming HTTP requests via middlewareOTEL_INSTRUMENTATION_HTTP_SERVER
HTTP ClientOutgoing HTTP requests via Laravel’s Http facadeOTEL_INSTRUMENTATION_HTTP_CLIENT
DatabaseSQL queries via Laravel’s query listenerOTEL_INSTRUMENTATION_QUERY
Queue JobsDispatched and executed queue jobsOTEL_INSTRUMENTATION_QUEUE
RedisRedis commandsOTEL_INSTRUMENTATION_REDIS
CacheCache hits, misses, and writes as span eventsOTEL_INSTRUMENTATION_CACHE
EventsLaravel events as span eventsOTEL_INSTRUMENTATION_EVENT
ViewsBlade view renderingOTEL_INSTRUMENTATION_VIEW
LivewireLivewire component renderingOTEL_INSTRUMENTATION_LIVEWIRE
Console CommandsArtisan commands (opt-in per command)OTEL_INSTRUMENTATION_CONSOLE
Laravel ScoutSearch, update, and delete operationsOTEL_INSTRUMENTATION_SCOUT

Signals

Traces

Distributed traces are the primary signal. Every instrumented operation creates a span inside the active trace. Spans are exported via OTLP to any compatible backend — Jaeger, Grafana Tempo, Honeycomb, Datadog, and others. The Tracer facade lets you create custom spans and access the active trace ID.

Metrics

The package collects HTTP server and client request durations, database and Redis operation durations, and any custom metrics you define with the Meter facade. Metrics are exported via OTLP.

Logs

An otlp log channel is automatically injected into Laravel’s logging system. When you log through this channel, log records are exported via OTLP with the active trace ID attached, correlating logs directly with traces.

Key features

Auto-instrumentation

Covers HTTP, database, queues, Redis, cache, events, views, Livewire, Scout, and console commands out of the box — no code changes required.

Manual tracing

Use the Tracer facade and its fluent SpanBuilder API when you need custom spans for business-level operations.

Tail sampling

Keep only meaningful traces. Built-in rules for errors and slow traces. Custom rules are supported via a simple interface.

Worker mode

Automatic detection and optimized flushing for long-running processes: Laravel Octane, Horizon, and queue workers.

User context

Automatically attaches the authenticated user ID to traces and logs. Customizable via a resolver callback.

Multiple exporters

OTLP over HTTP (protobuf or JSON) or gRPC, Zipkin, console output, or in-memory. Configure separate exporters per signal.

Requirements

  • PHP 8.2 or higher
  • Laravel 11, 12, or 13
  • An OpenTelemetry Collector or compatible backend (Jaeger, Grafana Tempo, Honeycomb, Datadog, etc.)

Get started

Installation

Install the package and publish the config file.

Quickstart

Emit your first traces in under five minutes.

HTTP server instrumentation

Learn how incoming requests are automatically traced.

Tracer facade

Full API reference for manual tracing.

Build docs developers (and LLMs) love