Sampling
Control your event consumption with sampling.
By default, Nightwatch captures all events at 100%. You can reduce the volume of data collected by enabling sampling β ideal for high-throughput or noisy environments.
Sampling environment variables:
π‘ Tip: We recommend starting with a sample rate of
0.1
on requests to build an understanding of your applicationβs profile and adjusting the rate based on your observations.
Request and command sampling
Sampling is supported for both HTTP requests and Artisan commands. When a request or command is sampled, all related events β including queries, jobs, exceptions, and outbound HTTP calls β will be captured.
Exception sampling
You can combine exception sampling with other sampling types. When you set both request sampling (10%) and exception sampling (50%), Nightwatch will:
- Capture all exceptions from the sampled requests
- Capture 50% of exceptions from non-sampled requests
To ignore exceptions on non-sampled requests, set NIGHTWATCH_EXCEPTION_SAMPLE_RATE=0
. This setting ensures that exceptions are captured only from sampled requests.
Examples:
1.0
β Capture 100% of events0.0
β Capture nothing0.75
β Capture 75% of events (randomly sampled)
Event Filtering
In addition to sampling, you can filter out specific event types entirely. This allows you to focus your event allocation on the events that matter most to your application.
When an event type is filtered, it is completely excluded from collection, no data will be sent to Nightwatch, and the event will not appear in your stream, traces, or usage metrics.
Available Filters
Set any of the following environment variables in your .env
file to true
to disable collection of that event type:
NIGHTWATCH_IGNORE_CACHE_EVENTS
β Exclude all cache eventsNIGHTWATCH_IGNORE_MAIL
β Exclude all mail eventsNIGHTWATCH_IGNORE_NOTIFICATIONS
β Exclude all notification eventsNIGHTWATCH_IGNORE_OUTGOING_REQUESTS
β Exclude all outgoing HTTP requestsNIGHTWATCH_IGNORE_QUERIES
β Exclude all database queries
Example: Ignoring cache events
For applications that make heavy use of caching, cache events can consume a significant portion of your quota. By filtering them out, you can preserve more of your allocation for higher-value signals like queries, jobs, and exceptions.
To ignore cache events, add the following to your .env
file:
Exception Throttling
Laravel provides simple ways to throttle exception reporting. When your app generates high volumes of exceptions, or when you need to protect against sudden spikes, you can use sampling to limit the number of logged exceptions.
https://laravel.com/docs/errors#throttling-reported-exceptions