Skip to content

Customization

Laritor is built to be highly configurable, so you can adapt it to your exact requirements.

FeatureEnvironment VariableDefaultDescription
Backend API KeyLARITOR_BACKEND_KEYIngest API key used by Laritor’s backend to authenticate event submissions.
Ingest Endpoint URLLARITOR_INGEST_ENDPOINTFull URL where events are sent for ingestion.
Enable / Disable LaritorLARITOR_ENABLEDfalseTemporarily pause all event collection without uninstalling.
Environment NameLARITOR_ENVAPP_ENV valueOverride the detected environment name.
Server NameLARITOR_SERVER_NAMEHostnameSet a custom server name (useful for serverless environments).
Max Events Per OccurrenceLARITOR_MAX_EVENTS_PER_OCCURRENCE5000Limit events per request/command to control usage.
Ingest Events without an OccurrenceLARITOR_INGEST_EVENTS_WITHOUT_OCCURRENCEtrueSend events that are not associated with an occurrence.

While Laritor records every supported event by default, some applications may prefer to filter out unwanted events to reduce observability costs.

You can do this by defining a custom filter class to selectively exclude events such as specific routes, jobs, or queries.

This gives you full control over what gets tracked, helping you reduce noise and manage observability costs more effectively.

Step 1: Generate the Filter Override Class
Section titled “Step 1: Generate the Filter Override Class”

Run the below command to generate a filter class which records all events by default. Useful if you want to record all events initially and override in the future based on your needs.

Terminal window
php artisan make:laritor-filter

You can override any method in this class to return true/false to determine whether a specific event should be recorded or not.

  • true - event is recorded
  • false - event is not recorded
Step 2: Register the Override in AppServiceProvider
Section titled “Step 2: Register the Override in AppServiceProvider”

In your app/Providers/AppServiceProvider.php file, register the filter class in the register() method as below:

public function register(): void
{
$this->app->bind(
\BinaryBuilds\LaritorClient\Override\LaritorOverride::class,
\App\Laritor\LaritorDataFilter::class
);
}

✅ Done! Laritor will now call your custom filter class as it prepares events for delivery.

MethodDescription
recordRequest($request, $response, $status, $duration, $user)Return false to ignore an inbound request.
recordQuery($query, $duration, $path)Return false to ignore a query.
recordException($exception)Return false to ignore an exception.
recordQueuedJob(string $connection, string $queue, string $job, string $status, $duration)Return false to ignore a queued job.
recordMail($mailable, $to, $subject)Return false to ignore mail.
recordNotification($notifiable, $notification)Return false to ignore a notification.
recordCommandOrScheduledTask(string $command, string $status, $duration)Return false to ignore a command or scheduled task.
recordOutboundRequest($url, $statusCode, $duration)Return false to ignore an outbound request.
recordCacheHit($cacheKey)Return false to ignore a cache event.
recordFeatureFlag($flag, $scope)Return false to ignore a feature-flag check.
recordLog($level, $message, array $context = [])Return false to ignore a log entry.
recordTaskScheduler()Return false to ignore task-scheduler health tracking.
isBot($request)Return whether a request should be identified as a bot.

These methods control whether Laritor includes individual payload fields. Return false to omit the field. Request methods receive $request, $response, $status, $duration, $user; outbound-request methods receive $url, $statusCode, $duration.

MethodControls
recordCommandContext(...), recordScheduledTaskContext(...), recordRequestContext(...), recordQueuedJobContext(...), recordLogContext(...)Laravel context attached to the corresponding event
recordDatabaseSchema()Database schema collection
recordQueryBindings($query, $duration, $path)SQL query bindings
recordRequestQueryParameters(...)Inbound request query parameters
recordRequestHeaders(...), recordRequestBody(...)Inbound request headers and body
recordResponseHeaders(...), recordResponseBody(...)Inbound response headers and body
recordSessionData(...)Session data for inbound requests
recordOutboundRequestHeaders(...), recordOutboundRequestBody(...)Outbound request headers and body
recordOutboundRequestResponseHeaders(...), recordOutboundRequestResponseBody(...)Outbound response headers and body
whitelistedVendors(): arrayVendors whose stack frames should be retained

DefaultOverride records request and response headers and session data by default. Request and response bodies are disabled by default. Redaction is still applied to all recorded data.

public function recordRequest($request, $response, $status, $duration, $user): bool
{
$path = $request->path();
if (
$path === 'health' ||
str_starts_with($path, 'telescope') ||
str_starts_with($path, 'horizon') ||
preg_match('/\.(js|css|jpg|jpeg|png|svg|gif|ico)$/i', $path)
) {
return false;
}
return true;
}
public function recordQuery($query, $duration, $path): bool
{
// Skip queries faster than 5ms
if ($duration < 5) {
return false;
}
// Ignore Telescope and Horizon-related queries
if (preg_match('/\b(telescope_entries|horizon_jobs|horizon_tags)\b/i', $query)) {
return false;
}
return true;
}
public function recordQueuedJob(string $connection, string $queue, string $job, string $status, $duration): bool
{
if ($queue === 'broadcasts') {
return false;
}
return true;
}

By default, Laritor will identify bot requests based on the user agent string and mark them as bot requests. If your internal applications such as a different app or microservices are making requests, They may be treated as bots. To avoid this, you can override the isBot method to not tag your internal requests as bots.

public function isBot($request): bool
{
$ua = strtolower($request->userAgent());
if (str_contains($ua, 'internal-bot')) {
return false;
}
return parent::isBot($request);
}

Laritor automatically redacts sensitive data before it leaves your servers. You can further customize the redaction logic by overriding the default redactor. This allows you to mask, replace, or remove data like email addresses, user information, IPs, and more tailored to your app’s privacy requirements.

Step 1: Publish the Redactor Override Class
Section titled “Step 1: Publish the Redactor Override Class”

Run the following artisan command to publish the redactor override class.

Terminal window
php artisan make:laritor-redactor

This command will create a new file in app/Laritor/LaritorDataRedactor.php. You can override any of the methods in this class to redact the data as per your needs.

In your app/Providers/AppServiceProvider.php, register the redactor in the boot() method as below:

public function boot(): void
{
$this->app->bind(
\BinaryBuilds\LaritorClient\Redactor\DataRedactor::class,
\App\Laritor\LaritorDataRedactor::class
);
}

✅ Once registered, Laritor will use your custom redactor for all outgoing data.

Redactor MethodWhat it redactsUse case
redactEmailAddress($email)Email addressesReplace or mask user emails
redactString($text)Generic string valuesRedact log lines, message bodies, etc.
redactArrayValue($key,$value)Array key-value pairsRedact keys like password, token, etc.
redactAuthenticatedUser(): arrayAuthenticated user detailsReturn only anonymized or partial data
redactIPAddress($ip)IP addressesMask or remove client/server IPs
redactUserAgent($ua)User-Agent headerStrip or normalize browser/device info
public function redactEmailAddress($address): string
{
[$user, $domain] = explode('@', $address);
return str_repeat('*', strlen($user)) . '@' . $domain;
}
public function redactString($text): string
{
// Redact common tokens or credentials in text
$patterns = [
'/Bearer\s+[A-Za-z0-9\-_\.=]+/i' => '[REDACTED_TOKEN]',
'/password\s*=\s*["\']?.+?["\']?/i' => 'password=[REDACTED]',
];
return preg_replace(array_keys($patterns), array_values($patterns), $text);
}

Redact specific array keys from request payloads, query params, headers, etc.

public function redactArrayValue($key, $value): string
{
$sensitiveKeys = [
'password', 'token', 'access_token', 'refresh_token',
'api_key', 'secret', 'authorization', 'auth_token',
];
if (in_array(strtolower($key), $sensitiveKeys, true)) {
return '*****';
}
return $value;
}

Customize / Redact the logged-in user’s personal data:

public function redactAuthenticatedUser(): array
{
$user = Auth::user();
return [
'id' => $user?->id,
'name' => $user?->id ? 'User #' . $user->id : null,
'email' => $user?->id ? 'user' . $user->id . '@redacted.com' : null,
];
}
public function redactString($text): string
{
if (app()->environment('production')) {
return '*REDACTED*';
}
return $text;
}

Send Additional Attributes For Authenticated User

Section titled “Send Additional Attributes For Authenticated User”

To include details such as a user’s role or team, see the Additional Authenticated User Attributes guide →.

With these configuration options, you can fine-tune Laritor’s behavior to align with your application’s requirements, performance goals, and privacy policies.

If you need help with advanced customization or have a specific use case not covered in this guide, feel free to reach out. We’re happy to help!

Email: [email protected]

Join: Laritor Discord