Flare by Spatie
    • Error Tracking
    • Performance Monitoring
    • Logs
  • Pricing
  • Docs
  • Blog
  • Changelog
  • Back to Flare ⌘↵ Shortcut: Command or Control Enter
  • Sign in
  • Try Flare for free
  • Error Tracking
  • Performance Monitoring
  • Logs
  • Pricing
  • Docs
  • Blog
  • Changelog
    • Back to Flare ⌘↵ Shortcut: Command or Control Enter
    • Try Flare for free
    • Sign in
Flare Flare PHP PHP JavaScript JavaScript Protocol Protocol
JavaScript
  • JavaScript
  • React
  • Vue
  • Svelte
  • Inertia
  • React Native
  • Electron
  • Getting Started
  • Introduction
  • Quick start
  • CDN installation
  • Errors
  • Reporting errors
  • Client hooks
  • Sourcemaps
  • Tracing
  • How tracing works
  • What gets traced
  • Web vitals
  • Manual spans
  • Sampling
  • Profiling
  • How component profiling works
  • Logs
  • Introduction
  • Levels
  • Attributes
  • Data Collection
  • Adding custom context
  • Adding glows
  • Automatic breadcrumbs
  • GDPR consent
  • Identifying users
  • Reference
  • API
  • Configuration

Identifying users

View as Markdown

When a user is logged in to your application, you can attach information about that user to the data you send, so you can see who was affected in Flare. The user is attached to error reports, to your logs, and to traces.

Call flare.setUser() once you know who the user is (after login, on app boot, in a route guard, etc.):

import { flare } from '@flareapp/js';

flare.setUser({
    id: 123,
    email: '[email protected]',
    fullName: 'Jane Doe',
});

The following fields are recognised:

Field Attribute sent Description
id user.id The user's unique identifier. Used to group occurrences.
email user.email Shown as the user's label, with a Gravatar.
fullName user.full_name Shown as the user's label when no email is present.

All fields are optional. Provide whichever you have; id is what links occurrences to a single user.

Sending extra attributes

Any additional keys you pass are collected under user.attributes and shown alongside the user in Flare:

flare.setUser({
    id: 123,
    email: '[email protected]',
    fullName: 'Jane Doe',
    plan: 'pro',
    teamId: 42,
});

Here plan and teamId are sent as user.attributes.

Where the user ends up

Error reports. Every report sent after setUser() carries the user.

The context pane of an error in Flare, showing the user with their name, email, and attributes

Logs. Every log record sent after setUser() carries the user as well.

Traces. The user is attached to the span at the top of a trace, for example a page load or a navigation span. Child spans inside that trace don't repeat it.

The client reads the user when that top span starts, not when the trace is sent. A page load that started before you called setUser() is sent without a user, even if you set one while the page was still loading. The next navigation does carry it. If you want the user on the page load itself, call setUser() as early as you can, for example straight after flare.light() when you already know who the user is.

Clearing the user

When the user logs out, clear the attached user by passing null:

flare.setUser(null);

Per-request scope (Node)

In @flareapp/node, setUser() attaches the user to the current request scope, so concurrent requests do not share or leak each other's user. Call it inside your request handler (typically within runWithContext(...)). See the @flareapp/node README for details on request-scoped context:

import { flare } from '@flareapp/node';

flare.setUser({ id: user.id, email: user.email, fullName: user.name });
GDPR consent API

On this page

  • Sending extra attributes
  • Where the user ends up
  • Clearing the user
  • Per-request scope (Node)

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
  • Blog
  • Newsletter
  • Changelog
  • Documentation
  • Affiliate program
  • uptime status badge Service status
  • Terms of use
  • DPA
  • Privacy & cookie Policy
Made in by Spatie logo
Flare