From cee1039057b01879d2afa3987177c5fdeabef8a8 Mon Sep 17 00:00:00 2001 From: Nicolas Hrubec Date: Thu, 4 Dec 2025 11:55:09 +0100 Subject: [PATCH 01/11] Add failing test --- .../tracing/langgraph/agent-scenario.mjs | 73 +++++++++++++++++++ .../suites/tracing/langgraph/test.ts | 40 ++++++++++ 2 files changed, 113 insertions(+) create mode 100644 dev-packages/node-integration-tests/suites/tracing/langgraph/agent-scenario.mjs diff --git a/dev-packages/node-integration-tests/suites/tracing/langgraph/agent-scenario.mjs b/dev-packages/node-integration-tests/suites/tracing/langgraph/agent-scenario.mjs new file mode 100644 index 000000000000..a0db57c630dd --- /dev/null +++ b/dev-packages/node-integration-tests/suites/tracing/langgraph/agent-scenario.mjs @@ -0,0 +1,73 @@ +import { ChatAnthropic } from '@langchain/anthropic'; +import { createReactAgent } from '@langchain/langgraph/prebuilt'; +import { HumanMessage, SystemMessage } from '@langchain/core/messages'; +import * as Sentry from '@sentry/node'; +import express from 'express'; + +function startMockAnthropicServer() { + const app = express(); + app.use(express.json()); + + app.post('/v1/messages', (req, res) => { + const model = req.body.model; + + // Simulate basic response + res.json({ + id: 'msg_react_agent_123', + type: 'message', + role: 'assistant', + content: [ + { + type: 'text', + text: 'Mock response from Anthropic!', + }, + ], + model: model, + stop_reason: 'end_turn', + stop_sequence: null, + usage: { + input_tokens: 10, + output_tokens: 15, + }, + }); + }); + + return new Promise(resolve => { + const server = app.listen(0, () => { + resolve(server); + }); + }); +} + +async function run() { + const server = await startMockAnthropicServer(); + const baseUrl = `http://localhost:${server.address().port}`; + + await Sentry.startSpan({ op: 'function', name: 'main' }, async () => { + // Create mocked LLM instance + const llm = new ChatAnthropic({ + model: 'claude-3-5-sonnet-20241022', + apiKey: 'mock-api-key', + clientOptions: { + baseURL: baseUrl, + }, + }); + + // Create a simple react agent with no tools + const agent = createReactAgent({ llm, tools: [] }); + + // Test: basic invocation + await agent.invoke({ + messages: [ + new SystemMessage('You are a helpful assistant.'), + new HumanMessage('What is the weather today?'), + ], + }); + }); + + await Sentry.flush(2000); + + server.close(); +} + +run(); diff --git a/dev-packages/node-integration-tests/suites/tracing/langgraph/test.ts b/dev-packages/node-integration-tests/suites/tracing/langgraph/test.ts index 6a67b5cd1e86..bc1646db5468 100644 --- a/dev-packages/node-integration-tests/suites/tracing/langgraph/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/langgraph/test.ts @@ -205,4 +205,44 @@ describe('LangGraph integration', () => { await createRunner().ignore('event').expect({ transaction: EXPECTED_TRANSACTION_WITH_TOOLS }).start().completed(); }); }); + + const EXPECTED_TRANSACTION_REACT_AGENT = { + transaction: 'main', + spans: expect.arrayContaining([ + // create_agent span + expect.objectContaining({ + data: expect.objectContaining({ + 'gen_ai.operation.name': 'create_agent', + 'sentry.op': 'gen_ai.create_agent', + 'sentry.origin': 'auto.ai.langgraph', + }), + description: expect.stringContaining('create_agent'), + op: 'gen_ai.create_agent', + origin: 'auto.ai.langgraph', + status: 'ok', + }), + // invoke_agent span + expect.objectContaining({ + data: expect.objectContaining({ + 'gen_ai.operation.name': 'invoke_agent', + 'sentry.op': 'gen_ai.invoke_agent', + 'sentry.origin': 'auto.ai.langgraph', + }), + description: expect.stringContaining('invoke_agent'), + op: 'gen_ai.invoke_agent', + origin: 'auto.ai.langgraph', + status: 'ok', + }), + ]), + }; + + createEsmAndCjsTests(__dirname, 'agent-scenario.mjs', 'instrument.mjs', (createRunner, test) => { + test('should instrument LangGraph createReactAgent with default PII settings', async () => { + await createRunner() + .ignore('event') + .expect({ transaction: EXPECTED_TRANSACTION_REACT_AGENT }) + .start() + .completed(); + }); + }); }); From 877b10edfb81133c50952a87fb5786d5324a1c93 Mon Sep 17 00:00:00 2001 From: Nicolas Hrubec Date: Thu, 4 Dec 2025 15:10:18 +0100 Subject: [PATCH 02/11] Try to instrument createReactAgent (doesn't work yet) --- packages/core/src/index.ts | 2 +- packages/core/src/tracing/langgraph/index.ts | 45 +++++++++++++++++++ .../tracing/langgraph/instrumentation.ts | 32 ++++++++++++- 3 files changed, 77 insertions(+), 2 deletions(-) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 387ba0aba4a2..d0e355b0e55f 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -152,7 +152,7 @@ export type { GoogleGenAIResponse } from './tracing/google-genai/types'; export { createLangChainCallbackHandler } from './tracing/langchain'; export { LANGCHAIN_INTEGRATION_NAME } from './tracing/langchain/constants'; export type { LangChainOptions, LangChainIntegration } from './tracing/langchain/types'; -export { instrumentStateGraphCompile, instrumentLangGraph } from './tracing/langgraph'; +export { instrumentStateGraphCompile, instrumentCreateReactAgent, instrumentLangGraph } from './tracing/langgraph'; export { LANGGRAPH_INTEGRATION_NAME } from './tracing/langgraph/constants'; export type { LangGraphOptions, LangGraphIntegration, CompiledGraph } from './tracing/langgraph/types'; export type { OpenAiClient, OpenAiOptions, InstrumentedMethod } from './tracing/openai/types'; diff --git a/packages/core/src/tracing/langgraph/index.ts b/packages/core/src/tracing/langgraph/index.ts index 5601cddf458b..c323d2d0d701 100644 --- a/packages/core/src/tracing/langgraph/index.ts +++ b/packages/core/src/tracing/langgraph/index.ts @@ -156,6 +156,51 @@ function instrumentCompiledGraphInvoke( }) as (...args: unknown[]) => Promise; } +/** + * Instruments createReactAgent to create spans for agent creation and invocation + * + * Creates a `gen_ai.create_agent` span when createReactAgent() is called + */ +export function instrumentCreateReactAgent( + originalCreateReactAgent: (...args: unknown[]) => CompiledGraph, + options: LangGraphOptions, +): (...args: unknown[]) => CompiledGraph { + return new Proxy(originalCreateReactAgent, { + apply(target, thisArg, args: unknown[]): CompiledGraph { + return startSpan( + { + op: 'gen_ai.create_agent', + name: 'create_agent', + attributes: { + [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: LANGGRAPH_ORIGIN, + [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'gen_ai.create_agent', + [GEN_AI_OPERATION_NAME_ATTRIBUTE]: 'create_agent', + }, + }, + () => { + try { + const compiledGraph = Reflect.apply(target, thisArg, args); + const compiledOptions = args.length > 0 ? (args[0] as Record) : {}; + const originalInvoke = compiledGraph.invoke; + if (originalInvoke && typeof originalInvoke === 'function') { + compiledGraph.invoke = instrumentCompiledGraphInvoke( + originalInvoke.bind(compiledGraph) as (...args: unknown[]) => Promise, + compiledGraph, + compiledOptions, + options, + ) as typeof originalInvoke; + } + + return compiledGraph; + } catch (error) { + throw error; + } + }, + ); + }, + }) as (...args: unknown[]) => CompiledGraph; +} + /** * Directly instruments a StateGraph instance to add tracing spans * diff --git a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts index d275e1b9d39b..03713f10a258 100644 --- a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts +++ b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts @@ -6,7 +6,7 @@ import { InstrumentationNodeModuleFile, } from '@opentelemetry/instrumentation'; import type { CompiledGraph, LangGraphOptions } from '@sentry/core'; -import { getClient, instrumentStateGraphCompile, SDK_VERSION } from '@sentry/core'; +import { getClient, instrumentStateGraphCompile, instrumentCreateReactAgent, SDK_VERSION } from '@sentry/core'; const supportedVersions = ['>=0.0.0 <2.0.0']; @@ -50,6 +50,16 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase exports, ), + new InstrumentationNodeModuleFile( + /** + * Patch the prebuilt subpath exports for CJS. + * The @langchain/langgraph/prebuilt entry point re-exports from dist/prebuilt/index.cjs + */ + '@langchain/langgraph/dist/prebuilt/index.cjs', + supportedVersions, + this._patch.bind(this), + exports => exports, + ), ], ); return module; @@ -83,6 +93,26 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase CompiledGraph, + options, + ); + /* + const originalCreateReactAgent = exports.createReactAgent; + Object.defineProperty(exports, 'createReactAgent', { + value: instrumentCreateReactAgent( + originalCreateReactAgent as (...args: unknown[]) => CompiledGraph, + options, + ), + writable: true, + enumerable: true, + configurable: true, + }); + */ + } + return exports; } } From 335ee5a382e0e6ce3d0626cbf47edd0617c204d0 Mon Sep 17 00:00:00 2001 From: Nicolas Hrubec Date: Wed, 10 Dec 2025 17:34:24 +0100 Subject: [PATCH 03/11] Use two modules --- .../tracing/langgraph/instrumentation.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts index 03713f10a258..7126a45321ff 100644 --- a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts +++ b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts @@ -31,8 +31,8 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase exports, ), + ], + ); + + const prebuiltModule = new InstrumentationNodeModuleDefinition( + '@langchain/langgraph/prebuilt', + supportedVersions, + this._patch.bind(this), + exports => exports, + [ new InstrumentationNodeModuleFile( /** * Patch the prebuilt subpath exports for CJS. @@ -62,7 +71,8 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase Date: Wed, 10 Dec 2025 17:38:26 +0100 Subject: [PATCH 04/11] clean comment --- .../tracing/langgraph/instrumentation.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts index 7126a45321ff..4538ddcda7ee 100644 --- a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts +++ b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts @@ -109,18 +109,6 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase CompiledGraph, options, ); - /* - const originalCreateReactAgent = exports.createReactAgent; - Object.defineProperty(exports, 'createReactAgent', { - value: instrumentCreateReactAgent( - originalCreateReactAgent as (...args: unknown[]) => CompiledGraph, - options, - ), - writable: true, - enumerable: true, - configurable: true, - }); - */ } return exports; From 819cf399962ea879cf5fb8f11ddca938d370cc64 Mon Sep 17 00:00:00 2001 From: Nicolas Hrubec Date: Wed, 10 Dec 2025 17:55:49 +0100 Subject: [PATCH 05/11] Split patch for main and prebuilt langgraph modules --- .../tracing/langgraph/instrumentation.ts | 59 ++++++++++++------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts index 4538ddcda7ee..e8fe0ca2fbe0 100644 --- a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts +++ b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts @@ -35,7 +35,7 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase exports, [ new InstrumentationNodeModuleFile( @@ -43,11 +43,11 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase exports, ), ], @@ -56,17 +56,19 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase exports, [ new InstrumentationNodeModuleFile( /** - * Patch the prebuilt subpath exports for CJS. - * The @langchain/langgraph/prebuilt entry point re-exports from dist/prebuilt/index.cjs - */ + * In CJS, LangGraph packages re-export from dist/prebuilt/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 + * _patchPrebuiltModule runs again on the concrete implementation + */ '@langchain/langgraph/dist/prebuilt/index.cjs', supportedVersions, - this._patch.bind(this), + this._patchPrebuiltModule.bind(this), exports => exports, ), ], @@ -76,20 +78,10 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase Date: Thu, 11 Dec 2025 17:27:29 +0100 Subject: [PATCH 06/11] revert stuff --- .../tracing/langgraph/instrumentation.ts | 85 +++++++------------ 1 file changed, 33 insertions(+), 52 deletions(-) diff --git a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts index e8fe0ca2fbe0..646460720721 100644 --- a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts +++ b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts @@ -6,7 +6,7 @@ import { InstrumentationNodeModuleFile, } from '@opentelemetry/instrumentation'; import type { CompiledGraph, LangGraphOptions } from '@sentry/core'; -import { getClient, instrumentStateGraphCompile, instrumentCreateReactAgent, SDK_VERSION } from '@sentry/core'; +import { getClient, instrumentCreateReactAgent, instrumentStateGraphCompile, SDK_VERSION } from '@sentry/core'; const supportedVersions = ['>=0.0.0 <2.0.0']; @@ -31,11 +31,11 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase exports, [ new InstrumentationNodeModuleFile( @@ -43,45 +43,45 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase exports, ), - ], - ); - - const prebuiltModule = new InstrumentationNodeModuleDefinition( - '@langchain/langgraph/prebuilt', - supportedVersions, - this._patchPrebuiltModule.bind(this), - exports => exports, - [ new InstrumentationNodeModuleFile( /** * In CJS, LangGraph packages re-export from dist/prebuilt/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 - * _patchPrebuiltModule runs again on the concrete implementation - */ + * _patch runs again on the concrete implementation + */ '@langchain/langgraph/dist/prebuilt/index.cjs', supportedVersions, - this._patchPrebuiltModule.bind(this), + this._patch.bind(this), exports => exports, ), ], ); - - return [mainModule, prebuiltModule]; + return module; } /** - * Patch logic applying instrumentation to the LangGraph main module. + * Core patch logic applying instrumentation to the LangGraph module. */ - private _patchMainModule(exports: PatchedModuleExports): PatchedModuleExports | void { - const options = this._getOptions(); + private _patch(exports: PatchedModuleExports): PatchedModuleExports | void { + const client = getClient(); + const defaultPii = Boolean(client?.getOptions().sendDefaultPii); + + const config = this.getConfig(); + const recordInputs = config.recordInputs ?? defaultPii; + const recordOutputs = config.recordOutputs ?? defaultPii; + + const options: LangGraphOptions = { + recordInputs, + recordOutputs, + }; // Patch StateGraph.compile to instrument both compile() and invoke() if (exports.StateGraph && typeof exports.StateGraph === 'function') { @@ -95,37 +95,18 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase CompiledGraph, + const originalCreateReactAgent = exports.createReactAgent; + Object.defineProperty(exports, 'createReactAgent', { + value: instrumentCreateReactAgent( + originalCreateReactAgent as (...args: unknown[]) => CompiledGraph, options, - ); - } + ), + writable: true, + enumerable: true, + configurable: true, + }); return exports; } - - /** - * Helper to get instrumentation options - */ - private _getOptions(): LangGraphOptions { - const client = getClient(); - const defaultPii = Boolean(client?.getOptions().sendDefaultPii); - const config = this.getConfig(); - - return { - recordInputs: config.recordInputs ?? defaultPii, - recordOutputs: config.recordOutputs ?? defaultPii, - }; - } } From 0246624f4c8fa973cd8c65c2fafe795ac94aa1a2 Mon Sep 17 00:00:00 2001 From: Nicolas Hrubec Date: Thu, 11 Dec 2025 17:45:33 +0100 Subject: [PATCH 07/11] now we get some spans for cjs --- .../tracing/langgraph/instrumentation.ts | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts index 646460720721..0aac8801fee4 100644 --- a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts +++ b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts @@ -71,6 +71,7 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase CompiledGraph, - options, - ), - writable: true, - enumerable: true, - configurable: true, - }); + 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; } From e9862c0d141b5d892677031d7db34b3312ca3baa Mon Sep 17 00:00:00 2001 From: Nicolas Hrubec Date: Thu, 11 Dec 2025 18:00:08 +0100 Subject: [PATCH 08/11] try to fix esm with explicit file wrap --- .../tracing/langgraph/instrumentation.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts index 0aac8801fee4..c739472cd758 100644 --- a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts +++ b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts @@ -62,8 +62,19 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase exports, ), + new InstrumentationNodeModuleFile( + /** + * ESM builds use dist/prebuilt/index.js (without .cjs extension) + * This catches ESM imports that resolve through the main package + */ + '@langchain/langgraph/dist/prebuilt/index.js', + supportedVersions, + this._patch.bind(this), + exports => exports, + ), ], ); + return module; } @@ -71,7 +82,6 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase Date: Thu, 11 Dec 2025 19:03:24 +0100 Subject: [PATCH 09/11] Fix formatting --- .../suites/tracing/langgraph/agent-scenario.mjs | 7 ++----- packages/core/src/tracing/langgraph/index.ts | 9 ++++++++- .../integrations/tracing/langgraph/instrumentation.ts | 5 +---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/dev-packages/node-integration-tests/suites/tracing/langgraph/agent-scenario.mjs b/dev-packages/node-integration-tests/suites/tracing/langgraph/agent-scenario.mjs index a0db57c630dd..cef786b8988f 100644 --- a/dev-packages/node-integration-tests/suites/tracing/langgraph/agent-scenario.mjs +++ b/dev-packages/node-integration-tests/suites/tracing/langgraph/agent-scenario.mjs @@ -1,6 +1,6 @@ import { ChatAnthropic } from '@langchain/anthropic'; -import { createReactAgent } from '@langchain/langgraph/prebuilt'; import { HumanMessage, SystemMessage } from '@langchain/core/messages'; +import { createReactAgent } from '@langchain/langgraph/prebuilt'; import * as Sentry from '@sentry/node'; import express from 'express'; @@ -58,10 +58,7 @@ async function run() { // Test: basic invocation await agent.invoke({ - messages: [ - new SystemMessage('You are a helpful assistant.'), - new HumanMessage('What is the weather today?'), - ], + messages: [new SystemMessage('You are a helpful assistant.'), new HumanMessage('What is the weather today?')], }); }); diff --git a/packages/core/src/tracing/langgraph/index.ts b/packages/core/src/tracing/langgraph/index.ts index c323d2d0d701..d29b97262aa3 100644 --- a/packages/core/src/tracing/langgraph/index.ts +++ b/packages/core/src/tracing/langgraph/index.ts @@ -177,7 +177,7 @@ export function instrumentCreateReactAgent( [GEN_AI_OPERATION_NAME_ATTRIBUTE]: 'create_agent', }, }, - () => { + span => { try { const compiledGraph = Reflect.apply(target, thisArg, args); const compiledOptions = args.length > 0 ? (args[0] as Record) : {}; @@ -193,6 +193,13 @@ export function instrumentCreateReactAgent( return compiledGraph; } catch (error) { + span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' }); + captureException(error, { + mechanism: { + handled: false, + type: 'auto.ai.langgraph.error', + }, + }); throw error; } }, diff --git a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts index c739472cd758..87077d457909 100644 --- a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts +++ b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts @@ -110,10 +110,7 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase CompiledGraph, - options, - ), + value: instrumentCreateReactAgent(originalCreateReactAgent as (...args: unknown[]) => CompiledGraph, options), writable: true, enumerable: true, configurable: true, From 481fc12164371a6e1206cad2f2e7aafb8275e410 Mon Sep 17 00:00:00 2001 From: Nicolas Hrubec Date: Thu, 11 Dec 2025 19:30:26 +0100 Subject: [PATCH 10/11] try catch --- .../src/integrations/tracing/langgraph/instrumentation.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts index 87077d457909..6bf50718b66b 100644 --- a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts +++ b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts @@ -107,10 +107,12 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase CompiledGraph, options); + try { + exports.createReactAgent = wrappedCreateReactAgent; + } catch (error) { Object.defineProperty(exports, 'createReactAgent', { - value: instrumentCreateReactAgent(originalCreateReactAgent as (...args: unknown[]) => CompiledGraph, options), + value: wrappedCreateReactAgent, writable: true, enumerable: true, configurable: true, From 5ec44274aa59bdf2e8e4bab7f77cbec59a6acf14 Mon Sep 17 00:00:00 2001 From: Nicolas Hrubec Date: Thu, 11 Dec 2025 19:48:13 +0100 Subject: [PATCH 11/11] Revert "try catch" This reverts commit 481fc12164371a6e1206cad2f2e7aafb8275e410. --- .../src/integrations/tracing/langgraph/instrumentation.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts index 6bf50718b66b..87077d457909 100644 --- a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts +++ b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts @@ -107,12 +107,10 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase CompiledGraph, options); - try { - exports.createReactAgent = wrappedCreateReactAgent; - } catch (error) { + if (exports.createReactAgent && typeof exports.createReactAgent === 'function') { + const originalCreateReactAgent = exports.createReactAgent; Object.defineProperty(exports, 'createReactAgent', { - value: wrappedCreateReactAgent, + value: instrumentCreateReactAgent(originalCreateReactAgent as (...args: unknown[]) => CompiledGraph, options), writable: true, enumerable: true, configurable: true,