Langflow (tracing)

Langflow is a visual framework by DataStax for building multi-agent and RAG applications. It provides a drag-and-drop interface for composing LLM pipelines with components for models, prompts, tools, and data sources. Langflow is built on LangChain, so Respan tracing uses respan-instrumentation-langchain to capture component runs, underlying LangChain calls, tools, retrievers, and LLM generations — and gateway routing through the OpenAI-compatible Respan endpoint.

Create an account at platform.respan.ai and grab an API key.

Run npx @respan/cli setup to set up with your coding agent.

See Langflow gateway setup to route this integration through the Respan gateway.

Setup

1

Install packages

$pip install respan-ai respan-instrumentation-langchain langflow langchain langchain-openai python-dotenv
2

Set environment variables

$export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
$export RESPAN_BASE_URL="https://api.respan.ai/api"

RESPAN_API_KEY is used to export traces to Respan. Set OPENAI_API_KEY too when your Langflow components call provider-backed models.

3

Initialize and run

Pass LangChainInstrumentor() to Respan(instrumentations=[...]). Langflow is built on LangChain, so in Python component runs are traced automatically. Reuse one callback handler when you want independent component runs grouped into a single trace.

There are two ways to run Langflow with tracing: run custom-component code directly (as below), or run a flow you built in the Langflow UI. A UI flow must be exported first (Share → Export) to a flow.json before run_flow_from_json can load it — this quickstart ships no standalone flow file, so the runnable example uses component code directly.

1from langchain_core.runnables import RunnableLambda
2from respan import Respan
3from respan_instrumentation_langchain import (
4 LangChainInstrumentor,
5 add_respan_callback,
6 get_callback_handler,
7)
8
9# Activates global instrumentation. Component runs are captured automatically;
10# the shared handler groups independent component root runs into one trace.
11respan = Respan(instrumentations=[LangChainInstrumentor()])
12
13handler = get_callback_handler()
14
15def langflow_config(name: str):
16 return add_respan_callback(
17 {
18 "run_name": name,
19 "tags": ["respan-langchain-example", "langflow", name],
20 "metadata": {
21 "example": name,
22 "framework": "langflow",
23 "langflow_component": "RoutingComponent",
24 },
25 },
26 handler,
27 )
28
29route_department = RunnableLambda(
30 lambda input: f"{input['department']}-workspace"
31)
32get_weather = RunnableLambda(
33 lambda input: f"It is sunny in {input['city']}."
34)
35
36route = route_department.invoke(
37 {"department": "security"},
38 config=langflow_config("langflow_route_department"),
39)
40weather = get_weather.invoke(
41 {"city": "Dublin"},
42 config=langflow_config("langflow_get_weather"),
43)
44print(f"{route}: {weather}")
4

View your trace

Open the Traces page to see your Langflow workflow with component-level operations, LLM calls, retriever spans, and tool calls.

Configuration

ParameterTypeDefaultDescription
api_keystr | NoneNoneFalls back to RESPAN_API_KEY env var.
base_urlstr | NoneNoneFalls back to RESPAN_BASE_URL env var.
instrumentationslist[]Plugin instrumentations to activate, e.g. LangChainInstrumentor().
group_langflow_root_runsboolTrue via get_callback_handler()Groups independent Langflow component root runs into one trace.
include_contentboolTrueIncludes component inputs and outputs on spans.
include_metadataboolTrueIncludes Langflow tags, metadata, and serialized runnable details.
customer_identifierstr | NoneNoneDefault customer identifier for all spans.
metadatadict | NoneNoneDefault metadata attached to all spans.
environmentstr | NoneNoneEnvironment tag, e.g. "production".

Attributes

In Respan()

Set defaults at initialization — these apply to all spans.

1from respan import Respan
2from respan_instrumentation_langchain import LangChainInstrumentor
3
4respan = Respan(
5 instrumentations=[LangChainInstrumentor()],
6 customer_identifier="user_123",
7 metadata={"service": "langflow-api", "version": "1.0.0"},
8)

With propagate_attributes

Override per-request using a context scope.

1from langflow.load import run_flow_from_json
2from respan import propagate_attributes
3
4def handle_request(user_id: str, question: str):
5 with propagate_attributes(
6 customer_identifier=user_id,
7 thread_identifier="conv_abc_123",
8 metadata={"plan": "pro"},
9 ):
10 result = run_flow_from_json(flow="flow.json", input_value=question)
11 print(result)
AttributeTypeDescription
customer_identifierstrIdentifies the end user in Respan analytics.
thread_identifierstrGroups related messages into a conversation.
metadatadictCustom key-value pairs. Merged with default metadata.

Decorators (optional)

Decorators are not required. Langflow runs are traced through LangChain callbacks. Use @workflow and @task (Python) or withWorkflow and withTask (TypeScript) when you want to group one or more flow executions inside a named application workflow.

1from respan import workflow, task
2
3@task(name="run_langflow_flow")
4def run_langflow_flow(question: str):
5 return run_flow_from_json(flow="flow.json", input_value=question)
6
7@workflow(name="langflow_request")
8def pipeline(question: str):
9 print(run_langflow_flow(question))
10
11pipeline("What is the meaning of life?")

Examples

Custom component callback grouping

Use one callback handler for the component invocation so multiple LangChain calls in the same custom component share a trace.

1from respan_instrumentation_langchain import add_respan_callback, get_callback_handler
2
3handler = get_callback_handler()
4config = add_respan_callback(
5 {
6 "run_name": "langflow_component",
7 "tags": ["langflow", "custom-component"],
8 "metadata": {
9 "framework": "langflow",
10 "langflow_component": "RoutingComponent",
11 },
12 },
13 handler,
14)
15
16result = chain.invoke({"question": "Route this request"}, config=config)

Exported flows

Export the flow from the Langflow UI (Share → Export) to a flow.json first. Exported flows can then be run normally after Respan telemetry is initialized. For custom components inside the flow, pass add_respan_callback(...) when invoking LangChain runnables.

1from langflow.load import run_flow_from_json
2
3result = run_flow_from_json(
4 flow="path/to/your/flow.json",
5 input_value="Summarize this support request.",
6)
7print(result)