Skip to content

Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.

[Fix]: token treated as a context manager when using Async Agno (#844)

Guy Rosin72f4a2b34996
diff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.toml
index 8dfb2886..94e2f7f2 100644
--- a/sdk/python/pyproject.toml
+++ b/sdk/python/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "openlit"
-version = "1.34.38"
+version = "1.34.39"
description = "OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications and GPUs, facilitating the integration of observability into your GenAI-driven projects"
authors = ["OpenLIT"]
license = "Apache-2.0"
diff --git a/sdk/python/src/openlit/instrumentation/agno/async_agno.py b/sdk/python/src/openlit/instrumentation/agno/async_agno.py
index 21906140..3a58c739 100644
--- a/sdk/python/src/openlit/instrumentation/agno/async_agno.py
+++ b/sdk/python/src/openlit/instrumentation/agno/async_agno.py
@@ -61,10 +61,13 @@ def async_agent_run_wrap(
) as span:
start_time = time.time()
# CRITICAL: Set the span context as current for nested calls
- with context_api.attach(
+ token = context_api.attach(
context_api.set_value("current_span", span, current_context)
- ):
+ )
+ try:
response = await wrapped(*args, **kwargs)
+ finally:
+ context_api.detach(token)
try:
# Process request using utils function with ALL attributes from semcov
@@ -195,11 +198,13 @@ def async_model_run_function_call_wrap(
) as span:
start_time = time.time()
# CRITICAL: Set the span context as current for nested calls
- with context_api.attach(
+ token = context_api.attach(
context_api.set_value("current_span", span, current_context)
- ):
+ )
+ try:
result = await wrapped(*args, **kwargs)
-
+ finally:
+ context_api.detach(token)
try:
# Process request using utils function with ALL attributes from semcov
process_tool_request(
@@ -266,10 +271,13 @@ def async_function_entrypoint_wrap(
) as span:
start_time = time.time()
# CRITICAL: Set the span context as current for nested calls
- with context_api.attach(
+ token = context_api.attach(
context_api.set_value("current_span", span, current_context)
- ):
+ )
+ try:
result = await wrapped(*args, **kwargs)
+ finally:
+ context_api.detach(token)
try:
# Process request using utils function with ALL attributes from semcov
@@ -857,10 +865,13 @@ def async_function_execute_wrap(
# Execute async tool with timing
start_time = time.time()
# CRITICAL: Set the span context as current for nested calls
- with context_api.attach(
+ token = context_api.attach(
context_api.set_value("current_span", span, current_context)
- ):
+ )
+ try:
result = await wrapped(*args, **kwargs)
+ finally:
+ context_api.detach(token)
try:
# Process request using utils function with ALL attributes from semcov