Back to Coolify

Nightwatch Configuration Reference

.cursor/skills/configure-nightwatch/reference.md

4.2.03.9 KB
Original Source

Nightwatch Configuration Reference

Configuration Summary by Event Type

Event TypeSamplingFilteringRedaction
RequestsNIGHTWATCH_REQUEST_SAMPLE_RATE, Route middlewareNot applicableHeaders, payload, URL, IP
CommandsNIGHTWATCH_COMMAND_SAMPLE_RATE, Event listenerNot applicableCommand arguments
QueriesParent contextrejectQueries(), NIGHTWATCH_IGNORE_QUERIESSQL statement
CacheParent contextrejectCacheKeys(), rejectCacheEvents(), NIGHTWATCH_IGNORE_CACHE_EVENTSCache key
JobsParent context, Queue::beforerejectQueuedJobs()Not applicable
MailParent contextrejectMail(), NIGHTWATCH_IGNORE_MAILSubject
NotificationsParent contextrejectNotifications(), NIGHTWATCH_IGNORE_NOTIFICATIONSNot applicable
Outgoing RequestsParent contextrejectOutgoingRequests(), NIGHTWATCH_IGNORE_OUTGOING_REQUESTSURL
ExceptionsNIGHTWATCH_EXCEPTION_SAMPLE_RATENot applicableException message

Production Recommendations

High-Traffic Applications

bash

# Conservative sampling

NIGHTWATCH_REQUEST_SAMPLE_RATE=0.01          # 1% of requests

NIGHTWATCH_COMMAND_SAMPLE_RATE=0.1           # 10% of commands

NIGHTWATCH_EXCEPTION_SAMPLE_RATE=1.0         # Always capture exceptions

# Filter noisy events

NIGHTWATCH_IGNORE_CACHE_EVENTS=true
NIGHTWATCH_IGNORE_QUERIES=true               # Or filter specific queries programmatically

Privacy-Conscious Applications

bash

# Disable sensitive data collection

NIGHTWATCH_CAPTURE_REQUEST_PAYLOAD=false
NIGHTWATCH_REDACT_HEADERS=Authorization,Cookie,Proxy-Authorization,X-XSRF-TOKEN

# Or use redaction in AppServiceProvider

bash

# Sample rates

NIGHTWATCH_REQUEST_SAMPLE_RATE=0.1
NIGHTWATCH_COMMAND_SAMPLE_RATE=1.0
NIGHTWATCH_EXCEPTION_SAMPLE_RATE=1.0

# Filter obvious noise programmatically

# Redact PII as needed


Verification Checklist

After configuration:

  • Sampling rates appropriate for traffic volume
  • Noisy events filtered (cache, certain queries)
  • Sensitive data redacted (PII, tokens, credentials)
  • Exceptions always captured for debugging
  • Test in development with NIGHTWATCH_REQUEST_SAMPLE_RATE=1.0
  • Monitor event quota usage in Nightwatch dashboard

Common Patterns

Filter Health Checks + Reduce Sampling

php
Route::get('/health', fn() => ['status' => 'ok'])
    ->middleware(Sample::never());

Exclude Internal/Vendor Queries

php
Nightwatch::rejectQueries(fn($q) =>
    str_contains($q->sql, 'telescope') ||
    str_contains($q->sql, 'pulse')
);

Protect User Data in Cache Keys

php
Nightwatch::redactCacheEvents(fn($e) =>
    $e->key = preg_replace('/user:\d+/', 'user:***', $e->key)
);