Documentation/PHP / Symfony

PHP / Symfony

Instrument Symfony APIs.

Track normalized kernel requests and move production delivery to your existing Messenger infrastructure.

Symfony 6.4–8.xPackage v0.2.0Production ready
01

Quickstart

Install and register the bundle.

The bundle registers a kernel event subscriber that captures matching main requests automatically. No controller middleware is required.

Terminalbash
composer require apirelio/symfony:^0.2
config/bundles.phpphp
// config/bundles.php
return [
    // ...
    Apirelio\Symfony\ApirelioBundle::class => ['all' => true],
];
02

Configuration

Add the project credentials.

Use a separate ingestion key and stable service name for every observed project. Only paths matching the configured patterns are recorded.

config/packages/apirelio.yamlyaml
# config/packages/apirelio.yaml
apirelio:
    enabled: '%env(bool:APIRELIO_ENABLED)%'
    endpoint: '%env(APIRELIO_ENDPOINT)%'
    api_key: '%env(APIRELIO_API_KEY)%'
    service: billing-api
    environment: production
    release: '%env(APIRELIO_RELEASE)%'
    transport: messenger
    paths:
        - /api/*
Normalized routes

/api/invoices/123 is stored as the Symfony route template /api/invoices/{invoice}.

03

Production delivery

Route events through Messenger.

The default transport dispatches locally and lets Messenger apply your retry and failure-transport policies outside the customer request.

Messenger routingyaml
# config/packages/messenger.yaml
framework:
    messenger:
        routing:
            'Apirelio\Symfony\Message\BufferApirelioEvents': async

# Run your normal worker:
# php bin/console messenger:consume async

For local diagnostics, switch to sync. The optional file_buffer transport can be flushed with php bin/console apirelio:flush.

04

Customer context

Resolve the authenticated account.

Implement the resolver after your authentication layer has populated the request, then alias it to the SDK contract.

ApiCustomerResolver.phpphp
use Symfony\Component\HttpFoundation\Request;
use Apirelio\Symfony\Contracts\CustomerResolver;
use Apirelio\Symfony\Data\ApirelioCustomer;

final class ApiCustomerResolver implements CustomerResolver
{
    public function resolve(Request $request): ?ApirelioCustomer
    {
        $client = $request->attributes->get('api_client');

        return $client === null ? null : new ApirelioCustomer(
            id: (string) $client->companyId,
            name: $client->companyName,
            plan: $client->plan,
        );
    }
}
config/services.yamlyaml
# config/services.yaml
services:
    Apirelio\Symfony\Contracts\CustomerResolver:
        alias: App\Apirelio\ApiCustomerResolver
05

Diagnostics

Add stable error context.

Inject ApirelioManager to override an error code or add allow-listed scalar metadata during the current request.

Controllerphp
public function __invoke(ApirelioManager $apirelio): Response
{
    $apirelio
        ->setErrorCode('INVALID_CURRENCY')
        ->addMetadata([
            'integration_type' => 'accounting',
            'region' => 'eu-central',
        ]);

    // ...
}
Privacy first

Response bodies are only inspected for the configured error-code path; they are never included in the emitted event.