PHPackages                             febryntara/laravel-telemetry-logger - 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. febryntara/laravel-telemetry-logger

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

febryntara/laravel-telemetry-logger
===================================

Comprehensive Laravel activity logger: all routes, requests, sessions, errors, with sensitive data filtering and microservice forwarding.

v1.0.3(5mo ago)013MITPHPPHP ^8.2CI passing

Since Mar 8Pushed 5mo agoCompare

[ Source](https://github.com/febryntara/laravel-telemetry-logger)[ Packagist](https://packagist.org/packages/febryntara/laravel-telemetry-logger)[ RSS](/packages/febryntara-laravel-telemetry-logger/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (4)Dependencies (7)Versions (5)Used By (0)

Laravel Telemetry Logger
========================

[](#laravel-telemetry-logger)

[![Latest Version on Packagist](https://camo.githubusercontent.com/27da5892f6d98aef4f9de48e58b26591eb6a7abe7ec12cf142cd0a9bf0701c4a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f66656272796e746172612f6c61726176656c2d74656c656d657472792d6c6f676765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/febryntara/laravel-telemetry-logger)[![GitHub Tests](https://camo.githubusercontent.com/49012861cd6f7029fdaefcacc7bf409f69e66c9e915529c247b204e1b4ed72ca/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f66656272796e746172612f6c61726176656c2d74656c656d657472792d6c6f676765722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/febryntara/laravel-telemetry-logger/actions)[![License](https://camo.githubusercontent.com/2b4027d6953d53026b98fe22c063f1bd043169afc41c1125bbb8fa0345a3a226/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f66656272796e746172612f6c61726176656c2d74656c656d657472792d6c6f676765722e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

Comprehensive Laravel activity logger. Captures every HTTP request (including GET), session data, user identity, errors, slow queries, queue jobs, and artisan commands — with **automatic sensitive data filtering** — and forwards all logs asynchronously to your own logging microservice.

Designed for AI-assisted anomaly detection, security auditing, and production debugging.

---

Features
--------

[](#features)

- ✅ **All HTTP methods** — GET, POST, PUT, PATCH, DELETE, etc.
- ✅ **Request metadata** — method, URL, route name, action, IP, User-Agent, referer
- ✅ **Request body** — with deep recursive sanitization of sensitive fields
- ✅ **Request headers** — with masking of sensitive headers (Authorization, Cookie, etc.)
- ✅ **File upload metadata** — filename, MIME type, size (no content)
- ✅ **Response logging** — status code, headers, optional response body
- ✅ **Session data** — session ID, and optionally session contents
- ✅ **Authenticated user** — user ID, email, name (or custom resolver)
- ✅ **Exception logging** — full stack trace, previous exceptions
- ✅ **Slow query logging** — SQL, bindings, execution time (configurable threshold)
- ✅ **Queue job logging** — processed and failed jobs
- ✅ **Artisan command logging** — command name, exit code
- ✅ **Async dispatch** — uses Laravel Queue, never blocks response
- ✅ **Retry with backoff** — configurable retries if microservice is down
- ✅ **Single &amp; adaptive send modes** — static one-by-one or auto-batch under load
- ✅ **Route exclusion** — skip routes like `telescope*`, `horizon*`, `_debugbar*`
- ✅ **Custom user resolver** — for non-standard auth systems

---

Requirements
------------

[](#requirements)

- PHP 8.1+
- Laravel 10.x or 11.x

---

Installation
------------

[](#installation)

```
composer require febryntara/laravel-telemetry-logger
```

Publish the config file:

```
php artisan vendor:publish --tag=telemetry-logger-config
```

---

Configuration
-------------

[](#configuration)

Add these to your `.env`:

```
# ── Required ──────────────────────────────────────────────────────────────────
TELEMETRY_LOGGER_ENABLED=true
TELEMETRY_LOGGER_ENDPOINT=https://your-microservice.com/api
TELEMETRY_LOGGER_TOKEN=your-secret-token

# ── Send Mode ─────────────────────────────────────────────────────────────────
# "single" (default) — send immediately and synchronously, no queue needed
# "adaptive"         — use queue, auto-batch when queue is backed up
TELEMETRY_SEND_MODE=single

# ── Token Header ──────────────────────────────────────────────────────────────
# "Authorization" (default) → Authorization: Bearer
# "X-API-Key"               → X-API-Key:
TELEMETRY_LOGGER_TOKEN_HEADER=Authorization

# ── Host Name (optional) ──────────────────────────────────────────────────────
# Override the hostname sent in every log payload.
# Defaults to system hostname (gethostname()) if not set.
TELEMETRY_LOGGER_HOST=my-app-server

# ── Queue (only needed when TELEMETRY_SEND_MODE=adaptive) ─────────────────────
TELEMETRY_LOGGER_QUEUE_NAME=telemetry
TELEMETRY_LOGGER_QUEUE_TRIES=3
TELEMETRY_LOGGER_QUEUE_BACKOFF=10

# ── Adaptive Mode (only needed when TELEMETRY_SEND_MODE=adaptive) ─────────────
TELEMETRY_ADAPTIVE_THRESHOLD=10
TELEMETRY_ADAPTIVE_BATCH_SIZE=50

# ── Optional Features ─────────────────────────────────────────────────────────
TELEMETRY_LOGGER_LOG_RESPONSES=false
TELEMETRY_LOGGER_INCLUDE_SESSION=false
TELEMETRY_LOGGER_SLOW_QUERIES=false
TELEMETRY_LOGGER_SLOW_QUERY_THRESHOLD=1000
TELEMETRY_LOGGER_LOG_JOBS=false
TELEMETRY_LOGGER_LOG_COMMANDS=false
```

---

Send Modes
----------

[](#send-modes)

The package supports two send modes, configurable via `TELEMETRY_SEND_MODE`.

### `single` (default)

[](#single-default)

Logs are sent **immediately and synchronously** to `POST /logs` — right when the request happens, before the response is returned. No queue involved, no cron needed, no delay.

```
TELEMETRY_SEND_MODE=single
```

Best for: most use cases, shared hosting, anywhere you want real-time logs without setting up a queue worker.

> **Note:** each log adds a small HTTP round-trip to your response time (typically &lt; 50ms on a local network). This is usually negligible but worth considering on very high-traffic applications.

### `adaptive`

[](#adaptive)

Logs are dispatched **asynchronously via Laravel Queue**. When the queue is healthy, logs go out one-by-one to `POST /logs`. When the queue starts backing up (depth ≥ threshold), payloads are accumulated in a cache buffer and flushed together to `POST /logs/batch` — reducing HTTP round-trips under load.

```
TELEMETRY_SEND_MODE=adaptive
TELEMETRY_ADAPTIVE_THRESHOLD=10   # queue depth that triggers batch mode
TELEMETRY_ADAPTIVE_BATCH_SIZE=50  # payloads per batch flush
```

Best for: high-traffic production apps with a dedicated queue worker (Supervisor/Horizon).

> **Note:** `adaptive` mode requires a running queue worker and your microservice to support `POST /logs/batch` with body `{ "logs": [...] }`. If your microservice is down, queued jobs are retained and delivered automatically once it recovers.

**How adaptive mode handles failures:** if a batch request fails, all payloads are pushed back into the cache buffer so nothing is lost. The job is then re-queued with the configured backoff and retries automatically.

---

Host Name
---------

[](#host-name)

By default, the `host` field in every log payload uses the system hostname (`gethostname()`). On shared hosting this is often an unreadable server name like `sg-nme-web621.main-hosting.eu`.

You can override it with a human-readable name via `.env`:

```
TELEMETRY_LOGGER_HOST=devloka-web
```

This is especially useful when you want the `host` field to match the `source_tag` name configured in your syslog API key.

---

Token Header &amp; Authentication
---------------------------------

[](#token-header--authentication)

The package supports any authentication header your microservice uses. Set it via `TELEMETRY_LOGGER_TOKEN_HEADER`:

```
# Default — sends Authorization: Bearer
TELEMETRY_LOGGER_TOKEN_HEADER=Authorization

# For microservices that use X-API-Key
TELEMETRY_LOGGER_TOKEN_HEADER=X-API-Key

# Any custom header
TELEMETRY_LOGGER_TOKEN_HEADER=X-Internal-Secret
```

### Automatic Token Redaction

[](#automatic-token-redaction)

Whatever header name you configure as `TELEMETRY_LOGGER_TOKEN_HEADER`, the package **automatically redacts it** from all logged payloads — even if it is not listed in `sensitive_headers`. This prevents your outbound API token from ever appearing in the logs sent to your microservice.

For example, if you set `TELEMETRY_LOGGER_TOKEN_HEADER=X-API-Key`, any incoming request that contains an `X-API-Key` header will have its value replaced with `***REDACTED***` in the log, regardless of what is in the `sensitive_headers` config.

---

Payload Structure
-----------------

[](#payload-structure)

Every log sent to your microservice follows this syslog-compatible format:

```
{
  "timestamp": "2024-01-01T00:00:00+00:00",
  "host":      "app-server-1",
  "service":   "my-app",
  "severity":  "info",
  "message":   "[INFO] POST api/login — 42.5 ms | user:12 | ip:123.4.5.6 | detail:{...}"
}
```

The `severity` field maps automatically from HTTP status codes:

StatusSeverity2xx`info`4xx`warning`5xx`error`Exceptions`error`Slow queries`warning`Eventsas passedThe `message` field contains a human-readable summary followed by the full telemetry detail JSON-encoded inline, including:

- `duration_ms`, `method`, `url`, `route_name`, `route_action`
- `ip`, `user_agent`, `referer`
- `headers` — with sensitive headers masked as `***REDACTED***`
- `body` — with sensitive fields recursively redacted
- `query`, `files`
- `response` — status code, headers, optional body
- `user` — id, email, name
- `session` — session ID (and optionally session contents)

---

Custom User Resolver
--------------------

[](#custom-user-resolver)

For non-standard auth (JWT, API keys, multi-guard), implement the contract:

```
use Febryntara\TelemetryLogger\Contracts\UserResolverContract;
use Illuminate\Http\Request;

class MyUserResolver implements UserResolverContract
{
    public function resolve(Request $request): ?array
    {
        $user = auth('api')->user();
        if (! $user) return null;

        return [
            'id'     => $user->id,
            'email'  => $user->email,
            'role'   => $user->role,
            'tenant' => $user->tenant_id,
        ];
    }
}
```

Then register it in `config/telemetry-logger.php`:

```
'user_resolver' => \App\Support\MyUserResolver::class,
```

---

Manual Logging
--------------

[](#manual-logging)

Use the Facade to log custom events from anywhere in your application:

```
use Febryntara\TelemetryLogger\Facades\TelemetryLogger;

// Log a custom event
TelemetryLogger::logEvent('payment.completed', [
    'order_id' => $order->id,
    'amount'   => $order->total,
], 'info');

// Log an exception manually
try {
    // ...
} catch (\Throwable $e) {
    TelemetryLogger::logException($e, request());
    throw $e;
}
```

---

Excluding Routes
----------------

[](#excluding-routes)

Add patterns in `config/telemetry-logger.php`:

```
'exclude_routes' => [
    'telescope*',
    'horizon*',
    '_debugbar*',
    'health',
    'api/ping',
    'livewire/update',
],
```

---

Queue Setup
-----------

[](#queue-setup)

For production, ensure you have a queue worker running:

```
php artisan queue:work --queue=telemetry,default
```

Or with Laravel Horizon, add to `config/horizon.php`:

```
'telemetry' => [
    'connection' => 'redis',
    'queue'      => ['telemetry'],
    'balance'    => 'simple',
    'processes'  => 1,
],
```

---

Testing
-------

[](#testing)

```
composer test
```

---

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md).

---

License
-------

[](#license)

MIT. See [LICENSE.md](LICENSE.md).

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance72

Regular maintenance activity

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

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.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

155d ago

PHP version history (2 changes)v1.0.0PHP ^8.1

v1.0.1PHP ^8.2

### Community

Maintainers

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

---

Top Contributors

[![febryntara](https://avatars.githubusercontent.com/u/75034265?v=4)](https://github.com/febryntara "febryntara (14 commits)")

---

Tags

laravelloggingtelemetryactivity-logMicroservicerequest log

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/febryntara-laravel-telemetry-logger/health.svg)

```
[![Health](https://phpackages.com/badges/febryntara-laravel-telemetry-logger/health.svg)](https://phpackages.com/packages/febryntara-laravel-telemetry-logger)
```

###  Alternatives

[laravel/scout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1.7k57.2M674](/packages/laravel-scout)[nuwave/lighthouse

A framework for serving GraphQL from Laravel

3.5k12.2M126](/packages/nuwave-lighthouse)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[illuminate/auth

The Illuminate Auth package.

9328.5M1.3k](/packages/illuminate-auth)[illuminate/broadcasting

The Illuminate Broadcasting package.

7127.4M233](/packages/illuminate-broadcasting)[illuminate/notifications

The Illuminate Notifications package.

483.1M1.2k](/packages/illuminate-notifications)

PHPackages © 2026

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