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

# Metadata

> Attach arbitrary key-value pairs to traces and spans

**Metadata** is key-value pairs attached to traces or spans — useful for model versions, request IDs, feature flags, or any structured context you want to search on.

## Using `observe`

Pass static metadata to `observe` for values known at definition time:

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from traceroot import observe

    @observe(name="process", type="agent", metadata={"version": "v2", "tier": "premium"})
    def process(query: str):
        return result
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    import { observe } from '@traceroot-ai/traceroot';

    const result = await observe(
      { name: 'process', type: 'agent', metadata: { version: 'v2', tier: 'premium' } },
      async () => doWork(query),
    );
    ```
  </Tab>
</Tabs>

## Using `using_attributes` / `usingAttributes`

Propagate metadata to all traces and spans within a block:

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from traceroot import using_attributes

    with using_attributes(metadata={"deploy": "canary", "region": "us-west-2"}):
        agent.run(query)
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    import { usingAttributes } from '@traceroot-ai/traceroot';

    await usingAttributes({ metadata: { deploy: 'canary', region: 'us-west-2' } }, async () => {
      await agent.run(query);
    });
    ```
  </Tab>
</Tabs>
