LangChain for Google Cloud Functions (JavaScript)

Adds instrumentation for LangChain. (default)

Import name: Sentry.langChainIntegration

This integration is enabled by default when tracing is enabled. If you'd like to modify your default integrations, read this.

The langChainIntegration adds instrumentation for langchain to capture agent tracing gen_ai spans, recording model, token usage, latency, and (when enabled) inputs and outputs.

Copied
Sentry.init({
  dsn: "___PUBLIC_DSN___",
  // Tracing must be enabled for agent tracing to work
  tracesSampleRate: 1.0,
  integrations: [Sentry.langChainIntegration()],
});

By default, tracing support is added to the following LangChain operations:

  • Chat model invocations - Captures spans for chat model calls
  • LLM invocations - Captures spans for LLM pipeline executions
  • Chain executions - Captures spans for chain invocations
  • Tool executions - Captures spans for tool calls

The integration automatically instruments the invoke(), stream(), and batch() runnable methods, across the following LangChain provider packages:

  • @langchain/anthropic
  • @langchain/openai
  • @langchain/google-genai
  • @langchain/mistralai
  • @langchain/google-vertexai
  • @langchain/groq

The integration captures gen_ai.embeddings spans for embedQuery() and embedDocuments() calls from these provider packages:

  • @langchain/openai
  • @langchain/google-genai
  • @langchain/mistralai
  • @langchain/google-vertexai

  • langchain: >=0.1.0 <2.0.0

Automatic embeddings instrumentation supports these package versions:

PackageSupported Versions
@langchain/openai>=0.1.0 <2.0.0
@langchain/google-genai>=0.1.0 <3.0.0
@langchain/mistralai>=0.1.0 <2.0.0
@langchain/google-common>=0.1.0 <3.0.0

For @langchain/google-vertexai, the version requirement applies to its @langchain/google-common dependency, which implements the embedding methods.

Type: boolean (optional)

Records inputs to LangChain operations (such as prompts and messages).

Defaults to true if dataCollection.genAI.inputs is true, which is the default.

Type: boolean (optional)

Records outputs from LangChain operations (such as generated text and responses).

Defaults to true if dataCollection.genAI.outputs is true, which is the default.

Copied
Sentry.init({
  dsn: "___PUBLIC_DSN___",
  tracesSampleRate: 1.0,
  integrations: [
    Sentry.langChainIntegration({
      recordInputs: false,
      recordOutputs: false,
    }),
  ],
});
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").