LaraBug

User Tracking

LaraBug automatically captures authenticated user information when exceptions occur, helping you understand which users are affected by specific errors.

Automatic User Detection

When a user is authenticated, LaraBug automatically includes their information in exception reports. By default, it captures the user model as an array.

Custom User Data

You can customize what user data is sent to LaraBug by implementing the Larabugable interface on your User model.

Implementing Larabugable

<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use LaraBug\Concerns\Larabugable;

class User extends Authenticatable implements Larabugable
{
    /**
     * Return custom data for LaraBug
     */
    public function toLarabug(): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'email' => $this->email,
            'role' => $this->role,
            'subscription' => $this->subscription_plan,
        ];
    }
}

What Gets Captured

Without the Larabugable interface, LaraBug captures:

  • All model attributes (via toArray())
  • Works automatically for any authenticated user

With the Larabugable interface:

  • Only the data you specify in toLarabug()
  • Full control over what information is sent

Filtering Sensitive Data

Even with automatic user capture, remember that the blacklist in your config will filter sensitive fields:

'blacklist' => [
    '*password*',
    '*token*',
    '*credit_card*',
],

Example: Minimal User Data

public function toLarabug(): array
{
    return [
        'id' => $this->id,
        'email' => $this->email,
    ];
}

Example: Detailed User Context

public function toLarabug(): array
{
    return [
        'id' => $this->id,
        'name' => $this->name,
        'email' => $this->email,
        'role' => $this->role,
        'plan' => $this->subscription?->plan_name,
        'created_at' => $this->created_at->toDateString(),
        'is_verified' => $this->hasVerifiedEmail(),
        'timezone' => $this->timezone,
        'locale' => $this->locale,
    ];
}

Guest Users

When no user is authenticated, LaraBug simply won't include user data in the exception report. The exception will still be tracked with all other contextual information.

Multi-Guard Authentication

LaraBug uses the default authentication guard. If you're using multiple guards:

// In your exception handler
if (auth('admin')->check()) {
    // Admin user is authenticated
}

The toLarabug() method will be called on whichever user model is authenticated.

Best Practices

  1. Privacy First - Only include data necessary for debugging
  2. Compliance - Ensure your user tracking complies with GDPR/privacy laws
  3. Consistency - Use the same structure across all user types
  4. Documentation - Document what user data you're tracking
  5. Review - Regularly review what data is being sent

What Data is Automatically Captured

Besides user information, LaraBug captures:

  • Request method and URL
  • Request headers (filtered by blacklist)
  • Request parameters (filtered by blacklist)
  • Session data (filtered by blacklist)
  • Cookies (filtered by blacklist)
  • Server information
  • PHP version
  • Environment name

All this data helps provide complete context for debugging exceptions.