Skip to content

Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.

[Feat]: Refactor ChromaDB OpenTelemetry Monitoring Instrumentation (#802)

Patcher7b8aa0454592
diff --git a/contributors/adding-new-vectordb-instrumentation.md b/contributors/adding-new-vectordb-instrumentation.md
index 847537e6..53782427 100644
--- a/contributors/adding-new-vectordb-instrumentation.md
+++ b/contributors/adding-new-vectordb-instrumentation.md
@@ -1,6 +1,6 @@
# Vector Database Instrumentation Guide
-This guide provides step-by-step instructions for adding a new vector database instrumentation to OpenLIT, following the established patterns and conventions.
+This guide provides step-by-step instructions for adding a new vector database instrumentation to OpenLIT, following the established patterns and conventions learned from Pinecone and ChromaDB implementations.
## Table of Contents
1. [File Structure](#file-structure)
@@ -13,13 +13,13 @@ This guide provides step-by-step instructions for adding a new vector database i
## File Structure
-Every vector database instrumentation follows a consistent **4-file structure**:
+Every vector database instrumentation follows a consistent **3-4 file structure**:
```
sdk/python/src/openlit/instrumentation/{database_name}/
├── __init__.py # Instrumentor class with dependency requirements
├── {database_name}.py # Sync wrapper functions
-├── async_{database_name}.py # Async wrapper functions
+├── async_{database_name}.py # Async wrapper functions (only if database supports async)
└── utils.py # Telemetry processing logic
```
@@ -28,10 +28,12 @@ sdk/python/src/openlit/instrumentation/{database_name}/
sdk/python/src/openlit/instrumentation/pinecone/
├── __init__.py
├── pinecone.py
-├── async_pinecone.py
+├── async_pinecone.py # Only if async operations exist
└── utils.py
```
+**Note**: If the database doesn't support async operations (like ChromaDB), omit the `async_{database_name}.py` file.
+
## Code Structure
### 1. DB_OPERATION_MAP Pattern
@@ -41,22 +43,24 @@ All vector database instrumentations use a centralized operation mapping in `uti
```python
# Operation mapping for simple span naming
DB_OPERATION_MAP = {
- "{database}.create_index": SemanticConvention.DB_OPERATION_CREATE_INDEX,
- "{database}.upsert": SemanticConvention.DB_OPERATION_UPSERT,
- "{database}.query": SemanticConvention.DB_OPERATION_QUERY,
- "{database}.search": SemanticConvention.DB_OPERATION_SEARCH,
- "{database}.fetch": SemanticConvention.DB_OPERATION_FETCH,
+ "{database}.create_collection": SemanticConvention.DB_OPERATION_CREATE_COLLECTION,
+ "{database}.add": SemanticConvention.DB_OPERATION_INSERT,
+ "{database}.get": SemanticConvention.DB_OPERATION_GET,
+ "{database}.query": SemanticConvention.DB_OPERATION_GET, # Both get() and query() are GET operations
"{database}.update": SemanticConvention.DB_OPERATION_UPDATE,
+ "{database}.upsert": SemanticConvention.DB_OPERATION_UPSERT,
"{database}.delete": SemanticConvention.DB_OPERATION_DELETE,
}
```
+**Key Learning**: Multiple endpoints can map to the same semantic operation. Use the `endpoint` parameter to differentiate implementation details.
+
### 2. General Wrap Pattern
Use the **general_wrap** pattern for efficiency:
```python
-def general_wrap(endpoint, version, environment, application_name, tracer,
+def general_wrap(gen_ai_endpoint, version, environment, application_name, tracer,
pricing_info, capture_message_content, metrics, disable_metrics):
"""
Create a wrapper for {database} operations using the general wrap pattern.
@@ -67,26 +71,32 @@ def general_wrap(endpoint, version, environment, application_name, tracer,
return wrapped(*args, **kwargs)
# Extract operation from endpoint
- db_operation = DB_OPERATION_MAP.get(endpoint, "unknown")
+ db_operation = DB_OPERATION_MAP.get(gen_ai_endpoint, "unknown")
# Server address calculation
server_address, server_port = set_server_address_and_port(
instance, "default-host", default_port
)
+ # Span naming: use operation + collection/namespace
+ if db_operation == "create_collection":
+ namespace = kwargs.get("name") or (args[0] if args else "unknown")
+ else:
+ namespace = getattr(instance, "name", "unknown") # For collection-based databases
+ span_name = f"{db_operation} {namespace}"
+
# CRITICAL: Use tracer.start_as_current_span() for proper context
- with tracer.start_as_current_span(f"{db_operation} {target}") as span:
- start_time = time.time()
-
+ with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
try:
+ start_time = time.time()
response = wrapped(*args, **kwargs)
- # Process response
- process_vectordb_response(
+ # Process response with endpoint information
+ response = process_vectordb_response(
response, db_operation, server_address, server_port,
environment, application_name, metrics, start_time, span,
capture_message_content, disable_metrics, version,
- instance, args, **kwargs
+ instance, args, endpoint=gen_ai_endpoint, **kwargs
)
return response
@@ -97,47 +107,154 @@ def general_wrap(endpoint, version, environment, application_name, tracer,
return wrapper
```
-### 3. Helper Functions
+### 3. Simplified Telemetry Pattern
-Include standard helper functions in `utils.py`:
+Based on ChromaDB learnings, use a simplified, consistent pattern:
```python
-def object_count(obj):
- """
- Counts length of object if it exists, else returns 0.
- """
- return len(obj) if obj else 0
-
def common_vectordb_logic(scope, environment, application_name,
- metrics, capture_message_content, disable_metrics, version, instance=None):
+ metrics, capture_message_content, disable_metrics, version,
+ instance=None, endpoint=None):
"""
Process vector database request and generate telemetry.
"""
- # Implementation details...
+ scope._end_time = time.time()
+
+ # Set common database span attributes using helper
+ common_db_span_attributes(scope, SemanticConvention.DB_SYSTEM_{DATABASE_NAME},
+ scope._server_address, scope._server_port, environment, application_name, version)
+
+ # Set DB operation specific attributes
+ scope._span.set_attribute(SemanticConvention.DB_OPERATION_NAME, scope._db_operation)
+ scope._span.set_attribute(SemanticConvention.DB_CLIENT_OPERATION_DURATION,
+ scope._end_time - scope._start_time)
+
+ # Handle operations with endpoint differentiation
+ if scope._db_operation == SemanticConvention.DB_OPERATION_GET:
+ collection_name = getattr(instance, "name", "unknown")
+
+ # Differentiate between different GET operations
+ if endpoint == "{database}.get":
+ query = scope._kwargs.get("ids", [])
+
+ # Standard database attributes
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
+ scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, collection_name)
+ scope._span.set_attribute(SemanticConvention.DB_VECTOR_COUNT, object_count(query))
+
+ # Database-specific attributes
+ scope._span.set_attribute(SemanticConvention.DB_FILTER,
+ str(scope._kwargs.get("where", "")))
+
+ # Response metrics
+ if scope._response and scope._response.get('ids'):
+ returned_rows = object_count(scope._response['ids']) # Adjust for response structure
+ scope._span.set_attribute(SemanticConvention.DB_RESPONSE_RETURNED_ROWS, returned_rows)
+
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
+ f"{scope._db_operation} {collection_name} "
+ f"ids={query} "
+ f"limit={scope._kwargs.get('limit', 'None')}")
+
+ elif endpoint == "{database}.query":
+ # Handle query-specific parameters
+ query_texts = scope._kwargs.get("query_texts", [])
+ query_embeddings = scope._kwargs.get("query_embeddings", [])
+
+ # Create query content representation
+ if query_texts:
+ query_content = f"texts={query_texts}"
+ elif query_embeddings:
+ query_content = f"embeddings={len(query_embeddings)} vectors"
+ else:
+ query_content = "no query provided"
+
+ # Standard database attributes
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, query_content)
+ scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, collection_name)
+ scope._span.set_attribute(SemanticConvention.DB_VECTOR_QUERY_TOP_K,
+ scope._kwargs.get("n_results", 10))
+
+ # Response metrics (adjust for nested response structure)
+ if scope._response and scope._response.get('ids'):
+ returned_rows = object_count(scope._response['ids'][0]) if scope._response['ids'] else 0
+ scope._span.set_attribute(SemanticConvention.DB_RESPONSE_RETURNED_ROWS, returned_rows)
+
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
+ f"{scope._db_operation} {collection_name} "
+ f"n_results={scope._kwargs.get('n_results', 10)} "
+ f"{query_content}")
+
+ elif scope._db_operation == SemanticConvention.DB_OPERATION_INSERT:
+ collection_name = getattr(instance, "name", "unknown")
+ query = scope._kwargs.get("ids", [])
+
+ # Standard database attributes
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
+ scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, collection_name)
+ scope._span.set_attribute(SemanticConvention.DB_VECTOR_COUNT, object_count(query))
+
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
+ f"{scope._db_operation} {collection_name} "
+ f"ids={query} "
+ f"documents={scope._kwargs.get('documents', 'None')}")
+
+ # ... similar patterns for other operations
+
+ scope._span.set_status(Status(StatusCode.OK))
+
+ # Record metrics using helper
+ if not disable_metrics:
+ record_db_metrics(metrics, SemanticConvention.DB_SYSTEM_{DATABASE_NAME},
+ scope._server_address, scope._server_port, environment, application_name,
+ scope._start_time, scope._end_time)
+```
+
+### 4. Key Telemetry Patterns
+
+**Essential Attributes for All Operations:**
+- `DB_QUERY_TEXT`: String representation of the query/operation
+- `DB_COLLECTION_NAME`: Collection name (for collection-based databases)
+- `DB_VECTOR_COUNT`: Count of primary query parameter
+- `DB_QUERY_SUMMARY`: Comprehensive operation summary
+
+**Query Summary Format:**
+```python
+f"{scope._db_operation} {collection_name} key_param={value} optional_param={value or 'None'}"
+```
+
+**Response Structure Handling:**
+```python
+# For flat arrays (like ChromaDB GET)
+returned_rows = object_count(scope._response['ids'])
+
+# For nested arrays (like ChromaDB QUERY)
+returned_rows = object_count(scope._response['ids'][0]) if scope._response['ids'] else 0
```
## Naming Conventions
### 1. File Names
- Use lowercase with underscores: `{database_name}.py`
-- Async files: `async_{database_name}.py`
+- Async files: `async_{database_name}.py` (only if needed)
- No hyphens, use underscores
### 2. Function Names
- Use `snake_case` consistently
- Standard function names:
- `general_wrap`
- - `async_general_wrap`
+ - `async_general_wrap` (if needed)
- `common_vectordb_logic`
- `process_vectordb_response`
### 3. Variable Names
- Use `snake_case` for all variables
+- **Simplified naming**: Use `query` for primary operation parameter
- Standard variable names:
- `server_address`, `server_port`
- `start_time`, `end_time`
- `db_operation`
- - `namespace`
+ - `collection_name` (for collection-based databases)
### 4. Class Names
- Use `PascalCase` for classes
@@ -161,7 +278,6 @@ def common_vectordb_logic(scope, environment, application_name,
Function description.
"""
```
-- Single line comments use `#`
### 4. Import Order
Follow this specific order:
@@ -170,7 +286,7 @@ Follow this specific order:
import time
# OpenTelemetry imports
-from opentelemetry.trace import Status, StatusCode
+from opentelemetry.trace import Status, StatusCode, SpanKind
from opentelemetry import context as context_api
# OpenLIT imports
@@ -178,6 +294,7 @@ from openlit.__helpers import (
common_db_span_attributes,
record_db_metrics,
handle_exception,
+ set_server_address_and_port,
)
from openlit.semcov import SemanticConvention
```
@@ -185,7 +302,7 @@ from openlit.semcov import SemanticConvention
### 5. Function Parameters
Standard parameter order:
```python
-def function_name(version, environment, application_name, tracer,
+def function_name(gen_ai_endpoint, version, environment, application_name, tracer,
pricing_info, capture_message_content, metrics, disable_metrics):
```
@@ -203,36 +320,35 @@ OpenLIT {DatabaseName} Instrumentation
"""
from typing import Collection
+import importlib.metadata
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
-from opentelemetry.instrumentation.utils import unwrap
from wrapt import wrap_function_wrapper
from openlit.instrumentation.{database_name}.{database_name} import general_wrap
-from openlit.instrumentation.{database_name}.async_{database_name} import async_general_wrap
+# Only import async if the database supports it
+# from openlit.instrumentation.{database_name}.async_{database_name} import async_general_wrap
+
+_instruments = ("{database-package} >= {version}",)
class {DatabaseName}Instrumentor(BaseInstrumentor):
"""
- OpenLIT Instrumentor for {DatabaseName}
+ An instrumentor for {DatabaseName}'s client library.
"""
def instrumentation_dependencies(self) -> Collection[str]:
- return ["{database-package-name}"]
+ return _instruments
def _instrument(self, **kwargs):
- """
- Instrument {DatabaseName} operations
- """
- # Extract parameters
- version = kwargs.get("version", "1.0.0")
+ version = importlib.metadata.version("{database-package}")
environment = kwargs.get("environment", "default")
application_name = kwargs.get("application_name", "default")
tracer = kwargs.get("tracer")
- pricing_info = kwargs.get("pricing_info")
+ pricing_info = kwargs.get("pricing_info", {})
capture_message_content = kwargs.get("capture_message_content", False)
- metrics = kwargs.get("metrics")
- disable_metrics = kwargs.get("disable_metrics", False)
+ metrics = kwargs.get("metrics_dict")
+ disable_metrics = kwargs.get("disable_metrics")
- # Wrap functions
+ # Wrap sync operations
wrap_function_wrapper(
"{database_module}",
"{Class}.{method}",
@@ -243,67 +359,45 @@ class {DatabaseName}Instrumentor(BaseInstrumentor):
),
)
+ # Only wrap async operations if database supports them
+ # wrap_function_wrapper(
+ # "{database_module}",
+ # "{AsyncClass}.{method}",
+ # async_general_wrap(
+ # "{database}.{operation}",
+ # version, environment, application_name, tracer,
+ # pricing_info, capture_message_content, metrics, disable_metrics
+ # ),
+ # )
+
def _uninstrument(self, **kwargs):
- """
- Uninstrument {DatabaseName} operations
- """
- unwrap({database_module}.{Class}, "{method}")
+ pass
```
### Step 3: Create Wrapper Files
-Create both sync and async wrapper files following the general_wrap pattern.
+Create sync (and async if needed) wrapper files following the general_wrap pattern.
### Step 4: Create utils.py
Include:
-- `DB_OPERATION_MAP`
+- `DB_OPERATION_MAP` with proper semantic operation mapping
- `object_count` helper
-- `common_vectordb_logic`
+- `common_vectordb_logic` with endpoint differentiation
- `process_vectordb_response`
-### Step 5: Operation-Specific Attributes
-Handle different operations in `common_vectordb_logic`:
-
-```python
-if scope._db_operation == SemanticConvention.DB_OPERATION_CREATE_INDEX:
- # Standard database attributes
- scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, scope._kwargs.get("name", ""))
-
- # Vector database specific attributes
- scope._span.set_attribute(SemanticConvention.DB_COLLECTION_DIMENSION, scope._kwargs.get("dimension", -1))
- scope._span.set_attribute(SemanticConvention.DB_SEARCH_SIMILARITY_METRIC, scope._kwargs.get("metric", "cosine"))
+### Step 5: Database-Specific Adaptations
-elif scope._db_operation == SemanticConvention.DB_OPERATION_QUERY:
- namespace = scope._kwargs.get("namespace", "default") or (scope._args[0] if scope._args else "unknown")
- query = scope._kwargs.get("vector", [])
-
- # Standard database attributes
- scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
- scope._span.set_attribute(SemanticConvention.DB_NAMESPACE, namespace)
-
- # Vector database specific attributes
- scope._span.set_attribute(SemanticConvention.DB_VECTOR_QUERY_TOP_K, scope._kwargs.get("top_k", -1))
- scope._span.set_attribute(SemanticConvention.DB_FILTER, str(scope._kwargs.get("filter", "")))
- scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
- f"{scope._db_operation} {namespace} "
- f"top_k={scope._kwargs.get('top_k', -1)} "
- f"filtered={scope._kwargs.get('filter', '')} "
- f"vector={scope._kwargs.get('vector', '')}")
-```
+**Server Address Patterns:**
+- Pinecone: `"pinecone.io", 443`
+- ChromaDB: `"localhost", 8000`
+- Adjust for your database's default
-### Step 6: Usage and Metrics Extraction
-Handle response processing and usage metrics:
+**Collection vs Namespace:**
+- Collection-based (ChromaDB): Use `DB_COLLECTION_NAME`
+- Namespace-based (Pinecone): Use `DB_NAMESPACE`
-```python
-# Extract usage information if available
-if scope._response.get("usage"):
- usage = scope._response["usage"]
- embed_tokens = usage.get("embed_total_tokens", 0)
- read_units = usage.get("read_units", 0)
- if embed_tokens:
- scope._span.set_attribute(SemanticConvention.DB_CLIENT_TOKEN_USAGE, embed_tokens)
- if read_units:
- scope._span.set_attribute("db.read_units", read_units)
-```
+**Response Structure:**
+- Flat arrays: `object_count(response['ids'])`
+- Nested arrays: `object_count(response['ids'][0])`
## Testing
@@ -312,7 +406,7 @@ Create `sdk/python/tests/test_{database_name}.py`:
```python
"""
-Tests for {DatabaseName} functionality using the {DatabaseName} Python library.
+Tests for {DatabaseName} functionality.
"""
import pytest
@@ -325,30 +419,29 @@ client = {ClientClass}()
# Initialize OpenLIT
openlit.init(environment="openlit-python-testing", application_name="openlit-python-{database}-test")
-def test_sync_{database}_query():
+def test_sync_{database}_operation():
"""
- Tests synchronous query operation.
+ Tests synchronous operation.
"""
try:
- response = client.query(
+ response = client.operation(
# parameters
)
assert response # Add appropriate assertions
except Exception as e:
- if "rate limit" in str(e).lower() or "429" in str(e):
+ if "rate limit" in str(e).lower():
print("Rate limit exceeded:", e)
- elif "credit" in str(e).lower():
- print("Insufficient balance:", e)
else:
raise
-async def test_async_{database}_query():
- """
- Tests asynchronous query operation.
- """
- # Similar structure for async tests
+# Add async tests only if database supports async
+# @pytest.mark.asyncio
+# async def test_async_{database}_operation():
+# """
+# Tests asynchronous operation.
+# """
+# pass
```
## Integration
@@ -359,7 +452,6 @@ Add to `sdk/python/src/openlit/instrumentation/__init__.py`:
```python
from openlit.instrumentation.{database_name} import {DatabaseName}Instrumentor
-# Add to instrumentors list
def auto_instrument(**kwargs):
"""
Auto-instrument supported libraries
@@ -374,33 +466,24 @@ def auto_instrument(**kwargs):
```
### Step 2: Add Semantic Conventions
-Add any new semantic conventions to `sdk/python/src/openlit/semcov/__init__.py`:
-
-```python
-# Vector Database Semantic Conventions
-DB_VECTOR_QUERY_TOP_K = "db.vector.query.top_k"
-DB_SEARCH_SIMILARITY_METRIC = "db.search.similarity_metric"
-DB_COLLECTION_DIMENSION = "db.collection.dimension"
-# ... other conventions
-```
-
-### Step 3: Update Dependencies
-Add the database package to test requirements if needed.
+Add any new semantic conventions to `sdk/python/src/openlit/semcov/__init__.py`.
## Key Reminders
-1. **Always use `tracer.start_as_current_span()`** - Never use `tracer.start_span()` as it breaks context propagation
+1. **Always use `tracer.start_as_current_span()`** - Never use `tracer.start_span()`
2. **Include suppression check** - Always check `context_api._SUPPRESS_INSTRUMENTATION_KEY`
-3. **Use consistent patterns** - Follow the established 4-file structure and general_wrap pattern
-4. **Handle errors gracefully** - Use `handle_exception()` for proper error handling
-5. **Set server address** - Always calculate and set server_address/server_port
-6. **Use helper functions** - Utilize `common_db_span_attributes()` and `record_db_metrics()`
-7. **Follow naming conventions** - Use semantic convention constants, not hardcoded strings
-8. **Test thoroughly** - Include both sync and async tests with error handling
+3. **Use simplified patterns** - Focus on essential telemetry attributes
+4. **Handle endpoint differentiation** - Use `endpoint` parameter for operations mapping to same semantic type
+5. **Semantic operation mapping** - Multiple endpoints can map to same DB operation
+6. **Response structure awareness** - Handle flat vs nested response arrays correctly
+7. **Collection vs namespace** - Use appropriate semantic convention for your database type
+8. **Default values** - Use `'None'` for missing values in query summaries
+9. **Test thoroughly** - Include both sync and async tests (if applicable)
## Example Implementation
-For a complete reference implementation, see the Pinecone instrumentation:
-- `sdk/python/src/openlit/instrumentation/pinecone/`
+For complete reference implementations, see:
+- **Pinecone**: Full 4-file structure with async support
+- **ChromaDB**: Simplified 3-file structure, collection-based, endpoint differentiation
-This guide ensures consistency across all vector database instrumentations and maintains the high quality standards of the OpenLIT project.
\ No newline at end of file
+This guide ensures consistency across all vector database instrumentations while accommodating database-specific requirements and maintaining high quality standards.
\ No newline at end of file
diff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.toml
index e3b5232d..3f8fb4ee 100644
--- a/sdk/python/pyproject.toml
+++ b/sdk/python/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "openlit"
-version = "1.34.24"
+version = "1.34.25"
description = "OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications and GPUs, facilitating the integration of observability into your GenAI-driven projects"
authors = ["OpenLIT"]
license = "Apache-2.0"
diff --git a/sdk/python/src/openlit/instrumentation/chroma/__init__.py b/sdk/python/src/openlit/instrumentation/chroma/__init__.py
index d18f8b88..8ac83f01 100644
--- a/sdk/python/src/openlit/instrumentation/chroma/__init__.py
+++ b/sdk/python/src/openlit/instrumentation/chroma/__init__.py
@@ -1,5 +1,7 @@
-# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
-"""Initializer of Auto Instrumentation of Chromadb Functions"""
+"""
+OpenLIT ChromaDB Instrumentation
+"""
+
from typing import Collection
import importlib.metadata
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
@@ -10,77 +12,79 @@ from openlit.instrumentation.chroma.chroma import general_wrap
_instruments = ("chromadb >= 0.4.0",)
class ChromaInstrumentor(BaseInstrumentor):
- """An instrumentor for Chromadb's client library."""
+ """
+ An instrumentor for ChromaDB's client library.
+ """
def instrumentation_dependencies(self) -> Collection[str]:
return _instruments
def _instrument(self, **kwargs):
- application_name = kwargs.get("application_name")
- environment = kwargs.get("environment")
+ version = importlib.metadata.version("chromadb")
+ environment = kwargs.get("environment", "default")
+ application_name = kwargs.get("application_name", "default")
tracer = kwargs.get("tracer")
+ pricing_info = kwargs.get("pricing_info", {})
+ capture_message_content = kwargs.get("capture_message_content", False)
metrics = kwargs.get("metrics_dict")
- pricing_info = kwargs.get("pricing_info")
- capture_message_content = kwargs.get("capture_message_content")
disable_metrics = kwargs.get("disable_metrics")
- version = importlib.metadata.version("chromadb")
+ # Sync operations
wrap_function_wrapper(
- "chromadb.db",
- "DB.create_collection",
+ "chromadb.db",
+ "DB.create_collection",
general_wrap("chroma.create_collection", version, environment, application_name,
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
)
wrap_function_wrapper(
- "chromadb",
- "Collection.add",
+ "chromadb",
+ "Collection.add",
general_wrap("chroma.add", version, environment, application_name,
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
)
wrap_function_wrapper(
- "chromadb",
- "Collection.get",
+ "chromadb",
+ "Collection.get",
general_wrap("chroma.get", version, environment, application_name,
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
)
wrap_function_wrapper(
- "chromadb",
- "Collection.peek",
+ "chromadb",
+ "Collection.peek",
general_wrap("chroma.peek", version, environment, application_name,
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
)
wrap_function_wrapper(
- "chromadb",
- "Collection.query",
+ "chromadb",
+ "Collection.query",
general_wrap("chroma.query", version, environment, application_name,
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
)
wrap_function_wrapper(
- "chromadb",
- "Collection.update",
+ "chromadb",
+ "Collection.update",
general_wrap("chroma.update", version, environment, application_name,
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
)
wrap_function_wrapper(
- "chromadb",
- "Collection.upsert",
+ "chromadb",
+ "Collection.upsert",
general_wrap("chroma.upsert", version, environment, application_name,
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
)
+
wrap_function_wrapper(
- "chromadb",
- "Collection.delete",
+ "chromadb",
+ "Collection.delete",
general_wrap("chroma.delete", version, environment, application_name,
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
)
-
- @staticmethod
def _uninstrument(self, **kwargs):
pass
diff --git a/sdk/python/src/openlit/instrumentation/chroma/chroma.py b/sdk/python/src/openlit/instrumentation/chroma/chroma.py
index 7472d924..f4c4976a 100644
--- a/sdk/python/src/openlit/instrumentation/chroma/chroma.py
+++ b/sdk/python/src/openlit/instrumentation/chroma/chroma.py
@@ -1,199 +1,59 @@
-# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, possibly-used-before-assignment
"""
-Module for monitoring ChromaDB.
+Module for monitoring ChromaDB API calls.
"""
-import logging
-from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
-from openlit.__helpers import handle_exception
-from openlit.semcov import SemanticConvention
-
-# Initialize logger for logging potential issues and operations
-logger = logging.getLogger(__name__)
-
-def object_count(obj):
- """
- Counts Length of object if it exists, Else returns None
- """
- try:
- cnt = len(obj)
- # pylint: disable=bare-except
- except:
- cnt = 0
-
- return cnt
+import time
+from opentelemetry.trace import SpanKind
+from opentelemetry import context as context_api
+from openlit.__helpers import (
+ handle_exception,
+ set_server_address_and_port,
+)
+from openlit.instrumentation.chroma.utils import (
+ process_vectordb_response,
+ DB_OPERATION_MAP,
+)
def general_wrap(gen_ai_endpoint, version, environment, application_name,
- tracer, pricing_info, capture_message_content, metrics, disable_metrics):
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):
"""
- Creates a wrapper around a function call to trace and log its execution metrics.
-
- This function wraps any given function to measure its execution time,
- log its operation, and trace its execution using OpenTelemetry.
-
- Parameters:
- - gen_ai_endpoint (str): A descriptor or name for the endpoint being traced.
- - version (str): The version of the Langchain application.
- - environment (str): The deployment environment (e.g., 'production', 'development').
- - application_name (str): Name of the Langchain application.
- - tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.
- - pricing_info (dict): Information about the pricing for internal metrics (currently not used).
- - capture_message_content (bool): Flag indicating whether to trace the content of the response.
-
- Returns:
- - function: A higher-order function that takes a function 'wrapped' and returns
- a new function that wraps 'wrapped' with additional tracing and logging.
+ Generates a telemetry wrapper for ChromaDB function calls.
"""
def wrapper(wrapped, instance, args, kwargs):
"""
- An inner wrapper function that executes the wrapped function, measures execution
- time, and records trace data using OpenTelemetry.
-
- Parameters:
- - wrapped (Callable): The original function that this wrapper will execute.
- - instance (object): The instance to which the wrapped function belongs. This
- is used for instance methods. For static and classmethods,
- this may be None.
- - args (tuple): Positional arguments passed to the wrapped function.
- - kwargs (dict): Keyword arguments passed to the wrapped function.
-
- Returns:
- - The result of the wrapped function call.
-
- The wrapper initiates a span with the provided tracer, sets various attributes
- on the span based on the function's execution and response, and ensures
- errors are handled and logged appropriately.
+ Wraps the ChromaDB function call.
"""
- with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
- response = wrapped(*args, **kwargs)
- try:
- span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
- span.set_attribute(SemanticConvention.GEN_AI_ENDPOINT,
- gen_ai_endpoint)
- span.set_attribute(DEPLOYMENT_ENVIRONMENT,
- environment)
- span.set_attribute(SERVICE_NAME,
- application_name)
- span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
- SemanticConvention.GEN_AI_OPERATION_TYPE_VECTORDB)
- span.set_attribute(SemanticConvention.DB_SYSTEM_NAME,
- SemanticConvention.DB_SYSTEM_CHROMA)
- span.set_attribute(SemanticConvention.DB_COLLECTION_NAME,
- instance.name)
+ if context_api.get_value(context_api._SUPPRESS_INSTRUMENTATION_KEY):
+ return wrapped(*args, **kwargs)
- if gen_ai_endpoint == "chroma.add":
- db_operation = SemanticConvention.DB_OPERATION_ADD
- span.set_attribute(SemanticConvention.DB_OPERATION_NAME,
- SemanticConvention.DB_OPERATION_ADD)
- span.set_attribute(SemanticConvention.DB_ID_COUNT,
- object_count(kwargs.get("ids", [])))
- span.set_attribute(SemanticConvention.DB_VECTOR_COUNT,
- object_count(kwargs.get("embeddings", [])))
- span.set_attribute(SemanticConvention.DB_VECTOR_COUNT,
- object_count(kwargs.get("metadatas", [])))
- span.set_attribute(SemanticConvention.DB_DOCUMENTS_COUNT,
- object_count(kwargs.get("documents", [])))
+ # Get server address and port using the standard helper
+ server_address, server_port = set_server_address_and_port(instance, "localhost", 8000)
- elif gen_ai_endpoint == "chroma.get":
- db_operation = SemanticConvention.DB_OPERATION_GET
- span.set_attribute(SemanticConvention.DB_OPERATION_NAME,
- SemanticConvention.DB_OPERATION_GET)
- span.set_attribute(SemanticConvention.DB_ID_COUNT,
- object_count(kwargs.get("ids", [])))
- span.set_attribute(SemanticConvention.DB_QUERY_LIMIT,
- kwargs.get("limit", ""))
- span.set_attribute(SemanticConvention.DB_OFFSET,
- kwargs.get("offset", ""))
- span.set_attribute(SemanticConvention.DB_WHERE_DOCUMENT,
- str(kwargs.get("where_document", "")))
+ db_operation = DB_OPERATION_MAP.get(gen_ai_endpoint, "unknown")
+ if db_operation == "create_collection":
+ namespace = kwargs.get("name") or (args[0] if args else "unknown")
+ else:
+ namespace = getattr(instance, "name", "unknown")
+ span_name = f"{db_operation} {namespace}"
- elif gen_ai_endpoint == "chroma.query":
- db_operation = SemanticConvention.DB_OPERATION_QUERY
- span.set_attribute(SemanticConvention.DB_OPERATION_NAME,
- SemanticConvention.DB_OPERATION_QUERY)
- span.set_attribute(SemanticConvention.DB_STATEMENT,
- str(kwargs.get("query_texts", "")))
- span.set_attribute(SemanticConvention.DB_N_RESULTS,
- kwargs.get("n_results", ""))
- span.set_attribute(SemanticConvention.DB_FILTER,
- str(kwargs.get("where", "")))
- span.set_attribute(SemanticConvention.DB_WHERE_DOCUMENT,
- str(kwargs.get("where_document", "")))
-
- elif gen_ai_endpoint == "chroma.update":
- db_operation = SemanticConvention.DB_OPERATION_UPDATE
- span.set_attribute(SemanticConvention.DB_OPERATION_NAME,
- SemanticConvention.DB_OPERATION_UPDATE)
- span.set_attribute(SemanticConvention.DB_VECTOR_COUNT,
- object_count(kwargs.get("embeddings", [])))
- span.set_attribute(SemanticConvention.DB_VECTOR_COUNT,
- object_count(kwargs.get("metadatas", [])))
- span.set_attribute(SemanticConvention.DB_ID_COUNT,
- object_count(kwargs.get("ids", [])))
- span.set_attribute(SemanticConvention.DB_DOCUMENTS_COUNT,
- object_count(kwargs.get("documents", [])))
-
- elif gen_ai_endpoint == "chroma.upsert":
- db_operation = SemanticConvention.DB_OPERATION_UPSERT
- span.set_attribute(SemanticConvention.DB_OPERATION_NAME,
- SemanticConvention.DB_OPERATION_UPSERT)
- span.set_attribute(SemanticConvention.DB_VECTOR_COUNT,
- object_count(kwargs.get("embeddings", [])))
- span.set_attribute(SemanticConvention.DB_VECTOR_COUNT,
- object_count(kwargs.get("metadatas", [])))
- span.set_attribute(SemanticConvention.DB_ID_COUNT,
- object_count(kwargs.get("ids", [])))
- span.set_attribute(SemanticConvention.DB_DOCUMENTS_COUNT,
- object_count(kwargs.get("documents", [])))
-
- elif gen_ai_endpoint == "chroma.delete":
- db_operation = SemanticConvention.DB_OPERATION_DELETE
- span.set_attribute(SemanticConvention.DB_OPERATION_NAME,
- SemanticConvention.DB_OPERATION_DELETE)
- span.set_attribute(SemanticConvention.DB_ID_COUNT,
- object_count(kwargs.get("ids", [])))
- span.set_attribute(SemanticConvention.DB_FILTER,
- str(kwargs.get("where", "")))
- span.set_attribute(SemanticConvention.DB_DELETE_ALL,
- kwargs.get("delete_all", False))
- span.set_attribute(SemanticConvention.DB_WHERE_DOCUMENT,
- str(kwargs.get("where_document", "")))
-
- elif gen_ai_endpoint == "chroma.peek":
- db_operation = SemanticConvention.DB_OPERATION_PEEK
- span.set_attribute(SemanticConvention.DB_OPERATION_NAME,
- SemanticConvention.DB_OPERATION_PEEK)
-
- span.set_status(Status(StatusCode.OK))
-
- if disable_metrics is False:
- attributes = {
- TELEMETRY_SDK_NAME:
- "openlit",
- SERVICE_NAME:
- application_name,
- SemanticConvention.DB_SYSTEM_NAME:
- SemanticConvention.DB_SYSTEM_CHROMA,
- DEPLOYMENT_ENVIRONMENT:
- environment,
- SemanticConvention.GEN_AI_OPERATION:
- SemanticConvention.GEN_AI_OPERATION_TYPE_VECTORDB,
- SemanticConvention.DB_OPERATION_NAME:
- db_operation
- }
-
- metrics["db_requests"].add(1, attributes)
+ with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
+ try:
+ start_time = time.time()
+ response = wrapped(*args, **kwargs)
- return response
+ # Process response and generate telemetry
+ response = process_vectordb_response(
+ response, db_operation, server_address, server_port,
+ environment, application_name, metrics, start_time, span,
+ capture_message_content, disable_metrics, version, instance, args, endpoint=gen_ai_endpoint, **kwargs
+ )
except Exception as e:
handle_exception(span, e)
- logger.error("Error in trace creation: %s", e)
- # Return original response
- return response
+ return response
+
return wrapper
diff --git a/sdk/python/src/openlit/instrumentation/chroma/utils.py b/sdk/python/src/openlit/instrumentation/chroma/utils.py
new file mode 100644
index 00000000..3bbd9da7
--- /dev/null
+++ b/sdk/python/src/openlit/instrumentation/chroma/utils.py
@@ -0,0 +1,227 @@
+"""
+ChromaDB OpenTelemetry instrumentation utility functions
+"""
+import time
+
+from opentelemetry.trace import Status, StatusCode
+
+from openlit.__helpers import (
+ common_db_span_attributes,
+ record_db_metrics,
+)
+from openlit.semcov import SemanticConvention
+
+# Operation mapping for simple span naming
+DB_OPERATION_MAP = {
+ "chroma.create_collection": SemanticConvention.DB_OPERATION_CREATE_COLLECTION,
+ "chroma.add": SemanticConvention.DB_OPERATION_INSERT,
+ "chroma.get": SemanticConvention.DB_OPERATION_GET,
+ "chroma.peek": SemanticConvention.DB_OPERATION_PEEK,
+ "chroma.query": SemanticConvention.DB_OPERATION_GET,
+ "chroma.update": SemanticConvention.DB_OPERATION_UPDATE,
+ "chroma.upsert": SemanticConvention.DB_OPERATION_UPSERT,
+ "chroma.delete": SemanticConvention.DB_OPERATION_DELETE,
+}
+
+def object_count(obj):
+ """
+ Counts length of object if it exists, else returns 0.
+ """
+ return len(obj) if obj else 0
+
+def common_vectordb_logic(scope, environment, application_name,
+ metrics, capture_message_content, disable_metrics, version, instance=None, endpoint=None):
+ """
+ Process vector database request and generate telemetry.
+ """
+
+ scope._end_time = time.time()
+
+ # Set common database span attributes using helper
+ common_db_span_attributes(scope, SemanticConvention.DB_SYSTEM_CHROMA, scope._server_address, scope._server_port,
+ environment, application_name, version)
+
+ # Set DB operation specific attributes
+ scope._span.set_attribute(SemanticConvention.DB_OPERATION_NAME, scope._db_operation)
+ scope._span.set_attribute(SemanticConvention.DB_CLIENT_OPERATION_DURATION, scope._end_time - scope._start_time)
+
+ # Set collection name from instance
+ if hasattr(instance, "name"):
+ scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, instance.name)
+
+ # Set Create Collection operation specific attributes
+ if scope._db_operation == SemanticConvention.DB_OPERATION_CREATE_COLLECTION:
+ # Standard database attributes
+ collection_name = scope._kwargs.get("name") or (scope._args[0] if scope._args else "unknown")
+ scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, collection_name)
+
+ # Vector database specific attributes (extensions)
+ metadata = scope._kwargs.get("metadata", {})
+ if metadata:
+ scope._span.set_attribute(SemanticConvention.DB_COLLECTION_METADATA, str(metadata))
+
+ elif scope._db_operation == SemanticConvention.DB_OPERATION_INSERT:
+ collection_name = getattr(instance, "name", "unknown")
+ query = scope._kwargs.get("ids", [])
+
+ # Standard database attributes
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
+ scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, collection_name)
+ scope._span.set_attribute(SemanticConvention.DB_VECTOR_COUNT, object_count(query))
+
+ # Vector database specific attributes (extensions)
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
+ f"{scope._db_operation} {collection_name} "
+ f"ids={query} "
+ f"documents={scope._kwargs.get('documents', [])}")
+
+ elif scope._db_operation == SemanticConvention.DB_OPERATION_GET:
+ collection_name = getattr(instance, "name", "unknown")
+
+ # Handle different GET operations based on endpoint
+ if endpoint == "chroma.get":
+ # Collection.get() - retrieve documents by IDs
+ query = scope._kwargs.get("ids", [])
+
+ # Standard database attributes
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
+ scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, collection_name)
+ scope._span.set_attribute(SemanticConvention.DB_VECTOR_COUNT, object_count(query))
+
+ # Vector database specific attributes (extensions)
+ scope._span.set_attribute(SemanticConvention.DB_FILTER, str(scope._kwargs.get("where", "")))
+
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
+ f"{scope._db_operation} {collection_name} "
+ f"ids={query} "
+ f"limit={scope._kwargs.get('limit', 'None')} "
+ f"offset={scope._kwargs.get('offset', 'None')}")
+
+ elif endpoint == "chroma.query":
+ query_texts = scope._kwargs.get("query_texts", [])
+ query_embeddings = scope._kwargs.get("query_embeddings", [])
+
+ # Create comprehensive query text (can be either embeddings or texts)
+ if query_texts:
+ query_content = f"texts={query_texts}"
+ elif query_embeddings:
+ query_content = f"embeddings={len(query_embeddings) if query_embeddings else 0} vectors"
+ else:
+ query_content = "no query provided"
+
+ # Standard database attributes
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, query_content)
+ scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, collection_name)
+
+ # Vector database specific attributes (extensions)
+ scope._span.set_attribute(SemanticConvention.DB_VECTOR_QUERY_TOP_K, scope._kwargs.get("n_results", 10))
+ scope._span.set_attribute(SemanticConvention.DB_FILTER, str(scope._kwargs.get("where", "")))
+
+ # Extract response metrics if available
+ if scope._response:
+ # Get number of results returned
+ if hasattr(scope._response, 'get') and scope._response.get('ids'):
+ returned_rows = object_count(scope._response['ids'][0]) if scope._response['ids'] else 0
+ scope._span.set_attribute(SemanticConvention.DB_RESPONSE_RETURNED_ROWS, returned_rows)
+
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
+ f"{scope._db_operation} {collection_name} "
+ f"n_results={scope._kwargs.get('n_results', 10)} "
+ f"{query_content} "
+ f"filter={scope._kwargs.get('where', 'None')}")
+
+ elif scope._db_operation == SemanticConvention.DB_OPERATION_UPDATE:
+ collection_name = getattr(instance, "name", "unknown")
+ query = scope._kwargs.get("ids", [])
+
+ # Standard database attributes
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
+ scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, collection_name)
+ scope._span.set_attribute(SemanticConvention.DB_VECTOR_COUNT, object_count(query))
+
+ # Vector database specific attributes (extensions)
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
+ f"{scope._db_operation} {collection_name} "
+ f"ids={query} "
+ f"embeddings={scope._kwargs.get('embeddings', 'None')} "
+ f"metadatas={scope._kwargs.get('metadatas', 'None')} "
+ f"documents={scope._kwargs.get('documents', 'None')}")
+
+ elif scope._db_operation == SemanticConvention.DB_OPERATION_UPSERT:
+ collection_name = getattr(instance, "name", "unknown")
+ query = scope._kwargs.get("ids", [])
+
+ # Standard database attributes
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
+ scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, collection_name)
+ scope._span.set_attribute(SemanticConvention.DB_VECTOR_COUNT, object_count(query))
+
+ # Vector database specific attributes (extensions)
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
+ f"{scope._db_operation} {collection_name} "
+ f"ids={query} "
+ f"embeddings={scope._kwargs.get('embeddings', 'None')} "
+ f"metadatas={scope._kwargs.get('metadatas', 'None')} "
+ f"documents={scope._kwargs.get('documents', 'None')}")
+
+ elif scope._db_operation == SemanticConvention.DB_OPERATION_DELETE:
+ collection_name = getattr(instance, "name", "unknown")
+ query = scope._kwargs.get("ids", [])
+
+ # Standard database attributes
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
+ scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, collection_name)
+ scope._span.set_attribute(SemanticConvention.DB_VECTOR_COUNT, object_count(query))
+
+ # Vector database specific attributes (extensions)
+ scope._span.set_attribute(SemanticConvention.DB_FILTER, str(scope._kwargs.get("where", "")))
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
+ f"{scope._db_operation} {collection_name} "
+ f"ids={query} "
+ f"filter={scope._kwargs.get('where', 'None')} "
+ f"delete_all={scope._kwargs.get('delete_all', False)}")
+
+ elif scope._db_operation == SemanticConvention.DB_OPERATION_PEEK:
+ collection_name = getattr(instance, "name", "unknown")
+ query = f"PEEK limit={scope._kwargs.get('limit', '')}"
+
+ # Standard database attributes
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, query)
+ scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, collection_name)
+ scope._span.set_attribute(SemanticConvention.DB_VECTOR_COUNT, scope._kwargs.get("limit", ""))
+
+ # Vector database specific attributes (extensions)
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
+ f"{scope._db_operation} {collection_name} "
+ f"limit={scope._kwargs.get('limit', 'None')}")
+
+ scope._span.set_status(Status(StatusCode.OK))
+
+ # Record metrics using helper
+ if not disable_metrics:
+ record_db_metrics(metrics, SemanticConvention.DB_SYSTEM_CHROMA, scope._server_address, scope._server_port,
+ environment, application_name, scope._start_time, scope._end_time)
+
+def process_vectordb_response(response, db_operation, server_address, server_port,
+ environment, application_name, metrics, start_time, span,
+ capture_message_content=False, disable_metrics=False,
+ version="1.0.0", instance=None, args=None, endpoint=None, **kwargs):
+ """
+ Process vector database response and generate telemetry following OpenTelemetry conventions.
+ """
+
+ scope = type("GenericScope", (), {})()
+
+ scope._start_time = start_time
+ scope._span = span
+ scope._kwargs = kwargs
+ scope._args = args or []
+ scope._db_operation = db_operation
+ scope._response = response
+ scope._server_address = server_address
+ scope._server_port = server_port
+
+ common_vectordb_logic(scope, environment, application_name,
+ metrics, capture_message_content, disable_metrics, version, instance, endpoint)
+
+ return response
diff --git a/sdk/python/src/openlit/instrumentation/pinecone/async_pinecone.py b/sdk/python/src/openlit/instrumentation/pinecone/async_pinecone.py
index 20de9f15..774a380f 100644
--- a/sdk/python/src/openlit/instrumentation/pinecone/async_pinecone.py
+++ b/sdk/python/src/openlit/instrumentation/pinecone/async_pinecone.py
@@ -50,10 +50,9 @@ def async_general_wrap(gen_ai_endpoint, version, environment, application_name,
capture_message_content, disable_metrics, version, instance, args, **kwargs
)
- return response
-
except Exception as e:
handle_exception(span, e)
- raise
+
+ return response
return wrapper
diff --git a/sdk/python/src/openlit/instrumentation/pinecone/pinecone.py b/sdk/python/src/openlit/instrumentation/pinecone/pinecone.py
index 81352da8..a8e0c831 100644
--- a/sdk/python/src/openlit/instrumentation/pinecone/pinecone.py
+++ b/sdk/python/src/openlit/instrumentation/pinecone/pinecone.py
@@ -50,10 +50,9 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
capture_message_content, disable_metrics, version, instance, args, **kwargs
)
- return response
-
except Exception as e:
handle_exception(span, e)
- raise
+
+ return response
return wrapper
diff --git a/sdk/python/src/openlit/instrumentation/pinecone/utils.py b/sdk/python/src/openlit/instrumentation/pinecone/utils.py
index 24ef8752..bcd384f9 100644
--- a/sdk/python/src/openlit/instrumentation/pinecone/utils.py
+++ b/sdk/python/src/openlit/instrumentation/pinecone/utils.py
@@ -72,7 +72,10 @@ def common_vectordb_logic(scope, environment, application_name,
# Vector database specific attributes (extensions)
scope._span.set_attribute(SemanticConvention.DB_VECTOR_QUERY_TOP_K, query.get("top_k", -1))
scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
- f"SEARCH {namespace} top_k={query.get('top_k', -1)} text={query_text} vector={query_vector}")
+ f"{scope._db_operation} {namespace} "
+ f"top_k={query.get('top_k', -1)} "
+ f"text={query_text} "
+ f"vector={query_vector}")
elif scope._db_operation == SemanticConvention.DB_OPERATION_QUERY:
namespace = scope._kwargs.get("namespace", "default") or (scope._args[0] if scope._args else "unknown")
@@ -101,7 +104,8 @@ def common_vectordb_logic(scope, environment, application_name,
# Vector database specific attributes (extensions)
scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
- f"FETCH {namespace} ids={query}")
+ f"{scope._db_operation} {namespace} "
+ f"ids={query}")
scope._span.set_attribute(SemanticConvention.DB_RESPONSE_RETURNED_ROWS, object_count(scope._response.vectors))
elif scope._db_operation == SemanticConvention.DB_OPERATION_UPDATE: