Installation Add the bundle via Composer:
composer require boson/trazas-bundle
Enable it in config/bundles.php:
Boson\TrazasBundle\BosonTrazasBundle::class => ['all' => true],
First Use Case
Inject the TrazasService into a controller or service:
use Boson\TrazasBundle\Service\TrazasService;
class MyController extends AbstractController
{
public function __construct(private TrazasService $trazasService) {}
public function index()
{
$this->trazasService->log('user_action', ['user_id' => 123]);
return new Response('Logged!');
}
}
Where to Look First
Resources/doc/index.rst for API details.config/packages/boson_trazas.yaml.EventListener/ for hooks (e.g., TrazasSubscriber).Logging Traces
Use TrazasService for structured logging:
$this->trazasService->log('event_name', [
'metadata' => ['key' => 'value'],
'context' => ['user_id' => 123, 'ip' => $request->getClientIp()]
]);
Integration with Symfony Events Subscribe to kernel events to auto-log actions:
# config/packages/boson_trazas.yaml
boson_trazas:
listeners:
- { event: 'kernel.request', method: 'onKernelRequest' }
Database Storage
Configure storage in boson_trazas.yaml:
boson_trazas:
storage:
driver: 'doctrine' # Options: 'doctrine', 'monolog', 'custom'
options:
table: 'app_trace_logs'
Custom Handlers
Extend TrazasHandlerInterface for custom storage:
class CustomTrazasHandler implements TrazasHandlerInterface
{
public function handle(array $trace): void
{
// Custom logic (e.g., send to external API)
}
}
Doctrine Dependency
driver: 'doctrine', ensure doctrine/doctrine-bundle is installed.Performance Overhead
level filtering:
boson_trazas:
level: 'info' # Options: 'debug', 'info', 'notice', 'warning', 'error'
Event Subscriber Conflicts
kernel.request) may cause duplicate logs.Check Log Levels Enable debug logs to verify trace storage:
monolog:
handlers:
main:
level: debug
Validate Configuration Use Symfony’s config validator:
php bin/console debug:config boson_trazas
Custom Handler Debugging
For driver: 'custom', implement TrazasHandlerInterface and verify the handle() method is called via:
$this->trazasService->log('test', []); // Check if your handler processes it
Add Fields to Traces
Extend the Trace entity (if using Doctrine) or modify the log() payload:
$this->trazasService->log('custom_event', [
'extra_field' => 'value',
'_custom_metadata' => ['processed' => true] // Prefix for custom keys
]);
Create Custom Commands Build CLI tools to export/analyze traces:
namespace App\Command;
use Boson\TrazasBundle\Service\TrazasService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ExportTracesCommand extends Command
{
protected static $defaultName = 'app:export-traces';
private TrazasService $trazasService;
public function __construct(TrazasService $trazasService)
{
$this->trazasService = $trazasService;
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$traces = $this->trazasService->getAllTraces();
// Export logic...
}
}
Override Templates
If the bundle includes views (e.g., for dashboards), override them in templates/boson_trazas/.
How can I help you explore Laravel packages today?