feat: Add option to deactivate tracing in service settings (#4527)

* Add option to deactivate tracing in service settings

* Add fixture to automatically deactivate tracing in tests using monkeypatch
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-11-12 23:41:07 -03:00 • committed by GitHub
commit 7c0c881488
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 1 deletions

View file

@ -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

View file

@ -58,6 +58,7 @@ class TracingService(Service):
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():
@ -70,7 +71,7 @@ class TracingService(Service):
self.logs_queue.task_done()
async def start(self) -> None:
if self.running:
if self.running or self.deactivated:
return
try:
self.running = True
@ -208,6 +209,9 @@ class TracingService(Service):
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
@ -251,6 +255,8 @@ class TracingService(Service):
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]

View file

@ -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