Skip to main content
Nightwatch includes several safeguards to help prevent sensitive data from being captured by default: You can also customize which user details are captured.

Manual Redaction

Some data sources may still contain sensitive information that Nightwatch can’t automatically redact. You can use the following methods to handle these cases:
SourceMethod
Raw database queriesNightwatch::redactQueries
Exception messagesNightwatch::redactExceptions
Cache key namesNightwatch::redactCacheEvents
Command argumentsNightwatch::redactCommands
Mail subjectsNightwatch::redactMail
Request URLs and IP addressesNightwatch::redactRequests
Outgoing request URLsNightwatch::redactOutgoingRequests
Each of these helpers accepts a callback that lets you modify the event record before it’s sent to Nightwatch. Your callback function will receive an event record object, allowing you to edit any property that is not marked readonly.
use Laravel\Nightwatch\Facades\Nightwatch;
use Laravel\Nightwatch\Records\CacheEvent;
use Laravel\Nightwatch\Records\Command;
use Laravel\Nightwatch\Records\Exception;
use Laravel\Nightwatch\Records\Mail;
use Laravel\Nightwatch\Records\OutgoingRequest;
use Laravel\Nightwatch\Records\Query;
use Laravel\Nightwatch\Records\Request;

Nightwatch::redactCacheEvents(function (CacheEvent $cacheEvent) {
    $cacheEvent->key = str_replace('secret', '***', $cacheEvent->key);
});

Nightwatch::redactCommands(function (Command $command) {
    $command->command = str_replace('secret', '***', $command->command);
});

Nightwatch::redactExceptions(function (Exception $exception) {
    $exception->message = str_replace('secret', '***', $exception->message);
});

Nightwatch::redactMail(function (Mail $mail) {
    $mail->subject = str_replace('secret', '***', $mail->subject);
});

Nightwatch::redactOutgoingRequests(function (OutgoingRequest $outgoingRequest) {
    $outgoingRequest->url = str_replace('secret', '***', $outgoingRequest->url);
});

Nightwatch::redactQueries(function (Query $query) {
    $query->sql = str_replace('secret', '***', $query->sql);
});

Nightwatch::redactRequests(function (Request $request) {
    $request->url = str_replace('secret', '***', $request->url);
    $request->ip = str_replace('secret', '***', $request->ip);
});