Configuration

Configuration options for OpenTelemetry PHP Distro.

OpenTelemetry PHP Distro supports standard OpenTelemetry SDK configuration and distro-specific options.

Configuration method

Configure via environment variables available to PHP processes:

  • OTEL_* for OpenTelemetry standard options
  • OTEL_PHP_* for distro-specific options

Example:

export OTEL_EXPORTER_OTLP_ENDPOINT="https://your-endpoint:443/"
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer <token>"
export OTEL_PHP_LOG_LEVEL_STDERR="INFO"

OpenTelemetry options

The distro supports standard OpenTelemetry PHP SDK options.

OptionDefaultAccepted valuesDescription
OTEL_EXPORTER_OTLP_ENDPOINThttp://localhost:4318URLOTLP endpoint URL
OTEL_EXPORTER_OTLP_HEADERS(empty)key=value,key2=value2OTLP request headers
OTEL_EXPORTER_OTLP_INSECUREfalsetrue or falseDisable TLS verification (testing only)
OTEL_EXPORTER_OTLP_CERTIFICATE(empty)Filesystem path (PEM)CA certificate path for OTLP TLS
OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE(empty)Filesystem path (PEM)Client certificate for OTLP mTLS
OTEL_EXPORTER_OTLP_CLIENT_KEY(empty)Filesystem path (PEM)Client key for OTLP mTLS
OTEL_EXPORTER_OTLP_CLIENT_KEYPASS(empty)StringPassphrase for encrypted OTLP client key
OTEL_SERVICE_NAMEunknown_serviceStringValue of service.name resource attribute
OTEL_RESOURCE_ATTRIBUTES(empty)key=value,key2=value2Resource attributes
OTEL_TRACES_SAMPLERparentbased_always_onSampler nameTrace sampler
OTEL_TRACES_SAMPLER_ARG(empty)String/numberSampler argument
OTEL_LOG_LEVELinfoerror, warn, info, debugSDK internal log level

Distro-specific options (OTEL_PHP_*)

All OTEL_PHP_* options can be set as environment variables or in php.ini.

For php.ini, use the opentelemetry_distro. prefix and lowercase option names.

Example:

export OTEL_PHP_ENABLED=true
opentelemetry_distro.enabled=true

General configuration

OptionDefaultAccepted valuesDescription
OTEL_PHP_ENABLEDtruetrue or falseEnables automatic bootstrap
OTEL_PHP_OPENTELEMETRY_EXTENSION_EMULATION_ENABLEDtruetrue or falseEnables registration of an emulated opentelemetry extension, allowing auto-instrumentations to work without opentelemetry.so
OTEL_PHP_NATIVE_OTLP_SERIALIZER_ENABLEDtruetrue or falseEnables native OTLP protobuf serializer

Asynchronous data sending

OptionDefaultAccepted valuesDescription
OTEL_PHP_ASYNC_TRANSPORTtruetrue or falseEnables background transfer of telemetry
OTEL_PHP_ASYNC_TRANSPORT_SHUTDOWN_TIMEOUT30sDuration (ms, s, m)Flush timeout at shutdown
OTEL_PHP_MAX_SEND_QUEUE_SIZE2MBInteger with optional B, MB, GBMax async buffer size per worker

Logging

OptionDefaultAccepted valuesDescription
OTEL_PHP_LOG_FILE(empty)Filesystem pathLog output file path
OTEL_PHP_LOG_LEVEL_FILEOFFOFF, CRITICAL, ERROR, WARNING, INFO, DEBUG, TRACEFile sink log level
OTEL_PHP_LOG_LEVEL_STDERROFFOFF, CRITICAL, ERROR, WARNING, INFO, DEBUG, TRACEStderr sink log level
OTEL_PHP_LOG_LEVEL_SYSLOGOFFOFF, CRITICAL, ERROR, WARNING, INFO, DEBUG, TRACESyslog sink log level
OTEL_PHP_LOG_FEATURES(empty)FEATURE=LEVEL,...Per-feature log levels

Transaction span

OptionDefaultAccepted valuesDescription
OTEL_PHP_TRANSACTION_SPAN_ENABLEDtruetrue or falseAuto root span for web SAPI
OTEL_PHP_TRANSACTION_SPAN_ENABLED_CLItruetrue or falseAuto root span for CLI
OTEL_PHP_TRANSACTION_URL_GROUPS(empty)Comma-separated wildcardsURL grouping patterns

Attribute-based instrumentation

OptionDefaultAccepted valuesDescription
OTEL_PHP_ATTR_HOOKS_ENABLEDfalsetrue or falseEnables #[WithSpan] / #[SpanAttribute] attribute-based span creation. See Attribute-based instrumentation.

Scoped dependencies bridge

OptionDefaultAccepted valuesDescription
OTEL_PHP_SCOPED_DEPS_BRIDGE_ENABLEDfalsetrue or falseLets the application’s own OpenTelemetry usage share the distro’s runtime (tracer provider, context) so its spans join the distro’s traces. See note below.

Inferred spans

OptionDefaultAccepted valuesDescription
OTEL_PHP_INFERRED_SPANS_ENABLEDfalsetrue or falseEnables inferred spans
OTEL_PHP_INFERRED_SPANS_REDUCTION_ENABLEDtruetrue or falseReduces consecutive duplicate frames
OTEL_PHP_INFERRED_SPANS_STACKTRACE_ENABLEDtruetrue or falseAttaches stacktrace to inferred spans
OTEL_PHP_INFERRED_SPANS_SAMPLING_INTERVAL50msDuration (ms, s, m)Stacktrace sampling interval
OTEL_PHP_INFERRED_SPANS_MIN_DURATION0Duration (ms, s, m)Minimum inferred span duration

Central configuration (OpAMP)

OptionDefaultAccepted valuesDescription
OTEL_PHP_OPAMP_ENDPOINT(empty)HTTP/HTTPS URL ending with /v1/opampOpAMP endpoint
OTEL_PHP_OPAMP_HEADERS(empty)key=value,key2=value2OpAMP request headers
OTEL_PHP_OPAMP_HEARTBEAT_INTERVAL30sDuration (ms, s, m)The interval between heartbeat messages sent to the OpAMP server.
OTEL_PHP_OPAMP_POLLING_INTERVAL30sDuration (ms, s, m)The interval at which the agent polls the OpAMP server for updated configuration. Independent from the heartbeat interval.
OTEL_PHP_OPAMP_SEND_TIMEOUT10sDuration (ms, s, m)OpAMP send timeout
OTEL_PHP_OPAMP_SEND_MAX_RETRIES3Integer >= 0Retry count
OTEL_PHP_OPAMP_SEND_RETRY_DELAY10sDuration (ms, s, m)Retry delay
OTEL_PHP_OPAMP_INSECUREfalsetrue or falseDisable TLS verification (testing only)
OTEL_PHP_OPAMP_CERTIFICATE(empty)Filesystem path (PEM)CA certificate path for OpAMP TLS
OTEL_PHP_OPAMP_CLIENT_CERTIFICATE(empty)Filesystem path (PEM)Client certificate path for OpAMP mTLS
OTEL_PHP_OPAMP_CLIENT_KEY(empty)Filesystem path (PEM)Client key path for OpAMP mTLS
OTEL_PHP_OPAMP_CLIENT_KEYPASS(empty)StringPassphrase for encrypted client key

Supportability

OptionDefaultAccepted valuesDescription
OTEL_PHP_SCOPED_DEPS_ENABLEDtruetrue or falseControls whether scoped (namespace-prefixed) or original dependencies are used by the distro. See note below.

Notes

  • Background transfer works with OTLP HTTP/protobuf mode.
  • OTEL_PHP_AUTOLOAD_ENABLED is enforced as enabled by the distro runtime.
  • The distro package includes multiple dependencies (OpenTelemetry SDK, various auto-instrumentation packages, and their transitive dependencies). To prevent namespace conflicts with the application’s own dependencies, the distro uses scoped (namespace-prefixed) dependencies by default. To fall back to unscoped dependencies, set OTEL_PHP_SCOPED_DEPS_ENABLED=false.

Scoped dependencies bridge interop

By default the distro’s OpenTelemetry runtime is scoped: its classes live under a unique namespace prefix, separate from the standard OpenTelemetry\* classes an application would install via Composer. As a result, the application’s own OpenTelemetry usage runs against a separate runtime and its spans are neither exported nor connected to the distro’s traces.

Setting OTEL_PHP_SCOPED_DEPS_BRIDGE_ENABLED=true bridges the two: before the application’s Composer autoloader runs, the distro registers class aliases mapping the unscoped OpenTelemetry\* API onto its scoped implementation. The application’s own OpenTelemetry usage then transparently uses the distro’s tracer provider and context, so its spans are exported and correctly parented within the distro’s traces.

This option has no effect when scoping is disabled (OTEL_PHP_SCOPED_DEPS_ENABLED=false): without scoping the distro already uses the unscoped OpenTelemetry\* classes, so sharing happens without any bridging.

File-based configuration (declarative)

As an alternative to environment variables, you can configure the SDK using a YAML configuration file by setting the OTEL_CONFIG_FILE environment variable:

export OTEL_CONFIG_FILE=/path/to/otel-config.yaml

When OTEL_CONFIG_FILE is set:

  • The SDK reads all configuration from the YAML file instead of individual OTEL_* environment variables.
  • Environment variable substitution (${MY_VAR:-default}) is supported within the YAML file.
  • Central configuration (OpAMP) is automatically disabled — file-based and remote configuration are mutually exclusive.
  • Distro-specific options (OTEL_PHP_*) continue to work as they are native extension options, independent of the SDK.

Distro resource detector

The distro provides a distro resource detector that adds telemetry.distro.name and telemetry.distro.version resource attributes. To activate it in file-based configuration, add it to the resource.detection/development.detectors section:

file_format: '1.0-rc.2'

resource:
  attributes:
    - name: service.name
      value: my-service
  detection/development:
    detectors:
      - distro: {}

propagator:
  composite:
    - tracecontext:
    - baggage:

tracer_provider:
  processors:
    - batch:
        exporter:
          otlp_http:
            endpoint: http://localhost:4318/v1/traces

meter_provider:
  readers:
    - periodic:
        exporter:
          otlp_http:
            endpoint: http://localhost:4318/v1/metrics

logger_provider:
  processors:
    - batch:
        exporter:
          otlp_http:
            endpoint: http://localhost:4318/v1/logs

For the full YAML schema, see the OpenTelemetry Configuration Schema.

Limitations

  • Central configuration (OpAMP) is not available when file-based configuration is active.
  • Resource detectors registered via Registry::registerResourceDetector() (for example, cloud provider detectors from opentelemetry-php-contrib) are not automatically active. They must provide a ComponentProvider and be explicitly listed in the YAML resource.detection/development.detectors section.