From 45da9e4060a9286088c0ad65fb0447d960aa7532 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Tue, 28 Jul 2026 12:14:27 +0200 Subject: [PATCH] ref(node): Remove vendored LangGraph instrumentation This instrumentation is dead code: the LangGraph integration is provided by the channel-based implementation in `@sentry/server-utils` (default since #22501), and the vendored OpenTelemetry instrumentation here is no longer wired up. Ref: #22346 Co-Authored-By: Claude Opus 4.8 --- .../integrations/tracing/langgraph/index.ts | 9 -- .../tracing/langgraph/instrumentation.ts | 119 ------------------ 2 files changed, 128 deletions(-) delete mode 100644 packages/node/src/integrations/tracing/langgraph/index.ts delete mode 100644 packages/node/src/integrations/tracing/langgraph/instrumentation.ts diff --git a/packages/node/src/integrations/tracing/langgraph/index.ts b/packages/node/src/integrations/tracing/langgraph/index.ts deleted file mode 100644 index 738b11ea80a4..000000000000 --- a/packages/node/src/integrations/tracing/langgraph/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { LangGraphOptions } from '@sentry/core'; -import { LANGGRAPH_INTEGRATION_NAME } from '@sentry/core'; -import { generateInstrumentOnce } from '../../../otel/instrument'; -import { SentryLangGraphInstrumentation } from './instrumentation'; - -export const instrumentLangGraph = generateInstrumentOnce( - LANGGRAPH_INTEGRATION_NAME, - options => new SentryLangGraphInstrumentation(options), -); diff --git a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts deleted file mode 100644 index b41bc4f16b65..000000000000 --- a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts +++ /dev/null @@ -1,119 +0,0 @@ -import { - InstrumentationBase, - type InstrumentationConfig, - type InstrumentationModuleDefinition, - InstrumentationNodeModuleDefinition, -} from '@opentelemetry/instrumentation'; -import { InstrumentationNodeModuleFile } from '../InstrumentationNodeModuleFile'; -import type { CompiledGraph, LangGraphOptions } from '@sentry/core'; -import { getClient, instrumentCreateReactAgent, instrumentStateGraph, SDK_VERSION } from '@sentry/core'; - -const supportedVersions = ['>=0.0.0 <2.0.0']; - -type LangGraphInstrumentationOptions = InstrumentationConfig & LangGraphOptions; - -/** - * Represents the patched shape of the LangGraph module export. - */ -interface PatchedModuleExports { - [key: string]: unknown; - StateGraph?: abstract new (...args: unknown[]) => unknown; - createReactAgent?: (...args: unknown[]) => CompiledGraph; -} - -/** - * Sentry LangGraph instrumentation using OpenTelemetry. - */ -export class SentryLangGraphInstrumentation extends InstrumentationBase { - public constructor(config: LangGraphInstrumentationOptions = {}) { - super('@sentry/instrumentation-langgraph', SDK_VERSION, config); - } - - /** - * Initializes the instrumentation by defining the modules to be patched. - */ - public init(): InstrumentationModuleDefinition[] { - return [ - new InstrumentationNodeModuleDefinition( - '@langchain/langgraph', - supportedVersions, - this._patch.bind(this), - exports => exports, - [ - new InstrumentationNodeModuleFile( - /** - * In CJS, LangGraph packages re-export from dist/index.cjs files. - * Patching only the root module sometimes misses the real implementation or - * gets overwritten when that file is loaded. We add a file-level patch so that - * _patch runs again on the concrete implementation - */ - '@langchain/langgraph/dist/index.cjs', - supportedVersions, - this._patch.bind(this), - exports => exports, - ), - new InstrumentationNodeModuleFile( - /** - * In CJS, the prebuilt submodule re-exports from dist/prebuilt/index.cjs. - * We add a file-level patch under the main module so that CJS require() - * of @langchain/langgraph/prebuilt gets patched. - */ - '@langchain/langgraph/dist/prebuilt/index.cjs', - supportedVersions, - this._patch.bind(this), - exports => exports, - ), - ], - ), - new InstrumentationNodeModuleDefinition( - '@langchain/langgraph/prebuilt', - supportedVersions, - this._patch.bind(this), - exports => exports, - [ - new InstrumentationNodeModuleFile( - /** - * In CJS, the prebuilt submodule re-exports from dist/prebuilt/index.cjs. - * We add file-level patches so _patch runs on the concrete implementation. - */ - '@langchain/langgraph/dist/prebuilt/index.cjs', - supportedVersions, - this._patch.bind(this), - exports => exports, - ), - ], - ), - ]; - } - - /** - * Core patch logic applying instrumentation to the LangGraph module. - */ - private _patch(exports: PatchedModuleExports): PatchedModuleExports | void { - const client = getClient(); - const genAI = client?.getDataCollectionOptions().genAI; - const options = { - ...this.getConfig(), - recordInputs: this.getConfig().recordInputs ?? genAI?.inputs ?? false, - recordOutputs: this.getConfig().recordOutputs ?? genAI?.outputs ?? false, - }; - - // Patch StateGraph.compile to instrument both compile() and invoke() - if (exports.StateGraph && typeof exports.StateGraph === 'function') { - instrumentStateGraph(exports.StateGraph.prototype as { compile: (...args: unknown[]) => unknown }, options); - } - - // Patch createReactAgent to instrument agent creation and invocation - if (exports.createReactAgent && typeof exports.createReactAgent === 'function') { - const originalCreateReactAgent = exports.createReactAgent; - Object.defineProperty(exports, 'createReactAgent', { - value: instrumentCreateReactAgent(originalCreateReactAgent as (...args: unknown[]) => CompiledGraph, options), - writable: true, - enumerable: true, - configurable: true, - }); - } - - return exports; - } -}