proemergotech / correlate-php-laravel by shakahl

Middleware to handle incoming correlation id header for Laravel and Lumen
3,180
2
4
Package Data
Maintainer Username: shakahl
Maintainer Contact: support@proemergotech.com (ProEmergotech Kft)
Package Create Date: 2017-06-15
Package Last Update: 2018-02-02
Language: PHP
License: MIT
Last Refreshed: 2024-04-26 03:05:01
Package Statistics
Total Downloads: 3,180
Monthly Downloads: 1
Daily Downloads: 0
Total Stars: 2
Total Watchers: 4
Total Forks: 1
Total Open Issues: 0

correlate-php-laravel


Overview

It's very difficult to track a request across the system when we are working with microservices. We came out with a solution for that. We generate a unique version 4 uuid for every request and every service passes this id via request headers to other services. We call this correlation ID.

Packages

Installation

  • Install via composer
composer require proemergotech/correlate-php-laravel

Setup for Laravel 5

Add the ProEmergotech\Correlate\Laravel\LaravelCorrelateMiddleware middleware to the $middleware property of your app/Http/Kernel.php class.

Setup for Lumen 5

Add service provider to bootstrap/app.php in your Lumen project.

// bootstrap/app.php

$app->register(\ProEmergotech\Correlate\Laravel\LaravelCorrelateServiceProvider::class);

Usage

This middleware automatically adds correlation id (coming from request header) to every log message. There are some macros added to the request object if you want to work with correlation id.

Using macros via request object:

if ($request->hasCorrelationId()) {
  $cid = $request->getCorrelationId();
}
// or if you can change the ID
$request->setCorrelationId(\ProEmergotech\Correlate\Correlate::id());

Contributing

See CONTRIBUTING.md file.

Credits

This package was developed by Soma Szélpál at Pro Emergotech Ltd..

Additional author is Miklós Boros at Pro Emergotech Ltd..

License

This project is released under the MIT License.