Skip to main content

Laminar.setTraceSessionId(sessionId)

Group this trace with others in a session.Parameters:
NameTypeDescription
sessionIdstringSession identifier to attach to the trace
Returns: voidOption A: Call inside an active span context
import { Laminar, observe } from '@lmnr-ai/lmnr';

await observe({ name: 'handle_message' }, async () => {
  Laminar.setTraceSessionId('conversation-abc-123');
});
Option B: Pass via observe options
import { observe } from '@lmnr-ai/lmnr';

await observe(
  { name: 'handle_message', sessionId: 'conversation-abc-123' },
  async () => {
    // ...
  },
);
Notes:
  • Must run within an active span context to attach to the current trace.
  • Prefer setting the session ID at your request/turn entry point so child spans inherit it.

Laminar.setTraceUserId(userId)

Associate trace with a user.Parameters:
NameTypeDescription
userIdstringUser identifier to attach to the trace
Returns: voidOption A: Call inside an active span context
import { Laminar, observe } from '@lmnr-ai/lmnr';

await observe({ name: 'handle_request' }, async () => {
  Laminar.setTraceUserId('user-456');
});
Option B: Pass via observe options
import { observe } from '@lmnr-ai/lmnr';

await observe(
  { name: 'handle_request', userId: 'user-456' },
  async () => {
    // ...
  },
);
Notes:
  • Must run within an active span context to attach to the current trace.
  • Prefer pseudonymous IDs (avoid emails, names, phone numbers).

Laminar.setTraceMetadata(metadata)

Add key-value metadata to the trace.Parameters:
NameTypeDescription
metadataRecord<string, any>JSON-serializable key-value pairs
Returns: voidOption A: Call inside an active span context
import { Laminar, observe } from '@lmnr-ai/lmnr';

await observe({ name: 'handle_request' }, async () => {
  Laminar.setTraceMetadata({
    environment: 'production',
    region: 'us-west',
    feature_flag: 'new-model-v2',
  });
});
Option B: Pass via observe options
import { observe } from '@lmnr-ai/lmnr';

await observe(
  {
    name: 'handle_request',
    metadata: { environment: 'production', region: 'us-west' },
  },
  async () => {
    // ...
  },
);
Notes:
  • Must run within an active span context to attach to the current trace.
  • A later call overwrites previous trace metadata—set all keys in one call.
  • Values must be JSON-serializable (non-primitive values are JSON-stringified). Stored under lmnr.association.properties.metadata.*.
Overwrite semantics examples
import { Laminar, observe } from '@lmnr-ai/lmnr';

// ✅ Good: set all keys in one call
await observe({ name: 'myFunction' }, async () => {
  Laminar.setTraceMetadata({ environment: 'production', region: 'us-west' });
});
import { Laminar, observe } from '@lmnr-ai/lmnr';

// ❌ Avoid: second call overwrites the first
await observe({ name: 'myFunction' }, async () => {
  Laminar.setTraceMetadata({ environment: 'production' });
  Laminar.setTraceMetadata({ region: 'us-west' });
});

Laminar.getTraceId()

Get the current trace ID.Returns: string | null — UUID string or null if no active span.
import { Laminar, observe } from '@lmnr-ai/lmnr';

await observe({ name: 'operation' }, async () => {
  const traceId = Laminar.getTraceId();
  console.log('Trace:', traceId);
  return { traceId, result };
});