Skip to content

Commit 614162a

Browse files
authored
No run collector (#930)
1 parent 7e9c4a0 commit 614162a

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

docs/observability/how_to_guides/trace_with_langchain.mdx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,16 @@ Note that if you do this at the **root** of a trace (i.e., the top-level run, th
224224

225225
## Access run (span) ID for LangChain invocations
226226

227-
When you invoke a LangChain object, you can access the run ID of the invocation. This run ID can be used to query the run in LangSmith.
228-
229-
In Python, you can use the `collect_runs` context manager to access the run ID.
227+
When you invoke a LangChain object, you can manually specify the run ID of the invocation. This run ID can be used to query the run in LangSmith.
230228

231229
In JS/TS, you can use a `RunCollectorCallbackHandler` instance to access the run ID.
232230

233231
<CodeTabs
234232
tabs={[
235-
PythonBlock(`from langchain_openai import ChatOpenAI
233+
PythonBlock(`import uuid\n
234+
from langchain_openai import ChatOpenAI
236235
from langchain_core.prompts import ChatPromptTemplate
237-
from langchain_core.output_parsers import StrOutputParser
238-
from langchain_core.tracers.context import collect_runs\n
236+
from langchain_core.output_parsers import StrOutputParser\n
239237
prompt = ChatPromptTemplate.from_messages([
240238
("system", "You are a helpful assistant. Please respond to the user's request only based on the given context."),
241239
("user", "Question: {question}\\n\\nContext: {context}")
@@ -245,12 +243,9 @@ output_parser = StrOutputParser()\n
245243
chain = prompt | model | output_parser\n
246244
question = "Can you summarize this morning's meetings?"
247245
context = "During this morning's meeting, we solved all world conflict."
248-
with collect_runs() as cb:
249-
result = chain.invoke({"question": question, "context": context})
250-
# Get the root run id
251-
# highlight-next-line
252-
run_id = cb.traced_runs[0].id
253-
print(run_id)`),
246+
my_uuid = uuid.uuid4()
247+
result = chain.invoke({"question": question, "context": context}, {"run_id": my_uuid})
248+
print(my_uuid)`),
254249
TypeScriptBlock(`import { ChatOpenAI } from "@langchain/openai";
255250
import { ChatPromptTemplate } from "@langchain/core/prompts";
256251
import { StringOutputParser } from "@langchain/core/output_parsers";

0 commit comments

Comments
 (0)