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

# Metadata

Trace metadata applies to the entire trace. Use it for information that's constant across spans:

* **Environment** — production, staging, development
* **Region** — us-west, eu-central
* **Deployment** — version numbers, feature flags, A/B test variants
* **Request context** — correlation IDs, upstream service info

Set metadata early—ideally where the trace begins—so all spans share the same context.

## Adding Metadata

Set metadata inside an active span context (for example, inside `observe()` or an `@observe`d function). If you call it outside any span context, it won’t attach to anything.

<Tabs items={['TypeScript', 'Python']}>
  <Tab title="TypeScript">
    ```typescript theme={null}
    import { Laminar, observe } from '@lmnr-ai/lmnr';

    await observe({ name: 'processRequest' }, async () => {
      Laminar.setTraceMetadata({
        environment: 'production',
        featureFlag: 'new-algorithm-v2',
        region: 'us-west',
      });
    });
    ```

    See also: [`Laminar.setTraceMetadata`](/sdk/trace-methods#ts-laminar-set-trace-metadata) and [`observe(..., { metadata })`](/sdk/observe#ts-observe)
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    from lmnr import Laminar, observe

    @observe()
    def process_request():
        Laminar.set_trace_metadata({
            "environment": "production",
            "feature_flag": "new-algorithm-v2",
            "region": "us-west",
        })
    ```

    See also: [`Laminar.set_trace_metadata`](/sdk/trace-methods#py-laminar-set-trace-metadata) and [`@observe(metadata=...)`](/sdk/observe#py-observe)
  </Tab>
</Tabs>

## Notes

* Setting trace metadata again overwrites the previous metadata—set all keys in one call.
* Keep metadata JSON-serializable and avoid sensitive data.

## Filtering by Metadata

In the Laminar UI, metadata filters currently match **exact key-value pairs** (for example, `region=us-west`).

## Metadata vs Tags

|          | Metadata                             | Tags                          |
| -------- | ------------------------------------ | ----------------------------- |
| Scope    | Entire trace                         | Individual spans              |
| Format   | Key-value pairs                      | String labels                 |
| Best for | Environment, cohort, request context | Categorization, review labels |

## Best Practices

* Use consistent keys (`environment`, `region`, `feature_flag`).
* Keep it lightweight and JSON-serializable.
* Avoid sensitive data (no sensitive keywords or personal information).
