> ## 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.

# Tracing Structure

You've initialized Tracevell. Your LLM calls are traced automatically. Now what?

This section covers what to do when auto-instrumentation isn't enough:

* **Trace your own functions** — Your agent has logic beyond LLM calls. Wrap functions with `@observe` to see them in traces.
* **Add context** — Attach user IDs, session IDs, metadata, and tags so you can filter and debug effectively.
* **Control what's captured** — Skip recording inputs/outputs for sensitive operations.

If you just want to trace LLM calls and framework operations, you don't need this section—[Integrations](https://tracevell.com/docs/integrations.md) has you covered. Come back here when you want deeper visibility into your own code.

## Why Structure Matters

Without structure, each LLM call becomes an isolated trace, making it hard to:

* Understand relationships between calls (routing → tool use → final answer)
* Follow multi-step workflows end-to-end
* Track conversations across turns
* Find the right trace quickly (by user/session/metadata)

Well-structured traces show a clear tree of spans for each request, plus stable identifiers that help you search and group related work.

## Quickstart

Start by creating a **parent span** for your request/turn, then set **user ID**, **session ID**, and **metadata** inside that span so everything downstream inherits it.

> [tab] TypeScript
>
> ```typescript theme={null}
> import { Tracevell, observe } from '@lmnr-ai/lmnr';
>
> Laminar.initialize({
>   projectApiKey: process.env.LMNR_PROJECT_API_KEY,
> });
>
> export async function handleRequest(userId: string, requestId: string) {
>   return observe({ name: 'handleRequest' }, async () => {
>     Laminar.setTraceUserId(userId);
>     Laminar.setTraceSessionId(`session-${requestId}`);
>     Laminar.setTraceMetadata({ environment: process.env.NODE_ENV });
>
>     // ... your LLM calls / tools / business logic ...
>   });
> }
> ```

> [tab] Python
>
> ```python theme={null}
> from lmnr import Tracevell, observe
> import os
>
> Laminar.initialize()
>
> @observe()
> def handle_request(user_id: str, request_id: str):
>     Laminar.set_trace_user_id(user_id)
>     Laminar.set_trace_session_id(f"session-{request_id}")
>     Laminar.set_trace_metadata({"environment": os.getenv("ENVIRONMENT")})
>
>     # ... your LLM calls / tools / business logic ...
> ```

## Quick Reference

| I want to... | Use |
| - | - |
| Trace a function I wrote | [Trace Functions](https://tracevell.com/docs/tracing/structure/observe-decorator.md) |
| Trace code that isn't a function | [Trace Parts of Your Code](https://tracevell.com/docs/tracing/structure/manual-span-creation.md) |
| Make a function show up as a tool call in transcript view | [Span Types](https://tracevell.com/docs/tracing/structure/span-types.md) |
| Group traces by conversation/workflow | [Sessions](https://tracevell.com/docs/tracing/structure/sessions.md) |
| Associate traces with users | [User ID](https://tracevell.com/docs/tracing/structure/user-id.md) |
| Add key-value context to traces | [Metadata](https://tracevell.com/docs/tracing/structure/metadata.md) |
| Add categorical labels to spans | [Tags](https://tracevell.com/docs/tracing/structure/tags.md) |
| Trace images sent to LLMs | [Tracing Images](https://tracevell.com/docs/tracing/structure/images.md) |
| Continue traces across services | [Continuing Traces](https://tracevell.com/docs/tracing/structure/continuing-traces.md) |
| Track costs for custom LLM spans | [LLM cost tracking](https://tracevell.com/docs/tracing/cost-tracking.md) |
| Ensure spans send in serverless/CLI | [Flushing & Shutting Down](https://tracevell.com/docs/tracing/structure/flushing-and-shutdown.md) |


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