> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://respan.ai/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://respan.ai/docs/_mcp/server.

# Chroma (tracing)

> Trace Chroma vector operations with Respan — auto-instrumented spans and full observability.

[Chroma](https://www.trychroma.com/) is an open-source vector database for building semantic search and Retrieval-Augmented Generation systems.

#### Set up Respan

Create an account at [platform.respan.ai](https://platform.respan.ai) and grab an [API key](https://platform.respan.ai/platform/gateway/api-keys).

Run `npx @respan/cli setup` to set up with your coding agent.

#### Example projects

* [Python examples](https://github.com/respanai/respan-example-projects/tree/main/python/tracing/chroma)

#### Tracing

## Setup

#### Install packages

```bash
pip install respan-ai respan-instrumentation-chroma chromadb
```

#### Set environment variables

```bash
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
```

`RESPAN_API_KEY` is used to export traces to Respan.

#### Initialize and run

```python
import os

import chromadb
from respan import Respan, workflow
from respan_instrumentation_chroma import ChromaInstrumentor

respan = Respan(
    api_key=os.environ["RESPAN_API_KEY"],
    instrumentations=[ChromaInstrumentor()],
)


@workflow(name="chroma_query_and_filters_workflow")
def run_chroma_query() -> dict:
    client = chromadb.Client()
    collection = client.get_or_create_collection("respan_docs")

    collection.upsert(
        ids=["doc-1"],
        embeddings=[[0.1, 0.2, 0.3]],
        documents=["Respan traces Chroma operations."],
        metadatas=[{"topic": "observability"}],
    )

    return collection.query(
        query_embeddings=[[0.1, 0.2, 0.3]],
        n_results=1,
        include=["documents", "metadatas", "distances"],
    )


print(run_chroma_query())
respan.shutdown()
```

#### View your trace

Open the [Traces page](https://platform.respan.ai/platform/traces) and search for workflow name `chroma_query_and_filters_workflow`.

## Configuration

| Parameter             | Type           | Default | Description                                                        |
| --------------------- | -------------- | ------- | ------------------------------------------------------------------ |
| `api_key`             | `str \| None`  | `None`  | Falls back to `RESPAN_API_KEY` env var.                            |
| `base_url`            | `str \| None`  | `None`  | Falls back to `RESPAN_BASE_URL` env var.                           |
| `instrumentations`    | `list`         | `[]`    | Plugin instrumentations to activate (e.g. `ChromaInstrumentor()`). |
| `customer_identifier` | `str \| None`  | `None`  | Default customer identifier for all spans.                         |
| `metadata`            | `dict \| None` | `None`  | Default metadata attached to all spans.                            |
| `environment`         | `str \| None`  | `None`  | Environment tag (e.g. `"production"`).                             |

## Attributes

### In Respan()

```python
from respan import Respan
from respan_instrumentation_chroma import ChromaInstrumentor

respan = Respan(
    instrumentations=[ChromaInstrumentor()],
    customer_identifier="user_123",
    metadata={"service": "chroma-vector-db", "version": "1.0.0"},
)
```

### With propagate_attributes

```python
import chromadb

from respan import Respan, propagate_attributes
from respan_instrumentation_chroma import ChromaInstrumentor

respan = Respan(instrumentations=[ChromaInstrumentor()])


def run_query_with_attributes(user_id: str):
    with propagate_attributes(
        customer_identifier=user_id,
        thread_identifier="chroma_thread",
        metadata={"index": "respan_docs"},
    ):
        collection = chromadb.Client().get_or_create_collection("respan_docs")
        return collection.query(query_embeddings=[[0.1, 0.2, 0.3]], n_results=3)
```

| Attribute             | Type   | Description                                           |
| --------------------- | ------ | ----------------------------------------------------- |
| `customer_identifier` | `str`  | Identifies the end user in Respan analytics.          |
| `thread_identifier`   | `str`  | Groups related messages into a conversation.          |
| `metadata`            | `dict` | Custom key-value pairs. Merged with default metadata. |