Download the PHP package mdavid-dev/symfony-correlation-id-bundle without Composer
On this page you can find all versions of the php package mdavid-dev/symfony-correlation-id-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mdavid-dev/symfony-correlation-id-bundle
More information about mdavid-dev/symfony-correlation-id-bundle
Files in mdavid-dev/symfony-correlation-id-bundle
Package symfony-correlation-id-bundle
Short Description Symfony bundle to manage correlation IDs across HTTP requests and responses
License MIT
Informations about the package symfony-correlation-id-bundle
Symfony Correlation ID Bundle
A Symfony bundle to automatically manage correlation IDs across HTTP requests and responses, making it easy to trace and debug your application.
Features
- Automatic ID Management: Extracts correlation ID from incoming request headers or generates a new UUID v4
- Monolog Integration: Automatically adds correlation ID to all logs
- Configurable & Secure: Validate incoming IDs (length, format), trust or ignore incoming headers
- Easy to Use: Zero-config installation with sensible defaults
- Production Ready: 100% test coverage, follows Symfony best practices
Installation
1. Install via Composer
2. Enable the Bundle
3. That's it!
The bundle works out-of-the-box with default configuration.
Quick Start
Once installed, the bundle automatically:
- Reads the X-Correlation-ID header from incoming requests
- Generates a UUID v4 if the header is missing
- Adds the correlation ID to all response headers
Example Request:
Example Response:
Configuration
Default Configuration
Validation & Security
By default, the bundle validates correlation IDs to prevent malicious input:
Security features:
- Rejects empty values
- Limits length to prevent buffer overflow attacks
- Blocks special characters that could be used for injection attacks (XSS, SQL injection, shell injection)
- Automatically generates a safe ID if validation fails
Customize the pattern for your needs:
UUID v4 only (strictest)
Allow more characters
Disable pattern validation (not recommended)
Configuration Examples
Custom Header Name
Disable Trust Header Always generate a new ID, ignoring incoming headers:
Enable Monolog Integration
Automatically add correlation ID to all logs:
Disable Monolog integration:
Usage in Your Application
Access the Correlation ID
Inject the CorrelationIdStorage service:
Available Methods
Monolog Integration
Automatic Logging
When Monolog integration is enabled (default), the correlation ID is automatically added to all log entries in the extra field.
Example log output:
Custom Log Key
Change the key name used in logs:
Requirements
Monolog integration requires the monolog/monolog package:
If Monolog is not installed, the integration is automatically disabled.
CLI Integration
When CLI integration is enabled (default), the bundle manages correlation IDs for Symfony Console commands.
Environment Variable
If cli.allow_env_var is true (default), you can pass a correlation ID via the CORRELATION_ID environment variable:
This is particularly useful when executing commands from a Process within an HTTP request context:
Automatic ID Generation
If no environment variable is provided, an ID is automatically generated using the configured generator and prefixed with cli.prefix (default: CLI-):
Example output for a generated ID: CLI-550e8400-e29b-41d4-a716-446655440000
Access in Commands
You can access the ID in your commands just like in controllers:
Advanced Usage
Custom ID Generator
Create your own generator:
Configure it:
Testing
Requirements
- PHP 8.2 or higher
- Symfony 6.4 or 7.0+
License
This bundle is released under the MIT License.
Contributing
Contributions are welcome! Please submit a Pull Request.
All versions of symfony-correlation-id-bundle with dependencies
symfony/config Version ^6.4|^7.0
symfony/dependency-injection Version ^6.4|^7.0
symfony/http-foundation Version ^6.4|^7.0
symfony/http-kernel Version ^6.4|^7.0
symfony/uid Version ^6.4|^7.0
symfony/yaml Version ^6.4|^7.0
symfony/console Version ^6.4|^7.0