openlit 1.34.30__py3-none-any.whl → 1.34.31__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openlit/__helpers.py +235 -86
- openlit/__init__.py +16 -13
- openlit/_instrumentors.py +2 -1
- openlit/evals/all.py +50 -21
- openlit/evals/bias_detection.py +47 -20
- openlit/evals/hallucination.py +53 -22
- openlit/evals/toxicity.py +50 -21
- openlit/evals/utils.py +54 -30
- openlit/guard/all.py +61 -19
- openlit/guard/prompt_injection.py +34 -14
- openlit/guard/restrict_topic.py +46 -15
- openlit/guard/sensitive_topic.py +34 -14
- openlit/guard/utils.py +58 -22
- openlit/instrumentation/ag2/__init__.py +24 -8
- openlit/instrumentation/ag2/ag2.py +34 -13
- openlit/instrumentation/ag2/async_ag2.py +34 -13
- openlit/instrumentation/ag2/utils.py +133 -30
- openlit/instrumentation/ai21/__init__.py +43 -14
- openlit/instrumentation/ai21/ai21.py +47 -21
- openlit/instrumentation/ai21/async_ai21.py +47 -21
- openlit/instrumentation/ai21/utils.py +299 -78
- openlit/instrumentation/anthropic/__init__.py +21 -4
- openlit/instrumentation/anthropic/anthropic.py +28 -17
- openlit/instrumentation/anthropic/async_anthropic.py +28 -17
- openlit/instrumentation/anthropic/utils.py +145 -35
- openlit/instrumentation/assemblyai/__init__.py +11 -2
- openlit/instrumentation/assemblyai/assemblyai.py +15 -4
- openlit/instrumentation/assemblyai/utils.py +120 -25
- openlit/instrumentation/astra/__init__.py +43 -10
- openlit/instrumentation/astra/astra.py +28 -5
- openlit/instrumentation/astra/async_astra.py +28 -5
- openlit/instrumentation/astra/utils.py +151 -55
- openlit/instrumentation/azure_ai_inference/__init__.py +43 -10
- openlit/instrumentation/azure_ai_inference/async_azure_ai_inference.py +53 -21
- openlit/instrumentation/azure_ai_inference/azure_ai_inference.py +53 -21
- openlit/instrumentation/azure_ai_inference/utils.py +307 -83
- openlit/instrumentation/bedrock/__init__.py +21 -4
- openlit/instrumentation/bedrock/bedrock.py +63 -25
- openlit/instrumentation/bedrock/utils.py +139 -30
- openlit/instrumentation/chroma/__init__.py +89 -16
- openlit/instrumentation/chroma/chroma.py +28 -6
- openlit/instrumentation/chroma/utils.py +167 -51
- openlit/instrumentation/cohere/__init__.py +63 -18
- openlit/instrumentation/cohere/async_cohere.py +63 -24
- openlit/instrumentation/cohere/cohere.py +63 -24
- openlit/instrumentation/cohere/utils.py +286 -73
- openlit/instrumentation/controlflow/__init__.py +35 -9
- openlit/instrumentation/controlflow/controlflow.py +66 -33
- openlit/instrumentation/crawl4ai/__init__.py +25 -10
- openlit/instrumentation/crawl4ai/async_crawl4ai.py +78 -31
- openlit/instrumentation/crawl4ai/crawl4ai.py +78 -31
- openlit/instrumentation/crewai/__init__.py +40 -15
- openlit/instrumentation/crewai/async_crewai.py +32 -7
- openlit/instrumentation/crewai/crewai.py +32 -7
- openlit/instrumentation/crewai/utils.py +159 -56
- openlit/instrumentation/dynamiq/__init__.py +46 -12
- openlit/instrumentation/dynamiq/dynamiq.py +74 -33
- openlit/instrumentation/elevenlabs/__init__.py +23 -4
- openlit/instrumentation/elevenlabs/async_elevenlabs.py +16 -4
- openlit/instrumentation/elevenlabs/elevenlabs.py +16 -4
- openlit/instrumentation/elevenlabs/utils.py +128 -25
- openlit/instrumentation/embedchain/__init__.py +11 -2
- openlit/instrumentation/embedchain/embedchain.py +68 -35
- openlit/instrumentation/firecrawl/__init__.py +24 -7
- openlit/instrumentation/firecrawl/firecrawl.py +46 -20
- openlit/instrumentation/google_ai_studio/__init__.py +45 -10
- openlit/instrumentation/google_ai_studio/async_google_ai_studio.py +67 -44
- openlit/instrumentation/google_ai_studio/google_ai_studio.py +67 -44
- openlit/instrumentation/google_ai_studio/utils.py +180 -67
- openlit/instrumentation/gpt4all/__init__.py +22 -7
- openlit/instrumentation/gpt4all/gpt4all.py +67 -29
- openlit/instrumentation/gpt4all/utils.py +285 -61
- openlit/instrumentation/gpu/__init__.py +128 -47
- openlit/instrumentation/groq/__init__.py +21 -4
- openlit/instrumentation/groq/async_groq.py +33 -21
- openlit/instrumentation/groq/groq.py +33 -21
- openlit/instrumentation/groq/utils.py +192 -55
- openlit/instrumentation/haystack/__init__.py +70 -24
- openlit/instrumentation/haystack/async_haystack.py +28 -6
- openlit/instrumentation/haystack/haystack.py +28 -6
- openlit/instrumentation/haystack/utils.py +196 -74
- openlit/instrumentation/julep/__init__.py +69 -19
- openlit/instrumentation/julep/async_julep.py +53 -27
- openlit/instrumentation/julep/julep.py +53 -28
- openlit/instrumentation/langchain/__init__.py +74 -63
- openlit/instrumentation/langchain/callback_handler.py +1100 -0
- openlit/instrumentation/langchain_community/__init__.py +13 -2
- openlit/instrumentation/langchain_community/async_langchain_community.py +23 -5
- openlit/instrumentation/langchain_community/langchain_community.py +23 -5
- openlit/instrumentation/langchain_community/utils.py +35 -9
- openlit/instrumentation/letta/__init__.py +68 -15
- openlit/instrumentation/letta/letta.py +99 -54
- openlit/instrumentation/litellm/__init__.py +43 -14
- openlit/instrumentation/litellm/async_litellm.py +51 -26
- openlit/instrumentation/litellm/litellm.py +51 -26
- openlit/instrumentation/litellm/utils.py +304 -102
- openlit/instrumentation/llamaindex/__init__.py +267 -90
- openlit/instrumentation/llamaindex/async_llamaindex.py +28 -6
- openlit/instrumentation/llamaindex/llamaindex.py +28 -6
- openlit/instrumentation/llamaindex/utils.py +204 -91
- openlit/instrumentation/mem0/__init__.py +11 -2
- openlit/instrumentation/mem0/mem0.py +50 -29
- openlit/instrumentation/milvus/__init__.py +10 -2
- openlit/instrumentation/milvus/milvus.py +31 -6
- openlit/instrumentation/milvus/utils.py +166 -67
- openlit/instrumentation/mistral/__init__.py +63 -18
- openlit/instrumentation/mistral/async_mistral.py +63 -24
- openlit/instrumentation/mistral/mistral.py +63 -24
- openlit/instrumentation/mistral/utils.py +277 -69
- openlit/instrumentation/multion/__init__.py +69 -19
- openlit/instrumentation/multion/async_multion.py +57 -26
- openlit/instrumentation/multion/multion.py +57 -26
- openlit/instrumentation/ollama/__init__.py +39 -18
- openlit/instrumentation/ollama/async_ollama.py +57 -26
- openlit/instrumentation/ollama/ollama.py +57 -26
- openlit/instrumentation/ollama/utils.py +226 -50
- openlit/instrumentation/openai/__init__.py +156 -32
- openlit/instrumentation/openai/async_openai.py +147 -67
- openlit/instrumentation/openai/openai.py +150 -67
- openlit/instrumentation/openai/utils.py +657 -185
- openlit/instrumentation/openai_agents/__init__.py +5 -1
- openlit/instrumentation/openai_agents/processor.py +110 -90
- openlit/instrumentation/phidata/__init__.py +13 -5
- openlit/instrumentation/phidata/phidata.py +67 -32
- openlit/instrumentation/pinecone/__init__.py +48 -9
- openlit/instrumentation/pinecone/async_pinecone.py +27 -5
- openlit/instrumentation/pinecone/pinecone.py +27 -5
- openlit/instrumentation/pinecone/utils.py +153 -47
- openlit/instrumentation/premai/__init__.py +22 -7
- openlit/instrumentation/premai/premai.py +51 -26
- openlit/instrumentation/premai/utils.py +246 -59
- openlit/instrumentation/pydantic_ai/__init__.py +49 -22
- openlit/instrumentation/pydantic_ai/pydantic_ai.py +69 -16
- openlit/instrumentation/pydantic_ai/utils.py +89 -24
- openlit/instrumentation/qdrant/__init__.py +19 -4
- openlit/instrumentation/qdrant/async_qdrant.py +33 -7
- openlit/instrumentation/qdrant/qdrant.py +33 -7
- openlit/instrumentation/qdrant/utils.py +228 -93
- openlit/instrumentation/reka/__init__.py +23 -10
- openlit/instrumentation/reka/async_reka.py +17 -11
- openlit/instrumentation/reka/reka.py +17 -11
- openlit/instrumentation/reka/utils.py +138 -36
- openlit/instrumentation/together/__init__.py +44 -12
- openlit/instrumentation/together/async_together.py +50 -27
- openlit/instrumentation/together/together.py +50 -27
- openlit/instrumentation/together/utils.py +301 -71
- openlit/instrumentation/transformers/__init__.py +2 -1
- openlit/instrumentation/transformers/transformers.py +13 -3
- openlit/instrumentation/transformers/utils.py +139 -36
- openlit/instrumentation/vertexai/__init__.py +81 -16
- openlit/instrumentation/vertexai/async_vertexai.py +33 -15
- openlit/instrumentation/vertexai/utils.py +123 -27
- openlit/instrumentation/vertexai/vertexai.py +33 -15
- openlit/instrumentation/vllm/__init__.py +12 -5
- openlit/instrumentation/vllm/utils.py +121 -31
- openlit/instrumentation/vllm/vllm.py +16 -10
- openlit/otel/events.py +35 -10
- openlit/otel/metrics.py +32 -24
- openlit/otel/tracing.py +24 -9
- openlit/semcov/__init__.py +72 -6
- {openlit-1.34.30.dist-info → openlit-1.34.31.dist-info}/METADATA +2 -1
- openlit-1.34.31.dist-info/RECORD +166 -0
- openlit/instrumentation/langchain/async_langchain.py +0 -102
- openlit/instrumentation/langchain/langchain.py +0 -102
- openlit/instrumentation/langchain/utils.py +0 -252
- openlit-1.34.30.dist-info/RECORD +0 -168
- {openlit-1.34.30.dist-info → openlit-1.34.31.dist-info}/LICENSE +0 -0
- {openlit-1.34.30.dist-info → openlit-1.34.31.dist-info}/WHEEL +0 -0
@@ -13,7 +13,11 @@ _instruments = ("pinecone >= 7.3.0",)
|
|
13
13
|
# Pinecone sync operations
|
14
14
|
PINECONE_SYNC_OPERATIONS = [
|
15
15
|
("pinecone.pinecone", "Pinecone.create_index", "pinecone.create_collection"),
|
16
|
-
(
|
16
|
+
(
|
17
|
+
"pinecone.pinecone",
|
18
|
+
"Pinecone.create_index_for_model",
|
19
|
+
"pinecone.create_collection",
|
20
|
+
),
|
17
21
|
("pinecone.db_data.index", "Index.upsert", "pinecone.upsert"),
|
18
22
|
("pinecone.db_data.index", "Index.upsert_records", "pinecone.upsert_records"),
|
19
23
|
("pinecone.db_data.index", "Index.query", "pinecone.query"),
|
@@ -26,18 +30,35 @@ PINECONE_SYNC_OPERATIONS = [
|
|
26
30
|
|
27
31
|
# Pinecone async operations
|
28
32
|
PINECONE_ASYNC_OPERATIONS = [
|
29
|
-
(
|
30
|
-
|
33
|
+
(
|
34
|
+
"pinecone.pinecone_asyncio",
|
35
|
+
"PineconeAsyncio.create_index",
|
36
|
+
"pinecone.create_index",
|
37
|
+
),
|
38
|
+
(
|
39
|
+
"pinecone.pinecone_asyncio",
|
40
|
+
"PineconeAsyncio.create_index_for_model",
|
41
|
+
"pinecone.create_index",
|
42
|
+
),
|
31
43
|
("pinecone.db_data.index_asyncio", "_IndexAsyncio.upsert", "pinecone.upsert"),
|
32
|
-
(
|
44
|
+
(
|
45
|
+
"pinecone.db_data.index_asyncio",
|
46
|
+
"_IndexAsyncio.upsert_records",
|
47
|
+
"pinecone.upsert_records",
|
48
|
+
),
|
33
49
|
("pinecone.db_data.index_asyncio", "_IndexAsyncio.query", "pinecone.query"),
|
34
50
|
("pinecone.db_data.index_asyncio", "_IndexAsyncio.search", "pinecone.search"),
|
35
51
|
("pinecone.db_data.index_asyncio", "_IndexAsyncio.fetch", "pinecone.fetch"),
|
36
|
-
(
|
52
|
+
(
|
53
|
+
"pinecone.db_data.index_asyncio",
|
54
|
+
"_IndexAsyncio.search_records",
|
55
|
+
"pinecone.search_records",
|
56
|
+
),
|
37
57
|
("pinecone.db_data.index_asyncio", "_IndexAsyncio.update", "pinecone.update"),
|
38
58
|
("pinecone.db_data.index_asyncio", "_IndexAsyncio.delete", "pinecone.delete"),
|
39
59
|
]
|
40
60
|
|
61
|
+
|
41
62
|
class PineconeInstrumentor(BaseInstrumentor):
|
42
63
|
"""
|
43
64
|
An instrumentor for Pinecone client library.
|
@@ -61,8 +82,17 @@ class PineconeInstrumentor(BaseInstrumentor):
|
|
61
82
|
wrap_function_wrapper(
|
62
83
|
module,
|
63
84
|
class_method,
|
64
|
-
general_wrap(
|
65
|
-
|
85
|
+
general_wrap(
|
86
|
+
endpoint,
|
87
|
+
version,
|
88
|
+
environment,
|
89
|
+
application_name,
|
90
|
+
tracer,
|
91
|
+
pricing_info,
|
92
|
+
capture_message_content,
|
93
|
+
metrics,
|
94
|
+
disable_metrics,
|
95
|
+
),
|
66
96
|
)
|
67
97
|
|
68
98
|
# Wrap async operations
|
@@ -70,8 +100,17 @@ class PineconeInstrumentor(BaseInstrumentor):
|
|
70
100
|
wrap_function_wrapper(
|
71
101
|
module,
|
72
102
|
class_method,
|
73
|
-
async_general_wrap(
|
74
|
-
|
103
|
+
async_general_wrap(
|
104
|
+
endpoint,
|
105
|
+
version,
|
106
|
+
environment,
|
107
|
+
application_name,
|
108
|
+
tracer,
|
109
|
+
pricing_info,
|
110
|
+
capture_message_content,
|
111
|
+
metrics,
|
112
|
+
disable_metrics,
|
113
|
+
),
|
75
114
|
)
|
76
115
|
|
77
116
|
def _uninstrument(self, **kwargs):
|
@@ -12,8 +12,18 @@ from openlit.instrumentation.pinecone.utils import (
|
|
12
12
|
set_server_address_and_port,
|
13
13
|
)
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
|
16
|
+
def async_general_wrap(
|
17
|
+
gen_ai_endpoint,
|
18
|
+
version,
|
19
|
+
environment,
|
20
|
+
application_name,
|
21
|
+
tracer,
|
22
|
+
pricing_info,
|
23
|
+
capture_message_content,
|
24
|
+
metrics,
|
25
|
+
disable_metrics,
|
26
|
+
):
|
17
27
|
"""
|
18
28
|
Generates a telemetry wrapper for Pinecone async function calls.
|
19
29
|
"""
|
@@ -43,9 +53,21 @@ def async_general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
43
53
|
try:
|
44
54
|
# Process response and generate telemetry
|
45
55
|
response = process_vectordb_response(
|
46
|
-
response,
|
47
|
-
|
48
|
-
|
56
|
+
response,
|
57
|
+
db_operation,
|
58
|
+
server_address,
|
59
|
+
server_port,
|
60
|
+
environment,
|
61
|
+
application_name,
|
62
|
+
metrics,
|
63
|
+
start_time,
|
64
|
+
span,
|
65
|
+
capture_message_content,
|
66
|
+
disable_metrics,
|
67
|
+
version,
|
68
|
+
instance,
|
69
|
+
args,
|
70
|
+
**kwargs,
|
49
71
|
)
|
50
72
|
|
51
73
|
except Exception as e:
|
@@ -12,8 +12,18 @@ from openlit.instrumentation.pinecone.utils import (
|
|
12
12
|
set_server_address_and_port,
|
13
13
|
)
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
|
16
|
+
def general_wrap(
|
17
|
+
gen_ai_endpoint,
|
18
|
+
version,
|
19
|
+
environment,
|
20
|
+
application_name,
|
21
|
+
tracer,
|
22
|
+
pricing_info,
|
23
|
+
capture_message_content,
|
24
|
+
metrics,
|
25
|
+
disable_metrics,
|
26
|
+
):
|
17
27
|
"""
|
18
28
|
Generates a telemetry wrapper for Pinecone function calls.
|
19
29
|
"""
|
@@ -43,9 +53,21 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
43
53
|
try:
|
44
54
|
# Process response and generate telemetry
|
45
55
|
response = process_vectordb_response(
|
46
|
-
response,
|
47
|
-
|
48
|
-
|
56
|
+
response,
|
57
|
+
db_operation,
|
58
|
+
server_address,
|
59
|
+
server_port,
|
60
|
+
environment,
|
61
|
+
application_name,
|
62
|
+
metrics,
|
63
|
+
start_time,
|
64
|
+
span,
|
65
|
+
capture_message_content,
|
66
|
+
disable_metrics,
|
67
|
+
version,
|
68
|
+
instance,
|
69
|
+
args,
|
70
|
+
**kwargs,
|
49
71
|
)
|
50
72
|
|
51
73
|
except Exception as e:
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"""
|
2
2
|
Pinecone OpenTelemetry instrumentation utility functions
|
3
3
|
"""
|
4
|
+
|
4
5
|
import time
|
5
6
|
from urllib.parse import urlparse
|
6
7
|
from opentelemetry.trace import Status, StatusCode
|
@@ -24,12 +25,14 @@ DB_OPERATION_MAP = {
|
|
24
25
|
"pinecone.search_records": SemanticConvention.DB_OPERATION_QUERY,
|
25
26
|
}
|
26
27
|
|
28
|
+
|
27
29
|
def object_count(obj):
|
28
30
|
"""
|
29
31
|
Counts length of object if it exists, else returns 0.
|
30
32
|
"""
|
31
33
|
return len(obj) if obj else 0
|
32
34
|
|
35
|
+
|
33
36
|
def set_server_address_and_port(instance):
|
34
37
|
"""
|
35
38
|
Extracts server address and port from Pinecone client instance.
|
@@ -70,8 +73,17 @@ def set_server_address_and_port(instance):
|
|
70
73
|
|
71
74
|
return server_address, server_port
|
72
75
|
|
73
|
-
|
74
|
-
|
76
|
+
|
77
|
+
def common_vectordb_logic(
|
78
|
+
scope,
|
79
|
+
environment,
|
80
|
+
application_name,
|
81
|
+
metrics,
|
82
|
+
capture_message_content,
|
83
|
+
disable_metrics,
|
84
|
+
version,
|
85
|
+
instance=None,
|
86
|
+
):
|
75
87
|
"""
|
76
88
|
Process vector database request and generate telemetry.
|
77
89
|
"""
|
@@ -79,25 +91,47 @@ def common_vectordb_logic(scope, environment, application_name,
|
|
79
91
|
scope._end_time = time.time()
|
80
92
|
|
81
93
|
# Set common database span attributes using helper
|
82
|
-
common_db_span_attributes(
|
83
|
-
|
94
|
+
common_db_span_attributes(
|
95
|
+
scope,
|
96
|
+
SemanticConvention.DB_SYSTEM_PINECONE,
|
97
|
+
scope._server_address,
|
98
|
+
scope._server_port,
|
99
|
+
environment,
|
100
|
+
application_name,
|
101
|
+
version,
|
102
|
+
)
|
84
103
|
|
85
104
|
# Set DB operation specific attributes
|
86
105
|
scope._span.set_attribute(SemanticConvention.DB_OPERATION_NAME, scope._db_operation)
|
87
|
-
scope._span.set_attribute(
|
106
|
+
scope._span.set_attribute(
|
107
|
+
SemanticConvention.DB_CLIENT_OPERATION_DURATION,
|
108
|
+
scope._end_time - scope._start_time,
|
109
|
+
)
|
88
110
|
|
89
111
|
# Set Create Index operation specific attributes
|
90
112
|
if scope._db_operation == SemanticConvention.DB_OPERATION_CREATE_COLLECTION:
|
91
113
|
# Standard database attributes
|
92
|
-
scope._span.set_attribute(
|
114
|
+
scope._span.set_attribute(
|
115
|
+
SemanticConvention.DB_COLLECTION_NAME, scope._kwargs.get("name", "")
|
116
|
+
)
|
93
117
|
|
94
118
|
# Vector database specific attributes (extensions)
|
95
|
-
scope._span.set_attribute(
|
96
|
-
|
97
|
-
|
119
|
+
scope._span.set_attribute(
|
120
|
+
SemanticConvention.DB_COLLECTION_DIMENSION,
|
121
|
+
scope._kwargs.get("dimension", -1),
|
122
|
+
)
|
123
|
+
scope._span.set_attribute(
|
124
|
+
SemanticConvention.DB_SEARCH_SIMILARITY_METRIC,
|
125
|
+
scope._kwargs.get("metric", "cosine"),
|
126
|
+
)
|
127
|
+
scope._span.set_attribute(
|
128
|
+
SemanticConvention.DB_COLLECTION_SPEC, str(scope._kwargs.get("spec", ""))
|
129
|
+
)
|
98
130
|
|
99
131
|
elif scope._db_operation == SemanticConvention.DB_OPERATION_SEARCH:
|
100
|
-
namespace = scope._kwargs.get("namespace", "default") or (
|
132
|
+
namespace = scope._kwargs.get("namespace", "default") or (
|
133
|
+
scope._args[0] if scope._args else "unknown"
|
134
|
+
)
|
101
135
|
query = scope._kwargs.get("query", {})
|
102
136
|
|
103
137
|
# Extract query text or vector from different possible locations
|
@@ -110,15 +144,21 @@ def common_vectordb_logic(scope, environment, application_name,
|
|
110
144
|
scope._span.set_attribute(SemanticConvention.DB_NAMESPACE, namespace)
|
111
145
|
|
112
146
|
# Vector database specific attributes (extensions)
|
113
|
-
scope._span.set_attribute(
|
114
|
-
|
147
|
+
scope._span.set_attribute(
|
148
|
+
SemanticConvention.DB_VECTOR_QUERY_TOP_K, query.get("top_k", -1)
|
149
|
+
)
|
150
|
+
scope._span.set_attribute(
|
151
|
+
SemanticConvention.DB_QUERY_SUMMARY,
|
115
152
|
f"{scope._db_operation} {namespace} "
|
116
153
|
f"top_k={query.get('top_k', -1)} "
|
117
154
|
f"text={query_text} "
|
118
|
-
f"vector={query_vector}"
|
155
|
+
f"vector={query_vector}",
|
156
|
+
)
|
119
157
|
|
120
158
|
elif scope._db_operation == SemanticConvention.DB_OPERATION_QUERY:
|
121
|
-
namespace = scope._kwargs.get("namespace", "default") or (
|
159
|
+
namespace = scope._kwargs.get("namespace", "default") or (
|
160
|
+
scope._args[0] if scope._args else "unknown"
|
161
|
+
)
|
122
162
|
query = scope._kwargs.get("vector", [])
|
123
163
|
|
124
164
|
# Standard database attributes
|
@@ -126,16 +166,24 @@ def common_vectordb_logic(scope, environment, application_name,
|
|
126
166
|
scope._span.set_attribute(SemanticConvention.DB_NAMESPACE, namespace)
|
127
167
|
|
128
168
|
# Vector database specific attributes (extensions)
|
129
|
-
scope._span.set_attribute(
|
130
|
-
|
131
|
-
|
169
|
+
scope._span.set_attribute(
|
170
|
+
SemanticConvention.DB_VECTOR_QUERY_TOP_K, scope._kwargs.get("top_k", "")
|
171
|
+
)
|
172
|
+
scope._span.set_attribute(
|
173
|
+
SemanticConvention.DB_FILTER, str(scope._kwargs.get("filter", ""))
|
174
|
+
)
|
175
|
+
scope._span.set_attribute(
|
176
|
+
SemanticConvention.DB_QUERY_SUMMARY,
|
132
177
|
f"{scope._db_operation} {namespace} "
|
133
178
|
f"top_k={scope._kwargs.get('top_k', -1)} "
|
134
179
|
f"filtered={scope._kwargs.get('filter', '')} "
|
135
|
-
f"vector={scope._kwargs.get('vector', '')}"
|
180
|
+
f"vector={scope._kwargs.get('vector', '')}",
|
181
|
+
)
|
136
182
|
|
137
183
|
elif scope._db_operation == SemanticConvention.DB_OPERATION_FETCH:
|
138
|
-
namespace = scope._kwargs.get("namespace", "default") or (
|
184
|
+
namespace = scope._kwargs.get("namespace", "default") or (
|
185
|
+
scope._args[0] if scope._args else "unknown"
|
186
|
+
)
|
139
187
|
query = scope._kwargs.get("ids", [])
|
140
188
|
|
141
189
|
# Standard database attributes
|
@@ -143,13 +191,19 @@ def common_vectordb_logic(scope, environment, application_name,
|
|
143
191
|
scope._span.set_attribute(SemanticConvention.DB_NAMESPACE, namespace)
|
144
192
|
|
145
193
|
# Vector database specific attributes (extensions)
|
146
|
-
scope._span.set_attribute(
|
147
|
-
|
148
|
-
f"ids={query}"
|
149
|
-
|
194
|
+
scope._span.set_attribute(
|
195
|
+
SemanticConvention.DB_QUERY_SUMMARY,
|
196
|
+
f"{scope._db_operation} {namespace} ids={query}",
|
197
|
+
)
|
198
|
+
scope._span.set_attribute(
|
199
|
+
SemanticConvention.DB_RESPONSE_RETURNED_ROWS,
|
200
|
+
object_count(scope._response.vectors),
|
201
|
+
)
|
150
202
|
|
151
203
|
elif scope._db_operation == SemanticConvention.DB_OPERATION_UPDATE:
|
152
|
-
namespace = scope._kwargs.get("namespace") or (
|
204
|
+
namespace = scope._kwargs.get("namespace") or (
|
205
|
+
scope._args[0] if scope._args else "unknown"
|
206
|
+
)
|
153
207
|
query = scope._kwargs.get("id", "")
|
154
208
|
|
155
209
|
# Standard database attributes
|
@@ -157,54 +211,98 @@ def common_vectordb_logic(scope, environment, application_name,
|
|
157
211
|
scope._span.set_attribute(SemanticConvention.DB_NAMESPACE, namespace)
|
158
212
|
|
159
213
|
# Vector database specific attributes (extensions)
|
160
|
-
scope._span.set_attribute(
|
214
|
+
scope._span.set_attribute(
|
215
|
+
SemanticConvention.DB_QUERY_SUMMARY,
|
161
216
|
f"{scope._db_operation} {namespace} "
|
162
217
|
f"id={query} "
|
163
218
|
f"values={scope._kwargs.get('values', [])} "
|
164
|
-
f"set_metadata={scope._kwargs.get('set_metadata', '')}"
|
219
|
+
f"set_metadata={scope._kwargs.get('set_metadata', '')}",
|
220
|
+
)
|
165
221
|
|
166
222
|
elif scope._db_operation == SemanticConvention.DB_OPERATION_UPSERT:
|
167
|
-
namespace = scope._kwargs.get("namespace") or (
|
168
|
-
|
223
|
+
namespace = scope._kwargs.get("namespace") or (
|
224
|
+
scope._args[0] if scope._args else "unknown"
|
225
|
+
)
|
226
|
+
query = scope._kwargs.get("vectors") or (
|
227
|
+
scope._args[1] if len(scope._args) > 1 else None
|
228
|
+
)
|
169
229
|
|
170
230
|
# Standard database attributes
|
171
231
|
scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
|
172
232
|
scope._span.set_attribute(SemanticConvention.DB_NAMESPACE, namespace)
|
173
233
|
|
174
234
|
# Vector database specific attributes (extensions)
|
175
|
-
scope._span.set_attribute(
|
176
|
-
|
177
|
-
|
235
|
+
scope._span.set_attribute(
|
236
|
+
SemanticConvention.DB_VECTOR_COUNT, object_count(query)
|
237
|
+
)
|
238
|
+
scope._span.set_attribute(
|
239
|
+
SemanticConvention.DB_QUERY_SUMMARY,
|
240
|
+
f"{scope._db_operation} {namespace} vectors_count={object_count(query)}",
|
241
|
+
)
|
178
242
|
|
179
243
|
elif scope._db_operation == SemanticConvention.DB_OPERATION_DELETE:
|
180
|
-
namespace = scope._kwargs.get("namespace") or (
|
181
|
-
|
244
|
+
namespace = scope._kwargs.get("namespace") or (
|
245
|
+
scope._args[0] if scope._args else "unknown"
|
246
|
+
)
|
247
|
+
query = scope._kwargs.get("ids") or (
|
248
|
+
scope._args[1] if len(scope._args) > 1 else None
|
249
|
+
)
|
182
250
|
|
183
251
|
# Standard database attributes
|
184
252
|
scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
|
185
253
|
scope._span.set_attribute(SemanticConvention.DB_NAMESPACE, namespace)
|
186
254
|
|
187
255
|
# Vector database specific attributes (extensions)
|
188
|
-
scope._span.set_attribute(
|
189
|
-
|
190
|
-
|
191
|
-
scope._span.set_attribute(
|
256
|
+
scope._span.set_attribute(
|
257
|
+
SemanticConvention.DB_ID_COUNT, object_count(scope._kwargs.get("ids"))
|
258
|
+
)
|
259
|
+
scope._span.set_attribute(
|
260
|
+
SemanticConvention.DB_FILTER, str(scope._kwargs.get("filter", ""))
|
261
|
+
)
|
262
|
+
scope._span.set_attribute(
|
263
|
+
SemanticConvention.DB_DELETE_ALL, scope._kwargs.get("delete_all", False)
|
264
|
+
)
|
265
|
+
scope._span.set_attribute(
|
266
|
+
SemanticConvention.DB_QUERY_SUMMARY,
|
192
267
|
f"{scope._db_operation} {namespace} "
|
193
268
|
f"ids={query} "
|
194
269
|
f"filter={scope._kwargs.get('filter', '')} "
|
195
|
-
f"delete_all={scope._kwargs.get('delete_all', False)}"
|
270
|
+
f"delete_all={scope._kwargs.get('delete_all', False)}",
|
271
|
+
)
|
196
272
|
|
197
273
|
scope._span.set_status(Status(StatusCode.OK))
|
198
274
|
|
199
275
|
# Record metrics using helper
|
200
276
|
if not disable_metrics:
|
201
|
-
record_db_metrics(
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
277
|
+
record_db_metrics(
|
278
|
+
metrics,
|
279
|
+
SemanticConvention.DB_SYSTEM_PINECONE,
|
280
|
+
scope._server_address,
|
281
|
+
scope._server_port,
|
282
|
+
environment,
|
283
|
+
application_name,
|
284
|
+
scope._start_time,
|
285
|
+
scope._end_time,
|
286
|
+
)
|
287
|
+
|
288
|
+
|
289
|
+
def process_vectordb_response(
|
290
|
+
response,
|
291
|
+
db_operation,
|
292
|
+
server_address,
|
293
|
+
server_port,
|
294
|
+
environment,
|
295
|
+
application_name,
|
296
|
+
metrics,
|
297
|
+
start_time,
|
298
|
+
span,
|
299
|
+
capture_message_content=False,
|
300
|
+
disable_metrics=False,
|
301
|
+
version="1.0.0",
|
302
|
+
instance=None,
|
303
|
+
args=None,
|
304
|
+
**kwargs,
|
305
|
+
):
|
208
306
|
"""
|
209
307
|
Process vector database response and generate telemetry following OpenTelemetry conventions.
|
210
308
|
"""
|
@@ -220,7 +318,15 @@ def process_vectordb_response(response, db_operation, server_address, server_por
|
|
220
318
|
scope._server_address = server_address
|
221
319
|
scope._server_port = server_port
|
222
320
|
|
223
|
-
common_vectordb_logic(
|
224
|
-
|
321
|
+
common_vectordb_logic(
|
322
|
+
scope,
|
323
|
+
environment,
|
324
|
+
application_name,
|
325
|
+
metrics,
|
326
|
+
capture_message_content,
|
327
|
+
disable_metrics,
|
328
|
+
version,
|
329
|
+
instance,
|
330
|
+
)
|
225
331
|
|
226
332
|
return response
|
@@ -5,12 +5,11 @@ import importlib.metadata
|
|
5
5
|
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
6
6
|
from wrapt import wrap_function_wrapper
|
7
7
|
|
8
|
-
from openlit.instrumentation.premai.premai import
|
9
|
-
chat, embedding
|
10
|
-
)
|
8
|
+
from openlit.instrumentation.premai.premai import chat, embedding
|
11
9
|
|
12
10
|
_instruments = ("premai >= 0.3.79",)
|
13
11
|
|
12
|
+
|
14
13
|
class PremAIInstrumentor(BaseInstrumentor):
|
15
14
|
"""
|
16
15
|
An instrumentor for Prem AI's client library.
|
@@ -33,16 +32,32 @@ class PremAIInstrumentor(BaseInstrumentor):
|
|
33
32
|
wrap_function_wrapper(
|
34
33
|
"premai.api",
|
35
34
|
"ChatCompletionsModule.create",
|
36
|
-
chat(
|
37
|
-
|
35
|
+
chat(
|
36
|
+
version,
|
37
|
+
environment,
|
38
|
+
application_name,
|
39
|
+
tracer,
|
40
|
+
pricing_info,
|
41
|
+
capture_message_content,
|
42
|
+
metrics,
|
43
|
+
disable_metrics,
|
44
|
+
),
|
38
45
|
)
|
39
46
|
|
40
47
|
# sync embedding
|
41
48
|
wrap_function_wrapper(
|
42
49
|
"premai.api",
|
43
50
|
"EmbeddingsModule.create",
|
44
|
-
embedding(
|
45
|
-
|
51
|
+
embedding(
|
52
|
+
version,
|
53
|
+
environment,
|
54
|
+
application_name,
|
55
|
+
tracer,
|
56
|
+
pricing_info,
|
57
|
+
capture_message_content,
|
58
|
+
metrics,
|
59
|
+
disable_metrics,
|
60
|
+
),
|
46
61
|
)
|
47
62
|
|
48
63
|
def _uninstrument(self, **kwargs):
|