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:
parent
e68c21a7af
commit
7c0c881488
3 changed files with 16 additions and 1 deletions
|
|
@ -171,6 +171,8 @@ class Settings(BaseSettings):
|
||||||
"""The maximum number of retries for the health check."""
|
"""The maximum number of retries for the health check."""
|
||||||
max_file_size_upload: int = 100
|
max_file_size_upload: int = 100
|
||||||
"""The maximum file size for the upload in MB."""
|
"""The maximum file size for the upload in MB."""
|
||||||
|
deactivate_tracing: bool = False
|
||||||
|
"""If set to True, tracing will be deactivated."""
|
||||||
|
|
||||||
@field_validator("dev")
|
@field_validator("dev")
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ class TracingService(Service):
|
||||||
self.running = False
|
self.running = False
|
||||||
self.worker_task: asyncio.Task | None = None
|
self.worker_task: asyncio.Task | None = None
|
||||||
self.end_trace_tasks: set[asyncio.Task] = set()
|
self.end_trace_tasks: set[asyncio.Task] = set()
|
||||||
|
self.deactivated = self.settings_service.settings.deactivate_tracing
|
||||||
|
|
||||||
async def log_worker(self) -> None:
|
async def log_worker(self) -> None:
|
||||||
while self.running or not self.logs_queue.empty():
|
while self.running or not self.logs_queue.empty():
|
||||||
|
|
@ -70,7 +71,7 @@ class TracingService(Service):
|
||||||
self.logs_queue.task_done()
|
self.logs_queue.task_done()
|
||||||
|
|
||||||
async def start(self) -> None:
|
async def start(self) -> None:
|
||||||
if self.running:
|
if self.running or self.deactivated:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
self.running = True
|
self.running = True
|
||||||
|
|
@ -208,6 +209,9 @@ class TracingService(Service):
|
||||||
inputs: dict[str, Any],
|
inputs: dict[str, Any],
|
||||||
metadata: dict[str, Any] | None = None,
|
metadata: dict[str, Any] | None = None,
|
||||||
):
|
):
|
||||||
|
if self.deactivated:
|
||||||
|
yield self
|
||||||
|
return
|
||||||
trace_id = trace_name
|
trace_id = trace_name
|
||||||
if component._vertex:
|
if component._vertex:
|
||||||
trace_id = component._vertex.id
|
trace_id = component._vertex.id
|
||||||
|
|
@ -251,6 +255,8 @@ class TracingService(Service):
|
||||||
return inputs
|
return inputs
|
||||||
|
|
||||||
def get_langchain_callbacks(self) -> list[BaseCallbackHandler]:
|
def get_langchain_callbacks(self) -> list[BaseCallbackHandler]:
|
||||||
|
if self.deactivated:
|
||||||
|
return []
|
||||||
callbacks = []
|
callbacks = []
|
||||||
for tracer in self._tracers.values():
|
for tracer in self._tracers.values():
|
||||||
if not tracer.ready: # type: ignore[truthy-function]
|
if not tracer.ready: # type: ignore[truthy-function]
|
||||||
|
|
|
||||||
|
|
@ -277,6 +277,13 @@ def json_memory_chatbot_no_llm():
|
||||||
return pytest.MEMORY_CHATBOT_NO_LLM.read_text(encoding="utf-8")
|
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")
|
@pytest.fixture(name="client")
|
||||||
async def client_fixture(
|
async def client_fixture(
|
||||||
session: Session, # noqa: ARG001
|
session: Session, # noqa: ARG001
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue