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:

NIGHTWATCH_EXCEPTION_SAMPLE_RATE=1.0
NIGHTWATCH_COMMAND_SAMPLE_RATE=1.0
NIGHTWATCH_REQUEST_SAMPLE_RATE=0.1 #Recommended

πŸ’‘ 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 events
  • 0.0 – Capture nothing
  • 0.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 events
  • NIGHTWATCH_IGNORE_MAIL β€” Exclude all mail events
  • NIGHTWATCH_IGNORE_NOTIFICATIONS β€” Exclude all notification events
  • NIGHTWATCH_IGNORE_OUTGOING_REQUESTS β€” Exclude all outgoing HTTP requests
  • NIGHTWATCH_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:

NIGHTWATCH_IGNORE_CACHE_EVENTS=true

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