From a98d0682073d3a7f92a947651324760a530e7c55 Mon Sep 17 00:00:00 2001 From: Hassieb Pakzad <68423100+hassiebp@users.noreply.github.com> Date: Tue, 24 Jun 2025 13:52:15 +0200 Subject: [PATCH] fix(observe): default IO capture on decorated functions --- langfuse/_client/observe.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/langfuse/_client/observe.py b/langfuse/_client/observe.py index cdfb04d7b..e37e91e99 100644 --- a/langfuse/_client/observe.py +++ b/langfuse/_client/observe.py @@ -65,8 +65,8 @@ def observe( *, name: Optional[str] = None, as_type: Optional[Literal["generation"]] = None, - capture_input: bool = True, - capture_output: bool = True, + capture_input: Optional[bool] = None, + capture_output: Optional[bool] = None, transform_to_string: Optional[Callable[[Iterable], str]] = None, ) -> Callable[[F], F]: ... @@ -76,8 +76,8 @@ def observe( *, name: Optional[str] = None, as_type: Optional[Literal["generation"]] = None, - capture_input: bool = True, - capture_output: bool = True, + capture_input: Optional[bool] = None, + capture_output: Optional[bool] = None, transform_to_string: Optional[Callable[[Iterable], str]] = None, ) -> Union[F, Callable[[F], F]]: """Wrap a function to create and manage Langfuse tracing around its execution, supporting both synchronous and asynchronous functions. @@ -149,14 +149,24 @@ def sub_process(): LANGFUSE_OBSERVE_DECORATOR_IO_CAPTURE_ENABLED, "True" ).lower() not in ("false", "0") + should_capture_input = ( + capture_input if capture_input is not None else function_io_capture_enabled + ) + + should_capture_output = ( + capture_output + if capture_output is not None + else function_io_capture_enabled + ) + def decorator(func: F) -> F: return ( self._async_observe( func, name=name, as_type=as_type, - capture_input=function_io_capture_enabled and capture_input, - capture_output=function_io_capture_enabled and capture_output, + capture_input=should_capture_input, + capture_output=should_capture_output, transform_to_string=transform_to_string, ) if asyncio.iscoroutinefunction(func) @@ -164,8 +174,8 @@ def decorator(func: F) -> F: func, name=name, as_type=as_type, - capture_input=function_io_capture_enabled and capture_input, - capture_output=function_io_capture_enabled and capture_output, + capture_input=should_capture_input, + capture_output=should_capture_output, transform_to_string=transform_to_string, ) )