Skip to content

Commit 1c83406

Browse files
authored
Merge branch 'main' into hassieb/lfe-4865-add-score-metadata
2 parents e9413e2 + 23650a7 commit 1c83406

1 file changed

Lines changed: 17 additions & 18 deletions

File tree

langfuse/_client/client.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,24 @@ 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))
168+
if not 0.0 <= sample_rate <= 1.0:
169+
raise ValueError(f"Sample rate must be between 0.0 and 1.0, got {sample_rate}")
164170

171+
self._tracing_enabled = (
172+
tracing_enabled
173+
and os.environ.get(LANGFUSE_TRACING_ENABLED, "True") != "False"
174+
)
175+
if not self._tracing_enabled:
176+
langfuse_logger.info(
177+
"Configuration: Langfuse tracing is explicitly disabled. No data will be sent to the Langfuse API."
178+
)
179+
180+
debug = debug if debug else (os.getenv(LANGFUSE_DEBUG, "False") == "True")
165181
if debug:
166182
logging.basicConfig(
167183
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
@@ -188,23 +204,6 @@ def __init__(
188204
self._otel_tracer = otel_trace_api.NoOpTracer()
189205
return
190206

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-
208207
# Initialize api and tracer if requirements are met
209208
self._resources = LangfuseResourceManager(
210209
public_key=public_key,

0 commit comments

Comments
 (0)