veris-ai 1.6.0__py3-none-any.whl → 1.7.0__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.

Potentially problematic release.


This version of veris-ai might be problematic. Click here for more details.

veris_ai/tool_mock.py CHANGED
@@ -172,67 +172,82 @@ class VerisSDK:
172
172
  # If not in simulation mode, execute the original function
173
173
  return await func(*args, **kwargs)
174
174
 
175
- # Handle spy mode - execute original function and log
176
- if mode == "spy":
177
- logger.info(f"Spying on function: {func.__name__}")
178
-
179
- # Log the tool call
180
- sig = inspect.signature(func)
181
- bound_args = sig.bind(*args, **kwargs)
182
- bound_args.apply_defaults()
183
- _ = bound_args.arguments.pop("ctx", None)
184
- _ = bound_args.arguments.pop("self", None)
185
- _ = bound_args.arguments.pop("cls", None)
186
-
187
- await log_tool_call_async(
188
- session_id=self.session_id,
189
- function_name=func.__name__,
190
- parameters=bound_args.arguments,
191
- docstring=inspect.getdoc(func) or "",
192
- )
193
-
194
- # Execute the original function
195
- result = await func(*args, **kwargs)
196
-
197
- # Log the response
198
- await log_tool_response_async(session_id=self.session_id, response=result)
199
-
200
- return result
201
-
202
- # Regular mock mode
203
- base_url = os.getenv("VERIS_ENDPOINT_URL")
204
- if not base_url:
205
- error_msg = "VERIS_ENDPOINT_URL environment variable is not set"
206
- raise ValueError(error_msg)
207
- endpoint = f"{base_url.rstrip('/')}/api/v2/tool_mock"
208
- # Default timeout of 30 seconds
209
- timeout = float(os.getenv("VERIS_MOCK_TIMEOUT", "90.0"))
210
-
211
- logger.info(f"Simulating function: {func.__name__}")
212
- payload, return_type_obj = create_mock_payload(*args, **kwargs)
213
-
214
- # Send request to endpoint with timeout
215
- # Inject current trace context headers if OpenTelemetry is available
216
- headers: dict[str, str] | None = None
175
+ async def _execute_mock_logic(session_id: str) -> object:
176
+ # Handle spy mode - execute original function and log
177
+ if mode == "spy":
178
+ logger.info(f"Spying on function: {func.__name__}")
179
+
180
+ # Log the tool call
181
+ sig = inspect.signature(func)
182
+ bound_args = sig.bind(*args, **kwargs)
183
+ bound_args.apply_defaults()
184
+ _ = bound_args.arguments.pop("ctx", None)
185
+ _ = bound_args.arguments.pop("self", None)
186
+ _ = bound_args.arguments.pop("cls", None)
187
+
188
+ await log_tool_call_async(
189
+ session_id=session_id,
190
+ function_name=func.__name__,
191
+ parameters=bound_args.arguments,
192
+ docstring=inspect.getdoc(func) or "",
193
+ )
194
+
195
+ # Execute the original function
196
+ result = await func(*args, **kwargs)
197
+
198
+ # Log the response
199
+ await log_tool_response_async(session_id=session_id, response=result)
200
+
201
+ return result
202
+
203
+ # Regular mock mode
204
+ base_url = os.getenv("VERIS_ENDPOINT_URL")
205
+ if not base_url:
206
+ error_msg = "VERIS_ENDPOINT_URL environment variable is not set"
207
+ raise ValueError(error_msg)
208
+ endpoint = f"{base_url.rstrip('/')}/api/v2/tool_mock"
209
+ # Default timeout of 30 seconds
210
+ timeout = float(os.getenv("VERIS_MOCK_TIMEOUT", "90.0"))
211
+
212
+ logger.info(f"Simulating function: {func.__name__}")
213
+ payload, return_type_obj = create_mock_payload(*args, **kwargs)
214
+
215
+ # Send request to endpoint with timeout
216
+ # Inject current trace context headers if OpenTelemetry is available
217
+ headers: dict[str, str] | None = None
218
+ try:
219
+ from opentelemetry.propagate import get_global_textmap # type: ignore[import-not-found]
220
+
221
+ headers = {}
222
+ get_global_textmap().inject(headers)
223
+ except Exception: # pragma: no cover - otel optional
224
+ headers = None
225
+
226
+ async with httpx.AsyncClient(timeout=timeout) as client:
227
+ response = await client.post(endpoint, json=payload, headers=headers)
228
+ response.raise_for_status()
229
+ mock_result = response.json()
230
+ logger.info(f"Mock response: {mock_result}")
231
+
232
+ if isinstance(mock_result, str):
233
+ with suppress(json.JSONDecodeError):
234
+ mock_result = json.loads(mock_result)
235
+ return convert_to_type(mock_result, return_type_obj)
236
+ return convert_to_type(mock_result, return_type_obj)
237
+
238
+ # Create a top-level span for the simulated mock call if OpenTelemetry is available
217
239
  try:
218
- from opentelemetry.propagate import get_global_textmap # type: ignore[import-not-found]
219
-
220
- headers = {}
221
- get_global_textmap().inject(headers)
222
- except Exception: # pragma: no cover - otel optional
223
- headers = None
224
-
225
- async with httpx.AsyncClient(timeout=timeout) as client:
226
- response = await client.post(endpoint, json=payload, headers=headers)
227
- response.raise_for_status()
228
- mock_result = response.json()
229
- logger.info(f"Mock response: {mock_result}")
230
-
231
- if isinstance(mock_result, str):
232
- with suppress(json.JSONDecodeError):
233
- mock_result = json.loads(mock_result)
234
- return convert_to_type(mock_result, return_type_obj)
235
- return convert_to_type(mock_result, return_type_obj)
240
+ from opentelemetry import trace # type: ignore[import-not-found]
241
+
242
+ tracer = trace.get_tracer("veris_ai.tool_mock")
243
+ span_name = f"mock.{func.__name__}"
244
+ with tracer.start_as_current_span(span_name) as span: # type: ignore[attr-defined]
245
+ span.set_attribute("veris_ai.session.id", self.session_id or "") # type: ignore[attr-defined]
246
+ span.set_attribute("veris_ai.mock.mode", mode) # type: ignore[attr-defined]
247
+ return await _execute_mock_logic(self.session_id)
248
+ except Exception:
249
+ # If OpenTelemetry is not available, run without span
250
+ return await _execute_mock_logic(self.session_id)
236
251
 
237
252
  @wraps(func)
238
253
  def sync_wrapper(
@@ -244,67 +259,82 @@ class VerisSDK:
244
259
  # If not in simulation mode, execute the original function
245
260
  return func(*args, **kwargs)
246
261
 
247
- # Handle spy mode - execute original function and log
248
- if mode == "spy":
249
- logger.info(f"Spying on function: {func.__name__}")
250
-
251
- # Log the tool call
252
- sig = inspect.signature(func)
253
- bound_args = sig.bind(*args, **kwargs)
254
- bound_args.apply_defaults()
255
- _ = bound_args.arguments.pop("ctx", None)
256
- _ = bound_args.arguments.pop("self", None)
257
- _ = bound_args.arguments.pop("cls", None)
258
-
259
- log_tool_call_sync(
260
- session_id=self.session_id,
261
- function_name=func.__name__,
262
- parameters=bound_args.arguments,
263
- docstring=inspect.getdoc(func) or "",
264
- )
265
-
266
- # Execute the original function
267
- result = func(*args, **kwargs)
268
-
269
- # Log the response
270
- log_tool_response_sync(session_id=self.session_id, response=result)
271
-
272
- return result
273
-
274
- # Regular mock mode
275
- base_url = os.getenv("VERIS_ENDPOINT_URL")
276
- if not base_url:
277
- error_msg = "VERIS_ENDPOINT_URL environment variable is not set"
278
- raise ValueError(error_msg)
279
- endpoint = f"{base_url.rstrip('/')}/api/v2/tool_mock"
280
- # Default timeout of 30 seconds
281
- timeout = float(os.getenv("VERIS_MOCK_TIMEOUT", "90.0"))
282
-
283
- logger.info(f"Simulating function: {func.__name__}")
284
- payload, return_type_obj = create_mock_payload(*args, **kwargs)
285
-
286
- # Send request to endpoint with timeout (synchronous)
287
- # Inject current trace context headers if OpenTelemetry is available
288
- headers: dict[str, str] | None = None
262
+ def _execute_mock_logic(session_id: str) -> object:
263
+ # Handle spy mode - execute original function and log
264
+ if mode == "spy":
265
+ logger.info(f"Spying on function: {func.__name__}")
266
+
267
+ # Log the tool call
268
+ sig = inspect.signature(func)
269
+ bound_args = sig.bind(*args, **kwargs)
270
+ bound_args.apply_defaults()
271
+ _ = bound_args.arguments.pop("ctx", None)
272
+ _ = bound_args.arguments.pop("self", None)
273
+ _ = bound_args.arguments.pop("cls", None)
274
+
275
+ log_tool_call_sync(
276
+ session_id=session_id,
277
+ function_name=func.__name__,
278
+ parameters=bound_args.arguments,
279
+ docstring=inspect.getdoc(func) or "",
280
+ )
281
+
282
+ # Execute the original function
283
+ result = func(*args, **kwargs)
284
+
285
+ # Log the response
286
+ log_tool_response_sync(session_id=session_id, response=result)
287
+
288
+ return result
289
+
290
+ # Regular mock mode
291
+ base_url = os.getenv("VERIS_ENDPOINT_URL")
292
+ if not base_url:
293
+ error_msg = "VERIS_ENDPOINT_URL environment variable is not set"
294
+ raise ValueError(error_msg)
295
+ endpoint = f"{base_url.rstrip('/')}/api/v2/tool_mock"
296
+ # Default timeout of 30 seconds
297
+ timeout = float(os.getenv("VERIS_MOCK_TIMEOUT", "90.0"))
298
+
299
+ logger.info(f"Simulating function: {func.__name__}")
300
+ payload, return_type_obj = create_mock_payload(*args, **kwargs)
301
+
302
+ # Send request to endpoint with timeout (synchronous)
303
+ # Inject current trace context headers if OpenTelemetry is available
304
+ headers: dict[str, str] | None = None
305
+ try:
306
+ from opentelemetry.propagate import get_global_textmap # type: ignore[import-not-found]
307
+
308
+ headers = {}
309
+ get_global_textmap().inject(headers)
310
+ except Exception: # pragma: no cover - otel optional
311
+ headers = None
312
+
313
+ with httpx.Client(timeout=timeout) as client:
314
+ response = client.post(endpoint, json=payload, headers=headers)
315
+ response.raise_for_status()
316
+ mock_result = response.json()
317
+ logger.info(f"Mock response: {mock_result}")
318
+
319
+ if isinstance(mock_result, str):
320
+ with suppress(json.JSONDecodeError):
321
+ mock_result = json.loads(mock_result)
322
+ return convert_to_type(mock_result, return_type_obj)
323
+ return convert_to_type(mock_result, return_type_obj)
324
+
325
+ # Create a top-level span for the simulated mock call if OpenTelemetry is available
289
326
  try:
290
- from opentelemetry.propagate import get_global_textmap # type: ignore[import-not-found]
291
-
292
- headers = {}
293
- get_global_textmap().inject(headers)
294
- except Exception: # pragma: no cover - otel optional
295
- headers = None
296
-
297
- with httpx.Client(timeout=timeout) as client:
298
- response = client.post(endpoint, json=payload, headers=headers)
299
- response.raise_for_status()
300
- mock_result = response.json()
301
- logger.info(f"Mock response: {mock_result}")
302
-
303
- if isinstance(mock_result, str):
304
- with suppress(json.JSONDecodeError):
305
- mock_result = json.loads(mock_result)
306
- return convert_to_type(mock_result, return_type_obj)
307
- return convert_to_type(mock_result, return_type_obj)
327
+ from opentelemetry import trace # type: ignore[import-not-found]
328
+
329
+ tracer = trace.get_tracer("veris_ai.tool_mock")
330
+ span_name = f"mock.{func.__name__}"
331
+ with tracer.start_as_current_span(span_name) as span: # type: ignore[attr-defined]
332
+ span.set_attribute("veris_ai.session.id", self.session_id or "") # type: ignore[attr-defined]
333
+ span.set_attribute("veris_ai.mock.mode", mode) # type: ignore[attr-defined]
334
+ return _execute_mock_logic(self.session_id)
335
+ except Exception:
336
+ # If OpenTelemetry is not available, run without span
337
+ return _execute_mock_logic(self.session_id)
308
338
 
309
339
  # Return the appropriate wrapper based on whether the function is async
310
340
  return async_wrapper if is_async else sync_wrapper
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: veris-ai
3
- Version: 1.6.0
3
+ Version: 1.7.0
4
4
  Summary: A Python package for Veris AI tools
5
5
  Project-URL: Homepage, https://github.com/veris-ai/veris-python-sdk
6
6
  Project-URL: Bug Tracker, https://github.com/veris-ai/veris-python-sdk/issues
@@ -3,13 +3,13 @@ veris_ai/__init__.py,sha256=Gh52-XfFpsxX37uqp8vuX0V3Np7f-Rlf5k3MMANu6e0,425
3
3
  veris_ai/logging.py,sha256=srEdVimcQSCsnwGhyzCydehD2JW1cQmwSRd3X20NQs0,5233
4
4
  veris_ai/models.py,sha256=6HINPxNFCakCVPcyEbUswWkXwb2K4lF0A8g8EvTMal4,213
5
5
  veris_ai/observability.py,sha256=fG5ixAiVDykLCdHUScKQNCsePLphKQ7PcaKkAGBVdF0,5113
6
- veris_ai/tool_mock.py,sha256=GTgHFXJ1Z0SvZje2Ws4bbCNjznFl5IFCJCaCSXkzK1Y,14184
6
+ veris_ai/tool_mock.py,sha256=C1BANT3LCMKOIwJm_nOFuNdHnaO9_tbjeDTtBcI41RI,16512
7
7
  veris_ai/utils.py,sha256=aqFFNuNiBehil6874nOHtU7G_bWHbFpVuubcz2AIx6I,9267
8
8
  veris_ai/jaeger_interface/README.md,sha256=kd9rKcE5xf3EyNaiHu0tjn-0oES9sfaK6Ih-OhhTyCM,2821
9
9
  veris_ai/jaeger_interface/__init__.py,sha256=KD7NSiMYRG_2uF6dOLKkGG5lNQe4K9ptEwucwMT4_aw,1128
10
10
  veris_ai/jaeger_interface/client.py,sha256=yJrh86wRR0Dk3Gq12DId99WogcMIVbL0QQFqVSevvlE,8772
11
11
  veris_ai/jaeger_interface/models.py,sha256=e64VV6IvOEFuzRUgvDAMQFyOZMRb56I-PUPZLBZ3rX0,1864
12
- veris_ai-1.6.0.dist-info/METADATA,sha256=c4BgajmFhmFI-DPmiC4sCJoeLJeZvM6CAY_5Bde2Lkg,8679
13
- veris_ai-1.6.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
- veris_ai-1.6.0.dist-info/licenses/LICENSE,sha256=2g4i20atAgtD5einaKzhQrIB-JrPhyQgD3bC0wkHcCI,1065
15
- veris_ai-1.6.0.dist-info/RECORD,,
12
+ veris_ai-1.7.0.dist-info/METADATA,sha256=dmWFBpwU2MK9tjnJtlrkQdqnR9C0yn0Lhb1TMWb-XvA,8679
13
+ veris_ai-1.7.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
+ veris_ai-1.7.0.dist-info/licenses/LICENSE,sha256=2g4i20atAgtD5einaKzhQrIB-JrPhyQgD3bC0wkHcCI,1065
15
+ veris_ai-1.7.0.dist-info/RECORD,,