From 3bd86a5406b4f16b55adca75f83dc3e98bbc1df3 Mon Sep 17 00:00:00 2001 From: James Idzik Date: Mon, 19 Jan 2026 15:06:28 -0500 Subject: [PATCH 1/2] fix: Skip trace url generation when tracing is disabled --- langfuse/_client/client.py | 3 +++ tests/test_core_sdk.py | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/langfuse/_client/client.py b/langfuse/_client/client.py index ded3103e5..cca922a09 100644 --- a/langfuse/_client/client.py +++ b/langfuse/_client/client.py @@ -2429,6 +2429,9 @@ def get_trace_url(self, *, trace_id: Optional[str] = None) -> Optional[str]: send_notification(f"Review needed for trace: {specific_trace_url}") ``` """ + if not self._tracing_enabled: + return None + project_id = self._get_project_id() final_trace_id = trace_id or self.get_current_trace_id() diff --git a/tests/test_core_sdk.py b/tests/test_core_sdk.py index b2661eef5..2888c0554 100644 --- a/tests/test_core_sdk.py +++ b/tests/test_core_sdk.py @@ -1976,6 +1976,19 @@ def test_generate_trace_id(): assert trace_url == f"http://localhost:3000/project/{project_id}/traces/{trace_id}" +def test_generate_trace_url_client_disabled(): + langfuse = Langfuse(tracing_enabled=False) + + with langfuse.start_as_current_span( + name="test-span", + ): + # The trace URL should be None because the client is disabled + trace_url = langfuse.get_trace_url() + assert trace_url is None + + langfuse.flush() + + def test_start_as_current_observation_types(): """Test creating different observation types using start_as_current_observation.""" langfuse = Langfuse() From 618eae24cfe333387b60965d58af9ea8039d2115 Mon Sep 17 00:00:00 2001 From: James Idzik Date: Thu, 22 Jan 2026 11:17:47 -0500 Subject: [PATCH 2/2] Allow fetching trace url when tracing disabled, but api keys available --- langfuse/_client/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/langfuse/_client/client.py b/langfuse/_client/client.py index cca922a09..7c22d9b90 100644 --- a/langfuse/_client/client.py +++ b/langfuse/_client/client.py @@ -2429,11 +2429,11 @@ def get_trace_url(self, *, trace_id: Optional[str] = None) -> Optional[str]: send_notification(f"Review needed for trace: {specific_trace_url}") ``` """ - if not self._tracing_enabled: + final_trace_id = trace_id or self.get_current_trace_id() + if not final_trace_id: return None project_id = self._get_project_id() - final_trace_id = trace_id or self.get_current_trace_id() return ( f"{self._base_url}/project/{project_id}/traces/{final_trace_id}"