Skip to content

darsyn/stack-request-id

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Request ID for Stack

Middleware for adding a request ID to your Symfony requests.

Build Status

Installation

First, add this project to your project's composer.json

$ composer require darsyn/stack-request-id ^1.0

Setting up

Update your app.php to include the middleware:

Before:

use Symfony\Component\HttpFoundation\Request;

$kernel = new AppKernel($env, $debug);
$kernel->loadClassCache();

$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

After:

use Darsyn\Stack\RequestId\Injector;
use Darsyn\Stack\RequestId\UuidGenerator;
use Symfony\Component\HttpFoundation\Request;

$kernel = new AppKernel($env, $debug);

// Stack it! Node name is optional.
$generator = new UuidGenerator($nodeName);
$stack = new Injector($kernel, $generator);

$kernel->loadClassCache();

$request = Request::createFromGlobals();
$response = $stack->handle($request);
$response->send();
$kernel->terminate($request, $response);

Adding the RequestId to your Monolog logs

If you use Symfony's MonologBundle you can add the request ID to your Monolog logs by adding the following service definition to your services.yml file:

services:

    darsyn.stack.request_id.monolog_processor:
        class: Darsyn\Stack\RequestId\Monolog\Processor
        tags:
            - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest, priority: 255 }
            - { name: monolog.processor }

Changing the Response Header

The default is X-Request-Id.

$stack = new Injector($kernel, $generator, 'Request-Id');

Disabling the Response Header

$stack = new Injector($kernel, $generator, null, false);

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%