Skip to content

Commit

Permalink
feat: avoid tracking calls when no nebuly arg is given
Browse files Browse the repository at this point in the history
  • Loading branch information
diegofiori committed Feb 29, 2024
1 parent 0635bb2 commit 5648a49
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 82 deletions.
12 changes: 12 additions & 0 deletions nebuly/monkey_patching.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,14 @@ def _is_generator(obj: Any, module: str) -> bool:
return False


def _is_in_context_manager() -> bool:
try:
get_nearest_open_interaction()
return True
except NotInInteractionContext:
return False


def coroutine_wrapper(
f: Callable[[Any], Any],
observer: Observer,
Expand Down Expand Up @@ -633,6 +641,8 @@ async def wrapper(*args: Any, **kwargs: Any) -> Any:
result = f(*args, **function_kwargs)
else:
result = await f(*args, **function_kwargs)
if len(nebuly_kwargs) == 0 and not _is_in_context_manager():
return result

if _is_generator(result, module):
logger.debug("Result is a generator")
Expand Down Expand Up @@ -735,6 +745,8 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:

called_start = datetime.now(timezone.utc)
result = f(*args, **function_kwargs)
if len(nebuly_kwargs) == 0 and not _is_in_context_manager():
return result

if _is_generator(result, module):
logger.debug("Result is a generator")
Expand Down
Loading

0 comments on commit 5648a49

Please sign in to comment.