Skip to content

Commit 1fb2d50

Browse files
committed
fix(core): gracefully handle missing keys
1 parent 26fd9e3 commit 1fb2d50

2 files changed

Lines changed: 18 additions & 22 deletions

File tree

langfuse/_client/client.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,22 @@ def __init__(
160160
sample_rate: Optional[float] = None,
161161
mask: Optional[MaskFunction] = None,
162162
):
163-
debug = debug if debug else (os.getenv(LANGFUSE_DEBUG, "False") == "True")
163+
self._host = host or os.environ.get(LANGFUSE_HOST, "https://cloud.langfuse.com")
164+
self._environment = environment or os.environ.get(LANGFUSE_TRACING_ENVIRONMENT)
165+
self._mask = mask
166+
self._project_id = None
167+
sample_rate = sample_rate or float(os.environ.get(LANGFUSE_SAMPLE_RATE, 1.0))
164168

169+
self._tracing_enabled = (
170+
tracing_enabled
171+
and os.environ.get(LANGFUSE_TRACING_ENABLED, "True") != "False"
172+
)
173+
if not self._tracing_enabled:
174+
langfuse_logger.info(
175+
"Configuration: Langfuse tracing is explicitly disabled. No data will be sent to the Langfuse API."
176+
)
177+
178+
debug = debug if debug else (os.getenv(LANGFUSE_DEBUG, "False") == "True")
165179
if debug:
166180
logging.basicConfig(
167181
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
@@ -188,23 +202,6 @@ def __init__(
188202
self._otel_tracer = otel_trace_api.NoOpTracer()
189203
return
190204

191-
self._host = host or os.environ.get(LANGFUSE_HOST, "https://cloud.langfuse.com")
192-
self._environment = environment or os.environ.get(LANGFUSE_TRACING_ENVIRONMENT)
193-
sample_rate = sample_rate or float(os.environ.get(LANGFUSE_SAMPLE_RATE, 1.0))
194-
195-
self._tracing_enabled = (
196-
tracing_enabled
197-
and os.environ.get(LANGFUSE_TRACING_ENABLED, "True") != "False"
198-
)
199-
200-
if not self._tracing_enabled:
201-
langfuse_logger.info(
202-
"Configuration: Langfuse tracing is explicitly disabled. No data will be sent to the Langfuse API."
203-
)
204-
205-
self._mask = mask
206-
self._project_id = None
207-
208205
# Initialize api and tracer if requirements are met
209206
self._resources = LangfuseResourceManager(
210207
public_key=public_key,

langfuse/_client/observe.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,9 @@ def sub_process():
145145
- For async functions, the decorator returns an async function wrapper.
146146
- For sync functions, the decorator returns a synchronous wrapper.
147147
"""
148-
function_io_capture_enabled = (
149-
os.environ.get(LANGFUSE_OBSERVE_DECORATOR_IO_CAPTURE_ENABLED, "True")
150-
.lower() not in ("false", "0")
151-
)
148+
function_io_capture_enabled = os.environ.get(
149+
LANGFUSE_OBSERVE_DECORATOR_IO_CAPTURE_ENABLED, "True"
150+
).lower() not in ("false", "0")
152151

153152
def decorator(func: F) -> F:
154153
return (

0 commit comments

Comments
 (0)