watchtowerapm / agent
A modern, open-source Laravel APM agent inspired by Laravel Nightwatch and the best of modern observability tooling.
Requires
- php: ^8.2
- ext-zlib: *
- guzzlehttp/promises: ^2.0|^3.0
- laravel/framework: ^10.0|^11.0|^12.0|^13.0
- monolog/monolog: ^3.6
- nesbot/carbon: ^2.0|^3.0
- psr/http-message: ^1.0|^2.0
- psr/log: ^1.0|^2.0|^3.0
- ramsey/uuid: ^4.0
- symfony/console: ^6.0|^7.0|^8.0
- symfony/http-foundation: ^6.0|^7.0|^8.0
- symfony/polyfill-php84: ^1.29
Requires (Dev)
- ext-pcntl: *
- ext-pdo: *
- aws/aws-sdk-php: ^3.349
- guzzlehttp/guzzle: ^7.8.2
- guzzlehttp/psr7: ^2.0|^3.0
- laravel/horizon: ^5.4
- laravel/pint: 1.21.0
- laravel/vapor-core: ^2.38.2
- livewire/livewire: ^2.0|^3.0
- mockery/mockery: ^1.0
- mongodb/laravel-mongodb: ^4.0|^5.0
- orchestra/testbench: ^8.0|^9.0|^10.0|^11.0
- orchestra/testbench-core: ^8.0|^9.0|^10.0|^11.0
- orchestra/workbench: ^8.0|^9.0|^10.0|^11.0
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^10.0|^11.0|^12.0
- singlestoredb/singlestoredb-laravel: ^1.0|^2.0
- spatie/laravel-ignition: ^2.0
- symfony/mailer: ^6.0|^7.0|^8.0
- symfony/mime: ^6.0|^7.0|^8.0
- symfony/var-dumper: ^6.0|^7.0|^8.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-21 18:56:07 UTC
README
Watchtower Laravel agent 1.1.1 — open-source APM instrumentation for Laravel that sends telemetry only to your Watchtower instance.
This project is derived from laravel/nightwatch v1.30.0 (MIT). It does not connect to Laravel’s hosted Nightwatch service. Composer authors are Watchtower; Nightwatch attribution lives in LICENSE.md and NOTICE.md.
| Package version | 1.1.1 (version.txt) |
| Git branch | 1.x |
| Wire protocol | watchtower / protocol_version 2 |
| PHP | 8.2–8.5 |
| Laravel | 10–13 |
Documentation
- Architecture — SDK, sidecar, platform
- Protocol — frames, HELLO/WELCOME, session, sequence, batch limits
- Fork and 1.0.0 scope — what we kept, what we own, what is deferred
- Development — test, lint, CI, phar, Docker
- Changelog
What it does
- Hooks Laravel (HTTP, queue, schedule, mail, cache, queries, exceptions, …).
- Sensors turn those events into records (existing
t+ field shapes). - The package opens TCP to a local sidecar (
WATCHTOWER_INGEST_URI, default127.0.0.1:2407) and speaks the Watchtower session protocol (not Nightwatchv1:tokenHash:payload). - The sidecar authenticates to
{WATCHTOWER_BASE_URL}/api/agent-authand forwards batches to the ingest URL in that response.
App --Watchtower frames--> sidecar --HTTPS--> Watchtower platform
Install
composer require watchtowerapm/agent
Publish config if you want a file in the app:
php artisan vendor:publish --tag=watchtower-config
Environment
WATCHTOWER_ENABLED=true WATCHTOWER_TOKEN= WATCHTOWER_INGEST_URI=127.0.0.1:2407
| Variable | Required | Purpose |
|---|---|---|
WATCHTOWER_TOKEN |
Yes for sidecar + HELLO hash | Platform bearer token |
WATCHTOWER_BASE_URL |
No | Platform origin. Defaults to https://api.watchtowers.cloud; set it only for a self-hosted or staging platform |
WATCHTOWER_INGEST_URI |
No | Where the app sends frames / sidecar listens |
WATCHTOWER_REMOTE_SETTINGS |
No | Default true: apply sampling and filters set in the Watchtower panel (agent writes bootstrap/cache/watchtower-settings.php) |
WATCHTOWER_ENABLED |
No | Default true |
WATCHTOWER_DEPLOY |
For watchtower:deploy |
Deploy identifier |
Sampling, filtering, and redaction: config/watchtower.php and configure-watchtower.
Optional logs:
LOG_CHANNEL=watchtower # or LOG_STACK=watchtower,single LOG_CHANNEL=stack
Run the sidecar
The Laravel process is not the sidecar. Run one sidecar per host (or container) that should accept local frames:
php artisan watchtower:agent
If agent/build/agent.phar exists, that binary is used; otherwise agent/src/agent.php. After protocol changes, use a rebuilt phar (CI commits it on 1.x).
Docker image from this repo:
docker build -f agent/Dockerfile -t watchtower-agent .
docker run --rm \
-e WATCHTOWER_TOKEN \
-p 2407:2407 \
watchtower-agent
Health: php artisan watchtower:status or php agent/watchtower-status (needs WATCHTOWER_TOKEN).
Deploy notification (HTTPS to the platform, not the local protocol):
php artisan watchtower:deploy
Protocol (short)
Framing: {byte_length}\\n{json}.
HELLO (protocol=watchtower, protocol_version=2, nonce, mac)
→ WELCOME (session_id, max_batch=500, nonce, mac)
→ telemetry_batch | ping (session_id, sequence=1, mac)
→ ACK
Every message is signed with HMAC-SHA256, using a key derived from the full WATCHTOWER_TOKEN (the token never crosses the socket); batch records are covered by an xxh128 digest inside the signature, to keep the cost per request low. Each side sends a fresh nonce, so a recorded exchange can't be replayed, and the app sends nothing until the sidecar has proved it holds the same token. The sidecar also rejects mismatched session, sequence ≠ 1, batch_version ≠ 2, and batches larger than 500. Keep the listen address on localhost or a private network anyway. Details: docs/protocol.md.
Repository layout
| Path | Role |
|---|---|
src/ |
Laravel package |
agent/ |
Sidecar, Docker, phar build |
tests/ |
Package tests |
agent/tests/ |
Sidecar tests |
docs/ |
Protocol and contributor docs |
Testing and CI
You do not need a real Watchtower in GitHub (or locally) to run the suite.
PHPUnit uses fixture WATCHTOWER_TOKEN / https://watchtower.test. Tests that would call a live /api/agent-auth skip when the URL is that fixture.
composer install composer test cd agent && composer install && composer test
Lint: vendor/bin/pint --test and vendor/bin/phpstan at the repo root and under agent/.
GitHub Actions (.github/workflows/pull_request.yml): Pint, PHPStan, phar build, package matrix (PHP × Laravel × prefer-lowest), agent tests, Docker health check. Secrets are optional; they default to the same fixtures.
Full contributor workflow: docs/development.md.
Versioning
- 1.0.0 is the first Watchtower package release (this is not Nightwatch 2.x and not “protocol 2”).
- Bump
version.txtandcomposer.jsontogether. protocol_version/batch_versionchange only when the wire contract changes (see protocol docs).
Terms of use
The code is MIT-licensed (see below). Using it with the Watchtower service is also governed by the Watchtower Terms of Service, which you accept when you create a Watchtower account. Under those terms, notwithstanding the MIT license, you agree to:
- use the agent only with the Watchtower service;
- send the monitoring data it collects only to Watchtower;
- install it only on systems you own or operate, or are authorized to monitor.
The terms also forbid using the service to build a competing product, benchmarking it other than for internal evaluation, and reverse engineering its non-open-source parts.
License
MIT. Portions derived from Laravel Nightwatch:
Copyright (c) Taylor Otwell
See LICENSE.md and NOTICE.md.