Package Data | |
---|---|
Maintainer Username: | bonsi |
Maintainer Contact: | ivo.bons@gmail.com (Ivo Bons) |
Package Create Date: | 2017-06-29 |
Package Last Update: | 2017-07-03 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-23 03:03:10 |
Package Statistics | |
---|---|
Total Downloads: | 15 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 4 |
Total Watchers: | 2 |
Total Forks: | 2 |
Total Open Issues: | 0 |
Generate an unique tag or identifier (aka TraceTag) for an application request to be tracked through your application.
Add it to your application logs or wherever to get a better overview which logged information belongs to the same request.
A monolog processor to add the TraceTag to your logs is included out of the box.
Mind you, this is still very much a work in progress!
Only tested with Laravel 5.4 currently.
Ability to aggregate all logs belonging to a specific request
This is exactly what the TraceTag core functionality is about: having a unique identifier available for a single request. TraceTag has no knowledge of the client, and will therefore generate a new tag on the next request.
Ability to aggregate all logs belonging to a specific client
This requires some work on your part as well: you will have to tell TraceTag which tag to use on subsequent requests from the same client.
A middleware (disabled by default) is included in the package to help you with that. It allows for setting the TraceTag from the outside using either a HTTP Header (default: "X-Trace-Tag") or an input field (default: "_trace_tag").
The TraceTag library will then store the provided value and TraceTag::tag();
will return that value on subsequent calls (within the same HTTP request that is).
The middleware will also attach a HTTP header to the response ("X-Trace-Tag"). It's your job to include the returned X-Trace-Tag value on the next HTTP request from the client. In doing so, the same TraceTag can be traced over multiple HTTP requests for the same client.
You can either let the TraceTag library generate such a tag using a Generator for you the first time, or ofcourse, provide your own.
Generate & get the TraceTag:
If no TraceTag has been set or generated, a call to the tag()
will generate one for you using the configured generator. The same TraceTag will then be returned for every subsequent call to the tag()
method.
$tag = app()->make(Bonsi\TraceTag\TraceTag::class)->tag();
$tag = TraceTag::tag();
Set the TraceTag:
This value will then be returned on subsequent calls to the tag()
method.
TraceTag::setTag('MY-CUSTOM-TAG');
You can also set the TraceTag from the outside to, for example, provide an unique tag across requests. The included included middleware can with that.
Since the package is still in development, make sure you add the following to your composer.json
:
"minimum-stability": "dev",
Add the package to your composer.json
composer require bonsi/laravel-tracetag
Update composer
composer update
Add the ServiceProvider to your app/config.php
'providers' => [
...
/*
* Package Service Providers...
*/
Bonsi\TraceTag\TraceTagServiceProvider::class,
...
Some of the generators require an additional composer package
Publish the configuration file
Get your own customizable config file if you want to change the default settings:
php artisan vendor:publish --provider="Bonsi\TraceTag\TraceTagServiceProvider"
This will copy a customizable config file to config/tracetag.php
.
Generator: A class responsible for generating a TraceTag. Included: Uuid4 & RandomInt.
Example generator tags:
Integration: A class responsible for injecting the TraceTag into various other parts of your application. Included: a Monolog processor to add the TraceTag to your logs.
Adding the TraceTag to your monolog logger is already enabled by default. The TraceTag will be added to monolog's 'extra' field.