You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The tracing/service.py service is a singleton, responsible for starting the tracers (langwatch, langsmith, langfuse) whenever a run happens. The problem is, when using a nested workflow, for example with "Flow as a Tool", this service gets reinitialized with a different run id, overriding the last one. As a result, the parent run is stop being tracked (unless for langchain callbacks that go on), and children runs each become new traces, with no run id connection to their parents
Moreover, when two flows are run in parallel, the last one to start sets the runId, so components executed in the first one might also end up being tracked there, as visible on the screenshot on this PR: #3830
As a solution, the tracing service should probably either stop being a singleton, at least not a global one (could be per run thread) and keep the parent reference OR it could stay a singleton but components during execution would inform their run id during tracing service calls and the singleton would keep the relation of parent and children runs to be passed for the tracing services to correct assemble the tree of calls, either on the same trace or separate tracers per child
Reproduction
Create a simple flow, just input/output, maybe an LLM call in the middle
Create another flow and use Flow as a Tool for the first one, tell the tool calling agent to call the tool twice, exactly and only twice
You can add print statements on the def initialize_tracers, def _start_traces, def _end_traces and def _end_all_traces for the self.run_id to see that it always changes to the last one to be executed
Expected behavior
_start_traces should know which run_id it is starting a trace for, so they don't get all tangled up together
Hey @rogeriochaves! I'm here to help you with any bugs, questions, or contributions you have for the Langflow framework. Let's tackle this issue together and get it resolved!
To resolve the issue with the tracing/service.py singleton reinitializing tracers for nested workflows, causing loss of tracking for parent runs and incorrect associations between parent and child runs, you need to ensure that tracers are not reinitialized for nested workflows. Instead, maintain the existing tracer context for nested workflows.
Here is a possible solution:
Modify the initialize_tracers method to check if tracers are already initialized.
Ensure that nested workflows use the existing tracer context.
This modification ensures that tracers are not reinitialized for nested workflows, preserving the tracking for parent runs and maintaining correct associations between parent and child runs [1][2].
Bug Description
The
tracing/service.py
service is a singleton, responsible for starting the tracers (langwatch, langsmith, langfuse) whenever a run happens. The problem is, when using a nested workflow, for example with "Flow as a Tool", this service gets reinitialized with a different run id, overriding the last one. As a result, the parent run is stop being tracked (unless for langchain callbacks that go on), and children runs each become new traces, with no run id connection to their parentsMoreover, when two flows are run in parallel, the last one to start sets the runId, so components executed in the first one might also end up being tracked there, as visible on the screenshot on this PR: #3830
As a solution, the tracing service should probably either stop being a singleton, at least not a global one (could be per run thread) and keep the parent reference OR it could stay a singleton but components during execution would inform their run id during tracing service calls and the singleton would keep the relation of parent and children runs to be passed for the tracing services to correct assemble the tree of calls, either on the same trace or separate tracers per child
Reproduction
def initialize_tracers
,def _start_traces
,def _end_traces
anddef _end_all_traces
for theself.run_id
to see that it always changes to the last one to be executedExpected behavior
_start_traces
should know which run_id it is starting a trace for, so they don't get all tangled up togetherWho can help?
No response
Operating System
Mac OS
Langflow Version
1.0.18
Python Version
3.11
Screenshot
No response
Flow File
20240917120814097_langflow_flows.zip
The text was updated successfully, but these errors were encountered: