Skip to content

Commit

Permalink
Remove circular dep
Browse files Browse the repository at this point in the history
  • Loading branch information
dqbd committed Jul 16, 2024
1 parent 0210975 commit 1746136
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
11 changes: 5 additions & 6 deletions langchain-core/src/callbacks/manager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { v4 as uuidv4 } from "uuid";
import type { RunTree } from "langsmith";
import { AgentAction, AgentFinish } from "../agents.js";
import type { ChainValues } from "../utils/types/index.js";
import { LLMResult } from "../outputs.js";
Expand All @@ -21,7 +20,6 @@ import { consumeCallback } from "./promises.js";
import { Serialized } from "../load/serializable.js";
import type { DocumentInterface } from "../documents/document.js";
import { isTracingEnabled } from "../utils/callbacks.js";
import { AsyncLocalStorageProviderSingleton } from "../singletons/index.js";

if (
/* #__PURE__ */ isTracingEnabled() &&
Expand Down Expand Up @@ -1049,9 +1047,9 @@ export class CallbackManager
getEnvironmentVariable("LANGCHAIN_VERBOSE") === "true" ||
options?.verbose;

const contextRun: RunTree | undefined =
AsyncLocalStorageProviderSingleton.getInstance().getStore();
const tracingV2Enabled = contextRun?.tracingEnabled || isTracingEnabled();
const tracingV2Enabled =
LangChainTracer.getTraceableRunTree()?.tracingEnabled ||
isTracingEnabled();

const tracingEnabled =
tracingV2Enabled ||
Expand Down Expand Up @@ -1082,7 +1080,8 @@ export class CallbackManager
// handoff between langchain and langsmith/traceable
// override the parent run ID
callbackManager._parentRunId =
tracerV2.getTraceableRunTree()?.id ?? callbackManager._parentRunId;
LangChainTracer.getTraceableRunTree()?.id ??
callbackManager._parentRunId;
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions langchain-core/src/tracers/tracer_langchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class LangChainTracer
// if we're inside traceable, we can obtain the traceable tree
// and populate the run map, which is used to correctly
// infer dotted order and execution order
const traceableTree = this.getTraceableRunTree();
const traceableTree = LangChainTracer.getTraceableRunTree();
if (traceableTree) {
let rootRun: RunTree = traceableTree;
const visited = new Set<string>();
Expand Down Expand Up @@ -140,14 +140,6 @@ export class LangChainTracer
return this.runMap.get(id);
}

getTraceableRunTree(): RunTree | undefined {
try {
return getCurrentRunTree();
} catch {
return undefined;
}
}

convertToRunTree(id: string): RunTree | undefined {
// create a run tree from a run map
const runTreeMap: Record<string, RunTree> = {};
Expand Down Expand Up @@ -194,4 +186,12 @@ export class LangChainTracer

return runTreeMap[id];
}

static getTraceableRunTree(): RunTree | undefined {
try {
return getCurrentRunTree();
} catch {
return undefined;
}
}
}

0 comments on commit 1746136

Please sign in to comment.