Skip to content
Merged
Show file tree
Hide file tree
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
35 changes: 17 additions & 18 deletions langfuse/_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,24 @@ def __init__(
sample_rate: Optional[float] = None,
mask: Optional[MaskFunction] = None,
):
debug = debug if debug else (os.getenv(LANGFUSE_DEBUG, "False") == "True")
self._host = host or os.environ.get(LANGFUSE_HOST, "https://cloud.langfuse.com")
self._environment = environment or os.environ.get(LANGFUSE_TRACING_ENVIRONMENT)
self._mask = mask
self._project_id = None
sample_rate = sample_rate or float(os.environ.get(LANGFUSE_SAMPLE_RATE, 1.0))
if not 0.0 <= sample_rate <= 1.0:
raise ValueError(f"Sample rate must be between 0.0 and 1.0, got {sample_rate}")

self._tracing_enabled = (
tracing_enabled
and os.environ.get(LANGFUSE_TRACING_ENABLED, "True") != "False"
)
if not self._tracing_enabled:
langfuse_logger.info(
"Configuration: Langfuse tracing is explicitly disabled. No data will be sent to the Langfuse API."
)

debug = debug if debug else (os.getenv(LANGFUSE_DEBUG, "False") == "True")
if debug:
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
Expand All @@ -188,23 +204,6 @@ def __init__(
self._otel_tracer = otel_trace_api.NoOpTracer()
return

self._host = host or os.environ.get(LANGFUSE_HOST, "https://cloud.langfuse.com")
self._environment = environment or os.environ.get(LANGFUSE_TRACING_ENVIRONMENT)
sample_rate = sample_rate or float(os.environ.get(LANGFUSE_SAMPLE_RATE, 1.0))

self._tracing_enabled = (
tracing_enabled
and os.environ.get(LANGFUSE_TRACING_ENABLED, "True") != "False"
)

if not self._tracing_enabled:
langfuse_logger.info(
"Configuration: Langfuse tracing is explicitly disabled. No data will be sent to the Langfuse API."
)

self._mask = mask
self._project_id = None

# Initialize api and tracer if requirements are met
self._resources = LangfuseResourceManager(
public_key=public_key,
Expand Down
7 changes: 3 additions & 4 deletions langfuse/_client/observe.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,9 @@ def sub_process():
- For async functions, the decorator returns an async function wrapper.
- For sync functions, the decorator returns a synchronous wrapper.
"""
function_io_capture_enabled = (
os.environ.get(LANGFUSE_OBSERVE_DECORATOR_IO_CAPTURE_ENABLED, "True")
.lower() not in ("false", "0")
)
function_io_capture_enabled = os.environ.get(
LANGFUSE_OBSERVE_DECORATOR_IO_CAPTURE_ENABLED, "True"
).lower() not in ("false", "0")

def decorator(func: F) -> F:
return (
Expand Down