request-tracing / request-tracing-bundle
Symfony bundle for request tracing
Installs: 1 589
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 1
Type:symfony-bundle
Requires
- php: >=8.1
- monolog/monolog: ^3.0
- symfony/framework-bundle: ^5.4||^6.3
- symfony/yaml: ^5.4||^6.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.8
- guzzlehttp/guzzle: ^7.0
- matthiasnoback/symfony-config-test: ^4.3
- matthiasnoback/symfony-dependency-injection-test: ^4.3
- phpstan/phpstan: ^1.5
- phpstan/phpstan-strict-rules: ^1.5
- phpstan/phpstan-symfony: ^1.3
- phpunit/phpunit: ^10.4
- psr/http-message: ^2.0
- symfony/browser-kit: ^5.4||^6.3
- symfony/monolog-bundle: ^3.7
This package is auto-updated.
Last update: 2024-12-12 13:40:36 UTC
README
Symfony bundle for request tracing.
This bundle ships with a Monolog processor and a Guzzle Middleware for logging and propagating request IDs.
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']