Skip to content

Node SDK auto-instrumentation for LangChain is not working too well #673

@howardyoo

Description

@howardyoo

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:

callbackManagerAny._configureSync = function (

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions