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

# Marqo (tracing)

> Trace Marqo tensor search operations with Respan — auto-instrumented spans and full observability.

[Marqo](https://www.marqo.ai/) is an end-to-end tensor search engine that combines vector search with traditional keyword search. It handles embedding generation, storage, and retrieval in a single platform, supporting text, images, and multimodal search. Respan gives you full observability over every index operation, search query, and embedding step.

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

#### Tracing

## Setup

#### Install packages

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

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

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

client = marqo.Client(url="http://localhost:8882")

client.create_index("documents", model="hf/e5-base-v2")

client.index("documents").add_documents(
    [
        {"title": "AI Observability", "description": "Respan provides tracing for AI applications."},
        {"title": "Tensor Search", "description": "Marqo combines vector and keyword search."},
        {"title": "Embeddings", "description": "Embeddings capture semantic meaning as vectors."},
    ],
    tensor_fields=["title", "description"],
)

results = client.index("documents").search("How does AI tracing work?")
for hit in results["hits"]:
    print(f"{hit['title']} (score: {hit['_score']:.4f})")

```

#### View your trace

Open the [Traces page](https://platform.respan.ai/platform/traces) to see your Marqo operation spans with index operations, queries, and embeddings.

## 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. `MarqoInstrumentor()`). |
| `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.marqo import MarqoInstrumentor

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

### With propagate_attributes

```python
from respan import Respan, propagate_attributes
from opentelemetry.instrumentation.marqo import MarqoInstrumentor

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

def search(user_id: str, query: str):
    with propagate_attributes(
        customer_identifier=user_id,
        thread_identifier="conv_abc_123",
        metadata={"plan": "pro"},
    ):
        return client.index("documents").search(query)
```

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