Skip to content

Commit a720608

Browse files
authored
fix(observe): default IO capture on decorated functions (#1221)
1 parent 0ce92db commit a720608

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

langfuse/_client/observe.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ def observe(
6565
*,
6666
name: Optional[str] = None,
6767
as_type: Optional[Literal["generation"]] = None,
68-
capture_input: bool = True,
69-
capture_output: bool = True,
68+
capture_input: Optional[bool] = None,
69+
capture_output: Optional[bool] = None,
7070
transform_to_string: Optional[Callable[[Iterable], str]] = None,
7171
) -> Callable[[F], F]: ...
7272

@@ -76,8 +76,8 @@ def observe(
7676
*,
7777
name: Optional[str] = None,
7878
as_type: Optional[Literal["generation"]] = None,
79-
capture_input: bool = True,
80-
capture_output: bool = True,
79+
capture_input: Optional[bool] = None,
80+
capture_output: Optional[bool] = None,
8181
transform_to_string: Optional[Callable[[Iterable], str]] = None,
8282
) -> Union[F, Callable[[F], F]]:
8383
"""Wrap a function to create and manage Langfuse tracing around its execution, supporting both synchronous and asynchronous functions.
@@ -149,23 +149,33 @@ def sub_process():
149149
LANGFUSE_OBSERVE_DECORATOR_IO_CAPTURE_ENABLED, "True"
150150
).lower() not in ("false", "0")
151151

152+
should_capture_input = (
153+
capture_input if capture_input is not None else function_io_capture_enabled
154+
)
155+
156+
should_capture_output = (
157+
capture_output
158+
if capture_output is not None
159+
else function_io_capture_enabled
160+
)
161+
152162
def decorator(func: F) -> F:
153163
return (
154164
self._async_observe(
155165
func,
156166
name=name,
157167
as_type=as_type,
158-
capture_input=function_io_capture_enabled and capture_input,
159-
capture_output=function_io_capture_enabled and capture_output,
168+
capture_input=should_capture_input,
169+
capture_output=should_capture_output,
160170
transform_to_string=transform_to_string,
161171
)
162172
if asyncio.iscoroutinefunction(func)
163173
else self._sync_observe(
164174
func,
165175
name=name,
166176
as_type=as_type,
167-
capture_input=function_io_capture_enabled and capture_input,
168-
capture_output=function_io_capture_enabled and capture_output,
177+
capture_input=should_capture_input,
178+
capture_output=should_capture_output,
169179
transform_to_string=transform_to_string,
170180
)
171181
)

0 commit comments

Comments
 (0)