LogTide

A proper Symfony Bundle for Symfony 6.4 and 7.x with semantic YAML/XML configuration, DI container integration, and event subscribers for automated request/console tracing.

Installation

composer require logtide/logtide-symfony

If you're using Symfony Flex, the bundle is registered automatically. Otherwise, add it to config/bundles.php:

<?php
// config/bundles.php

return [
    // ...
    LogTide\Symfony\LogtideBundle::class => ['all' => true],
];

Quick Start

Add your DSN to .env:

LOGTIDE_DSN=https://[email protected]

Create the bundle configuration:

# config/packages/logtide.yaml
logtide:
    dsn: '%env(LOGTIDE_DSN)%'
    environment: '%kernel.environment%'

That's it! The bundle registers the Hub, event subscribers, and integrations automatically.

Configuration

# config/packages/logtide.yaml
logtide:
    dsn: '%env(LOGTIDE_DSN)%'
    service: 'my-symfony-app'         # default: 'symfony'
    environment: '%kernel.environment%'
    release: '1.2.3'

    # Batching
    batch_size: 100                   # default: 100
    flush_interval: 5000              # ms, default: 5000
    max_buffer_size: 10000            # default: 10000
    max_retries: 3                    # default: 3

    # Tracing
    traces_sample_rate: 1.0           # 0.0-1.0, default: 1.0

    # Privacy
    send_default_pii: false           # default: false

    # Debug
    debug: false                      # default: false

Configuration Reference

Option Type Default Description
dsnstringData Source Name
servicestring'symfony'Service name
environmentstringDeployment environment
releasestringApp version
batch_sizeint100Max events per batch (min: 1)
flush_intervalint5000Flush interval in ms (min: 100)
traces_sample_ratefloat1.0Trace sampling rate (0.0–1.0)
send_default_piiboolfalseSend PII (IP, cookies, etc.)
debugboolfalseEnable internal debug logging

Request Subscriber

The RequestSubscriber automatically handles scope lifecycle per HTTP request:

  • • Pushes a new scope on kernel.request
  • • Extracts traceparent header for distributed tracing
  • • Starts a SERVER span with HTTP method, route, and URL attributes
  • • Captures exceptions on kernel.exception
  • • Finishes the span and pops the scope on kernel.response
  • • Injects traceparent into outgoing response headers

Console Subscriber

Requires symfony/console. Automatically traces Artisan-like console commands:

  • • Creates a span for each command on console.command
  • • Captures errors on console.error
  • • Finishes the span on console.terminate

Doctrine Integration

Requires doctrine/dbal. Records SQL queries as breadcrumbs with query text, parameters, and execution time.

<?php
// Doctrine queries are automatically recorded as breadcrumbs:
// {
//   type: "query",
//   category: "doctrine",
//   message: "SELECT u.* FROM users u WHERE u.id = ?",
//   data: { duration_ms: 2.5, params: [123] }
// }

Using the Hub

The HubInterface is registered as a service in the DI container. Inject it into your services or controllers:

<?php

namespace App\Controller;

use LogTide\Enum\LogLevel;
use LogTide\State\HubInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

class OrderController extends AbstractController
{
    public function __construct(
        private readonly HubInterface $hub,
    ) {}

    public function checkout(): Response
    {
        $this->hub->captureLog(LogLevel::INFO, 'Checkout started', [
            'user_id' => $this->getUser()->getId(),
        ]);

        try {
            // ... process order
        } catch (\Throwable $e) {
            $this->hub->captureException($e);
            throw $e;
        }

        return $this->json(['status' => 'ok']);
    }
}

You can also use the procedural API anywhere in your code:

<?php

use function LogTide\{info, error, captureException, addBreadcrumb};
use LogTide\Breadcrumb\Breadcrumb;
use LogTide\Enum\BreadcrumbType;

addBreadcrumb(new Breadcrumb(BreadcrumbType::DEFAULT, 'Processing order', category: 'app'));
info('Order processed', ['order_id' => $orderId]);

Best Practices

1. Use Kernel Environment
Set environment: '%kernel.environment%' in the config to automatically pick up dev, prod, or test.
2. Type-Hint HubInterface
Inject LogTide\State\HubInterface into your services via constructor injection. Autowiring resolves it automatically.
3. Messenger Workers
Make sure the LOGTIDE_DSN environment variable is available to your Messenger worker processes for background job monitoring.
Esc

Type to search across all documentation pages