|
1 | 1 | import asyncio |
2 | 2 | import inspect |
3 | 3 | import logging |
| 4 | +import os |
4 | 5 | from functools import wraps |
5 | 6 | from typing import ( |
6 | 7 | Any, |
|
20 | 21 |
|
21 | 22 | from typing_extensions import ParamSpec |
22 | 23 |
|
| 24 | +from langfuse._client.environment_variables import ( |
| 25 | + LANGFUSE_OBSERVE_DECORATOR_IO_CAPTURE_ENABLED, |
| 26 | +) |
23 | 27 | from langfuse._client.get_client import get_client |
24 | 28 | from langfuse._client.span import LangfuseGeneration, LangfuseSpan |
25 | 29 | from langfuse.types import TraceContext |
@@ -141,24 +145,28 @@ def sub_process(): |
141 | 145 | - For async functions, the decorator returns an async function wrapper. |
142 | 146 | - For sync functions, the decorator returns a synchronous wrapper. |
143 | 147 | """ |
| 148 | + function_io_capture_enabled = ( |
| 149 | + os.environ.get(LANGFUSE_OBSERVE_DECORATOR_IO_CAPTURE_ENABLED, "True") |
| 150 | + .lower() not in ("false", "0") |
| 151 | + ) |
144 | 152 |
|
145 | 153 | def decorator(func: F) -> F: |
146 | 154 | return ( |
147 | 155 | self._async_observe( |
148 | 156 | func, |
149 | 157 | name=name, |
150 | 158 | as_type=as_type, |
151 | | - capture_input=capture_input, |
152 | | - capture_output=capture_output, |
| 159 | + capture_input=function_io_capture_enabled and capture_input, |
| 160 | + capture_output=function_io_capture_enabled and capture_output, |
153 | 161 | transform_to_string=transform_to_string, |
154 | 162 | ) |
155 | 163 | if asyncio.iscoroutinefunction(func) |
156 | 164 | else self._sync_observe( |
157 | 165 | func, |
158 | 166 | name=name, |
159 | 167 | as_type=as_type, |
160 | | - capture_input=capture_input, |
161 | | - capture_output=capture_output, |
| 168 | + capture_input=function_io_capture_enabled and capture_input, |
| 169 | + capture_output=function_io_capture_enabled and capture_output, |
162 | 170 | transform_to_string=transform_to_string, |
163 | 171 | ) |
164 | 172 | ) |
|
0 commit comments