Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sdk): AGE-272 Propagate func errors up in @ag.instrument() wrappers #1846

Merged
merged 4 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading