Flare by Spatie
  • Features
  • Pricing
  • Docs
  • Blog
  • LOG IN
  • START TRACKING
  • Home
  • Features
  • Pricing
  • Docs
  • Blog
    • Try Flare for free
    • Sign in
Flare Flare Laravel Laravel PHP PHP JavaScript JavaScript
  • General
  • Introduction
  • Installation
  • Censoring collected data
  • Ignoring collected data
  • Errors
  • Adding custom context
  • Customising error grouping
  • Handling errors
  • Linking to errors
  • Reporting errors
  • Performance
  • Introduction
  • Sampling
  • Limits
  • Modify spans and events
  • Data Collection
  • Application info
  • Application lifecycle
  • Cache events
  • Console commands
  • Customise error report
  • Database transactions
  • Dumps
  • Errors when tracing
  • Exception context
  • External http requests
  • Filesystem operations
  • Git information
  • Glows
  • Identifying users
  • Logs
  • Queries
  • Redis commands
  • Requests
  • Routing
  • Server info
  • Solutions
  • Spans
  • Stacktrace arguments
  • Views
  • Older Packages
  • Flare Client PHP V1

Identifying users

When a user is logged into your application and an error/trace occurs, helpful information about the user can be sent to Flare.

To do this, a UserAttributesProvider should be created as such:

use Spatie\FlareClient\AttributesProviders\ UserAttributesProvider;

class CustomUserAttributesProvider extends UserAttributesProvider
{
    public function id(mixed $user): string|int|null
    {
        return $user->id;
    }

    public function fullName(mixed $user): string|null
    {
        return "{$user->first_name} {$user->last_name}";
    }

    public function email(mixed $user): string|null
    {
        return $user->email;
    }

    public function attributes(mixed $user): array
    {
        return [
            'team_id' => $user->team_id
        ];
    }
}

Implementing all these methods is not required; you can mix and match the ones you need.

The attributes method can return a key-value array with extra information about the user other than its name, email, or ID.

The custom provider then should be registered within the Flare config as such:

$config->userAttributesProvider(CustomUserAttributesProvider::class)
Glows Logs

Monitor your web apps and sites from errors to slowdowns with Flare, the easiest application monitoring platform for Laravel, PHP & Javascript.

  • Platform
  • Error Tracking
  • Performance Monitoring
  • Pricing
  • Support
  • Resources
  • Blog
  • Changelog
  • Documentation
  • Affiliate program
  • Service status
  • Terms of use
  • DPA
  • Privacy & Cookie Policy
Flare