OpenTelemetry PHP Installation
Please follow the installation guide first, when adding a new application to AppSignal.
Then make sure to install the AppSignal collector before proceeding.
Install the OpenTelemetry PHP extension
First, make sure the build dependencies required to install the OpenTelemetry PHP extension are installed.
sudo apt-get install gcc make autoconf
brew install gcc make autoconf
Then, install the OpenTelemetry PHP extension using either PECL, pie, pickle, or docker-php-extension-installer:
pecl install opentelemetry
# Install pie (skip this step if pie is already installed) curl -L https://github.com/php/pie/releases/latest/download/pie.phar -o /usr/local/bin/pie && chmod +x /usr/local/bin/pie # Install the extension pie install open-telemetry/ext-opentelemetry
# Install pickle (skip this step if pickle is already installed) curl -L https://github.com/FriendsOfPHP/pickle/releases/latest/download/pickle.phar -o /usr/local/bin/pickle && chmod +x /usr/local/bin/pickle # Install the extension pickle install opentelemetry
# Use the docker-php-extension-installer script in your Dockerfile when using official PHP Docker images ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ RUN install-php-extensions opentelemetry
Finally, enable the extension in your PHP installation's configuration file. The configuration file is usually named php.ini
, and its location can be found by running php --ini
. Add the following lines to it:
[opentelemetry] extension=opentelemetry.so
Install the OpenTelemetry packages
First, configure Composer to disallow certain plugins that may conflict with the OpenTelemetry packages:
composer config allow-plugins.tbachert/spi false composer config allow-plugins.php-http/discovery false
Then, use Composer to install the OpenTelemetry SDK and OTLP exporter package:
composer require open-telemetry/sdk open-telemetry/exporter-otlp
Configure OpenTelemetry in your application
Add this appsignal.php
file at the root of your application with the OpenTelemetry exporter and AppSignal configuration. Then, require()
that file before your application starts.
Make sure to update the values below with your AppSignal application name, environment and push API key, and to replace the exporter endpoint with the address of your AppSignal collector if needed.
<?php use OpenTelemetry\API\Globals; use OpenTelemetry\API\Logs\EventLogger; use OpenTelemetry\API\Logs\LogRecord; use OpenTelemetry\API\Trace\Propagation\TraceContextPropagator; use OpenTelemetry\Contrib\Otlp\LogsExporter; use OpenTelemetry\Contrib\Otlp\MetricExporter; use OpenTelemetry\Contrib\Otlp\SpanExporter; use OpenTelemetry\SDK\Common\Attribute\Attributes; use OpenTelemetry\SDK\Common\Export\Stream\StreamTransportFactory; use OpenTelemetry\SDK\Logs\LoggerProvider; use OpenTelemetry\SDK\Logs\Processor\SimpleLogRecordProcessor; use OpenTelemetry\SDK\Metrics\MeterProvider; use OpenTelemetry\SDK\Metrics\MetricReader\ExportingReader; use OpenTelemetry\SDK\Resource\ResourceInfo; use OpenTelemetry\SDK\Resource\ResourceInfoFactory; use OpenTelemetry\SDK\Sdk; use OpenTelemetry\SDK\Trace\Sampler\AlwaysOnSampler; use OpenTelemetry\SDK\Trace\Sampler\ParentBased; use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor; use OpenTelemetry\SDK\Trace\TracerProvider; use OpenTelemetry\SemConv\ResourceAttributes; use OpenTelemetry\Contrib\Otlp\OtlpHttpTransportFactory; // Replace with your application name $name = "My application"; // Replace with your application environment $environment = "production"; // Replace with your AppSignal push API key $pushApiKey = "0000-0000-0000-0000"; // Replace with your service name like "Web server" $serviceName = "My App"; // Replace with the address of your AppSignal collector if it's running on another host $collector = 'http://appsignal-collector:8099'; $revision = trim(shell_exec('git rev-parse HEAD 2>/dev/null')) ?: 'unknown'; $resource = ResourceInfoFactory::emptyResource()->merge(ResourceInfo::create(Attributes::create([ 'service.name' => $serviceName, 'appsignal.config.name' => $name, 'appsignal.config.environment' => $environment, 'appsignal.config.push_api_key' => $pushApiKey, 'appsignal.config.revision' => $revision, 'appsignal.config.language_integration' => 'php', 'appsignal.config.app_path' => __DIR__, 'host.name' => gethostname(), ]))); $spanExporter = new SpanExporter( (new OtlpHttpTransportFactory())->create("$collector/v1/traces", 'application/x-protobuf') ); $logExporter = new LogsExporter( (new OtlpHttpTransportFactory())->create("$collector/v1/logs", 'application/x-protobuf') ); $reader = new ExportingReader( new MetricExporter( (new OtlpHttpTransportFactory())->create("$collector/v1/metrics", 'application/x-protobuf') ) ); $meterProvider = MeterProvider::builder() ->setResource($resource) ->addReader($reader) ->build(); $tracerProvider = TracerProvider::builder() ->addSpanProcessor( new SimpleSpanProcessor($spanExporter) ) ->setResource($resource) ->setSampler(new ParentBased(new AlwaysOnSampler())) ->build(); $loggerProvider = LoggerProvider::builder() ->setResource($resource) ->addLogRecordProcessor( new SimpleLogRecordProcessor($logExporter) ) ->build(); Sdk::builder() ->setTracerProvider($tracerProvider) ->setMeterProvider($meterProvider) ->setLoggerProvider($loggerProvider) ->setPropagator(TraceContextPropagator::getInstance()) ->setAutoShutdown(true) ->buildAndRegisterGlobal();
Install OpenTelemetry instrumentations
By itself, the OpenTelemetry for PHP SDK does not instrument your application, meaning that no data is exported to the AppSignal collector.
To instrument your application, you will need to install the relevant OpenTelemetry instrumentations for the frameworks and libraries that your application uses.
For popular frameworks like Laravel and Symfony, see our dedicated PHP instrumentation guides:
For other frameworks and libraries, check the list of available OpenTelemetry instrumentations on Packagist.
Test the app!
Now that all the components are connected, start your app with the required environment variables and test if you see data arrive in AppSignal. Check the "Errors > Issue list" and "Performance > Traces" page specifically.
If after following our installation instructions you still don't see data in AppSignal, let us know and we'll help you finalize your OpenTelemetry installation!