Symfony

Please follow the PHP installation guide first before continuing with this guide.

Install the Symfony instrumentation

Install the OpenTelemetry Symfony instrumentation package:

Shell
composer require open-telemetry/opentelemetry-auto-symfony

Configure Symfony

If you are using Symfony, you can require the appsignal.php file from the public/index.php file, before the Symfony application is created. This ensures that the OpenTelemetry SDK is initialized before Symfony starts handling requests.

public/index.php
<?php use App\Kernel; require_once dirname(__DIR__).'/vendor/autoload_runtime.php'; // Load the AppSignal configuration before the Kernel is created require_once dirname(__DIR__).'/appsignal.php'; return function (array $context) { return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']); };

To be able to configure AppSignal using the .env file loaded by your Symfony application, load the environment variables for your app in the appsignal.php file, and update the variables to read from the environment variables.

appsignal.php
<?php // Add this right below the imports at the top of the file use Symfony\Component\Dotenv\Dotenv; // Load environment variables using Symfony's Dotenv if (file_exists(__DIR__ . '/.env')) { $dotenv = new Dotenv(); $dotenv->load(__DIR__ . '/.env'); } // Check if required environment variables are set if (empty($_ENV['APPSIGNAL_APP_NAME']) || empty($_ENV['APPSIGNAL_APP_ENV']) || empty($_ENV['APPSIGNAL_PUSH_API_KEY'])) { // Skip OpenTelemetry configuration if required env vars are not set return; } // Read config from environment variables $name = $_ENV['APPSIGNAL_APP_NAME']; $environment = $_ENV['APPSIGNAL_APP_ENV']; $pushApiKey = $_ENV['APPSIGNAL_PUSH_API_KEY'];