openlit 1.34.23__py3-none-any.whl → 1.34.24__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 CHANGED
@@ -205,11 +205,22 @@ def set_server_address_and_port(client_instance: Any,
205
205
  config = getattr(client_instance, 'sdk_configuration', None)
206
206
  base_url = getattr(config, 'server_url', None)
207
207
 
208
+ if not base_url:
209
+ # Attempt to get host from instance.config.host (used by Pinecone and other vector DBs)
210
+ config = getattr(client_instance, 'config', None)
211
+ base_url = getattr(config, 'host', None)
212
+
208
213
  if base_url:
209
214
  if isinstance(base_url, str):
210
- url = urlparse(base_url)
211
- server_address = url.hostname or default_server_address
212
- server_port = url.port if url.port is not None else default_server_port
215
+ # Check if it's a full URL or just a hostname
216
+ if base_url.startswith(('http://', 'https://')):
217
+ url = urlparse(base_url)
218
+ server_address = url.hostname or default_server_address
219
+ server_port = url.port if url.port is not None else default_server_port
220
+ else:
221
+ # If it's just a hostname (like Pinecone's case), use it directly
222
+ server_address = base_url
223
+ server_port = default_server_port
213
224
  else: # base_url might not be a str; handle as an object.
214
225
  server_address = getattr(base_url, 'host', None) or default_server_address
215
226
  port_attr = getattr(base_url, 'port', None)
@@ -442,3 +453,37 @@ def record_image_metrics(metrics, gen_ai_operation, gen_ai_system, server_addres
442
453
  metrics["genai_client_operation_duration"].record(end_time - start_time, attributes)
443
454
  metrics["genai_requests"].add(1, attributes)
444
455
  metrics["genai_cost"].record(cost, attributes)
456
+
457
+ def common_db_span_attributes(scope, db_system, server_address, server_port,
458
+ environment, application_name, version):
459
+ """
460
+ Set common span attributes for database operations.
461
+ """
462
+
463
+ scope._span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
464
+ scope._span.set_attribute(SemanticConvention.GEN_AI_OPERATION, SemanticConvention.GEN_AI_OPERATION_TYPE_VECTORDB)
465
+ scope._span.set_attribute(SemanticConvention.DB_SYSTEM_NAME, db_system)
466
+ scope._span.set_attribute(SemanticConvention.SERVER_ADDRESS, server_address)
467
+ scope._span.set_attribute(SemanticConvention.SERVER_PORT, server_port)
468
+ scope._span.set_attribute(DEPLOYMENT_ENVIRONMENT, environment)
469
+ scope._span.set_attribute(SERVICE_NAME, application_name)
470
+ scope._span.set_attribute(SemanticConvention.DB_SDK_VERSION, version)
471
+
472
+ def record_db_metrics(metrics, db_system, server_address, server_port,
473
+ environment, application_name, start_time, end_time):
474
+ """
475
+ Record database-specific metrics for the operation.
476
+ """
477
+
478
+ attributes = create_metrics_attributes(
479
+ operation=SemanticConvention.GEN_AI_OPERATION_TYPE_VECTORDB,
480
+ system=db_system,
481
+ request_model=db_system,
482
+ server_address=server_address,
483
+ server_port=server_port,
484
+ response_model=db_system,
485
+ service_name=application_name,
486
+ deployment_environment=environment,
487
+ )
488
+ metrics["db_requests"].add(1, attributes)
489
+ metrics["db_client_operation_duration"].record(end_time - start_time, attributes)
@@ -1,66 +1,174 @@
1
- # pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
2
1
  """Initializer of Auto Instrumentation of Pinecone Functions"""
2
+
3
3
  from typing import Collection
4
4
  import importlib.metadata
5
5
  from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
6
6
  from wrapt import wrap_function_wrapper
7
7
 
8
8
  from openlit.instrumentation.pinecone.pinecone import general_wrap
9
+ from openlit.instrumentation.pinecone.async_pinecone import async_general_wrap
9
10
 
10
- _instruments = ("pinecone-client >= 2.2.0",)
11
+ _instruments = ("pinecone >= 7.3.0",)
11
12
 
12
13
  class PineconeInstrumentor(BaseInstrumentor):
13
- """An instrumentor for Pinecone's client library."""
14
+ """
15
+ An instrumentor for Pinecone's client library.
16
+ """
14
17
 
15
18
  def instrumentation_dependencies(self) -> Collection[str]:
16
19
  return _instruments
17
20
 
18
21
  def _instrument(self, **kwargs):
19
- application_name = kwargs.get("application_name")
20
- environment = kwargs.get("environment")
22
+ version = importlib.metadata.version("pinecone")
23
+ environment = kwargs.get("environment", "default")
24
+ application_name = kwargs.get("application_name", "default")
21
25
  tracer = kwargs.get("tracer")
26
+ pricing_info = kwargs.get("pricing_info", {})
27
+ capture_message_content = kwargs.get("capture_message_content", False)
22
28
  metrics = kwargs.get("metrics_dict")
23
- pricing_info = kwargs.get("pricing_info")
24
- capture_message_content = kwargs.get("capture_message_content")
25
29
  disable_metrics = kwargs.get("disable_metrics")
26
- version = importlib.metadata.version("pinecone-client")
27
30
 
31
+ # Sync operations
28
32
  wrap_function_wrapper(
29
- "pinecone.control.pinecone",
33
+ "pinecone.pinecone",
30
34
  "Pinecone.create_index",
31
- general_wrap("pinecone.create_index", version, environment, application_name,
32
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
35
+ general_wrap("pinecone.create_collection", version, environment, application_name,
36
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
37
+ )
38
+
39
+ wrap_function_wrapper(
40
+ "pinecone.pinecone",
41
+ "Pinecone.create_index_for_model",
42
+ general_wrap("pinecone.create_collection", version, environment, application_name,
43
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
33
44
  )
34
45
 
35
46
  wrap_function_wrapper(
36
- "pinecone.data.index",
47
+ "pinecone.db_data.index",
37
48
  "Index.upsert",
38
49
  general_wrap("pinecone.upsert", version, environment, application_name,
39
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
50
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
51
+ )
52
+
53
+ wrap_function_wrapper(
54
+ "pinecone.db_data.index",
55
+ "Index.upsert_records",
56
+ general_wrap("pinecone.upsert_records", version, environment, application_name,
57
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
40
58
  )
41
59
 
42
60
  wrap_function_wrapper(
43
- "pinecone.data.index",
61
+ "pinecone.db_data.index",
44
62
  "Index.query",
45
63
  general_wrap("pinecone.query", version, environment, application_name,
46
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
64
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
65
+ )
66
+
67
+ wrap_function_wrapper(
68
+ "pinecone.db_data.index",
69
+ "Index.search",
70
+ general_wrap("pinecone.search", version, environment, application_name,
71
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
47
72
  )
48
73
 
49
74
  wrap_function_wrapper(
50
- "pinecone.data.index",
75
+ "pinecone.db_data.index",
76
+ "Index.fetch",
77
+ general_wrap("pinecone.fetch", version, environment, application_name,
78
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
79
+ )
80
+
81
+ wrap_function_wrapper(
82
+ "pinecone.db_data.index",
83
+ "Index.search_records",
84
+ general_wrap("pinecone.search_records", version, environment, application_name,
85
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
86
+ )
87
+
88
+ wrap_function_wrapper(
89
+ "pinecone.db_data.index",
51
90
  "Index.update",
52
91
  general_wrap("pinecone.update", version, environment, application_name,
53
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
92
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
54
93
  )
55
94
 
56
95
  wrap_function_wrapper(
57
- "pinecone.data.index",
96
+ "pinecone.db_data.index",
58
97
  "Index.delete",
59
98
  general_wrap("pinecone.delete", version, environment, application_name,
60
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
99
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
61
100
  )
62
101
 
102
+ # Async operations
103
+ wrap_function_wrapper(
104
+ "pinecone.pinecone_asyncio",
105
+ "PineconeAsyncio.create_index",
106
+ async_general_wrap("pinecone.create_index", version, environment, application_name,
107
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
108
+ )
109
+
110
+ wrap_function_wrapper(
111
+ "pinecone.pinecone_asyncio",
112
+ "PineconeAsyncio.create_index_for_model",
113
+ async_general_wrap("pinecone.create_index", version, environment, application_name,
114
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
115
+ )
116
+
117
+ wrap_function_wrapper(
118
+ "pinecone.db_data.index_asyncio",
119
+ "_IndexAsyncio.upsert",
120
+ async_general_wrap("pinecone.upsert", version, environment, application_name,
121
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
122
+ )
123
+
124
+ wrap_function_wrapper(
125
+ "pinecone.db_data.index_asyncio",
126
+ "_IndexAsyncio.upsert_records",
127
+ async_general_wrap("pinecone.upsert_records", version, environment, application_name,
128
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
129
+ )
130
+
131
+ wrap_function_wrapper(
132
+ "pinecone.db_data.index_asyncio",
133
+ "_IndexAsyncio.query",
134
+ async_general_wrap("pinecone.query", version, environment, application_name,
135
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
136
+ )
137
+
138
+ wrap_function_wrapper(
139
+ "pinecone.db_data.index_asyncio",
140
+ "_IndexAsyncio.search",
141
+ async_general_wrap("pinecone.search", version, environment, application_name,
142
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
143
+ )
144
+
145
+ wrap_function_wrapper(
146
+ "pinecone.db_data.index_asyncio",
147
+ "_IndexAsyncio.fetch",
148
+ async_general_wrap("pinecone.fetch", version, environment, application_name,
149
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
150
+ )
151
+
152
+ wrap_function_wrapper(
153
+ "pinecone.db_data.index_asyncio",
154
+ "_IndexAsyncio.search_records",
155
+ async_general_wrap("pinecone.search_records", version, environment, application_name,
156
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
157
+ )
158
+
159
+ wrap_function_wrapper(
160
+ "pinecone.db_data.index_asyncio",
161
+ "_IndexAsyncio.update",
162
+ async_general_wrap("pinecone.update", version, environment, application_name,
163
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
164
+ )
165
+
166
+ wrap_function_wrapper(
167
+ "pinecone.db_data.index_asyncio",
168
+ "_IndexAsyncio.delete",
169
+ async_general_wrap("pinecone.delete", version, environment, application_name,
170
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
171
+ )
63
172
 
64
- @staticmethod
65
173
  def _uninstrument(self, **kwargs):
66
174
  pass
@@ -0,0 +1,59 @@
1
+ """
2
+ Module for monitoring Pinecone async API calls.
3
+ """
4
+
5
+ import time
6
+ from opentelemetry.trace import SpanKind
7
+ from opentelemetry import context as context_api
8
+ from openlit.__helpers import (
9
+ handle_exception,
10
+ set_server_address_and_port,
11
+ )
12
+ from openlit.instrumentation.pinecone.utils import (
13
+ process_vectordb_response,
14
+ DB_OPERATION_MAP,
15
+ )
16
+
17
+ def async_general_wrap(gen_ai_endpoint, version, environment, application_name,
18
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):
19
+ """
20
+ Generates a telemetry wrapper for Pinecone async function calls.
21
+ """
22
+
23
+ async def wrapper(wrapped, instance, args, kwargs):
24
+ """
25
+ Wraps the Pinecone async function call.
26
+ """
27
+
28
+ if context_api.get_value(context_api._SUPPRESS_INSTRUMENTATION_KEY):
29
+ return await wrapped(*args, **kwargs)
30
+
31
+ # Get server address and port using the standard helper
32
+ server_address, server_port = set_server_address_and_port(instance, "pinecone.io", 443)
33
+
34
+ db_operation = DB_OPERATION_MAP.get(gen_ai_endpoint, "unknown")
35
+ if db_operation == "create_collection":
36
+ namespace = kwargs.get("name") or (args[0] if args else "unknown")
37
+ else:
38
+ namespace = kwargs.get("namespace") or (args[0] if args else "unknown")
39
+ span_name = f"{db_operation} {namespace}"
40
+
41
+ with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
42
+ try:
43
+ start_time = time.time()
44
+ response = await wrapped(*args, **kwargs)
45
+
46
+ # Process response and generate telemetry
47
+ response = process_vectordb_response(
48
+ response, db_operation, server_address, server_port,
49
+ environment, application_name, metrics, start_time, span,
50
+ capture_message_content, disable_metrics, version, instance, args, **kwargs
51
+ )
52
+
53
+ return response
54
+
55
+ except Exception as e:
56
+ handle_exception(span, e)
57
+ raise
58
+
59
+ return wrapper
@@ -1,173 +1,59 @@
1
- # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, possibly-used-before-assignment
2
1
  """
3
- Module for monitoring Pinecone.
2
+ Module for monitoring Pinecone API calls.
4
3
  """
5
4
 
6
- import logging
7
- from opentelemetry.trace import SpanKind, Status, StatusCode
8
- from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
9
- from openlit.__helpers import handle_exception
10
- from openlit.semcov import SemanticConvention
11
-
12
- # Initialize logger for logging potential issues and operations
13
- logger = logging.getLogger(__name__)
14
-
15
- def object_count(obj):
16
- """
17
- Counts Length of object if it exists, Else returns None
18
- """
19
-
20
- if obj:
21
- return len(obj)
22
-
23
- return None
5
+ import time
6
+ from opentelemetry.trace import SpanKind
7
+ from opentelemetry import context as context_api
8
+ from openlit.__helpers import (
9
+ handle_exception,
10
+ set_server_address_and_port,
11
+ )
12
+ from openlit.instrumentation.pinecone.utils import (
13
+ process_vectordb_response,
14
+ DB_OPERATION_MAP,
15
+ )
24
16
 
25
17
  def general_wrap(gen_ai_endpoint, version, environment, application_name,
26
- tracer, pricing_info, capture_message_content, metrics, disable_metrics):
18
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):
27
19
  """
28
- Wraps a Pinecone operation to trace and log its execution metrics.
29
-
30
- This function is intended to wrap around Pinecone operations in order to
31
- measure their execution time, log relevant information, and trace the execution
32
- using OpenTelemetry. This helps in monitoring and debugging operations within
33
- the Pinecone space.
34
-
35
- Parameters:
36
- - pinecone_operation (str): The specific Pinecone operation being monitored.
37
- Examples include 'create_index', 'query', 'upsert', etc.
38
- - version (str): The version of the application interfacing with Pinecone.
39
- - environment (str): The deployment environment, such as 'production' or 'development'.
40
- - application_name (str): The name of the application performing the Pinecone operation.
41
- - tracer (opentelemetry.trace.Tracer): An object used for OpenTelemetry tracing.
42
- - pricing_info (dict): Information about pricing, not used in current implementation.
43
- - capture_message_content (bool): A flag indicating whether the content of responses should be traced.
44
-
45
- Returns:
46
- - function: A decorator function that, when applied, wraps the target function with
47
- additional functionality for tracing and logging Pinecone operations.
20
+ Generates a telemetry wrapper for Pinecone function calls.
48
21
  """
49
22
 
50
23
  def wrapper(wrapped, instance, args, kwargs):
51
24
  """
52
- Executes the wrapped Pinecone operation, adding tracing and logging.
53
-
54
- This inner wrapper function captures the execution of Pinecone operations,
55
- annotating the operation with relevant metrics and tracing information, and
56
- ensuring any exceptions are caught and logged appropriately.
57
-
58
- Parameters:
59
- - wrapped (Callable): The Pinecone operation to be wrapped and executed.
60
- - instance (object): The instance on which the operation is called (for class methods).
61
- - args (tuple): Positional arguments for the Pinecone operation.
62
- - kwargs (dict): Keyword arguments for the Pinecone operation.
63
-
64
- Returns:
65
- - Any: The result of executing the wrapped Pinecone operation.
25
+ Wraps the Pinecone function call.
66
26
  """
67
27
 
68
- with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
69
- response = wrapped(*args, **kwargs)
70
-
71
- try:
72
- span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
73
- span.set_attribute(SemanticConvention.GEN_AI_ENDPOINT,
74
- gen_ai_endpoint)
75
- span.set_attribute(DEPLOYMENT_ENVIRONMENT,
76
- environment)
77
- span.set_attribute(SERVICE_NAME,
78
- application_name)
79
- span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
80
- SemanticConvention.GEN_AI_OPERATION_TYPE_VECTORDB)
81
- span.set_attribute(SemanticConvention.DB_SYSTEM_NAME,
82
- SemanticConvention.DB_SYSTEM_PINECONE)
83
-
84
- if gen_ai_endpoint == "pinecone.create_index":
85
- db_operation = SemanticConvention.DB_OPERATION_CREATE_INDEX
86
- span.set_attribute(SemanticConvention.DB_OPERATION_NAME,
87
- SemanticConvention.DB_OPERATION_CREATE_INDEX)
88
- span.set_attribute(SemanticConvention.DB_INDEX_NAME,
89
- kwargs.get("name", ""))
90
- span.set_attribute(SemanticConvention.DB_INDEX_DIMENSION,
91
- kwargs.get("dimensions", ""))
92
- span.set_attribute(SemanticConvention.DB_INDEX_METRIC,
93
- kwargs.get("metric", ""))
94
- span.set_attribute(SemanticConvention.DB_INDEX_SPEC,
95
- str(kwargs.get("spec", "")))
96
-
97
- elif gen_ai_endpoint == "pinecone.query":
98
- db_operation = SemanticConvention.DB_OPERATION_QUERY
99
- span.set_attribute(SemanticConvention.DB_OPERATION_NAME,
100
- SemanticConvention.DB_OPERATION_QUERY)
101
- span.set_attribute(SemanticConvention.DB_STATEMENT,
102
- str(kwargs.get("vector")))
103
- span.set_attribute(SemanticConvention.DB_N_RESULTS,
104
- kwargs.get("top_k", ""))
105
- span.set_attribute(SemanticConvention.DB_FILTER,
106
- str(kwargs.get("filter", "")))
107
- span.set_attribute(SemanticConvention.DB_NAMESPACE,
108
- str(kwargs.get("namespace", "")))
28
+ if context_api.get_value(context_api._SUPPRESS_INSTRUMENTATION_KEY):
29
+ return wrapped(*args, **kwargs)
109
30
 
110
- elif gen_ai_endpoint == "pinecone.update":
111
- db_operation = SemanticConvention.DB_OPERATION_UPDATE
112
- span.set_attribute(SemanticConvention.DB_OPERATION_NAME,
113
- SemanticConvention.DB_OPERATION_UPDATE)
114
- span.set_attribute(SemanticConvention.DB_UPDATE_ID,
115
- kwargs.get("id",""))
116
- span.set_attribute(SemanticConvention.DB_UPDATE_VALUES,
117
- str(kwargs.get("values",[])))
118
- span.set_attribute(SemanticConvention.DB_NAMESPACE,
119
- str(kwargs.get("namespace", "")))
120
- span.set_attribute(SemanticConvention.DB_UPDATE_METADATA,
121
- str(kwargs.get("set_metadata", "")))
31
+ # Get server address and port using the standard helper
32
+ server_address, server_port = set_server_address_and_port(instance, "pinecone.io", 443)
122
33
 
123
- elif gen_ai_endpoint == "pinecone.upsert":
124
- db_operation = SemanticConvention.DB_OPERATION_UPSERT
125
- span.set_attribute(SemanticConvention.DB_OPERATION_NAME,
126
- SemanticConvention.DB_OPERATION_UPSERT)
127
- span.set_attribute(SemanticConvention.DB_VECTOR_COUNT,
128
- object_count(kwargs.get("vectors")))
34
+ db_operation = DB_OPERATION_MAP.get(gen_ai_endpoint, "unknown")
35
+ if db_operation == "create_collection":
36
+ namespace = kwargs.get("name") or (args[0] if args else "unknown")
37
+ else:
38
+ namespace = kwargs.get("namespace") or (args[0] if args else "unknown")
39
+ span_name = f"{db_operation} {namespace}"
129
40
 
130
- elif gen_ai_endpoint == "pinecone.delete":
131
- db_operation = SemanticConvention.DB_OPERATION_DELETE
132
- span.set_attribute(SemanticConvention.DB_OPERATION_NAME,
133
- SemanticConvention.DB_OPERATION_DELETE)
134
- span.set_attribute(SemanticConvention.DB_ID_COUNT,
135
- object_count(kwargs.get("ids")))
136
- span.set_attribute(SemanticConvention.DB_FILTER,
137
- str(kwargs.get("filter", "")))
138
- span.set_attribute(SemanticConvention.DB_DELETE_ALL,
139
- kwargs.get("delete_all", False))
140
- span.set_attribute(SemanticConvention.DB_NAMESPACE,
141
- kwargs.get("namespace", ""))
142
-
143
- span.set_status(Status(StatusCode.OK))
144
-
145
- if disable_metrics is False:
146
- attributes = {
147
- TELEMETRY_SDK_NAME:
148
- "openlit",
149
- SERVICE_NAME:
150
- application_name,
151
- SemanticConvention.DB_SYSTEM_NAME:
152
- SemanticConvention.DB_SYSTEM_PINECONE,
153
- DEPLOYMENT_ENVIRONMENT:
154
- environment,
155
- SemanticConvention.GEN_AI_OPERATION:
156
- SemanticConvention.GEN_AI_OPERATION_TYPE_VECTORDB,
157
- SemanticConvention.DB_OPERATION_NAME:
158
- db_operation
159
- }
41
+ with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
42
+ try:
43
+ start_time = time.time()
44
+ response = wrapped(*args, **kwargs)
160
45
 
161
- metrics["db_requests"].add(1, attributes)
46
+ # Process response and generate telemetry
47
+ response = process_vectordb_response(
48
+ response, db_operation, server_address, server_port,
49
+ environment, application_name, metrics, start_time, span,
50
+ capture_message_content, disable_metrics, version, instance, args, **kwargs
51
+ )
162
52
 
163
- # Return original response
164
53
  return response
165
54
 
166
55
  except Exception as e:
167
56
  handle_exception(span, e)
168
- logger.error("Error in trace creation: %s", e)
169
-
170
- # Return original response
171
- return response
57
+ raise
172
58
 
173
59
  return wrapper
@@ -0,0 +1,182 @@
1
+ """
2
+ Pinecone OpenTelemetry instrumentation utility functions
3
+ """
4
+ import time
5
+
6
+ from opentelemetry.trace import Status, StatusCode
7
+
8
+ from openlit.__helpers import (
9
+ common_db_span_attributes,
10
+ record_db_metrics,
11
+ )
12
+ from openlit.semcov import SemanticConvention
13
+
14
+ # Operation mapping for simple span naming
15
+ DB_OPERATION_MAP = {
16
+ "pinecone.create_collection": SemanticConvention.DB_OPERATION_CREATE_COLLECTION,
17
+ "pinecone.upsert": SemanticConvention.DB_OPERATION_UPSERT,
18
+ "pinecone.query": SemanticConvention.DB_OPERATION_QUERY,
19
+ "pinecone.search": SemanticConvention.DB_OPERATION_SEARCH,
20
+ "pinecone.fetch": SemanticConvention.DB_OPERATION_FETCH,
21
+ "pinecone.update": SemanticConvention.DB_OPERATION_UPDATE,
22
+ "pinecone.delete": SemanticConvention.DB_OPERATION_DELETE,
23
+ "pinecone.upsert_records": SemanticConvention.DB_OPERATION_UPSERT,
24
+ "pinecone.search_records": SemanticConvention.DB_OPERATION_QUERY,
25
+ }
26
+
27
+ def object_count(obj):
28
+ """
29
+ Counts length of object if it exists, else returns 0.
30
+ """
31
+ return len(obj) if obj else 0
32
+
33
+ def common_vectordb_logic(scope, environment, application_name,
34
+ metrics, capture_message_content, disable_metrics, version, instance=None):
35
+ """
36
+ Process vector database request and generate telemetry.
37
+ """
38
+
39
+ scope._end_time = time.time()
40
+
41
+ # Set common database span attributes using helper
42
+ common_db_span_attributes(scope, SemanticConvention.DB_SYSTEM_PINECONE, scope._server_address, scope._server_port,
43
+ environment, application_name, version)
44
+
45
+ # Set DB operation specific attributes
46
+ scope._span.set_attribute(SemanticConvention.DB_OPERATION_NAME, scope._db_operation)
47
+ scope._span.set_attribute(SemanticConvention.DB_CLIENT_OPERATION_DURATION, scope._end_time - scope._start_time)
48
+
49
+ # Set Create Index operation specific attributes
50
+ if scope._db_operation == SemanticConvention.DB_OPERATION_CREATE_COLLECTION:
51
+ # Standard database attributes
52
+ scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, scope._kwargs.get("name", ""))
53
+
54
+ # Vector database specific attributes (extensions)
55
+ scope._span.set_attribute(SemanticConvention.DB_COLLECTION_DIMENSION, scope._kwargs.get("dimension", -1))
56
+ scope._span.set_attribute(SemanticConvention.DB_SEARCH_SIMILARITY_METRIC, scope._kwargs.get("metric", "cosine"))
57
+ scope._span.set_attribute(SemanticConvention.DB_COLLECTION_SPEC, str(scope._kwargs.get("spec", "")))
58
+
59
+ elif scope._db_operation == SemanticConvention.DB_OPERATION_SEARCH:
60
+ namespace = scope._kwargs.get("namespace", "default") or (scope._args[0] if scope._args else "unknown")
61
+ query = scope._kwargs.get("query", {})
62
+
63
+ # Extract query text or vector from different possible locations
64
+ query_text = query.get("inputs", {}).get("text", "")
65
+ query_vector = query.get("vector", {})
66
+ query_content = query_text or str(query_vector)
67
+
68
+ # Standard database attributes
69
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, query_content)
70
+ scope._span.set_attribute(SemanticConvention.DB_NAMESPACE, namespace)
71
+
72
+ # Vector database specific attributes (extensions)
73
+ scope._span.set_attribute(SemanticConvention.DB_VECTOR_QUERY_TOP_K, query.get("top_k", -1))
74
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
75
+ f"SEARCH {namespace} top_k={query.get('top_k', -1)} text={query_text} vector={query_vector}")
76
+
77
+ elif scope._db_operation == SemanticConvention.DB_OPERATION_QUERY:
78
+ namespace = scope._kwargs.get("namespace", "default") or (scope._args[0] if scope._args else "unknown")
79
+ query = scope._kwargs.get("vector", [])
80
+
81
+ # Standard database attributes
82
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
83
+ scope._span.set_attribute(SemanticConvention.DB_NAMESPACE, namespace)
84
+
85
+ # Vector database specific attributes (extensions)
86
+ scope._span.set_attribute(SemanticConvention.DB_VECTOR_QUERY_TOP_K, scope._kwargs.get("top_k", ""))
87
+ scope._span.set_attribute(SemanticConvention.DB_FILTER, str(scope._kwargs.get("filter", "")))
88
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
89
+ f"{scope._db_operation} {namespace} "
90
+ f"top_k={scope._kwargs.get('top_k', -1)} "
91
+ f"filtered={scope._kwargs.get('filter', '')} "
92
+ f"vector={scope._kwargs.get('vector', '')}")
93
+
94
+ elif scope._db_operation == SemanticConvention.DB_OPERATION_FETCH:
95
+ namespace = scope._kwargs.get("namespace", "default") or (scope._args[0] if scope._args else "unknown")
96
+ query = scope._kwargs.get("ids", [])
97
+
98
+ # Standard database attributes
99
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
100
+ scope._span.set_attribute(SemanticConvention.DB_NAMESPACE, namespace)
101
+
102
+ # Vector database specific attributes (extensions)
103
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
104
+ f"FETCH {namespace} ids={query}")
105
+ scope._span.set_attribute(SemanticConvention.DB_RESPONSE_RETURNED_ROWS, object_count(scope._response.vectors))
106
+
107
+ elif scope._db_operation == SemanticConvention.DB_OPERATION_UPDATE:
108
+ namespace = scope._kwargs.get("namespace") or (scope._args[0] if scope._args else "unknown")
109
+ query = scope._kwargs.get("id", "")
110
+
111
+ # Standard database attributes
112
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, query)
113
+ scope._span.set_attribute(SemanticConvention.DB_NAMESPACE, namespace)
114
+
115
+ # Vector database specific attributes (extensions)
116
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
117
+ f"{scope._db_operation} {namespace} "
118
+ f"id={query} "
119
+ f"values={scope._kwargs.get('values', [])} "
120
+ f"set_metadata={scope._kwargs.get('set_metadata', '')}")
121
+
122
+ elif scope._db_operation == SemanticConvention.DB_OPERATION_UPSERT:
123
+ namespace = scope._kwargs.get("namespace") or (scope._args[0] if scope._args else "unknown")
124
+ query = scope._kwargs.get("vectors") or (scope._args[1] if len(scope._args) > 1 else None)
125
+
126
+ # Standard database attributes
127
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
128
+ scope._span.set_attribute(SemanticConvention.DB_NAMESPACE, namespace)
129
+
130
+ # Vector database specific attributes (extensions)
131
+ scope._span.set_attribute(SemanticConvention.DB_VECTOR_COUNT, object_count(query))
132
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
133
+ f"{scope._db_operation} {namespace} vectors_count={object_count(query)}")
134
+
135
+ elif scope._db_operation == SemanticConvention.DB_OPERATION_DELETE:
136
+ namespace = scope._kwargs.get("namespace") or (scope._args[0] if scope._args else "unknown")
137
+ query = scope._kwargs.get("ids") or (scope._args[1] if len(scope._args) > 1 else None)
138
+
139
+ # Standard database attributes
140
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
141
+ scope._span.set_attribute(SemanticConvention.DB_NAMESPACE, namespace)
142
+
143
+ # Vector database specific attributes (extensions)
144
+ scope._span.set_attribute(SemanticConvention.DB_ID_COUNT, object_count(scope._kwargs.get("ids")))
145
+ scope._span.set_attribute(SemanticConvention.DB_FILTER, str(scope._kwargs.get("filter", "")))
146
+ scope._span.set_attribute(SemanticConvention.DB_DELETE_ALL, scope._kwargs.get("delete_all", False))
147
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
148
+ f"{scope._db_operation} {namespace} "
149
+ f"ids={query} "
150
+ f"filter={scope._kwargs.get('filter', '')} "
151
+ f"delete_all={scope._kwargs.get('delete_all', False)}")
152
+
153
+ scope._span.set_status(Status(StatusCode.OK))
154
+
155
+ # Record metrics using helper
156
+ if not disable_metrics:
157
+ record_db_metrics(metrics, SemanticConvention.DB_SYSTEM_PINECONE, scope._server_address, scope._server_port,
158
+ environment, application_name, scope._start_time, scope._end_time)
159
+
160
+ def process_vectordb_response(response, db_operation, server_address, server_port,
161
+ environment, application_name, metrics, start_time, span,
162
+ capture_message_content=False, disable_metrics=False,
163
+ version="1.0.0", instance=None, args=None, **kwargs):
164
+ """
165
+ Process vector database response and generate telemetry following OpenTelemetry conventions.
166
+ """
167
+
168
+ scope = type("GenericScope", (), {})()
169
+
170
+ scope._start_time = start_time
171
+ scope._span = span
172
+ scope._kwargs = kwargs
173
+ scope._args = args or []
174
+ scope._db_operation = db_operation
175
+ scope._response = response
176
+ scope._server_address = server_address
177
+ scope._server_port = server_port
178
+
179
+ common_vectordb_logic(scope, environment, application_name,
180
+ metrics, capture_message_content, disable_metrics, version, instance)
181
+
182
+ return response
@@ -23,6 +23,7 @@ class SemanticConvention:
23
23
 
24
24
  # GenAI Metric Names (OTel Semconv)
25
25
  GEN_AI_CLIENT_TOKEN_USAGE = "gen_ai.client.token.usage"
26
+ DB_CLIENT_TOKEN_USAGE = "db.client.token.usage"
26
27
  GEN_AI_CLIENT_OPERATION_DURATION = "gen_ai.client.operation.duration"
27
28
  GEN_AI_SERVER_REQUEST_DURATION = "gen_ai.server.request.duration"
28
29
  GEN_AI_SERVER_TBT = "gen_ai.server.time_per_output_token"
@@ -56,9 +57,12 @@ class SemanticConvention:
56
57
  GEN_AI_RESPONSE_FINISH_REASON = "gen_ai.response.finish_reasons"
57
58
  GEN_AI_RESPONSE_ID = "gen_ai.response.id"
58
59
  GEN_AI_RESPONSE_MODEL = "gen_ai.response.model"
60
+
59
61
  GEN_AI_USAGE_INPUT_TOKENS = "gen_ai.usage.input_tokens"
60
62
  GEN_AI_USAGE_OUTPUT_TOKENS = "gen_ai.usage.output_tokens"
61
63
  GEN_AI_USAGE_REASONING_TOKENS = "gen_ai.usage.reasoning_tokens"
64
+ GEN_AI_USAGE_READ_UNITS = "gen_ai.usage.read_units"
65
+ GEN_AI_USAGE_RERANK_UNITS = "gen_ai.usage.rerank_units"
62
66
  GEN_AI_TOOL_CALL_ID = "gen_ai.tool.call.id"
63
67
  GEN_AI_TOOL_NAME = "gen_ai.tool.name"
64
68
  GEN_AI_TOOL_ARGS = "gen_ai.tool.args"
@@ -190,6 +194,7 @@ class SemanticConvention:
190
194
  DB_NAMESPACE = "db.namespace"
191
195
  DB_OPERATION_NAME = "db.operation.name"
192
196
  DB_QUERY_TEXT = "db.query.text"
197
+ DB_QUERY_SUMMARY = "db.query.summary"
193
198
  DB_RESPONSE_RETURNED_ROWS = "db.response.returned_rows"
194
199
 
195
200
 
@@ -208,6 +213,8 @@ class SemanticConvention:
208
213
  DB_OPERATION_INSERT = "INSERT"
209
214
  DB_OPERATION_SELECT = "SELECT"
210
215
  DB_OPERATION_QUERY = "QUERY"
216
+ DB_OPERATION_SEARCH = "SEARCH"
217
+ DB_OPERATION_FETCH = "FETCH"
211
218
  DB_OPERATION_REPLACE = "findAndModify"
212
219
  DB_OPERATION_FIND_AND_DELETE = "findAndDelete"
213
220
  DB_OPERATION_DELETE = "DELETE"
@@ -217,7 +224,7 @@ class SemanticConvention:
217
224
  DB_OPERATION_ADD = "ADD"
218
225
  DB_OPERATION_PEEK = "peePEEKk"
219
226
  DB_ID_COUNT = "db.ids_count"
220
- DB_VECTOR_COUNT = "db.vector_count"
227
+ DB_VECTOR_COUNT = "db.vector.count"
221
228
  DB_METADATA = "db.metadata"
222
229
  DB_METADATA_COUNT = "db.metadatas_count"
223
230
  DB_DOCUMENTS_COUNT = "db.documents_count"
@@ -230,15 +237,20 @@ class SemanticConvention:
230
237
  DB_N_RESULTS = "db.n_results"
231
238
  DB_DELETE_ALL = "db.delete_all"
232
239
  DB_INDEX_NAME = "db.index.name"
240
+ DB_COLLECTION_DIMENSION = "db.collection.dimension"
233
241
  DB_INDEX_DIMENSION = "db.index.dimension"
234
242
  DB_COLLECTION_DIMENSION = "db.collection.dimension"
243
+ DB_SEARCH_SIMILARITY_METRIC = "db.search.similarity_metric"
235
244
  DB_INDEX_METRIC = "db.create_index.metric"
245
+ DB_COLLECTION_SPEC = "db.collection.spec"
236
246
  DB_INDEX_SPEC = "db.create_index.spec"
237
247
  DB_NAMESPACE = "db.query.namespace"
238
248
  DB_UPDATE_METADATA = "db.update.metadata"
239
249
  DB_UPDATE_VALUES = "db.update.values"
240
250
  DB_UPDATE_ID = "db.update.id"
241
251
  DB_DELETE_ID = "db.delete.id"
252
+ DB_VECTOR_QUERY_TOP_K = "db.vector.query.top_k"
253
+ DB_VECTOR_QUERY_FILTER = "db.vector.query.filter"
242
254
 
243
255
  DB_SYSTEM_CHROMA = "chroma"
244
256
  DB_SYSTEM_PINECONE = "pinecone"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: openlit
3
- Version: 1.34.23
3
+ Version: 1.34.24
4
4
  Summary: OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications and GPUs, facilitating the integration of observability into your GenAI-driven projects
5
5
  License: Apache-2.0
6
6
  Keywords: OpenTelemetry,otel,otlp,llm,tracing,openai,anthropic,claude,cohere,llm monitoring,observability,monitoring,gpt,Generative AI,chatGPT,gpu
@@ -1,4 +1,4 @@
1
- openlit/__helpers.py,sha256=UmW0E97r7UUps2rkdQ-S_lXhaeH3Txp-umyAOon45mk,16458
1
+ openlit/__helpers.py,sha256=kfbLD_rtiOGhd79MuaRK6jjEvbrN8fhZ8b0DACEKkw4,18518
2
2
  openlit/__init__.py,sha256=tYsR2OkDOq7Zf3wBOd3kFfosqUKgZxljMm6mZagMUiI,24296
3
3
  openlit/evals/__init__.py,sha256=nJe99nuLo1b5rf7pt9U9BCdSDedzbVi2Fj96cgl7msM,380
4
4
  openlit/evals/all.py,sha256=oWrue3PotE-rB5WePG3MRYSA-ro6WivkclSHjYlAqGs,7154
@@ -117,8 +117,10 @@ openlit/instrumentation/openai_agents/__init__.py,sha256=tRTSIrUtkXc_lfQnVanXmQL
117
117
  openlit/instrumentation/openai_agents/openai_agents.py,sha256=kRWPgjofcOviMi3w7CsRvJO3SCjqPmuq-PM800vIM7g,2678
118
118
  openlit/instrumentation/phidata/__init__.py,sha256=tqls5-UI6FzbjxYgq_qqAfALhWJm8dHn2NtgqiQA4f8,1557
119
119
  openlit/instrumentation/phidata/phidata.py,sha256=ohrxs6i0Oik75P2BrjNGbK71tdZg94ZMmaXixrXwV5M,4834
120
- openlit/instrumentation/pinecone/__init__.py,sha256=0guSEPmObaZiOF8yHExpOGY-qW_egHXfZGog3rKGi8M,2596
121
- openlit/instrumentation/pinecone/pinecone.py,sha256=7hVUlC0HOj0yQyvLasfdb6kS46hRJQdoSRzZQ4ixIkk,8850
120
+ openlit/instrumentation/pinecone/__init__.py,sha256=DaWkIeG_ukn_JkBfz11TgPjORUUE9vPPjt42dH_26Jk,7210
121
+ openlit/instrumentation/pinecone/async_pinecone.py,sha256=JBQgro4GYQhnp7IMGnk0xmJQJrQZjuVyOwTRc8x3qQU,2098
122
+ openlit/instrumentation/pinecone/pinecone.py,sha256=_Jo_xh44sWDnqv2pA2Jx1ptDol25epJASfxKfHDHrzI,2056
123
+ openlit/instrumentation/pinecone/utils.py,sha256=_Ims5EwmuVd3r2OBg5If2JY7HqsPA_luhmLW9AMsUjw,8995
122
124
  openlit/instrumentation/premai/__init__.py,sha256=3YlqyV-eNA_4aVUHDVUQUvGJRW8iVVcRtREw91yhbyw,1728
123
125
  openlit/instrumentation/premai/premai.py,sha256=rWRqfoIZUbTz-M7zgC2Z92gTVv9fCj1Z4iJcsG86YeI,6438
124
126
  openlit/instrumentation/premai/utils.py,sha256=K7EKGRDDh1X3OznG4z8H506zzFOHN6MH3oqtxM5eUyM,11409
@@ -149,8 +151,8 @@ openlit/instrumentation/vllm/vllm.py,sha256=VzazF2f4LLwjZDO_G8lIN_d622oSJM0fIO9w
149
151
  openlit/otel/events.py,sha256=VrMjTpvnLtYRBHCiFwJojTQqqNpRCxoD4yJYeQrtPsk,3560
150
152
  openlit/otel/metrics.py,sha256=GM2PDloBGRhBTkHHkYaqmOwIAQkY124ZhW4sEqW1Fgk,7086
151
153
  openlit/otel/tracing.py,sha256=tjV2bEbEDPUB1Z46gE-UsJsb04sRdFrfbhIDkxViZc0,3103
152
- openlit/semcov/__init__.py,sha256=8oIh2VC667NDh8FA3M-ESusHmeus1sgDUD8binx_nAc,13519
153
- openlit-1.34.23.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
154
- openlit-1.34.23.dist-info/METADATA,sha256=I28zXVmrGZFQxfl8ayXqVX2YSHYTX0R5upGyteI5tLg,23470
155
- openlit-1.34.23.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
156
- openlit-1.34.23.dist-info/RECORD,,
154
+ openlit/semcov/__init__.py,sha256=9QRSBwOvUS6z7T0HZkE9XlTEnqp-76R_BXM2o4IaEA8,14070
155
+ openlit-1.34.24.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
156
+ openlit-1.34.24.dist-info/METADATA,sha256=NKUgBOoqkr6scsH-Y8H6DVnjV6cf1Cqx0X5MVx1OPHk,23470
157
+ openlit-1.34.24.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
158
+ openlit-1.34.24.dist-info/RECORD,,