laravel/nightwatch
Official Laravel Nightwatch package. Collects application metrics and performance data from your Laravel app and securely sends it to the hosted Nightwatch monitoring platform for deep, Laravel-optimized insights and observability.
Install the Package
composer require laravel/nightwatch
Publish the config file:
php artisan vendor:publish --provider="Laravel\Nightwatch\NightwatchServiceProvider"
Configure .env
Add your Nightwatch API token and project ID:
NIGHTWATCH_API_TOKEN=your_api_token_here
NIGHTWATCH_PROJECT_ID=your_project_id_here
First Use Case: Track HTTP Requests
Enable HTTP request monitoring in config/nightwatch.php:
'http' => [
'enabled' => true,
],
No additional code needed—requests are automatically tracked.
Sampling and Ignoring Events
.env:
NIGHTWATCH_COMMAND_SAMPLE_RATE=0.1 # 10% of commands
NIGHTWATCH_SCHEDULED_TASK_SAMPLE_RATE=0.5 # 50% of tasks
Nightwatch::ignore('command', 'queue:work');
Custom Event Tracking
Nightwatch::event('custom.event', [
'key' => 'value',
'user_id' => auth()->id(),
]);
Deploy Tracking
nightwatch:deploy command:
php artisan nightwatch:deploy --message="Production release v1.0"
- run: php artisan nightwatch:deploy --message="Deployed via CI"
Exception Redaction
Nightwatch::redact('password', 'secret_*');
Vapor Sub-Minute Scheduling
vapor:schedule commands for sub-minute tasks:
NIGHTWATCH_SCHEDULED_TASK_SAMPLE_RATE=0.3 # Applies to Vapor schedules
NIGHTWATCH_QUEUE_SAMPLE_RATE to control frequency.NIGHTWATCH_SCHEDULED_TASK_SAMPLE_RATE=0.3
Nightwatch::ignore('cache', 'livewire-checksum-*');
Sampling Conflicts
NIGHTWATCH_SCHEDULED_TASK_SAMPLE_RATE overrides NIGHTWATCH_COMMAND_SAMPLE_RATE for tasks. Set both explicitly if needed.Token Expiry
NIGHTWATCH_API_TOKEN is missing.Vendor Command Sampling
octane:status). Re-enable via:
Nightwatch::ignore('command', false); // Global override
Windows stdout/stderr
Nightwatch::writeToStdout('Log message'); // Sync on Windows
Laravel 13 Compatibility
Nightwatch::digest(); // Transmit pending events
storage/logs/nightwatch.log for agent activity.Custom Metrics
Extend the Nightwatch facade to log domain-specific data:
Nightwatch::extend(function ($nightwatch) {
$nightwatch->event('custom.metric', ['value' => $this->getMetric()]);
});
Agent Configuration Override default behavior via service provider:
public function boot()
{
Nightwatch::ignore('cache', 'my-custom-key-*');
}
Boost Skills
Use pre-built skills (e.g., configure-nightwatch) for common setups:
php artisan boost:skill configure-nightwatch
Naming Conventions
snake_case for consistency). The package now enforces this internally.How can I help you explore Laravel packages today?