apirelio / flightphp
Fail-safe FlightPHP middleware for Apirelio customer integration analytics.
Requires
- php: ^8.2
- ext-curl: *
- ext-mbstring: *
- apirelio/php-core: ^1.0
- flightphp/core: ^3.10
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5 || ^12.0 || ^13.0
This package is auto-updated.
Last update: 2026-08-28 10:59:37 UTC
README
Documentation · Live demo · Packagist · Apirelio
Customer-aware API monitoring middleware for FlightPHP 3. It captures route-level operational telemetry without request or response payloads and delegates the shared event contract, privacy filtering and delivery to apirelio/php-core.
See the live customer-impact demo →
Install in 30 seconds
composer require apirelio/flightphp:^1.0
use Apirelio\FlightPHP\ApirelioMiddleware; use Apirelio\FlightPHP\Config as ApirelioConfig; use flight\Engine; $app = new Engine; $apirelio = new ApirelioMiddleware($app, new ApirelioConfig( apiKey: (string) getenv('APIRELIO_API_KEY'), service: 'billing-api', environment: getenv('APP_ENV') ?: 'production', release: getenv('APP_RELEASE') ?: null, paths: ['/api/*'], bufferPath: __DIR__.'/../storage/apirelio-events.ndjson', )); $app->group('/api', function () use ($app): void { $app->get('/invoices/@id', [InvoiceController::class, 'show'], false, 'invoices:view'); }, [$apirelio]); $app->start();
Flight executes before() before the route and after() afterwards. Apirelio reads the matched Route::$pattern and alias from Router::$executedRoute; an internal flight.error listener records the exception class when the route fails.
Identify the customer
use Apirelio\Core\Data\ApirelioApplication; use Apirelio\Core\Data\ApirelioCustomer; $apirelio = new ApirelioMiddleware( app: $app, config: $config, customerResolver: static function (Engine $app, array $params): ?ApirelioCustomer { $account = $app->account(); return $account === null ? null : new ApirelioCustomer( id: (string) $account->id, name: $account->name, plan: $account->plan, ); }, applicationResolver: static fn (Engine $app): ApirelioApplication => new ApirelioApplication( id: (string) $app->apiClient()->id, ), );
Add safe request context
$apirelio->context()?->addMetadata(['region' => 'eu-central']); $apirelio->context()?->setErrorCode('PAYMENT_REQUIRED');
Only scalar metadata keys listed in metadataKeys are retained. Sensitive-looking keys are always rejected. Request bodies, response bodies, query strings, credentials, cookies, client IPs and exception messages are never captured.
Example application
The example directory contains a complete FlightPHP API bootstrap. Connect it to a project and then open the live Apirelio demo to see the resulting customer-level workflow.
Requirements
- PHP 8.2+
- FlightPHP 3.10+
- ext-curl and ext-mbstring
License
MIT
