This guide provides step-by-step instructions for setting up OpenTelemetry (OTel) instrumentation in your PHP applications to enable comprehensive observability. OpenTelemetry is an open-source framework that helps you collect telemetry data—such as traces, metrics, and logs—from your app to monitor its performance and health.
Once your telemetry data is captured, you can configure an exporter to send it directly to Atatus for advanced monitoring and insights.
The process of setting up OpenTelemetry in PHP involves three key steps:
Instrumenting Your PHP Application: Add the necessary OpenTelemetry components to your PHP app for trace and metric collection.
Configuring the Exporter: Set up the exporter to send your telemetry data to Atatus.
Validating the Setup: Verify that the configuration is working and that your data is being correctly sent to Atatus.
Requirements
- PHP 8.0+
- PECL
- Composer
Sending Telemetry Data to Atatus in Two Ways
Send Telemetry Traces to Atatus
Send Traces Using the OTel Collector Binary
Send Telemetry Traces to Atatus
Install dependencies (apt)
sudo apt-get install gcc make autoconf
Install OpenTelemetry and Protobuf Extensions. With our environment set up we can install the extension using PECL
pecl install opentelemetry pecl install protobuf
Enable the OpenTelemetry Extension, Need to add below extension to
php.ini
file.# php.ini [opentelemetry] extension=opentelemetry.so
Verify Extension
php -m | grep opentelemetry ## This should output: # opentelemetry
Install Composer Dependencies
composer config allow-plugins.php-http/discovery false composer require \ open-telemetry/sdk \ open-telemetry/exporter-otlp \ php-http/guzzle7-adapter \ open-telemetry/opentelemetry-auto-slim
Set Environment Variables and Run
env OTEL_PHP_AUTOLOAD_ENABLED=true \ OTEL_SERVICE_NAME=<service_name> \ OTEL_EXPORTER_OTLP_ENDPOINT="https://otel-rx.atatus.com:443" \ OTEL_EXPORTER_OTLP_HEADERS="api-key=ATATUS_INGESTION_KEY" \ OTEL_TRACES_EXPORTER=otlp \ OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf \ OTEL_PROPAGATORS=baggage,tracecontext \ php -S localhost:8080 app.php
You can get the ATATUS_INGESTION_KEY
from Settings -> Account Settings -> API Keys in Atatus dashboard.
Send Traces Using the OTel Collector Binary
To collect and send traces to Atatus, it's recommended to install the OpenTelemetry (OTel) Collector binary. The OTel Collector helps gather logs, host metrics, resource, and infrastructure attributes, enabling richer contextual data and easier signal correlation.
For detailed instructions on setting up the OTel Collector binary on your VM, please refer to the official installation guide. Once the Collector is up and running, you can proceed with instrumenting your Java application to start sending telemetry data to Atatus.
Install dependencies (apt)
sudo apt-get install gcc make autoconf
Install OpenTelemetry and Protobuf Extensions. With our environment set up we can install the extension using PECL
pecl install opentelemetry pecl install protobuf
Enable the OpenTelemetry Extension, Need to add below extension to
php.ini
file.# php.ini [opentelemetry] extension=opentelemetry.so
Verify Extension
php -m | grep opentelemetry ## This should output: # opentelemetry
Install Composer Dependencies
composer config allow-plugins.php-http/discovery false composer require \ open-telemetry/sdk \ open-telemetry/exporter-otlp \ php-http/guzzle7-adapter \ open-telemetry/opentelemetry-auto-slim
Set Environment Variables and Run
env OTEL_PHP_AUTOLOAD_ENABLED=true \ OTEL_SERVICE_NAME=<SERVICE_NAME> \ OTEL_TRACES_EXPORTER=otlp \ OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf \ OTEL_EXPORTER_OTLP_ENDPOINT=<COLLECTOR_ENDPOINT> \ OTEL_PROPAGATORS=baggage,tracecontext \ php -S localhost:8080 app.php