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

# LanceDB (tracing)

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

[LanceDB](https://lancedb.com/) is a serverless vector database built on the Lance columnar format. It supports embedded (in-process) and cloud deployments, with automatic versioning, fast retrieval, and native integration with ML frameworks. Respan gives you full observability over every table operation, vector search, and filter query.

#### 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/lancedb)

#### Tracing

## Setup

#### Install packages

```bash
pip install respan-ai opentelemetry-instrumentation-lancedb lancedb
```

#### 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 lancedb
from respan import Respan
from opentelemetry.instrumentation.lancedb import LanceInstrumentor

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

db = lancedb.connect("/tmp/lancedb")

data = [
    {"text": "Respan provides AI observability.", "vector": [0.1, 0.2, 0.3, 0.4]},
    {"text": "Vector databases enable semantic search.", "vector": [0.5, 0.6, 0.7, 0.8]},
    {"text": "LanceDB uses the Lance format.", "vector": [0.2, 0.3, 0.4, 0.5]},
]
table = db.create_table("documents", data, mode="overwrite")

results = table.search([0.1, 0.2, 0.3, 0.4]).limit(2).to_list()
for result in results:
    print(result["text"], result["_distance"])

```

#### View your trace

Open the [Traces page](https://platform.respan.ai/platform/traces) to see your LanceDB operation spans with table operations, vector searches, and filters.

## 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. `LanceInstrumentor()`). |
| `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 opentelemetry.instrumentation.lancedb import LanceInstrumentor

respan = Respan(
    instrumentations=[LanceInstrumentor()],
    customer_identifier="user_123",
    metadata={"service": "rag-api", "version": "1.0.0"},
)
```

### With propagate_attributes

```python
from respan import Respan, propagate_attributes
from opentelemetry.instrumentation.lancedb import LanceInstrumentor

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

def search(user_id: str, query_vector):
    with propagate_attributes(
        customer_identifier=user_id,
        thread_identifier="conv_abc_123",
        metadata={"plan": "pro"},
    ):
        return table.search(query_vector).limit(2).to_list()
```

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