Sign Up
Open in ChatGPT Open in Claude Open in Perplexity

Symfony OpenTelemetry Guide

monoscope has no dedicated Symfony package. Use OpenTelemetry’s zero-code PHP auto-instrumentation with the Symfony instrumentation instead. It creates spans for incoming requests, HttpClient calls and Messenger messages, and sends them to monoscope with no changes to your code.


Prerequisites

You need a monoscope project and its API key. If you do not have them yet, follow Get started.

Set Up With Your Coding Agent

Your coding agent can add the instrumentation for you. Install the monoscope skills and the monoscope CLI:

# Claude Code
claude plugin marketplace add monoscope-tech/skills
claude plugin install monoscope-skills@monoscope-skills

# Cursor, Codex, Cline and other agents
npx skills add monoscope-tech/skills

# monoscope CLI
curl https://monoscopehq.com/install.sh | sh
monoscope auth login

Then ask your agent to instrument the project. In Claude Code, run:

/monoscope-skills:instrument Add OpenTelemetry for monoscope to this project

The skill uses the CLI to add the SDK and to make sure that events arrive. To do the setup by hand, follow the steps below. For help from a person, email us.

Installation

Install the OpenTelemetry PHP extension:

pecl install opentelemetry

Then add it to your php.ini file:

[opentelemetry]
extension=opentelemetry.so

Then install the SDK, the OTLP exporter and the Symfony instrumentation:

composer require \
    open-telemetry/sdk \
    open-telemetry/exporter-otlp \
    open-telemetry/opentelemetry-auto-symfony

To trace SQL queries, also install open-telemetry/opentelemetry-auto-pdo. Other auto-instrumentation packages are listed in the OpenTelemetry registry.

Configuration

Set these environment variables in your shell or your deployment platform:

OTEL_PHP_AUTOLOAD_ENABLED=true
OTEL_SERVICE_NAME=your-service-name
OTEL_TRACES_EXPORTER=otlp
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_ENDPOINT=https://otel.monoscopehq.com
OTEL_RESOURCE_ATTRIBUTES="x-api-key=YOUR_API_KEY"
OTEL_PROPAGATORS=baggage,tracecontext

Tip

Replace YOUR_API_KEY with an API key from Settings > API Keys in monoscope.

The extension reads these variables when PHP starts, before Symfony loads .env. With PHP-FPM, set them in the pool configuration (env[OTEL_SERVICE_NAME] = your-service-name) or in the container environment.

Console Commands

The instrumentation covers HTTP requests and Messenger handlers (messenger:consume). Console commands and scheduled tasks need a span of their own. Wrap the body of execute():

use OpenTelemetry\API\Globals;
use OpenTelemetry\API\Trace\StatusCode;

protected function execute(InputInterface $input, OutputInterface $output): int
{
    $span = Globals::tracerProvider()->getTracer('app')->spanBuilder('app:my-command')->startSpan();
    $scope = $span->activate();
    try {
        // ... command logic
        return Command::SUCCESS;
    } catch (\Throwable $e) {
        $span->recordException($e);
        $span->setStatus(StatusCode::STATUS_ERROR);
        throw $e;
    } finally {
        $scope->detach();
        $span->end();
    }
}

The SDK flushes spans when the PHP process shuts down.

Next Steps


OpenTelemetry PHP zero-code docs