Skip to content

Commit

Permalink
fix(sdk): AGE-272 Propagate func errors up in @ag.instrument() wrappers
Browse files Browse the repository at this point in the history
Func errors used to be set as func result. Now they are propagated up by forwarding the exception up (raise e).
  • Loading branch information
jp-agenta committed Jul 5, 2024
1 parent bcc99ef commit 0bfc70b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
2 changes: 2 additions & 0 deletions agenta-cli/agenta/sdk/decorators/llm_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ async def wrapper(*args, **kwargs) -> Any:
{"config": config_params, "environment": "playground"}
)

# Exceptions are all handled inside self.execute_function()
llm_result = await self.execute_function(
func, *args, params=func_params, config_params=config_params
)

return llm_result

@functools.wraps(func)
Expand Down
33 changes: 18 additions & 15 deletions agenta-cli/agenta/sdk/decorators/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,20 @@ async def async_wrapper(*args, **kwargs):
try:
result = await func(*args, **kwargs)
self.tracing.update_span_status(span=span, value="OK")
except Exception as e:
result = str(e)
self.tracing.set_span_attribute(
{"traceback_exception": traceback.format_exc()}
)
self.tracing.update_span_status(span=span, value="ERROR")
finally:
self.tracing.end_span(
outputs=(
{"message": result} if not isinstance(result, dict) else result
)
)
return result
return result

except Exception as e:
self.tracing.set_span_attribute(
{"traceback_exception": traceback.format_exc()}
)
self.tracing.update_span_status(span=span, value="ERROR")
self.tracing.end_span(outputs={})
raise e

@wraps(func)
def sync_wrapper(*args, **kwargs):
Expand All @@ -89,17 +90,19 @@ def sync_wrapper(*args, **kwargs):
try:
result = func(*args, **kwargs)
self.tracing.update_span_status(span=span, value="OK")
except Exception as e:
result = str(e)
self.tracing.set_span_attribute(
{"traceback_exception": traceback.format_exc()}
)
self.tracing.update_span_status(span=span, value="ERROR")
finally:
self.tracing.end_span(
outputs=(
{"message": result} if not isinstance(result, dict) else result
)
)
return result

except Exception as e:
self.tracing.set_span_attribute(
{"traceback_exception": traceback.format_exc()}
)
self.tracing.update_span_status(span=span, value="ERROR")
self.tracing.end_span(outputs={})
raise e

return async_wrapper if is_coroutine_function else sync_wrapper
2 changes: 1 addition & 1 deletion agenta-cli/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "agenta"
version = "0.17.5"
version = "0.17.6-alpha.1"
description = "The SDK for agenta is an open-source LLMOps platform."
readme = "README.md"
authors = ["Mahmoud Mabrouk <[email protected]>"]
Expand Down

0 comments on commit 0bfc70b

Please sign in to comment.