# OpenTelemetry for Symfony

Trace every request, database query and outgoing call of a Symfony app with OpenTelemetry's auto-instrumentation, and send it to Flowhawk.

OpenTelemetry for PHP instruments Symfony through a PHP extension and Composer packages. Your controllers don't change: requests, Doctrine and PDO queries, and HttpClient calls become spans.

## What you get

- Every request as a trace, with its database calls and outgoing HTTP calls, in [Traces](https://flowhawk.dev/docs/signals#traces).
- Requests matched to your [business flows](https://flowhawk.dev/docs/flows) by service and route on our side, so you see "checkout is failing at place order" rather than a list of endpoints.
- Exceptions grouped into [Issues](https://flowhawk.dev/docs/signals#issues), slow and N+1 database queries on each database's page, and deploys found from `service.version`.
- Alerts, incidents and the on-call agent, which reads these traces when something breaks.

## Set it up

### 1. Install the extension and the packages

```
pecl install opentelemetry          # the extension auto-instrumentation needs
composer require open-telemetry/sdk open-telemetry/exporter-otlp \
  open-telemetry/opentelemetry-auto-symfony open-telemetry/opentelemetry-auto-pdo
```

Enable the extension in your php.ini (`extension=opentelemetry`) for both PHP-FPM and the CLI, so Messenger workers and console commands are traced too. Check with `php --ri opentelemetry`.

### 2. Point it at Flowhawk

First create an ingest key: in the app, open **Settings > API keys** and pick **Services**. In the examples below, `KEY` stands for that key. Keep it out of your repository, like any other secret.

Set these in the environment of PHP-FPM and your workers (Symfony's `.env` is read too late):

```
OTEL_PHP_AUTOLOAD_ENABLED=true
OTEL_SERVICE_NAME=orders
OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.flowhawk.dev
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer%20KEY
OTEL_RESOURCE_ATTRIBUTES=deployment.environment=production,service.version=1.4.2
```

The space in the header is written `%20`. Set `service.version` to your release, so a deploy shows as a change next to the flows it made better or worse.

### 3. Deploy and send a request

Each request becomes a trace named after its route, with its queries and outgoing calls as spans inside it.

## Check it arrived

Open **Setup** in the app. It lists each service that sent data in the last 15 minutes. If yours isn't there, [Help and troubleshooting](https://flowhawk.dev/docs/help) says why telemetry can be refused (a wrong key, an empty balance) and how to see it.

## Common questions

### Is there a Flowhawk SDK for PHP?

It isn't on Packagist yet. Plain OpenTelemetry as above works today: Flowhawk matches your requests to flows by service and route. Switching to the SDK later adds exact flow tags across services and sampling per flow, and nothing else changes.

### What about Laravel or Slim?

See the [Laravel guide](https://flowhawk.dev/integrations/opentelemetry-laravel), or use `open-telemetry/opentelemetry-auto-slim` for Slim ([PHP guide](https://flowhawk.dev/docs/languages#php)).

## Related

[**OpenTelemetry for Laravel**Trace every request, queue job and database query of a Laravel app with OpenTelemetry's auto-instrumentation, and send it to Flowhawk.](https://flowhawk.dev/integrations/opentelemetry-laravel) [**OpenTelemetry for Ruby on Rails**Trace a Rails app's requests, Active Record queries, Active Job and Sidekiq jobs with OpenTelemetry, and send them to Flowhawk.](https://flowhawk.dev/integrations/opentelemetry-rails) [**Heroku log drain**Send the logs of a Heroku app to Flowhawk with one HTTPS drain. No add-on and no code change.](https://flowhawk.dev/integrations/heroku-log-drain)

[Try it free for 14 days](https://app.flowhawk.dev/signup?trial=1) [Read the getting started guide](https://flowhawk.dev/docs/getting-started)

---

URL: https://flowhawk.dev/integrations/opentelemetry-symfony
