Quickstart
Install and register the bundle.
The bundle registers a kernel event subscriber that captures matching main requests automatically. No controller middleware is required.
composer require apirelio/symfony:^0.2// config/bundles.php
return [
// ...
Apirelio\Symfony\ApirelioBundle::class => ['all' => true],
];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.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/*/api/invoices/123 is stored as the Symfony route template /api/invoices/{invoice}.
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.
# config/packages/messenger.yaml
framework:
messenger:
routing:
'Apirelio\Symfony\Message\BufferApirelioEvents': async
# Run your normal worker:
# php bin/console messenger:consume asyncFor local diagnostics, switch to sync. The optional file_buffer transport can be flushed with php bin/console apirelio:flush.
Customer context
Resolve the authenticated account.
Implement the resolver after your authentication layer has populated the request, then alias it to the SDK contract.
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.yaml
services:
Apirelio\Symfony\Contracts\CustomerResolver:
alias: App\Apirelio\ApiCustomerResolverDiagnostics
Add stable error context.
Inject ApirelioManager to override an error code or add allow-listed scalar metadata during the current request.
public function __invoke(ApirelioManager $apirelio): Response
{
$apirelio
->setErrorCode('INVALID_CURRENCY')
->addMetadata([
'integration_type' => 'accounting',
'region' => 'eu-central',
]);
// ...
}Response bodies are only inspected for the configured error-code path; they are never included in the emitted event.