Observe PHP applications in real-time. Gain insights into your app's performance and identify potential issues proactively.
Instrumenting your PHP application to generate traces, logs, and metrics is a powerful way to gain deep insights into its behavior and performance. For example, to get a clearer picture of your Laravel applications and the database statements generated through Eloquent ORM. By adding instrumentation, you enable your application to emit valuable data that can be used for monitoring, troubleshooting, and optimization.
Dash0 supports automatic instrumentation of PHP applications through OpenTelemetry's open-source and vendor-agnostic packages.
Want AI to set this up for you? Install the Dash0 Agent Skills to let Claude Code, Cursor, or Windsurf instrument your application automatically with OpenTelemetry best practices.
The opentelemetry-php-contrib repository offers a comprehensive set of auto-instrumentation libraries that enable observability for PHP workloads without requiring any application code changes.
This guide demonstrates how to instrument a PHP application built with the Slim Framework by installing a minimal set of packages and applying the required configuration to enable auto-instrumentation. We also encourage the use of any additional auto-instrumentation libraries relevant to the technologies used in your application, as listed in the repository above.
Within the Instrumentation section of the opentelemetry-php-contrib repository, a wide range of auto-instrumentation libraries is available. In this example, we will utilize the auto-instrumentation for common PHP frameworks and HTTP clients by installing the required OpenTelemetry packages.
1. Install the required packages
composer require \
open-telemetry/sdk \
open-telemetry/opentelemetry-auto-slim \
open-telemetry/exporter-otlp \
open-telemetry/opentelemetry-auto-psr18These packages provide:
Step 2: Install PHP Extension
To install the required PHP extension, use the appropriate command for your operating system:
Linux (APT-based distributions):
sudo apt-get install gcc make autoconfmacOS (Homebrew):
brew install gcc make autoconfAfter finish the installation by building and installing the PHP extension, run:
pecl install opentelemetryStep 3: Run your app with the appropriate otel environment variables
OTEL_PHP_AUTOLOAD_ENABLED=true \
OTEL_SERVICE_NAME="my-first-observable-php-service" \
OTEL_TRACES_EXPORTER="otlp" \
OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf" \
OTEL_EXPORTER_OTLP_ENDPOINT="{{endpoint_otlp_http}}" \
OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer {{token}}" \
php -S localhost:8000 -t publicIn case you are not using the Dash0 operator for Kubernetes to deploy your application, you should extend the OpenTelemetry resource attributes to include the Pod UID. This is important to merge the resources between logs,traces and metrics. You can do this by adding the following environment variables to your deployment:
env:
- name: K8S_POD_UID
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.uid
- name: K8S_POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: OTEL_RESOURCE_ATTRIBUTES
value: k8s.pod.name=$(K8S_POD_NAME),k8s.pod.uid=$(K8S_POD_UID)This will add the k8s.pod.name and k8s.pod.uid attributes to the OpenTelemetry resource attributes, which will be included in all telemetry data sent to Dash0.
To read more about resource equality and merging, please refer to the Dash0 docs.
In order to learn more about the importance of resource attributes read the blog post OpenTelemetry resource attributes: Best practices for Kubernetes
To see which libraries are automatically instrumented, refer to the OpenTelemetry registry.