Symfony
Quick Start

Symfony

The traceway/opentelemetry-symfony bundle automatically instruments your Symfony application and exports traces to Traceway's OTLP endpoints — no manual instrumentation needed.

Prerequisites

  • PHP 8.1+
  • Symfony 6.4+
  • Composer
  • A Traceway project (create one in the dashboard)

Step 1: Install Packages

composer require traceway/opentelemetry-symfony open-telemetry/exporter-otlp php-http/guzzle7-adapter

Step 2: Register the Bundle

If Symfony Flex doesn't register it automatically, add it to config/bundles.php:

// config/bundles.php
return [
    // ...
    Traceway\OpenTelemetryBundle\OpenTelemetryBundle::class => ['all' => true],
];

Step 3: Configure Environment Variables

Add the following to your .env file, replacing the endpoint and token with your project values:

Important: OTEL_PHP_AUTOLOAD_ENABLED=true is required — without it, the OpenTelemetry SDK will not start and no telemetry will be collected.

OTEL_PHP_AUTOLOAD_ENABLED=true
OTEL_SERVICE_NAME=my-symfony-app
OTEL_TRACES_EXPORTER=otlp
OTEL_METRICS_EXPORTER=otlp
OTEL_LOGS_EXPORTER=otlp
OTEL_EXPORTER_OTLP_PROTOCOL=http/json
OTEL_EXPORTER_OTLP_ENDPOINT=https://your-traceway-instance.com/api/otel
OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer your-project-token"

Your Traceway dashboard includes a Connection page with a ready-made config snippet and your project token. Go to Connection in the sidebar to grab it.

Note: Use http/json instead of http/protobuf. The protobuf encoder has known deprecation warnings on PHP 8.4+ that can cause noisy logs.

Step 4: Initialize the SDK

Add the SDK autoloader to your public/index.php, after the Composer autoload:

<?php
// public/index.php
 
use App\Kernel;
 
require_once dirname(__DIR__) . '/vendor/autoload.php';
 
\OpenTelemetry\SDK\SdkAutoloader::autoload();
 
$kernel = new Kernel($_SERVER['APP_ENV'] ?? 'dev', (bool) ($_SERVER['APP_DEBUG'] ?? true));
$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

What Gets Captured

Once configured, the bundle automatically captures:

  • Endpoints — every HTTP request with method and route template (e.g., GET /users/{id})
  • Status codes — 2xx, 4xx, 5xx responses
  • Exceptions — unhandled errors with stack traces
  • Client IP, body size, user agent — standard HTTP attributes
  • Doctrine queries — if doctrine/dbal is installed
  • Console commands — Symfony CLI commands
  • Messenger jobs — dispatched and consumed messages (see Tasks)

Configuration (Optional)

Create config/packages/open_telemetry.yaml to customize behavior:

open_telemetry:
    excluded_paths:
        - /_profiler
        - /_wdt
        - /health
    record_client_ip: true          # default: true (set false for GDPR)
    error_status_threshold: 500     # HTTP status >= this marked as error
    messenger_root_spans: true      # tasks appear as independent jobs in Traceway

Test Your Integration

Add a test route to verify data is flowing:

// src/Controller/TestController.php
namespace App\Controller;
 
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
 
class TestController
{
    #[Route('/testing', name: 'testing')]
    public function index(): Response
    {
        throw new \RuntimeException("Test error from Traceway integration");
    }
}

Visit /testing in your browser, then check the Traceway dashboard — the exception should appear within a few seconds.

Next Steps

  • Exceptions — manually capture caught exceptions with context
  • Spans — create custom spans to measure sub-operations
  • Tasks — trace Symfony Messenger background jobs
  • Metrics — track custom counters, histograms, and gauges
  • Logs — forward Monolog / PSR-3 logs to Traceway
  • OpenTelemetry docs — how OTel traces, metrics, and logs map to Traceway