PHPackages                             bonsi/laravel-tracetag - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. bonsi/laravel-tracetag

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

bonsi/laravel-tracetag
======================

Trace a request through your application using a tag

4152PHP

Since Jul 3Pushed 8y ago1 watchersCompare

[ Source](https://github.com/bonsi/laravel-tracetag)[ Packagist](https://packagist.org/packages/bonsi/laravel-tracetag)[ RSS](/packages/bonsi-laravel-tracetag/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel TraceTag
================

[](#laravel-tracetag)

[![Build Status](https://camo.githubusercontent.com/f7ed371ae5539cac0a34fdda2da1f9e79d05c49474d64053d0585b83a9e936a3/68747470733a2f2f7472617669732d63692e6f72672f626f6e73692f6c61726176656c2d74726163657461672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/bonsi/laravel-tracetag)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#)

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.

### Use cases

[](#use-cases)

- **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.

### Usage

[](#usage)

- Generate &amp; 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.

### Install

[](#install)

- 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

    - RandomInt: *no extra package required*
    - Uuid4: ~~ramsey/uuid@~3.0~~ This dependency is now defined as required. Although it's only required if one were to use the Uuid4Generator, adding the dependency as an "optional" dependency in for example composer's "suggests" list doesn't feel right. The way to go here would be to extract the generators in this package to their own composer package so that the dependencies per generator could be specified in their own composer.json. But, since the generators are barely 10 lines of code, this would be an overkill at the moment in my opinion.
- 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`.

### Concepts

[](#concepts)

- **Generator**: A class responsible for generating a TraceTag. Included: Uuid4 &amp; RandomInt.

    Example generator tags:

    - RandomInt: 9208221171113638741
    - Uuid4: 857fac7b-1a0a-491b-9235-5214e6819351
    - *or: brew your own (by implementing the Generator interface)*
- **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.

### Todo's:

[](#todos)

- Add middleware for adding a TraceTag as a header
- Add a facade
- Add tests
- Add more generators
- Add more integrations

### Integrations

[](#integrations)

#### Monolog

[](#monolog)

Adding the TraceTag to your monolog logger is already enabled by default. The TraceTag will be added to monolog's 'extra' field.

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cf6940bf12b79f962999bbd340840481e82ec31b461645cccde7021e86752499?d=identicon)[bonsi](/maintainers/bonsi)

---

Top Contributors

[![bonsi](https://avatars.githubusercontent.com/u/1137656?v=4)](https://github.com/bonsi "bonsi (1 commits)")

---

Tags

laravellaravel-5-packagelaravel-packagelaravel5laravel5-packagelaravel54tagtraceunique-identifier

### Embed Badge

![Health badge](/badges/bonsi-laravel-tracetag/health.svg)

```
[![Health](https://phpackages.com/badges/bonsi-laravel-tracetag/health.svg)](https://phpackages.com/packages/bonsi-laravel-tracetag)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B10.9k](/packages/psr-log)[open-telemetry/api

API for OpenTelemetry PHP.

1938.5M263](/packages/open-telemetry-api)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2326.5M317](/packages/open-telemetry-sdk)[illuminated/console-logger

Logging and Notifications for Laravel Console Commands.

8676.7k](/packages/illuminated-console-logger)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
