Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve end_traces so it doesn't block the build loop #3482

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/backend/base/langflow/graph/graph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ def __init__(
edges (List[Dict[str, str]]): A list of dictionaries representing the edges of the graph.
flow_id (Optional[str], optional): The ID of the flow. Defaults to None.
"""
if not log_config:
log_config = {"disable": False}
configure(**log_config)
if log_config:
configure(**log_config)
self._start = start
self._state_model = None
self._end = end
Expand Down
12 changes: 8 additions & 4 deletions src/backend/base/langflow/services/tracing/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
from collections import defaultdict
from contextlib import asynccontextmanager
from typing import TYPE_CHECKING, Any, Dict, Optional, List
from typing import TYPE_CHECKING, Any, Dict, List, Optional
from uuid import UUID

from loguru import logger
Expand All @@ -12,11 +12,12 @@
from langflow.services.tracing.schema import Log

if TYPE_CHECKING:
from langchain.callbacks.base import BaseCallbackHandler

from langflow.custom.custom_component.component import Component
from langflow.graph.vertex.base import Vertex
from langflow.services.monitor.service import MonitorService
from langflow.services.settings.service import SettingsService
from langchain.callbacks.base import BaseCallbackHandler


def _get_langsmith_tracer():
Expand Down Expand Up @@ -210,8 +211,11 @@ async def trace_context(
self._end_traces(trace_id, trace_name, e)
raise e
finally:
self._end_traces(trace_id, trace_name, None)
self._reset_io()
asyncio.create_task(asyncio.to_thread(self._end_and_reset, trace_id, trace_name, None))

async def _end_and_reset(self, trace_id: str, trace_name: str, error: Exception | None = None):
self._end_traces(trace_id, trace_name, error)
self._reset_io()

def set_outputs(
self,
Expand Down
Loading