Skip to content

Commit 0246624

Browse files
committed
now we get some spans for cjs
1 parent 435ee61 commit 0246624

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

packages/node/src/integrations/tracing/langgraph/instrumentation.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase<LangGrap
7171
* Core patch logic applying instrumentation to the LangGraph module.
7272
*/
7373
private _patch(exports: PatchedModuleExports): PatchedModuleExports | void {
74+
console.log('patching LangGraph module');
7475
const client = getClient();
7576
const defaultPii = Boolean(client?.getOptions().sendDefaultPii);
7677

@@ -96,16 +97,18 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase<LangGrap
9697
}
9798

9899
// Patch createReactAgent to instrument the agent creation and invocation
99-
const originalCreateReactAgent = exports.createReactAgent;
100-
Object.defineProperty(exports, 'createReactAgent', {
101-
value: instrumentCreateReactAgent(
102-
originalCreateReactAgent as (...args: unknown[]) => CompiledGraph,
103-
options,
104-
),
105-
writable: true,
106-
enumerable: true,
107-
configurable: true,
108-
});
100+
if (exports.createReactAgent && typeof exports.createReactAgent === 'function') {
101+
const originalCreateReactAgent = exports.createReactAgent;
102+
Object.defineProperty(exports, 'createReactAgent', {
103+
value: instrumentCreateReactAgent(
104+
originalCreateReactAgent as (...args: unknown[]) => CompiledGraph,
105+
options,
106+
),
107+
writable: true,
108+
enumerable: true,
109+
configurable: true,
110+
});
111+
}
109112

110113
return exports;
111114
}

0 commit comments

Comments
 (0)