MCPcopy Create free account
hub / github.com/getsentry/sentry-javascript / apply

Function apply

packages/core/src/tracing/langgraph/index.ts:61–114  ·  view source on GitHub ↗
(target, thisArg, args: unknown[])

Source from the content-addressed store, hash-verified

59
60 const wrapped = new Proxy(originalCompile, {
61 apply(target, thisArg, args: unknown[]): CompiledGraph {
62 // Skip when called from within createReactAgent to avoid duplicate instrumentation
63 if (_insideCreateReactAgent) {
64 return Reflect.apply(target, thisArg, args);
65 }
66
67 return startSpan(
68 {
69 op: 'gen_ai.create_agent',
70 name: 'create_agent',
71 attributes: {
72 [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: LANGGRAPH_ORIGIN,
73 [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'gen_ai.create_agent',
74 [GEN_AI_OPERATION_NAME_ATTRIBUTE]: 'create_agent',
75 },
76 },
77 span => {
78 try {
79 const compiledGraph = Reflect.apply(target, thisArg, args);
80 const compileOptions = args.length > 0 ? (args[0] as Record<string, unknown>) : {};
81
82 // Extract graph name
83 if (compileOptions?.name && typeof compileOptions.name === 'string') {
84 span.setAttribute(GEN_AI_AGENT_NAME_ATTRIBUTE, compileOptions.name);
85 span.updateName(`create_agent ${compileOptions.name}`);
86 }
87
88 // Instrument agent invoke method on the compiled graph
89 const originalInvoke = compiledGraph.invoke;
90 if (originalInvoke && typeof originalInvoke === 'function') {
91 compiledGraph.invoke = instrumentCompiledGraphInvoke(
92 originalInvoke.bind(compiledGraph) as (...args: unknown[]) => Promise<unknown>,
93 compiledGraph,
94 compileOptions,
95 options,
96 undefined,
97 sentryHandler,
98 ) as typeof originalInvoke;
99 }
100
101 return compiledGraph;
102 } catch (error) {
103 span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });
104 captureException(error, {
105 mechanism: {
106 handled: false,
107 type: 'auto.ai.langgraph.error',
108 },
109 });
110 throw error;
111 }
112 },
113 );
114 },
115 }) as (...args: unknown[]) => CompiledGraph;
116
117 Object.defineProperty(wrapped, SENTRY_PATCHED, { value: true, enumerable: false });

Callers

nothing calls this directly

Calls 15

startSpanFunction · 0.90
captureExceptionFunction · 0.90
shouldEnableTruncationFunction · 0.90
getTruncatedJsonStringFunction · 0.90
getJsonStringFunction · 0.90
setResponseAttributesFunction · 0.90
extractLLMFromParamsFunction · 0.90

Tested by

no test coverage detected