openlit 1.34.25__py3-none-any.whl → 1.34.27__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.
@@ -10,9 +10,37 @@ from openlit.instrumentation.pinecone.async_pinecone import async_general_wrap
10
10
 
11
11
  _instruments = ("pinecone >= 7.3.0",)
12
12
 
13
+ # Pinecone sync operations
14
+ PINECONE_SYNC_OPERATIONS = [
15
+ ("pinecone.pinecone", "Pinecone.create_index", "pinecone.create_collection"),
16
+ ("pinecone.pinecone", "Pinecone.create_index_for_model", "pinecone.create_collection"),
17
+ ("pinecone.db_data.index", "Index.upsert", "pinecone.upsert"),
18
+ ("pinecone.db_data.index", "Index.upsert_records", "pinecone.upsert_records"),
19
+ ("pinecone.db_data.index", "Index.query", "pinecone.query"),
20
+ ("pinecone.db_data.index", "Index.search", "pinecone.search"),
21
+ ("pinecone.db_data.index", "Index.fetch", "pinecone.fetch"),
22
+ ("pinecone.db_data.index", "Index.search_records", "pinecone.search_records"),
23
+ ("pinecone.db_data.index", "Index.update", "pinecone.update"),
24
+ ("pinecone.db_data.index", "Index.delete", "pinecone.delete"),
25
+ ]
26
+
27
+ # Pinecone async operations
28
+ PINECONE_ASYNC_OPERATIONS = [
29
+ ("pinecone.pinecone_asyncio", "PineconeAsyncio.create_index", "pinecone.create_index"),
30
+ ("pinecone.pinecone_asyncio", "PineconeAsyncio.create_index_for_model", "pinecone.create_index"),
31
+ ("pinecone.db_data.index_asyncio", "_IndexAsyncio.upsert", "pinecone.upsert"),
32
+ ("pinecone.db_data.index_asyncio", "_IndexAsyncio.upsert_records", "pinecone.upsert_records"),
33
+ ("pinecone.db_data.index_asyncio", "_IndexAsyncio.query", "pinecone.query"),
34
+ ("pinecone.db_data.index_asyncio", "_IndexAsyncio.search", "pinecone.search"),
35
+ ("pinecone.db_data.index_asyncio", "_IndexAsyncio.fetch", "pinecone.fetch"),
36
+ ("pinecone.db_data.index_asyncio", "_IndexAsyncio.search_records", "pinecone.search_records"),
37
+ ("pinecone.db_data.index_asyncio", "_IndexAsyncio.update", "pinecone.update"),
38
+ ("pinecone.db_data.index_asyncio", "_IndexAsyncio.delete", "pinecone.delete"),
39
+ ]
40
+
13
41
  class PineconeInstrumentor(BaseInstrumentor):
14
42
  """
15
- An instrumentor for Pinecone's client library.
43
+ An instrumentor for Pinecone client library.
16
44
  """
17
45
 
18
46
  def instrumentation_dependencies(self) -> Collection[str]:
@@ -28,147 +56,23 @@ class PineconeInstrumentor(BaseInstrumentor):
28
56
  metrics = kwargs.get("metrics_dict")
29
57
  disable_metrics = kwargs.get("disable_metrics")
30
58
 
31
- # Sync operations
32
- wrap_function_wrapper(
33
- "pinecone.pinecone",
34
- "Pinecone.create_index",
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),
44
- )
45
-
46
- wrap_function_wrapper(
47
- "pinecone.db_data.index",
48
- "Index.upsert",
49
- general_wrap("pinecone.upsert", version, environment, application_name,
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),
58
- )
59
-
60
- wrap_function_wrapper(
61
- "pinecone.db_data.index",
62
- "Index.query",
63
- general_wrap("pinecone.query", version, environment, application_name,
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),
72
- )
73
-
74
- wrap_function_wrapper(
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",
90
- "Index.update",
91
- general_wrap("pinecone.update", version, environment, application_name,
92
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
93
- )
94
-
95
- wrap_function_wrapper(
96
- "pinecone.db_data.index",
97
- "Index.delete",
98
- general_wrap("pinecone.delete", version, environment, application_name,
99
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
100
- )
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
- )
59
+ # Wrap sync operations
60
+ for module, class_method, endpoint in PINECONE_SYNC_OPERATIONS:
61
+ wrap_function_wrapper(
62
+ module,
63
+ class_method,
64
+ general_wrap(endpoint, version, environment, application_name,
65
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
66
+ )
67
+
68
+ # Wrap async operations
69
+ for module, class_method, endpoint in PINECONE_ASYNC_OPERATIONS:
70
+ wrap_function_wrapper(
71
+ module,
72
+ class_method,
73
+ async_general_wrap(endpoint, version, environment, application_name,
74
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
75
+ )
172
76
 
173
77
  def _uninstrument(self, **kwargs):
174
78
  pass
@@ -5,13 +5,11 @@ Module for monitoring Pinecone async API calls.
5
5
  import time
6
6
  from opentelemetry.trace import SpanKind
7
7
  from opentelemetry import context as context_api
8
- from openlit.__helpers import (
9
- handle_exception,
10
- set_server_address_and_port,
11
- )
8
+ from openlit.__helpers import handle_exception
12
9
  from openlit.instrumentation.pinecone.utils import (
13
10
  process_vectordb_response,
14
11
  DB_OPERATION_MAP,
12
+ set_server_address_and_port,
15
13
  )
16
14
 
17
15
  def async_general_wrap(gen_ai_endpoint, version, environment, application_name,
@@ -29,7 +27,7 @@ def async_general_wrap(gen_ai_endpoint, version, environment, application_name,
29
27
  return await wrapped(*args, **kwargs)
30
28
 
31
29
  # Get server address and port using the standard helper
32
- server_address, server_port = set_server_address_and_port(instance, "pinecone.io", 443)
30
+ server_address, server_port = set_server_address_and_port(instance)
33
31
 
34
32
  db_operation = DB_OPERATION_MAP.get(gen_ai_endpoint, "unknown")
35
33
  if db_operation == "create_collection":
@@ -39,10 +37,10 @@ def async_general_wrap(gen_ai_endpoint, version, environment, application_name,
39
37
  span_name = f"{db_operation} {namespace}"
40
38
 
41
39
  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)
40
+ start_time = time.time()
41
+ response = await wrapped(*args, **kwargs)
45
42
 
43
+ try:
46
44
  # Process response and generate telemetry
47
45
  response = process_vectordb_response(
48
46
  response, db_operation, server_address, server_port,
@@ -5,13 +5,11 @@ Module for monitoring Pinecone API calls.
5
5
  import time
6
6
  from opentelemetry.trace import SpanKind
7
7
  from opentelemetry import context as context_api
8
- from openlit.__helpers import (
9
- handle_exception,
10
- set_server_address_and_port,
11
- )
8
+ from openlit.__helpers import handle_exception
12
9
  from openlit.instrumentation.pinecone.utils import (
13
10
  process_vectordb_response,
14
11
  DB_OPERATION_MAP,
12
+ set_server_address_and_port,
15
13
  )
16
14
 
17
15
  def general_wrap(gen_ai_endpoint, version, environment, application_name,
@@ -29,7 +27,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
29
27
  return wrapped(*args, **kwargs)
30
28
 
31
29
  # Get server address and port using the standard helper
32
- server_address, server_port = set_server_address_and_port(instance, "pinecone.io", 443)
30
+ server_address, server_port = set_server_address_and_port(instance)
33
31
 
34
32
  db_operation = DB_OPERATION_MAP.get(gen_ai_endpoint, "unknown")
35
33
  if db_operation == "create_collection":
@@ -39,10 +37,10 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
39
37
  span_name = f"{db_operation} {namespace}"
40
38
 
41
39
  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)
40
+ start_time = time.time()
41
+ response = wrapped(*args, **kwargs)
45
42
 
43
+ try:
46
44
  # Process response and generate telemetry
47
45
  response = process_vectordb_response(
48
46
  response, db_operation, server_address, server_port,
@@ -2,7 +2,7 @@
2
2
  Pinecone OpenTelemetry instrumentation utility functions
3
3
  """
4
4
  import time
5
-
5
+ from urllib.parse import urlparse
6
6
  from opentelemetry.trace import Status, StatusCode
7
7
 
8
8
  from openlit.__helpers import (
@@ -30,6 +30,46 @@ def object_count(obj):
30
30
  """
31
31
  return len(obj) if obj else 0
32
32
 
33
+ def set_server_address_and_port(instance):
34
+ """
35
+ Extracts server address and port from Pinecone client instance.
36
+
37
+ Args:
38
+ instance: Pinecone client instance
39
+
40
+ Returns:
41
+ tuple: (server_address, server_port)
42
+ """
43
+ server_address = "pinecone.io"
44
+ server_port = 443
45
+
46
+ # Try getting base_url from multiple potential attributes
47
+ base_client = getattr(instance, "_client", None)
48
+ base_url = getattr(base_client, "base_url", None)
49
+
50
+ if not base_url:
51
+ # Attempt to get host from instance.config.host (used by Pinecone)
52
+ config = getattr(instance, "config", None)
53
+ base_url = getattr(config, "host", None)
54
+
55
+ if base_url:
56
+ if isinstance(base_url, str):
57
+ # Check if its a full URL or just a hostname
58
+ if base_url.startswith(("http://", "https://")):
59
+ try:
60
+ url = urlparse(base_url)
61
+ if url.hostname:
62
+ server_address = url.hostname
63
+ if url.port:
64
+ server_port = url.port
65
+ except Exception:
66
+ pass
67
+ else:
68
+ # Just a hostname
69
+ server_address = base_url
70
+
71
+ return server_address, server_port
72
+
33
73
  def common_vectordb_logic(scope, environment, application_name,
34
74
  metrics, capture_message_content, disable_metrics, version, instance=None):
35
75
  """