Associating Traces with Users

Tracking which user triggered a particular trace is crucial for:

  • User-specific debugging
  • Analyzing usage patterns
  • Filtering traces in the dashboard
  • Compliance with data regulations

In Laminar, you can associate traces with users by setting user ID on a trace.

Setting User ID

This allows you to filter and search for traces by user ID later.

import { Laminar, observe } from '@lmnr-ai/lmnr';

// Option 1. directly pass userId to observe
await observe({
    name: 'processUserRequest',
    userId: 'user_123'
}, async () => {
    // Process user request here
});

// Option 2.Use Laminar.setTraceUserId
await observe({
    name: 'processUserRequest',
}, async () => {
    Laminar.setTraceUserId('user_123');
    // Process user request here
});

Privacy Considerations

When including user IDs in traces, consider the following privacy practices:

  • Use anonymous or pseudonymous IDs rather than personally identifiable information
  • Consider your data retention policies
  • Use Laminar’s tracing level settings to control sensitive data
  • Follow relevant data protection regulations
// Use TracingLevel.META_ONLY for sensitive user operations
import { withTracingLevel, TracingLevel } from "@lmnr-ai/lmnr";

withTracingLevel(TracingLevel.META_ONLY, () => {
    // Sensitive operations here will only record metadata
    // Input/output content won't be saved
});