> ## Documentation Index
> Fetch the complete documentation index at: https://tracevell.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# User ID

Link traces to your users to make debugging and analytics easier.

* Set a user ID at the trace level so every span in the trace carries it.
* Use it to filter traces by user in the Tracevell UI and analyze patterns across user segments.

Assign the user ID at the entry point of your application (API handler, consumer, job) so all child spans inherit it.

## Setting User ID

You can associate a user with a trace either by:

1. Passing `userId` / `user_id` to `observe` / `@observe`
2. Calling `setTraceUserId` / `set_trace_user_id` inside a span context

> [tab] TypeScript
>
> ```typescript theme={null}
> import { observe } from '@lmnr-ai/lmnr';
>
> export async function handleRequest(userId: string) {
>   return observe({ name: 'handleRequest', userId }, async () => {
>     // ... LLM calls / tools ...
>   });
> }
> ```
>
> See also: [`observe(..., { userId })`](https://tracevell.com/docs/sdk/observe#ts-observe) and [`Laminar.setTraceUserId`](https://tracevell.com/docs/sdk/trace-methods#ts-tracevell-set-trace-user-id)

> [tab] Python
>
> ```python theme={null}
> from lmnr import Tracevell, observe
>
> @observe()
> def handle_request(user_id: str):
>     Laminar.set_trace_user_id(user_id)
>     # ... LLM calls / tools ...
> ```
>
> See also: [`@observe()`](https://tracevell.com/docs/sdk/observe#py-observe) and [`Laminar.set_trace_user_id`](https://tracevell.com/docs/sdk/trace-methods#py-tracevell-set-trace-user-id)

## Privacy Considerations

* Prefer anonymous or pseudonymous IDs over PII (avoid emails, phone numbers, names).
* For sensitive operations, avoid recording inputs/outputs with `observe({ ignoreInput: true, ignoreOutput: true })` / `@observe(ignore_input=True, ignore_output=True)`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.