Download the PHP package philiprehberger/laravel-correlation-id without Composer

On this page you can find all versions of the php package philiprehberger/laravel-correlation-id. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-correlation-id

Laravel Correlation ID

Tests Latest Version on Packagist Last updated

Laravel middleware that generates or propagates correlation IDs for request tracing with automatic log context injection.

Requirements

Installation

The service provider is registered automatically via Laravel package auto-discovery.

Optionally publish the config:

Usage

Accessing the Correlation ID

Configuration

How It Works

  1. The middleware inspects incoming request headers in the order defined by request_headers.
  2. The first non-empty value found is used as-is (propagation path).
  3. When no matching header is present, a new ID is generated using the configured generator.
  4. The ID is stored as a request attribute and shared with the log context.
  5. After the handler returns, the ID is written to the response header defined by response_header.

Validating Incoming IDs

Incoming correlation IDs from request headers are validated before they are trusted. A value that is too long or contains disallowed characters (newlines, control characters, spaces) is discarded and a fresh ID is generated instead — so an untrusted client cannot inject arbitrary content into your logs, responses, or downstream requests.

You can reuse the same rule in application code:

Custom ID Generator

Control how new correlation IDs are generated when no upstream header is present:

Queue Job Propagation

Propagate the correlation ID from the dispatching context into queued jobs:

The TracksCorrelationId trait captures the current correlation ID when the job is created. The CorrelationIdJobMiddleware restores it when the job runs on a worker.

HTTP Client Propagation

Automatically forward the correlation ID to outgoing HTTP requests made with Laravel's HTTP client:

The middleware adds the X-Correlation-ID header (or your custom header) to every outgoing request.

Trace Spans

Track the timing of operations within a request using lightweight trace spans:

Spans are immutable value objects. Calling endSpan() returns a new instance with the end time set and stores it for later retrieval.

Sentry Integration

When sentry/sentry-laravel is installed and 'sentry' => true, the middleware sets correlation_id as a tag on every Sentry event captured during the request.

API

Class / Method Description
AddCorrelationId middleware Generates or propagates the correlation ID and injects it into logs and responses
CorrelationId::get() Read the current correlation ID (null if not yet set)
CorrelationId::set(string $id) Override the correlation ID (useful in tests or CLI commands)
CorrelationId::generate() Generate a new correlation ID using the configured generator
CorrelationId::isValid(string $id) Check a candidate ID against the configured length and pattern rules
CorrelationId::reset() Clear the correlation ID and all trace spans for the current request
CorrelationId::httpMiddleware(?string $headerName) Returns a Guzzle middleware closure for HTTP client propagation
CorrelationId::startSpan(string $name, array $metadata) Start a new trace span linked to the current correlation ID
CorrelationId::endSpan(Span $span) End a span and store it for retrieval
CorrelationId::spans() Get all completed trace spans
CorrelationId::clearSpans() Clear all stored trace spans
$request->correlationId() Request macro that returns the current correlation ID
TracksCorrelationId trait Captures the correlation ID at dispatch time for queue jobs
CorrelationIdJobMiddleware Queue job middleware that restores the correlation ID
PropagateCorrelationId::handler() Static factory for the HTTP client propagation middleware
Span value object Immutable span with name, durationMs(), toArray()

Development

Support

If you find this project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT


All versions of laravel-correlation-id with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/http Version ^11.0|^12.0
illuminate/log Version ^11.0|^12.0
illuminate/support Version ^11.0|^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package philiprehberger/laravel-correlation-id contains the following files

Loading the files please wait ...