open-telemetry/opentelemetry-auto-psr3

OpenTelemetry auto-instrumentation for PSR-3 (Logger Interface).

Package info

github.com/opentelemetry-php/contrib-auto-psr3

Homepage

pkg:composer/open-telemetry/opentelemetry-auto-psr3

Statistics

Installs: 1 242 792

Dependents: 1

Suggesters: 1

Stars: 0

0.2.0 2026-03-24 16:33 UTC

Requires

Suggests

None

Provides

None

Conflicts

None

Replaces

None

Apache-2.0 fcf4d9b6ea43a8001e19804517a83e8865875365

PSR3instrumentationtracingopentelemetryopen-telemetryotel

This package is auto-updated.

Last update: 2026-06-08 12:54:37 UTC


README

👁 Releases
👁 Issues
👁 Source
👁 Mirror
👁 Latest Version
👁 Stable

This is a read-only subtree split of https://github.com/open-telemetry/opentelemetry-php-contrib.

OpenTelemetry PSR-3 auto-instrumentation

Please read https://opentelemetry.io/docs/instrumentation/php/automatic/ for instructions on how to install and configure the extension and SDK.

Overview

Auto-instrumentation hooks are registered via composer, and depending on the mode, will:

  • automatically inject trace id and span id into log message context of any psr3 logger; or
  • transform the message into the OpenTelemetry LogRecord format, for export to an OpenTelemetry logging-compatible backend

Mode

The package can operate in two modes, controlled by the environment variable OTEL_PHP_PSR3_MODE:

inject

Inject trace_id and span_id of the active trace span into the context of each logged message. Depending on the PSR-3 implementation, the values may be written to the log output, or may be available for interpolation into the log message.

For example:

putenv('OTEL_PHP_PSR3_MODE=inject');
require 'vendor/autoload.php';

$logger = /* create logger */
$logger->info('trace_id={trace_id} span_id={span_id}');

export

The logged output will be processed and emitted by the logger as normal, but the output will also be encoded using the OpenTelemetry log model and can be exported to an OpenTelemetry-compatible backend.

putenv('OTEL_PHP_PSR3_MODE=export');
putenv('OTEL_PHP_AUTOLOAD_ENABLED=true');
putenv('OTEL_LOGS_EXPORTER=console');
require 'vendor/autoload.php';

$logger = /* create logger */
$logger->info('Hello, OTEL');

Configuration

The extension can be disabled via runtime configuration:

OTEL_PHP_DISABLED_INSTRUMENTATIONS=psr3