Download the PHP package juliendufresne/inter-app-request-identifier without Composer
On this page you can find all versions of the php package juliendufresne/inter-app-request-identifier. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download juliendufresne/inter-app-request-identifier
More information about juliendufresne/inter-app-request-identifier
Files in juliendufresne/inter-app-request-identifier
Package inter-app-request-identifier
Short Description Defines an interface to identify a process running between multiple applications
License MIT
Informations about the package inter-app-request-identifier
Inter App Request Identifiers
Defines an interface to identify a process running between multiple applications.
When you work with multiple application calling each other, it is hard to follow which application calls which other application.
Furthermore, when you have to see the logs of an application, you can not see where the request come from.
This library provides a solution:
- when an application calls another one, it adds some identifiers in the request header to keep track of who is the caller
- when an application receives a call from another one, it checks if the headers are set and will use them for further request
- it adds an extra section in your monolog logs containing:
- an identification of the current application process
- an identification of the caller who initiate the call to this application
- an identification of the root caller who initiate the global call.
Installation
Example
Generator
Generator is used to generate unique request id for the current running application.
This library provides one default generator: the RamseyUuidGenerator.
If you want to use it, you must install the ramsey/uuid
package.
You can define your own generator by implementing the UniqueIdGeneratorInterface
Guzzle
If you are using guzzle (package guzzlehttp/guzzle) to perform http requests, you can either add the RequestIdMiddleware to your handler stack:
or use our factory to create a guzzle client:
Changing the headers sent
By default, sent headers are:
X-Root-Request-Id
for the root application identifierX-Parent-Request-Id
for the current application identifier (that will become the parent application of the http request)
You can change this in the middleware:
Keep in mind that if you change this, you might want to change this in every applications
Monolog
If you are using monolog to manage your application logs, you can use the RequestIdentifierProcessor:
Changing the extra keys
By default, the processor will add a request_id
array entry in the extra
section with the following keys:
current
for the current application identifierroot
for the root application identifierparent
for the parent application identifier
You can change this in the processor instantiation: