From c09d7e412e62df2b1c4f41765b8de06db4f2624d Mon Sep 17 00:00:00 2001
From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com>
Date: Mon, 23 Mar 2026 15:36:47 +0100
Subject: [PATCH] feat(monitoring): add Laravel Nightwatch monitoring support
- Install laravel/nightwatch package for application monitoring
- Create Nightwatch console command to start the monitoring agent
- Add NIGHTWATCH_ENABLED and NIGHTWATCH_TOKEN environment variables
- Configure nightwatch settings in config/constants.php
- Set up Docker s6-overlay services for both development and production
- Disable Nightwatch by default in test environment
---
.env.development.example | 4 +
app/Console/Commands/Nightwatch.php | 22 +++++
composer.json | 1 +
composer.lock | 98 ++++++++++++++++++-
config/constants.php | 4 +
.../dependencies.d/init-setup | 1 +
.../s6-overlay/s6-rc.d/nightwatch-agent/run | 12 +++
.../s6-overlay/s6-rc.d/nightwatch-agent/type | 1 +
.../s6-rc.d/user/contents.d/nightwatch-agent | 1 +
.../dependencies.d/init-script | 1 +
.../s6-overlay/s6-rc.d/nightwatch-agent/run | 11 +++
.../s6-overlay/s6-rc.d/nightwatch-agent/type | 1 +
.../s6-rc.d/user/contents.d/nightwatch-agent | 1 +
phpunit.xml | 1 +
14 files changed, 157 insertions(+), 2 deletions(-)
create mode 100644 app/Console/Commands/Nightwatch.php
create mode 100644 docker/development/etc/s6-overlay/s6-rc.d/nightwatch-agent/dependencies.d/init-setup
create mode 100644 docker/development/etc/s6-overlay/s6-rc.d/nightwatch-agent/run
create mode 100644 docker/development/etc/s6-overlay/s6-rc.d/nightwatch-agent/type
create mode 100644 docker/development/etc/s6-overlay/s6-rc.d/user/contents.d/nightwatch-agent
create mode 100644 docker/production/etc/s6-overlay/s6-rc.d/nightwatch-agent/dependencies.d/init-script
create mode 100644 docker/production/etc/s6-overlay/s6-rc.d/nightwatch-agent/run
create mode 100644 docker/production/etc/s6-overlay/s6-rc.d/nightwatch-agent/type
create mode 100644 docker/production/etc/s6-overlay/s6-rc.d/user/contents.d/nightwatch-agent
diff --git a/.env.development.example b/.env.development.example
index b0b15f324..594b89201 100644
--- a/.env.development.example
+++ b/.env.development.example
@@ -24,6 +24,10 @@ RAY_ENABLED=false
# Enable Laravel Telescope for debugging
TELESCOPE_ENABLED=false
+# Enable Laravel Nightwatch monitoring
+NIGHTWATCH_ENABLED=false
+NIGHTWATCH_TOKEN=
+
# Selenium Driver URL for Dusk
DUSK_DRIVER_URL=http://selenium:4444
diff --git a/app/Console/Commands/Nightwatch.php b/app/Console/Commands/Nightwatch.php
new file mode 100644
index 000000000..40fd86a81
--- /dev/null
+++ b/app/Console/Commands/Nightwatch.php
@@ -0,0 +1,22 @@
+info('Nightwatch is enabled on this server.');
+ $this->call('nightwatch:agent');
+ }
+
+ exit(0);
+ }
+}
diff --git a/composer.json b/composer.json
index d4fb1eb8e..e2b16b31b 100644
--- a/composer.json
+++ b/composer.json
@@ -18,6 +18,7 @@
"laravel/fortify": "^1.34.0",
"laravel/framework": "^12.49.0",
"laravel/horizon": "^5.43.0",
+ "laravel/nightwatch": "^1.24",
"laravel/pail": "^1.2.4",
"laravel/prompts": "^0.3.11|^0.3.11|^0.3.11",
"laravel/sanctum": "^4.3.0",
diff --git a/composer.lock b/composer.lock
index 993835a42..3a66fdd5a 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "19bb661d294e5cf623e68830604e4f60",
+ "content-hash": "40bddea995c1744e4aec517263109a2f",
"packages": [
{
"name": "aws/aws-crt-php",
@@ -2065,6 +2065,100 @@
},
"time": "2026-02-21T14:20:09+00:00"
},
+ {
+ "name": "laravel/nightwatch",
+ "version": "v1.24.4",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/laravel/nightwatch.git",
+ "reference": "127e9bb9928f0fcf69b52b244053b393c90347c8"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/laravel/nightwatch/zipball/127e9bb9928f0fcf69b52b244053b393c90347c8",
+ "reference": "127e9bb9928f0fcf69b52b244053b393c90347c8",
+ "shasum": ""
+ },
+ "require": {
+ "ext-zlib": "*",
+ "guzzlehttp/promises": "^2.0",
+ "laravel/framework": "^10.0|^11.0|^12.0|^13.0",
+ "monolog/monolog": "^3.6",
+ "nesbot/carbon": "^2.0|^3.0",
+ "php": "^8.2",
+ "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"
+ },
+ "require-dev": {
+ "aws/aws-sdk-php": "^3.349",
+ "ext-pcntl": "*",
+ "ext-pdo": "*",
+ "guzzlehttp/guzzle": "^7.0",
+ "guzzlehttp/psr7": "^2.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",
+ "orchestra/testbench-core": "^8.0|^9.0|^10.0",
+ "orchestra/workbench": "^8.0|^9.0|^10.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"
+ },
+ "type": "library",
+ "extra": {
+ "laravel": {
+ "aliases": {
+ "Nightwatch": "Laravel\\Nightwatch\\Facades\\Nightwatch"
+ },
+ "providers": [
+ "Laravel\\Nightwatch\\NightwatchServiceProvider"
+ ]
+ }
+ },
+ "autoload": {
+ "files": [
+ "agent/helpers.php"
+ ],
+ "psr-4": {
+ "Laravel\\Nightwatch\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Taylor Otwell",
+ "email": "taylor@laravel.com"
+ }
+ ],
+ "description": "The official Laravel Nightwatch package.",
+ "homepage": "https://nightwatch.laravel.com",
+ "keywords": [
+ "Insights",
+ "laravel",
+ "monitoring"
+ ],
+ "support": {
+ "docs": "https://nightwatch.laravel.com/docs",
+ "issues": "https://github.com/laravel/nightwatch/issues",
+ "source": "https://github.com/laravel/nightwatch"
+ },
+ "time": "2026-03-18T23:25:05+00:00"
+ },
{
"name": "laravel/pail",
"version": "v1.2.6",
@@ -17209,5 +17303,5 @@
"php": "^8.4"
},
"platform-dev": {},
- "plugin-api-version": "2.9.0"
+ "plugin-api-version": "2.6.0"
}
diff --git a/config/constants.php b/config/constants.php
index 9c6454cae..803a0a0bd 100644
--- a/config/constants.php
+++ b/config/constants.php
@@ -55,6 +55,10 @@
'is_scheduler_enabled' => env('SCHEDULER_ENABLED', true),
],
+ 'nightwatch' => [
+ 'is_nightwatch_enabled' => env('NIGHTWATCH_ENABLED', false),
+ ],
+
'docker' => [
'minimum_required_version' => '24.0',
],
diff --git a/docker/development/etc/s6-overlay/s6-rc.d/nightwatch-agent/dependencies.d/init-setup b/docker/development/etc/s6-overlay/s6-rc.d/nightwatch-agent/dependencies.d/init-setup
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/docker/development/etc/s6-overlay/s6-rc.d/nightwatch-agent/dependencies.d/init-setup
@@ -0,0 +1 @@
+
diff --git a/docker/development/etc/s6-overlay/s6-rc.d/nightwatch-agent/run b/docker/development/etc/s6-overlay/s6-rc.d/nightwatch-agent/run
new file mode 100644
index 000000000..1166ccd08
--- /dev/null
+++ b/docker/development/etc/s6-overlay/s6-rc.d/nightwatch-agent/run
@@ -0,0 +1,12 @@
+#!/command/execlineb -P
+
+# Use with-contenv to ensure environment variables are available
+with-contenv
+cd /var/www/html
+
+foreground {
+ php
+ artisan
+ start:nightwatch
+}
+
diff --git a/docker/development/etc/s6-overlay/s6-rc.d/nightwatch-agent/type b/docker/development/etc/s6-overlay/s6-rc.d/nightwatch-agent/type
new file mode 100644
index 000000000..5883cff0c
--- /dev/null
+++ b/docker/development/etc/s6-overlay/s6-rc.d/nightwatch-agent/type
@@ -0,0 +1 @@
+longrun
diff --git a/docker/development/etc/s6-overlay/s6-rc.d/user/contents.d/nightwatch-agent b/docker/development/etc/s6-overlay/s6-rc.d/user/contents.d/nightwatch-agent
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/docker/development/etc/s6-overlay/s6-rc.d/user/contents.d/nightwatch-agent
@@ -0,0 +1 @@
+
diff --git a/docker/production/etc/s6-overlay/s6-rc.d/nightwatch-agent/dependencies.d/init-script b/docker/production/etc/s6-overlay/s6-rc.d/nightwatch-agent/dependencies.d/init-script
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/docker/production/etc/s6-overlay/s6-rc.d/nightwatch-agent/dependencies.d/init-script
@@ -0,0 +1 @@
+
diff --git a/docker/production/etc/s6-overlay/s6-rc.d/nightwatch-agent/run b/docker/production/etc/s6-overlay/s6-rc.d/nightwatch-agent/run
new file mode 100644
index 000000000..80d73eadb
--- /dev/null
+++ b/docker/production/etc/s6-overlay/s6-rc.d/nightwatch-agent/run
@@ -0,0 +1,11 @@
+#!/command/execlineb -P
+
+# Use with-contenv to ensure environment variables are available
+with-contenv
+cd /var/www/html
+foreground {
+ php
+ artisan
+ start:nightwatch
+}
+
diff --git a/docker/production/etc/s6-overlay/s6-rc.d/nightwatch-agent/type b/docker/production/etc/s6-overlay/s6-rc.d/nightwatch-agent/type
new file mode 100644
index 000000000..5883cff0c
--- /dev/null
+++ b/docker/production/etc/s6-overlay/s6-rc.d/nightwatch-agent/type
@@ -0,0 +1 @@
+longrun
diff --git a/docker/production/etc/s6-overlay/s6-rc.d/user/contents.d/nightwatch-agent b/docker/production/etc/s6-overlay/s6-rc.d/user/contents.d/nightwatch-agent
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/docker/production/etc/s6-overlay/s6-rc.d/user/contents.d/nightwatch-agent
@@ -0,0 +1 @@
+
diff --git a/phpunit.xml b/phpunit.xml
index 6716b6b84..5d55acf75 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -22,6 +22,7 @@
+