Skip to content

Commit e942f6e

Browse files
Fix decorator initialization failures by adding auto-initialization logic
- Add auto-initialization to decorator factory when tracer is not initialized - Follow same pattern as start_trace() function for consistency - Add proper logging for debugging initialization attempts - Maintain backward compatibility by falling back to unwrapped function on failure - Fixes silent failures of @agent, @tool, @task decorators when SDK not initialized Co-Authored-By: Alex <[email protected]>
1 parent 7e961e9 commit e942f6e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

agentops/sdk/decorators/factory.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,16 @@ def wrapper(
8282
wrapped_func: Callable[..., Any], instance: Optional[Any], args: tuple, kwargs: Dict[str, Any]
8383
) -> Any:
8484
if not tracer.initialized:
85-
return wrapped_func(*args, **kwargs)
85+
logger.warning("AgentOps SDK not initialized. Attempting to initialize with defaults before applying decorator.")
86+
try:
87+
from agentops import init
88+
init()
89+
if not tracer.initialized:
90+
logger.error("SDK initialization failed. Decorator will not instrument function.")
91+
return wrapped_func(*args, **kwargs)
92+
except Exception as e:
93+
logger.error(f"SDK auto-initialization failed during decorator application: {e}. Decorator will not instrument function.")
94+
return wrapped_func(*args, **kwargs)
8695

8796
operation_name = name or wrapped_func.__name__
8897
is_async = asyncio.iscoroutinefunction(wrapped_func)

0 commit comments

Comments
 (0)