PHP Slim
Prerequisites
- PHP 8.0+
- composer
Installation
-
Install the required dependencies:
-
Install the required tools:
- Linux
- Mac
sudo apt-get install php-pear php-dev libtool make gcc autoconf libz-dev zip
brew install php libtool make gcc autoconf zlib zip
-
Build the extensions:
sudo pecl install opentelemetry
sudo pecl install protobuf -
Add the extensions to your php.ini file:
[opentelemetry]
extension=opentelemetry.so
extension=protobuf.so -
Verify that the extensions are installed and enabled:
php --ri opentelemetry
php --ri protobuf -
Add additional dependencies to your application:
composer config allow-plugins.php-http/discovery true
composer require php-http/guzzle7-adapter \
open-telemetry/sdk \
open-telemetry/opentelemetry-auto-slim \
open-telemetry/exporter-otlp \
open-telemetry/opentelemetry-auto-psr15 \
open-telemetry/opentelemetry-auto-psr18
# Install instrumentation packages for libraries used in your project.
# Visit the below link for a list of available instrumentation packages.
# https://opentelemetry.io/ecosystem/registry/?component=instrumentation&language=php
#
#composer require open-telemetry/opentelemetry-auto-guzzle
-
-
Modify the application run command as follows:
OTEL_PHP_AUTOLOAD_ENABLED=true \
OTEL_SERVICE_NAME=<app_name> \
OTEL_METRICS_EXPORTER=none \
OTEL_LOGS_EXPORTER=none \
OTEL_TRACES_EXPORTER=otlp \
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf \
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://<ip_address_of_cubeapm_server>:4318/v1/traces \
OTEL_EXPORTER_OTLP_COMPRESSION=gzip \
OTEL_PROPAGATORS=baggage,tracecontext \
php myapp.php
Data should now be visible in your CubeAPM account.
Troubleshooting
Traces exporter can be changed from otlp
to console
to output traces on console.
The following command can be tried on the application host server to check connectivity to CubeAPM server(s):
telnet <ip_address_of_cubeapm_server> 4318