How inspector-apm/inspector-laravel works
Project type and purpose
• This is a Laravel package (“inspector-laravel”) that instruments a Laravel or Lumen application for code‐execution monitoring (APM).
• It plugs into the host app via service providers, middleware, event listeners, and a CLI command to capture request traces, DB queries, job executions, exceptions, outgoing HTTP calls, email sends, Redis calls, etc., then ships that data to the external Inspector ingestion API.
File structure
• Top‐level:
• config/inspector.php – user config and ingestion key
• src/InspectorServiceProvider.php – registers all instrumentation providers
• src/Providers/* – each service provider hooks into one type of event (DB, jobs, exceptions, email, HTTP client, Redis, notifications, gates, stacktraces)
• src/Middleware/WebRequestMonitoring.php – wraps each HTTP request
• src/Commands/TestCommand.php – php artisan inspector:test CLI
• src/OutOfMemoryBootstrapper.php – listens early for memory limits
• src/Facades/Inspector.php – user‐friendly facade
• src/Filters.php – drop/allow rules
• Tests exercise configuration, middleware, providers, helpers.
Key insights from README
• Must register the service provider (Laravel auto or manual for Lumen).
• Must attach WebRequestMonitoring middleware to web and api groups.
• The CLI command verifies connectivity.
• All captured events are forwarded to Inspector’s cloud endpoints over HTTP.
Components
a. Main components
1. Host Laravel Application
2. Inspector Laravel Package
• Configuration Loader
• InspectorServiceProvider
• Instrumentation Providers
• Middleware
• Facade & Filters
• CLI Command
3. External Inspector Ingestion API (cloud)
4. Underlying Laravel subsystems: HTTP Kernel, Queue Worker, Event Dispatcher, DB, Mailer, HTTP Client, Redis, Notification, Gate, Exception Handler
b. Relationships & Data Flows
• On app bootstrap, InspectorServiceProvider registers instrumentation providers.
• HTTP Request → Kernel → WebRequestMonitoring middleware → start trace → passes through app → end trace → Inspector client dispatches telemetry.
• DB queries, Job starts/completes, exceptions, outgoing HTTP/email/Redis calls → listeners in respective Providers → send spans.
• CLI (inspector:test) uses Facade → dispatches a test event.
• All spans are batched or streamed to Inspector Ingestion API.
c. Architectural patterns
• Inversion of Control / Service Provider pattern for extension
• Middleware pipeline for request tracing
• Observer/Event listener pattern for capturing domain events
• Facade for a simple developer API
d. Key technologies
• PHP 7.2+, Laravel ≥5.5 or Lumen
• Composer for package management
• REST/HTTP client (Guzzle or built-in) for ingestion
• Laravel Service Container, Event Dispatcher, Middleware
• PHPUnit for tests
Detail
• That InspectorServiceProvider is the “entry point” registering all providers.