OpenTelemetry instrumentation for Qdrant vector database client library, enabling automatic tracing and observability
npx @tessl/cli install tessl/pypi-opentelemetry-instrumentation-qdrant@0.46.0OpenTelemetry instrumentation for the Qdrant vector database client library, enabling automatic tracing and observability for client-side operations against Qdrant vector databases. This library instruments both synchronous and asynchronous Qdrant client methods to capture telemetry data including database operations, query performance metrics, and error tracking.
pip install opentelemetry-instrumentation-qdrantfrom opentelemetry.instrumentation.qdrant import QdrantInstrumentorFor type annotations:
from typing import Collection, Any, Optional, Callable
from opentelemetry.instrumentation.instrumentor import BaseInstrumentorfrom opentelemetry.instrumentation.qdrant import QdrantInstrumentor
# Enable instrumentation
QdrantInstrumentor().instrument()
# Now all Qdrant client operations will be automatically traced
import qdrant_client
client = qdrant_client.QdrantClient("localhost", port=6333)
# Operations like search, upsert, etc. will now generate tracesMain class for enabling and disabling Qdrant client instrumentation.
class QdrantInstrumentor(BaseInstrumentor):
def __init__(self, exception_logger: Optional[Callable[[Exception], None]] = None):
"""
Initialize the Qdrant instrumentor.
Args:
exception_logger: Optional callable for logging exceptions that occur
during instrumentation. Function should accept an Exception
parameter.
"""
def instrument(self, **kwargs: Any) -> None:
"""
Enable instrumentation for Qdrant client operations.
Args:
**kwargs: Additional instrumentation options including:
- tracer_provider: OpenTelemetry tracer provider to use
"""
def uninstrument(self, **kwargs: Any) -> None:
"""
Disable instrumentation for Qdrant client operations.
Args:
**kwargs: Additional uninstrumentation options
"""
def instrumentation_dependencies(self) -> Collection[str]:
"""
Get the list of packages that this instrumentor depends on.
Returns:
Collection[str]: List containing "qdrant-client >= 1.7"
"""Package version constant.
from opentelemetry.instrumentation.qdrant.version import __version__
__version__: str # Current package version (e.g., "0.46.2")The package supports automatic instrumentation discovery through OpenTelemetry's plugin system:
# The instrumentor can be automatically discovered and applied
# when using opentelemetry-bootstrap or similar auto-instrumentation toolsWhen instrumentation is enabled, the following Qdrant client operations are automatically traced:
upsert - Insert or update points in a collectionadd - Add documents to a collectionupload_points - Upload points to a collectionupload_records - Upload records to a collectionupload_collection - Upload an entire collectionsearch - Vector similarity searchsearch_batch - Batch vector searchessearch_groups - Search with result groupingquery - Query collection with filtersquery_batch - Batch queriesdiscover - Discovery search operationsdiscover_batch - Batch discovery searchesrecommend - Recommendation searchesrecommend_batch - Batch recommendationsrecommend_groups - Grouped recommendationsscroll - Scroll through collection pointsdelete - Delete points from collectiondelete_vectors - Delete specific vectorsdelete_payload - Delete point payload dataset_payload - Set payload for pointsoverwrite_payload - Overwrite point payloadupdate_vectors - Update vector databatch_update_points - Batch point updatesThe instrumentation automatically captures:
SpanAttributes.VECTOR_DB_VENDORqdrant.{method}.collection_name (e.g., qdrant.search.collection_name)SpanAttributes.QDRANT_UPSERT_POINTS_COUNT for upsert operationsqdrant.{method}.points_count for upload methods (add, upload_points, upload_records, upload_collection)SpanAttributes.VECTOR_DB_QUERY_TOP_Kqdrant.{method}.requests_count (for search_batch, recommend_batch, discover_batch)The instrumentation includes robust error handling:
from opentelemetry.instrumentation.qdrant import QdrantInstrumentor
# Enable instrumentation
instrumentor = QdrantInstrumentor()
instrumentor.instrument()
# Use Qdrant client normally - all operations will be traced
import qdrant_client
client = qdrant_client.QdrantClient("localhost", port=6333)def my_exception_logger(exception):
print(f"Instrumentation error: {exception}")
instrumentor = QdrantInstrumentor(exception_logger=my_exception_logger)
instrumentor.instrument()# Disable instrumentation when needed
instrumentor.uninstrument()from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
# Set up custom tracer provider
trace.set_tracer_provider(TracerProvider())
# Use custom tracer provider with instrumentation
instrumentor.instrument(tracer_provider=trace.get_tracer_provider())This instrumentation works with:
qdrant_client.QdrantClientqdrant_client.AsyncQdrantClientThe package has minimal runtime dependencies:
qdrant-client >= 1.7 (the client library being instrumented)wrapt for method wrapping