Skip to content

Commit

Permalink
Send a dummy run tree in case there's no tracer present
Browse files Browse the repository at this point in the history
  • Loading branch information
dqbd committed Jul 16, 2024
1 parent d348779 commit 03efaa0
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions langchain-core/src/singletons/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { RunTree } from "langsmith";
import { CallbackManager } from "../callbacks/manager.js";
import { LangChainTracer } from "../tracers/tracer_langchain.js";

Expand All @@ -21,6 +22,7 @@ export class MockAsyncLocalStorage implements AsyncLocalStorageInterface {
const mockAsyncLocalStorage = new MockAsyncLocalStorage();

const TRACING_ALS_KEY = Symbol.for("ls:tracing_async_local_storage");
const LC_CHILD_KEY = Symbol.for("lc:child_config");

class AsyncLocalStorageProvider {
getInstance(): AsyncLocalStorageInterface {
Expand All @@ -32,7 +34,7 @@ class AsyncLocalStorageProvider {
// this has the runnable config
// which means that I should also have an instance of a LangChainTracer
// with the run map prepopulated
return storage.getStore()?.extra?.[Symbol.for("lc:child_config")];
return storage.getStore()?.extra?.[LC_CHILD_KEY];
}

runWithConfig<T>(config: any, callback: () => T): T {
Expand All @@ -53,13 +55,10 @@ class AsyncLocalStorageProvider {
const runTree =
langChainTracer && parentRunId
? langChainTracer.convertToRunTree(parentRunId)
: undefined;
: new RunTree({ name: "<runnable_lambda>", tracingEnabled: false });

if (runTree) {
runTree.extra = {
...runTree.extra,
[Symbol.for("lc:child_config")]: config,
};
runTree.extra = { ...runTree.extra, [LC_CHILD_KEY]: config };
}

return storage.run(runTree, callback);
Expand Down

0 comments on commit 03efaa0

Please sign in to comment.