Manually Reporting Exceptions

Nightwatch automatically listens to all exceptions reported within your Laravel application:

report($e); // Nightwatch will capture this exception...

If you’re not seeing an exception in your Nightwatch dashboard, you can explicitly report it using the facade:

use Laravel\Nightwatch\Facades\Nightwatch;

Nightwatch::report($e);

📘 This is only needed in rare cases where exceptions are not captured automatically.

Customizing User Details

Nightwatch can capture information about the currently authenticated user. By default, it collects the user’s name and email attributes and uses them as the display name and username.

If you want to customize what’s captured — for example, using a user’s first_name and last_name instead — you can do so in your AppServiceProvider using the Nightwatch::user method.

Custom User fields

use Illuminate\Contracts\Auth\Authenticatable;
use Laravel\Nightwatch\Facades\Nightwatch;

Nightwatch::user(fn (Authenticatable $user) => [
    'name' => "{$user->first_name} {$user->last_name}",
    'username' => $user->email,
]);

Omitting User fields

You can choose to exclude one or both fields by omitting them from the returned array:

// Exclude both fields...
Nightwatch::user(fn (Authenticatable $user) => []);

// Only include the name field...
Nightwatch::user(fn (Authenticatable $user) => [
'name' => $user->name,
]);

Monitoring Guzzle Requests

Nightwatch automatically captures outgoing HTTP requests made via Laravel’s Http client. If you’re using Guzzle directly, you can still capture these requests by attaching Nightwatch’s middleware to your Guzzle stack.

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Handler\CurlHandler;
use Laravel\Nightwatch\Facades\Nightwatch;

// Set up the handler stack...
$stack = new HandlerStack;
$stack->setHandler(new CurlHandler);

// Push Nightwatch's middleware...
$stack->push(Nightwatch::guzzleMiddleware());

// Create the client with the stack...
$client = new Client(['handler' => $stack]);

Requests made by $client will now be monitored by Nightwatch.

Customizing the Agent Port

By default, the Nightwatch agent listens on port 2407. You can change this by setting a different ingest URI and using the --listen-on flag when starting the agent.

To run the agent on port 2408, update your .env file:

NIGHTWATCH_INGEST_URI=127.0.0.1:2408

Then start the agent using the matching port:

php artisan nightwatch:agent --listen-on=127.0.0.1:2408

Running Multiple Agents

If you’re running more than one Laravel application or environment on the same server, you can run multiple Nightwatch agents in parallel — each on a unique port.

Each agent must use a different port. See Customizing the Agent Port for instructions on how to set this per instance.

Here’s an example setup running two agents in the one server:

# App 1 - /var/www/app-1
NIGHTWATCH_INGEST_URI=127.0.0.1:2407
php artisan nightwatch:agent --listen-on=127.0.0.1:2407

# App 2: /var/www/app-2
NIGHTWATCH_INGEST_URI=127.0.0.1:2408
php artisan nightwatch:agent --listen-on=127.0.0.1:2408