Start free trial
Start free trial Log in

14-day free trial. No credit card.

OpenTelemetry in Laravel

  • Glossary
  • 2 minute read

What is OpenTelemetry and how do I use it in Laravel?

OpenTelemetry (OTel) is a vendor-neutral specification and SDK suite for emitting traces, metrics, and logs. In Laravel, install open-telemetry/sdk + an OTLP exporter, configure a tracer, and ship spans to an OTel Collector that forwards to your backend of choice (Tempo, Jaeger, SigNoz, Datadog, Honeycomb). Use OTel when portability or polyglot tracing matters. For Laravel-specific depth, the Nightwatch package (used by Nightwatch Cloud and NightOwl) captures framework context OTel's generic instrumentation doesn't.

Updated

OpenTelemetry is the closest thing observability has to a standard, and like most standards it's verbose and easy to over-adopt. For a Laravel team the useful question isn't "is OTel good" (it is) but "is it the right tool for the part of the system I'm instrumenting." For a single Laravel app the answer is often no; at a boundary between services it's often yes.

The pitch

Before OTel, every APM vendor had its own SDK. Switching vendors meant rewriting instrumentation. OTel decouples: your code emits OTel spans, a Collector forwards them to whatever backend you want. Today that might be Tempo; tomorrow Honeycomb; ten years from now, something not yet invented. Your instrumentation doesn't change.

The three pillars

  • Traces: request waterfalls across services. The most mature OTel pillar.
  • Metrics: counters, gauges, histograms. Solid but newer than tracing.
  • Logs: structured log records with trace correlation. Stable in the PHP SDK, though support still varies across other languages.

Setting up OTel in Laravel

Terminal
composer require \
    open-telemetry/sdk \
    open-telemetry/exporter-otlp \
    open-telemetry/sem-conv
app/Providers/TelemetryServiceProvider.php
use OpenTelemetry\API\Trace\Propagation\TraceContextPropagator;
use OpenTelemetry\Contrib\Otlp\OtlpHttpTransportFactory;
use OpenTelemetry\Contrib\Otlp\SpanExporter;
use OpenTelemetry\SDK\Common\Attribute\Attributes;
use OpenTelemetry\SDK\Resource\ResourceInfo;
use OpenTelemetry\SDK\Resource\ResourceInfoFactory;
use OpenTelemetry\SDK\Sdk;
use OpenTelemetry\SDK\Trace\SpanProcessor\BatchSpanProcessorBuilder;
use OpenTelemetry\SDK\Trace\TracerProvider;
use OpenTelemetry\SemConv\Attributes\DeploymentAttributes;
use OpenTelemetry\SemConv\Attributes\ServiceAttributes;

public function register(): void
{
    $transport = (new OtlpHttpTransportFactory())->create(
        'http://localhost:4318/v1/traces', 'application/x-protobuf'
    );
    $exporter = new SpanExporter($transport);

    $resource = ResourceInfoFactory::defaultResource()->merge(
        ResourceInfo::create(Attributes::create([
            ServiceAttributes::SERVICE_NAME => config('app.name'),
            DeploymentAttributes::DEPLOYMENT_ENVIRONMENT_NAME => config('app.env'),
        ]))
    );

    $tracerProvider = TracerProvider::builder()
        ->addSpanProcessor((new BatchSpanProcessorBuilder($exporter))->build())
        ->setResource($resource)
        ->build();

    Sdk::builder()
        ->setTracerProvider($tracerProvider)
        ->setPropagator(TraceContextPropagator::getInstance())
        ->setAutoShutdown(true)
        ->buildAndRegisterGlobal();
}

Run an OTel Collector alongside your app. Forward spans to Tempo, Jaeger, SigNoz, or any SaaS vendor that speaks OTLP.

OTel vs Nightwatch (Laravel's first-party package)

  • OTel: vendor-neutral, polyglot, generic. You get portability at the cost of Laravel depth.
  • Nightwatch: Laravel-specific, framework-aware, captures queries grouped by SQL, queue job classes, scheduled tasks with minimal code. Not portable to non-Laravel services.

A common split: use the Nightwatch package (via NightOwl or Nightwatch Cloud) for Laravel-native monitoring; add OTel only at service boundaries where you need cross-service traces.

Get Laravel-aware monitoring without a tracer setup

NightOwl is built on laravel/nightwatch, which records routes, queries, queued jobs, scheduled tasks, cache, mail and notifications without any tracer or exporter to configure. You can keep OpenTelemetry for the calls that cross into other services.

No credit card needed.

Frequently asked questions

Anything else, write to support@usenightowl.com

What is OpenTelemetry?

An open-source, vendor-neutral specification and SDK suite for emitting traces, metrics, and logs. It decouples instrumentation (the SDK in your app) from the backend (Jaeger, Tempo, Datadog, Honeycomb, etc.), so you can switch backends without re-instrumenting. Often abbreviated OTel.

Does Laravel support OpenTelemetry?

Yes, via the open-telemetry/sdk PHP package. You install the SDK and an exporter, then either instrument manually or add the official open-telemetry/opentelemetry-auto-laravel package (still in beta), which needs PHP's opentelemetry extension. Setup is a few composer packages plus config; functional but more manual than single-vendor Laravel SDKs.

When should I use OpenTelemetry instead of a vendor SDK?

Pick OTel when: (1) you want to switch observability vendors without re-instrumenting, (2) you're polyglot and want one spec across services, (3) you want to ship to multiple backends simultaneously (e.g., Tempo for traces + Prometheus for metrics). Pick a vendor SDK when: (1) you're committed to one platform anyway, (2) the vendor ships a better Laravel-first integration.

What's OTLP?

OpenTelemetry Protocol: the wire format OTel SDKs use to send telemetry. Usually over gRPC (binary, efficient) or HTTP/protobuf. Most modern trace backends (Tempo, Jaeger 1.35+, SigNoz, Honeycomb, Datadog) accept OTLP natively, which is what lets you switch backends without touching your code.

Is NightOwl built on OpenTelemetry?

No. NightOwl is built on laravel/nightwatch, the official Laravel instrumentation package. Nightwatch is Laravel-specific. It captures framework-aware context (routes, queries grouped by SQL, queued job classes, scheduled tasks, cache events, mail, notifications) that generic OTel instrumentation doesn't see as cleanly. Different design tradeoff: less portability, more Laravel depth.

Can I run OpenTelemetry alongside Laravel Nightwatch?

Yes. They don't conflict. OTel emits its own spans; Nightwatch emits Laravel-specific records. A common setup in multi-service architectures is to run both: OTel for cross-service traces, Nightwatch for deep Laravel-native monitoring within the Laravel app. Pick one to be the primary dashboard.

How do I get started with OpenTelemetry in Laravel?

composer require open-telemetry/sdk open-telemetry/exporter-otlp open-telemetry/sem-conv. Register a tracer provider in a service provider with your app.name and environment, and make it global with Sdk::builder()->buildAndRegisterGlobal(). Start an OTel Collector (Docker Compose) to receive spans and forward to your backend. Instrument critical paths manually at first; adopt auto-instrumentation (the opentelemetry PECL extension plus the open-telemetry/opentelemetry-auto-laravel package) once you've seen value. See the official OTel PHP docs.

Keep reading

Flat pricing, whatever your traffic does

Every plan starts with a 14-day free trial. No credit card needed.

Hobby
$5 a month

One app for a side project. Issues and alerts, with a 14-day dashboard window.

Start my 14-day trial
TeamRecommended
$15 a month

Up to 3 apps and 5 people per team. Full history, the MCP server, data clearing and agent health.

Start my 14-day trial
Agency
$69 a month

Unlimited client apps and people, one overview of every app, and apps you can hand over.

Start my 14-day trial