Install the Package
composer require inspector-apm/inspector-symfony
Configure the Ingestion Key
Create config/packages/inspector.yaml:
inspector:
ingestion_key: "YOUR_INSPECTOR_INGESTION_KEY"
(Obtain the key from your Inspector dashboard.)
Enable the Bundle
Add to config/bundles.php:
return [
// ...
Inspector\InspectorSymfonyBundle::class => ['all' => true],
];
Verify Integration Run a request and check the Inspector UI for traces.
APP_ENV=prod or APP_ENV=dev to isolate issues.Automatic Instrumentation
Manual Instrumentation (Advanced)
Use the Inspector\Inspector service to manually start/stop spans:
use Inspector\Inspector;
public function someAction(Inspector $inspector)
{
$span = $inspector->startSpan('custom_operation');
try {
// Business logic
} finally {
$span->finish();
}
}
Event-Based Tracing
Attach spans to Symfony events (e.g., Kernel::CONTROLLER):
# config/services.yaml
services:
App\EventListener\InspectorListener:
tags:
- { name: 'kernel.event_listener', event: 'kernel.controller', method: 'onKernelController }
public function onKernelController(GetResponseForControllerEvent $event, Inspector $inspector)
{
$span = $inspector->startSpan('pre_controller_logic');
// ...
}
Database Query Tracing
Integrate with Doctrine listeners (if using doctrine/doctrine-bundle):
use Inspector\Inspector;
use Doctrine\DBAL\Event\Listeners\SQLLogger;
public function __construct(Inspector $inspector)
{
$this->inspector = $inspector;
}
public function postConnect(ConnectionEventArgs $args)
{
$logger = new SQLLogger($this->inspector);
$args->getConnection()->getConfiguration()->setSQLLogger($logger);
}
%env(INSPECTOR_KEY)% in inspector.yaml for security.inspector.yaml:
inspector:
ingestion_key: "YOUR_KEY"
sampling:
rate: 0.1 # Sample 10% of requests
$span->setAttribute('user_id', $user->getId());
$span->setAttribute('custom_metric', 42);
try {
// Risky code
} catch (\Exception $e) {
$span->recordException($e);
throw $e;
}
Performance Overhead
sampling.rate) or disable in production temporarily:
inspector:
enabled: "%kernel.debug%" # Only trace in dev
Sensitive Data Leaks
$span->setAttribute('user_email', strtok($user->getEmail(), '@'));
Doctrine Integration Conflicts
Inspector\Doctrine\SQLLogger explicitly.Missing Traces in CLI
php bin/console) may not appear in Inspector.public function handle()
{
$inspector = $this->getInspector();
$span = $inspector->startSpan('cli_command');
// Command logic
$span->finish();
}
Check Bundle Status Verify the bundle is loaded:
php bin/console debug:container inspector
Should return Inspector\InspectorSymfonyBundle.
Enable Debug Logging
Add to config/packages/dev/inspector.yaml:
inspector:
debug: true
Check logs for initialization errors.
Validate Ingestion Key Test with a dummy key first to rule out auth issues:
inspector:
ingestion_key: "test_123"
(No data will be sent, but errors will surface.)
Network Issues If traces don’t appear, check:
ingest.inspector.dev.Custom Span Processors
Extend Inspector\SpanProcessorInterface to modify spans before sending:
class CustomSpanProcessor implements SpanProcessorInterface
{
public function process(Span $span, Context $context): void
{
$span->setAttribute('custom_tag', 'value');
}
}
Register in services.yaml:
services:
App\SpanProcessor\CustomSpanProcessor:
tags: ['inspector.span_processor']
Override Default Instrumentation Disable auto-instrumentation and implement your own:
inspector:
auto_instrument: false
Then manually instrument critical paths (e.g., via event listeners).
Custom Metrics
Use Inspector\Metrics to track business metrics:
$metrics->increment('orders.processed');
$metrics->set('inventory.level', 100);
Async Processing For long-running tasks (e.g., queues), use background spans:
$span = $inspector->startSpan('async_task', ['async' => true]);
// Dispatch to a queue worker
How can I help you explore Laravel packages today?