Skip to content
Merged
Changes from all commits
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
26 changes: 18 additions & 8 deletions langfuse/_client/observe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]: ...

Expand All @@ -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.
Expand Down Expand Up @@ -149,23 +149,33 @@ 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)
else self._sync_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,
)
)
Expand Down
Loading