Skip to content

Commit

Permalink
feat: Add option to deactivate tracing in service settings (langflow-…
Browse files Browse the repository at this point in the history
…ai#4527)

* Add option to deactivate tracing in service settings

* Add fixture to automatically deactivate tracing in tests using monkeypatch
  • Loading branch information
ogabrielluiz authored and diogocabral committed Nov 26, 2024
1 parent 0bc445e commit fc6c582
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/backend/base/langflow/services/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ class Settings(BaseSettings):
"""The maximum number of retries for the health check."""
max_file_size_upload: int = 100
"""The maximum file size for the upload in MB."""
deactivate_tracing: bool = False
"""If set to True, tracing will be deactivated."""

@field_validator("dev")
@classmethod
Expand Down
8 changes: 7 additions & 1 deletion src/backend/base/langflow/services/tracing/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(self, settings_service: SettingsService):
self.running = False
self.worker_task: asyncio.Task | None = None
self.end_trace_tasks: set[asyncio.Task] = set()
self.deactivated = self.settings_service.settings.deactivate_tracing

async def log_worker(self) -> None:
while self.running or not self.logs_queue.empty():
Expand All @@ -70,7 +71,7 @@ async def log_worker(self) -> None:
self.logs_queue.task_done()

async def start(self) -> None:
if self.running:
if self.running or self.deactivated:
return
try:
self.running = True
Expand Down Expand Up @@ -208,6 +209,9 @@ async def trace_context(
inputs: dict[str, Any],
metadata: dict[str, Any] | None = None,
):
if self.deactivated:
yield self
return
trace_id = trace_name
if component._vertex:
trace_id = component._vertex.id
Expand Down Expand Up @@ -251,6 +255,8 @@ def _cleanup_inputs(self, inputs: dict[str, Any]):
return inputs

def get_langchain_callbacks(self) -> list[BaseCallbackHandler]:
if self.deactivated:
return []
callbacks = []
for tracer in self._tracers.values():
if not tracer.ready: # type: ignore[truthy-function]
Expand Down
7 changes: 7 additions & 0 deletions src/backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ def json_memory_chatbot_no_llm():
return pytest.MEMORY_CHATBOT_NO_LLM.read_text(encoding="utf-8")


@pytest.fixture(autouse=True)
def deactivate_tracing(monkeypatch):
monkeypatch.setenv("LANGFLOW_DEACTIVATE_TRACING", "true")
yield
monkeypatch.undo()


@pytest.fixture(name="client")
async def client_fixture(
session: Session, # noqa: ARG001
Expand Down

0 comments on commit fc6c582

Please sign in to comment.