Milvus (tracing)
Milvus is an open-source vector database built for scalable similarity search. It supports billion-scale vector data, multiple index types (IVF, HNSW, DiskANN), and hybrid search combining vector similarity with scalar filtering. Respan gives you full observability over every collection operation, search, and insert.
Set up Respan
Create an account at platform.respan.ai and grab an API key .
Paste this into your coding agent:
Help me set up Respan tracing with the Milvus integration.
Follow https://www.respan.ai/docs/integrations/milvus.mdSetup
Install packages
pip install respan-ai opentelemetry-instrumentation-milvus pymilvusSet environment variables
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"RESPAN_API_KEY is used to export traces to Respan.
Initialize and run
from pymilvus import MilvusClient
from respan import Respan
from opentelemetry.instrumentation.milvus import MilvusInstrumentor
respan = Respan(instrumentations=[MilvusInstrumentor()])
client = MilvusClient(uri="http://localhost:19530")
client.create_collection(collection_name="documents", dimension=4)
data = [
{"id": 1, "vector": [0.1, 0.2, 0.3, 0.4], "text": "AI observability with Respan"},
{"id": 2, "vector": [0.5, 0.6, 0.7, 0.8], "text": "Vector similarity search"},
{"id": 3, "vector": [0.2, 0.3, 0.4, 0.5], "text": "Scalable vector indexing"},
]
client.insert(collection_name="documents", data=data)
results = client.search(
collection_name="documents",
data=[[0.1, 0.2, 0.3, 0.4]],
limit=2,
output_fields=["text"],
)
for hits in results:
for hit in hits:
print(f"{hit['entity']['text']} (distance: {hit['distance']:.4f})")
View your trace
Open the Traces page to see your Milvus operation spans.
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. MilvusInstrumentor()). |
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()
from respan import Respan
from opentelemetry.instrumentation.milvus import MilvusInstrumentor
respan = Respan(
instrumentations=[MilvusInstrumentor()],
customer_identifier="user_123",
metadata={"service": "vector-api", "version": "1.0.0"},
)With propagate_attributes
from respan import Respan, propagate_attributes
from opentelemetry.instrumentation.milvus import MilvusInstrumentor
respan = Respan(instrumentations=[MilvusInstrumentor()])
def search(user_id: str, query_vector):
with propagate_attributes(
customer_identifier=user_id,
thread_identifier="conv_abc_123",
metadata={"plan": "pro"},
):
return client.search(collection_name="documents", data=[query_vector], limit=2)| 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. |