Installation Add the package via Composer:
composer require cedriclombardot/pinba-bundle:dev-master
Register the bundle in app/Kernel.php:
$bundles = [
// ...
new CedricLombardot\PinbaBundle\CedricLombardotPinbaBundle(),
];
Basic Configuration
Ensure config.yml includes the bundle’s configuration (if needed):
pinba:
script_name_pattern: "{PATH_INFO}" # Default; adjust as needed
First Use Case
pinba_collector) is running to receive logs.http://localhost:8080/pinba) for logged data.Request Logging
The bundle intercepts Symfony’s onKernelRequest event to log request metadata (URI, HTTP method, headers, etc.) to Pinba. No manual instrumentation is required for basic usage.
Custom Script Naming
Override the default script name (e.g., {PATH_INFO}) via config.yml to include dynamic segments:
pinba:
script_name_pattern: "api/{_route}" # Uses Symfony’s routing syntax
Use case: Group API endpoints by route names for better visualization.
Database Query Logging (Propel)
Replace Propel’s PDO with PinbaPropelPDO to log SQL queries:
propel:
dbal:
connections:
default:
classname: CedricLombardot\PinbaBundle\Propel\PinbaPropelPDO
# ... rest of config
Use case: Track slow Propel queries in Pinba’s UI.
Manual Instrumentation For custom logic (e.g., background jobs), manually log events:
use CedricLombardot\PinbaBundle\Pinba\Pinba;
Pinba::log('custom.event', [
'data' => 'value',
'context' => ['key' => 'value']
]);
kernel.request):
$eventDispatcher->addListener('kernel.request', function () {
Pinba::log('custom.metric', ['value' => 42]);
});
# config_prod.yml
pinba:
enabled: true
# config_dev.yml
pinba:
enabled: false
pinba_collector:latest) for local development.Missing Collector
pinba_collector) is running and configured to listen on the correct UDP port (default: 8126).PDO Override Conflicts
PinbaPropelPDO may conflict with other PDO wrappers (e.g., Doctrine’s).Script Name Collisions
script_name_pattern may generate duplicate or ambiguous names.{_route}.{_controller}) or sanitize patterns:
pinba:
script_name_pattern: "route.{{ _route|replace({' ': '_'}) }}"
Performance Overhead
if (rand(0, 100) < 10) { // 10% sample
Pinba::log('slow.query', ['query' => $sql]);
}
debug to see Pinba-related events:
monolog:
handlers:
main:
level: debug
tcpdump to verify Pinba packets are sent:
tcpdump -i any -n udp port 8126
CedricLombardotPinbaBundle by extending the bundle class or using a debug flag in config.Custom Data Collectors
Extend the bundle’s PinbaCollector to add custom metrics:
class CustomPinbaCollector extends \CedricLombardot\PinbaBundle\Pinba\PinbaCollector
{
public function collectCustomData()
{
$this->log('custom.metric', ['value' => $this->getCustomValue()]);
}
}
Register it in services.yml:
services:
pinba.collector:
class: AppBundle\Pinba\CustomPinbaCollector
Event Subscribers Hook into Symfony’s events to enrich Pinba data:
class PinbaSubscriber implements EventSubscriberInterface
{
public function onKernelRequest(GetResponseEvent $event)
{
Pinba::log('user.action', ['user_id' => $event->getRequest()->get('user_id')]);
}
// ...
}
Configuration Overrides Dynamically adjust Pinba behavior via runtime config:
$container->get('pinba')->setScriptNamePattern('dynamic.{_route}');
How can I help you explore Laravel packages today?