request-tracing / request-tracing-bundle
Symfony bundle for request tracing
Package info
github.com/request-tracing/request-tracing-bundle
Type:symfony-bundle
pkg:composer/request-tracing/request-tracing-bundle
Requires
- php: ^8.2
- monolog/monolog: ^3.0
- symfony/framework-bundle: ^6.4.13||^7.4||^8.1
- symfony/yaml: ^6.4||^7.4||^8.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.95
- guzzlehttp/guzzle: ^7.0||^8.0
- matthiasnoback/symfony-config-test: ^6.2
- matthiasnoback/symfony-dependency-injection-test: ^6.3
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.2
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpstan/phpstan-symfony: ^2.0
- phpunit/phpunit: ^11.5||^12.5||^13.0
- psr/http-message: ^2.0
- symfony/browser-kit: ^6.4||^7.4||^8.1
- symfony/monolog-bundle: ^3.11||^4.0
- symfony/runtime: ^6.4||^7.4||^8.1
README
Symfony bundle for request tracing.
This bundle ships with a Monolog processor and a Guzzle Middleware for logging and propagating request IDs.
Requirements
This bundle supports the PHP and Symfony versions that are officially supported by their maintainers:
Installation
composer require request-tracing/request-tracing-bundle
If you are using Symfony Flex everything works out-of-the-box.
If not, you should add this bundle manually to your config/bundles.php.
By default, the bundle will look for a X-Request-Id HTTP request header and use its value if present.
You can configure the header name with the following config:
# config/packages/request_tracing.yaml request_tracing: header: my_custom_header_name
Monolog
This bundle will add the request ID to the context of each log record created with Monolog. Be sure to install the Monolog bundle first:
composer require symfony/monolog-bundle
I recommend formatting Monolog in JSON format for easier log processing in tools like Datadog:
# config/packages/monolog.yaml monolog: handlers: main: formatter: monolog.formatter.json
Guzzle
If you use the Guzzle HTTP client in your application you can use the Guzzle Middleware provided by this bundle to pass the request ID of the original HTTP request as a header to a subsequent HTTP request. This way you will be able to correlate HTTP requests when analyzing (access) logs.
The middleware is available in the Dependency Injection Container by its FQCN. Here's an example services configuration:
services: GuzzleHttp\Client: arguments: - { handler: '@GuzzleHttp\HandlerStack' } GuzzleHttp\HandlerStack: factory: ['GuzzleHttp\HandlerStack', 'create'] calls: - push: ['@RequestTracing\RequestTracingBundle\GuzzleHttp\RequestIdMiddleware']
Contributing
make dependencies # install the Composer dependencies
make test # run the test suite
make coverage # report the test coverage
make phpstan # run static analysis
make php-cs-fixer # fix coding standards violations
make qa # run all quality assurance checks