Flare by Spatie
    • Error Tracking
    • Performance Monitoring
    • Logs Coming soon
  • Pricing
  • Docs
  • Insights
  • Changelog
  • Back to Flare ⌘↵ Shortcut: Command or Control Enter
  • Sign in
  • Try Flare for free
  • Error Tracking
  • Performance Monitoring
  • Logs Coming soon
  • Pricing
  • Docs
  • Insights
  • Changelog
    • Back to Flare ⌘↵ Shortcut: Command or Control Enter
    • Try Flare for free
    • Sign in
Flare Flare Laravel Laravel PHP PHP JavaScript JavaScript React React Vue Vue Protocol Protocol
  • General
  • Installation
  • Integrating into a framework
  • Attribute providers
  • Application lifecycle
  • Censoring collected data
  • Ignoring collected data
  • Flare daemon
  • Errors
  • Introduction
  • Customise error report
  • Customising error grouping
  • Linking to errors
  • Logs
  • Introduction
  • Levels
  • With errors
  • Performance
  • Introduction
  • Sampling
  • Limits
  • Modify spans and events
  • Data Collection
  • Application info
  • Cache events
  • Console commands
  • Custom context
  • Database transactions
  • Dumps
  • Errors when tracing
  • Exception context
  • External http requests
  • Filesystem operations
  • Git information
  • Glows
  • Identifying users
  • Jobs and queues
  • Queries
  • Redis commands
  • Requests
  • Routing
  • Server info
  • Spans
  • Stacktrace arguments
  • Views
  • Older Packages
  • Flare Client PHP V2
  • Flare Client PHP V1

Identifying users

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

To do this, extend the UserAttributesProvider base class and override the methods you care about. The user is available as $this->user inside each method:

use Spatie\FlareClient\AttributesProviders\UserAttributesProvider;

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

    public function fullName(): ?string
    {
        return "{$this->user->first_name} {$this->user->last_name}";
    }

    public function email(): ?string
    {
        return $this->user->email;
    }

    public function attributes(): array
    {
        return [
            'team_id' => $this->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.

Passing the user to recorders

Attribute providers are passed directly to the recorder methods that need them. When you end a request, pass an instance of your provider:

$flare->request()->recordEnd(
    userAttributesProvider: new CustomUserAttributesProvider($currentUser),
);

If your framework integration ends requests through one of the helpers, the helpers also accept a userAttributesProvider argument:

$flare->request()->recordEndFromSymfonyResponse(
    response: $response,
    userAttributesProvider: new CustomUserAttributesProvider($currentUser),
);

Pulling the user out of the request

If your RequestAttributesProvider already has access to the request object (and the request can produce the user), you can override the user resolution there. Implement RequestAttributesProvider and have it return the user via your custom provider; the request recorder picks it up automatically when the same provider exposes user information through its attributes.

The same provider pattern applies to all recorders that record framework objects. See Attribute providers for a complete tour of the providers Flare ships with and how to write your own.

Glows Jobs and queues
  • On this page
  • Passing the user to recorders
  • Pulling the user out of the request

Catch errors and fix slowdowns with Flare, the full-stack application monitoring platform for Laravel, PHP & JavaScript.

  • Platform
  • Error Tracking
  • Performance Monitoring
  • Pricing
  • Support
  • Resources
  • Insights
  • Newsletter
  • Changelog
  • Documentation
  • Affiliate program
  • uptime status badge Service status
  • Terms of use
  • DPA
  • Privacy & cookie Policy
Made in by
Flare