PHPackages                             scau009/deferred-logger-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. scau009/deferred-logger-bundle

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

scau009/deferred-logger-bundle
==============================

Symfony bundle for deferred logging with distributed tracing support (W3C Trace Context, Jaeger, Zipkin compatible)

v1.0.2(8mo ago)14MITPHPPHP ^8.0

Since Oct 29Pushed 8mo agoCompare

[ Source](https://github.com/scau009/DeferredLoggerBundle)[ Packagist](https://packagist.org/packages/scau009/deferred-logger-bundle)[ Docs](https://github.com/scau009/DeferredLoggerBundle)[ RSS](/packages/scau009-deferred-logger-bundle/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (3)Versions (4)Used By (0)

DeferredLoggerBundle
====================

[](#deferredloggerbundle)

Install
-------

[](#install)

Require the bundle via composer (when published) or add to your `composer.json` and `composer install`.

Register bundle in `config/bundles.php`:

```
return [
    Barry\DeferredLoggerBundle\BarryDeferredLoggerBundle::class => ['all' => true],
];
```

Configure (optional)
--------------------

[](#configure-optional)

```
# config/packages/barry_deferred_logger.yaml
barry_deferred_logger:
  logger_channel: app
  auto_flush_on_exception: true
  auto_flush_on_request: true
  enable_sql_logging: false            # Enable automatic Doctrine SQL logging
  inject_trace_id_in_response: true    # Inject trace ID in response headers
  enable_messenger_trace: true         # Enable Messenger trace propagation
```

Features
--------

[](#features)

### 1. Automatic SQL Logging

[](#1-automatic-sql-logging)

When `enable_sql_logging: true`, the bundle automatically captures all Doctrine SQL queries with:

- Original SQL statement
- Query parameters
- Formatted SQL (with parameters interpolated for readability)
- Execution time in milliseconds

No need to manually call `DeferredLogger::contextSql()` anymore!

### 2. Distributed Tracing Support

[](#2-distributed-tracing-support)

The bundle provides **production-ready distributed tracing** with the following features:

#### Trace Context Propagation

[](#trace-context-propagation)

Automatically extracts trace IDs from incoming requests, supporting multiple standards:

1. **W3C Trace Context** (`traceparent` header) - Industry standard
2. **X-Trace-ID** - Common in microservices
3. **X-Request-ID** - Used by Nginx, load balancers
4. **X-Correlation-ID** - Alternative correlation header

If no trace ID is found, a new one is automatically generated.

#### Response Header Injection

[](#response-header-injection)

When `inject_trace_id_in_response: true` (default), the bundle adds trace headers to every response:

```
X-Trace-ID: 550e8400e29b41d4a716446655440000
X-Span-ID: 7f3a9e4c6b2d8f1a
traceparent: 00-550e8400e29b41d4a716446655440000-7f3a9e4c6b2d8f1a-01
```

This allows:

- Frontend clients to correlate requests with logs
- API consumers to trace requests across microservices
- Debugging tools to link distributed operations

#### Microservices Integration

[](#microservices-integration)

**Service A → Service B example:**

```
// Service A: Making a request to Service B
$traceId = DeferredLogger::getTraceId();

$response = $httpClient->request('POST', 'https://service-b/api/endpoint', [
    'headers' => [
        'X-Trace-ID' => $traceId,  // Pass trace ID to downstream service
    ],
]);
```

Service B will automatically pick up the trace ID from the header and use it in its logs!

#### Long-Running Process Support (Swoole/RoadRunner)

[](#long-running-process-support-swooleroadrunner)

The bundle properly resets trace context on each request:

```
// StartRequestSubscriber automatically calls:
$instance->reset();  // Clear buffer and trace context
$traceContext = TraceContext::fromHeaders($request->headers->all());
$instance->setTraceContext($traceContext);
```

#### Log Output Format

[](#log-output-format)

All logs include comprehensive trace information:

```
{
  "trace_id": "550e8400e29b41d4a716446655440000",
  "span_id": "7f3a9e4c6b2d8f1a",
  "parent_span_id": null,
  "sampled": true,
  "info": [...]
}
```

#### Integration with Tracing Systems

[](#integration-with-tracing-systems)

The trace format is compatible with:

- **Jaeger** - Uber's distributed tracing system
- **Zipkin** - Twitter's distributed tracing system
- **AWS X-Ray** - Amazon's tracing service
- **Google Cloud Trace** - GCP tracing service
- Any system supporting W3C Trace Context

#### Best Practices

[](#best-practices)

1. **API Gateway**: Extract trace ID from incoming requests or generate at the edge
2. **Propagate Downstream**: Always pass `X-Trace-ID` to downstream services
3. **Log Aggregation**: Use trace\_id to group logs across services (e.g., ELK, Datadog)
4. **Frontend Integration**: Return trace ID to clients for support tickets
5. **Monitoring**: Create dashboards grouped by trace\_id for request flow visualization

### 3. Symfony Messenger Integration

[](#3-symfony-messenger-integration)

**Automatic trace propagation across async messages!**

When `enable_messenger_trace: true` (default), the bundle automatically:

#### How It Works

[](#how-it-works)

1. **Message Dispatch**: When you dispatch a message, the current trace context is automatically attached as a `TraceContextStamp`
2. **Async Processing**: When a worker processes the message, the trace context is restored
3. **Child Spans**: Async operations create child spans, maintaining the parent-child relationship

#### Example

[](#example)

```
// In your HTTP controller (Request A)
use Symfony\Component\Messenger\MessageBusInterface;

public function processOrder(MessageBusInterface $bus): Response
{
    // Current trace_id: 550e8400-e29b-41d4-a716-446655440000
    // Current span_id: 7f3a9e4c6b2d8f1a

    DeferredLogger::contextInfo('Dispatching order processing');

    // Dispatch async message - trace context is AUTOMATICALLY attached
    $bus->dispatch(new ProcessOrderMessage($orderId));

    return new JsonResponse(['status' => 'queued']);
}
```

```
// In your Message Handler (Async Worker)
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler]
class ProcessOrderHandler
{
    public function __invoke(ProcessOrderMessage $message): void
    {
        // Trace context is AUTOMATICALLY restored!
        // trace_id: 550e8400-e29b-41d4-a716-446655440000 (SAME as parent)
        // span_id: a1b2c3d4e5f6g7h8 (NEW child span)
        // parent_span_id: 7f3a9e4c6b2d8f1a (points to parent)

        DeferredLogger::contextInfo('Processing order in async worker');

        // All logs here will have the SAME trace_id as the original request!
    }
}
```

#### Benefits

[](#benefits)

- **Cross-Process Tracing**: Track requests from HTTP handler through async workers
- **No Manual Work**: Zero code changes needed, works automatically
- **Worker Isolation**: Each message gets its own span, properly cleaned up after processing
- **Queue Debugging**: Find all logs related to a specific message across multiple workers

#### Configuration

[](#configuration)

```
barry_deferred_logger:
  enable_messenger_trace: true  # Enabled by default
```

#### Advanced: Manual Trace Control

[](#advanced-manual-trace-control)

If needed, you can access trace info in handlers:

```
#[AsMessageHandler]
class MyHandler
{
    public function __invoke(MyMessage $message): void
    {
        $traceId = DeferredLogger::getTraceId();

        // Make external API call with trace propagation
        $this->httpClient->request('POST', 'https://external-api.com', [
            'headers' => ['X-Trace-ID' => $traceId],
        ]);
    }
}
```

#### Trace Flow Visualization

[](#trace-flow-visualization)

```
HTTP Request (trace: 550e8400)
  └─ span: 7f3a9e4c
      ├─ Log: "Order received"
      ├─ Dispatch Message ✉
      └─ Response sent

Async Worker (trace: 550e8400)  ← SAME trace_id!
  └─ span: a1b2c3d4 (parent: 7f3a9e4c)
      ├─ Log: "Processing order"
      ├─ SQL: UPDATE orders...
      └─ Log: "Order completed"

```

All logs searchable by `trace_id: 550e8400` in your log aggregation system!

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance61

Regular maintenance activity

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

247d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18747266?v=4)[BarryBear](/maintainers/scau009)[@scau009](https://github.com/scau009)

---

Top Contributors

[![bloomChi-Barry](https://avatars.githubusercontent.com/u/226630008?v=4)](https://github.com/bloomChi-Barry "bloomChi-Barry (5 commits)")[![scau009](https://avatars.githubusercontent.com/u/18747266?v=4)](https://github.com/scau009 "scau009 (1 commits)")

---

Tags

symfonyloggingdoctrineW3CmonologMessengerobservabilityjaegerzipkindistributed-tracingtrace-context

### Embed Badge

![Health badge](/badges/scau009-deferred-logger-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/scau009-deferred-logger-bundle/health.svg)](https://phpackages.com/packages/scau009-deferred-logger-bundle)
```

###  Alternatives

[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1189.8k](/packages/rcsofttech-audit-trail-bundle)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M388](/packages/easycorp-easyadmin-bundle)[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.8k3.8M508](/packages/pimcore-pimcore)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9421.6k61](/packages/open-dxp-opendxp)[web-auth/webauthn-framework

FIDO2/Webauthn library for PHP and Symfony Bundle.

515100.5k3](/packages/web-auth-webauthn-framework)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
