Skip to main content
This package integrates Laravel’s logging system with OpenTelemetry. Log records are exported to your configured backend (such as an OTLP collector) and automatically correlated with the active trace when one is running.

The otlp log channel

The package automatically registers an otlp log channel in Laravel’s logging system. You can reference it directly in config/logging.php without defining it yourself, but you can also override its configuration:
// config/logging.php
'channels' => [
    // Automatically registered — override only if you need to change defaults
    'otlp' => [
        'driver' => 'monolog',
        'handler' => \Keepsuit\LaravelOpenTelemetry\Support\OpenTelemetryMonologHandler::class,
        'level' => 'debug',
    ],
],
The handler forwards each log record through the Logger facade, which emits it as an OpenTelemetry log record with the correct severity, timestamp, and any active trace context.

Set otlp as the default channel

To send all application logs to OpenTelemetry, set it as the default channel:
// config/logging.php
'default' => env('LOG_CHANNEL', 'otlp'),

Stack otlp with other channels

To send logs to both OpenTelemetry and another destination (for example, the standard daily file channel):
// config/logging.php
'default' => env('LOG_CHANNEL', 'stack'),

'channels' => [
    'stack' => [
        'driver' => 'stack',
        'channels' => ['daily', 'otlp'],
    ],
],

Logger facade

You can also send logs directly to OpenTelemetry without going through Laravel’s log system by using the Logger facade:
use Keepsuit\LaravelOpenTelemetry\Facades\Logger;

Logger::emergency('my log message');
Logger::alert('my log message');
Logger::critical('my log message');
Logger::error('my log message');
Logger::warning('my log message');
Logger::notice('my log message');
Logger::info('my log message');
Logger::debug('my log message');
All methods accept an optional $context array as a second argument:
Logger::info('User logged in', ['user.id' => $user->id]);
You can also use the generic log method with a PSR-3 log level:
Logger::log('warning', 'Disk space low', ['used_percent' => 92]);

Trace ID injection

Correlating logs with traces lets you jump from a log record directly to the trace in your observability backend. This package supports trace ID injection in two ways:

Automatic injection via the otlp channel

When you use the otlp log channel or the Logger facade, the active trace ID is always included in the exported log record. No additional configuration is needed.

Injection into other log channels

When using other log channels (for example, daily or stderr), the package can inject the trace ID into Laravel’s shared log context so it appears in every log record:
use Keepsuit\LaravelOpenTelemetry\Facades\Tracer;

// After starting a trace manually, call this to inject the trace ID
Tracer::updateLogContext();
When using the built-in instrumentations (e.g. the HTTP server instrumentation), updateLogContext is called automatically at the start of each request.

Configuration

Trace ID injection is controlled by two options in config/opentelemetry.php:
'logs' => [
    /**
     * Inject the active trace ID into the log context for non-OTLP channels.
     * When using the otlp channel, the trace ID is always injected regardless of this setting.
     */
    'inject_trace_id' => true,

    /**
     * The field name used for the trace ID in the log context.
     */
    'trace_id_field' => 'trace_id',
],
OptionDefaultDescription
logs.inject_trace_idtrueInject the trace ID into the log context for non-OTLP log channels
logs.trace_id_fieldtrace_idField name added to log records containing the trace ID
When you start a root span manually (rather than relying on automatic instrumentation), call Tracer::updateLogContext() after activating the span to ensure the trace ID is available in non-OTLP log channels.

Build docs developers (and LLMs) love