Node SDK auto-instrumentation for LangChain is not working too well
Problem Statement
I tried to use toolchain's langchain auto instrumentation. However, it wasn't firing. Looked like something? was blocking the instrumentation trying to monkey patch the _configureSync like this: https://github.com/traceloop/openllmetry-js/blob/b5878c5eae9833f520d2b8a2e41d39f4a19f5006/packages/instrumentation-langchain/src/instrumentation.ts#L77
But somehow, this code was not being called.
Other library that works.
After trying some other libraries that were available, I found this : https://arize-ai.github.io/openinference which has the instrumentation for langchain : https://arize-ai.github.io/openinference/js/packages/openinference-instrumentation-langchain/, and in the code, they do a similar approach:
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
import { LangChainInstrumentation } from "@arizeai/openinference-instrumentation-langchain";
import * as CallbackManagerModule from "@langchain/core/callbacks/manager";
const provider = new NodeTracerProvider();
provider.register();
const lcInstrumentation = new LangChainInstrumentation();
// LangChain must be manually instrumented as it doesn't have a traditional module structure
lcInstrumentation.manuallyInstrument(CallbackManagerModule);
by exposing and also calling manuallyInstrument function, which is here:
https://github.com/Arize-ai/openinference/blob/2bc34dea3ddb4a12f754a7c3a8eca3721a27ad79/js/packages/openinference-instrumentation-langchain/src/instrumentation.ts#L81
Some solution
Maybe langchain auto instrumentation should take a look at how this works and apply any appropriate changes...
Thanks for reporting @howardyoo - can you share a snippet of the code you were trying to run and the langchain version you're using?
I'm also having serious issues with this instrumentation and "langchain": "^0.3.34": when the instrumentation is used, LangChain.js is not streaming events properly when using LangGraph agents, most events are missing. When the instrumentation is removed, all events are sent properly.