Skip to main content
User context tells Proliferate who experienced an error, enabling user-centric debugging and support.

Why Set User Context?

With user context, you can:
  • Find all errors for a specific user: “Show me everything that went wrong for [email protected]
  • Count affected users: “This bug affected 150 unique users”
  • Prioritize by impact: “This error hit 5 enterprise users vs. 500 free users”
  • Provide better support: Quickly find errors when a user reports a problem

Setting User Context

import Proliferate from '@proliferate/sdk';

// After user logs in
Proliferate.setUser({
  id: 'user_123',
  email: '[email protected]',  // Optional
});

// All subsequent errors include this user context

User Context Schema

interface UserContext {
  id: string;       // Required: Unique user identifier
  email?: string;   // Optional: User's email
}
id
string
required
A unique identifier for the user. Should be stable, unique, and non-sensitive. Good choices:
  • Database primary key: "user_123"
  • UUID: "550e8400-e29b-41d4-a716-446655440000"
  • External ID: "auth0|1234567890"
email
string
The user’s email address. Useful for quick identification and searching in the dashboard.

When to Set User Context

After Login

async function handleLogin(credentials) {
  const user = await authService.login(credentials);

  // Set user context immediately after successful login
  Proliferate.setUser({
    id: user.id,
    email: user.email,
  });

  redirectToDashboard();
}

On App Initialization

async function initializeApp() {
  const user = await authService.getCurrentUser();

  if (user) {
    Proliferate.setUser({
      id: user.id,
      email: user.email,
    });
  }

  // Continue with app setup...
}

In React

function AuthProvider({ children }) {
  const [user, setUser] = useState(null);

  useEffect(() => {
    authService.getCurrentUser().then(user => {
      setUser(user);
      if (user) {
        Proliferate.setUser({ id: user.id, email: user.email });
      }
    });
  }, []);

  const login = async (credentials) => {
    const user = await authService.login(credentials);
    setUser(user);
    Proliferate.setUser({ id: user.id, email: user.email });
  };

  const logout = async () => {
    await authService.logout();
    setUser(null);
    Proliferate.setUser(null);  // Clear user context
  };

  return (
    <AuthContext.Provider value={{ user, login, logout }}>
      {children}
    </AuthContext.Provider>
  );
}

In FastAPI (Python)

from fastapi import Depends, Request
import proliferate

async def get_current_user(request: Request):
    """Dependency that extracts and sets user context."""
    token = request.headers.get("Authorization")
    user = await verify_token(token)

    if user:
        proliferate.set_user({
            'id': str(user.id),
            'email': user.email,
        })

    return user

@app.get("/api/dashboard")
async def get_dashboard(user: User = Depends(get_current_user)):
    # User context is already set
    # Any errors here will include user info
    return {"data": get_dashboard_data(user)}

Clearing User Context

Clear the user context when the user logs out:
async function handleLogout() {
  await authService.logout();
  Proliferate.setUser(null);  // Clear user context
  redirectToLogin();
}

Privacy Considerations

Never include sensitive data like passwords, SSNs, or credit card numbers in user context.
// Good - include useful identifiers
Proliferate.setUser({
  id: user.id,
  email: user.email,
});

// Bad - don't include sensitive data
Proliferate.setUser({
  id: user.id,
  password: user.password,          // Never!
  ssn: user.socialSecurityNumber,   // Never!
});

Pseudonymization

If your privacy policy requires it, use hashed identifiers:
import { sha256 } from 'some-hash-library';

Proliferate.setUser({
  id: user.id,
  email: sha256(user.email),  // e.g., "a3f2e1d4..."
});

Context Inheritance

User context is automatically included in:
  • Errors: Both automatic and manual captures
  • Messages: When using captureMessage()
  • Logs: When logging is enabled
  • Replays: When session replay is enabled
Proliferate.setUser({ id: 'user_123' });

// All of these include the user context
Proliferate.captureException(error);
Proliferate.captureMessage('User action', { level: 'info' });
Proliferate.logger.info('Log entry');
// Replay data also includes user context

Combining with Account Context

For B2B applications, combine user context with account context:
Proliferate.setUser({ id: user.id, email: user.email });
Proliferate.setAccount({ id: account.id, name: account.name });

// Error shows:
// User: [email protected] (user_123)
// Account: Acme Corp (acct_456)
See Account Context for more details.