diff --git a/dev-packages/browser-integration-tests/suites/tracing/ai-providers/langgraph/subject.js b/dev-packages/browser-integration-tests/suites/tracing/ai-providers/langgraph/subject.js index 70741f5d111f..f539d69ecd52 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/ai-providers/langgraph/subject.js +++ b/dev-packages/browser-integration-tests/suites/tracing/ai-providers/langgraph/subject.js @@ -1,12 +1,12 @@ import { MockStateGraph } from './mocks.js'; -import { instrumentLangGraph } from '@sentry/browser'; +import { instrumentStateGraph } from '@sentry/browser'; // Test that manual instrumentation doesn't crash the browser // The instrumentation automatically creates spans // Test both agent creation and invocation const graph = new MockStateGraph(); -instrumentLangGraph(graph, { recordInputs: false, recordOutputs: false }); +instrumentStateGraph(graph, { recordInputs: false, recordOutputs: false }); const compiledGraph = graph.compile({ name: 'mock-graph' }); const response = await compiledGraph.invoke({ diff --git a/dev-packages/browser-integration-tests/utils/generatePlugin.ts b/dev-packages/browser-integration-tests/utils/generatePlugin.ts index 61ccbf6a39d8..cb23a3377659 100644 --- a/dev-packages/browser-integration-tests/utils/generatePlugin.ts +++ b/dev-packages/browser-integration-tests/utils/generatePlugin.ts @@ -40,6 +40,7 @@ const IMPORTED_INTEGRATION_CDN_BUNDLE_PATHS: Record = { instrumentAnthropicAiClient: 'instrumentanthropicaiclient', instrumentOpenAiClient: 'instrumentopenaiclient', instrumentGoogleGenAIClient: 'instrumentgooglegenaiclient', + instrumentStateGraph: 'instrumentstategraph', instrumentLangGraph: 'instrumentlanggraph', createLangChainCallbackHandler: 'createlangchaincallbackhandler', instrumentLangChainEmbeddings: 'instrumentlangchainembeddings', diff --git a/dev-packages/cloudflare-integration-tests/suites/tracing/langgraph/index.ts b/dev-packages/cloudflare-integration-tests/suites/tracing/langgraph/index.ts index 0153302d598c..2c021727fcc6 100644 --- a/dev-packages/cloudflare-integration-tests/suites/tracing/langgraph/index.ts +++ b/dev-packages/cloudflare-integration-tests/suites/tracing/langgraph/index.ts @@ -53,7 +53,7 @@ export default Sentry.withSentry( .addEdge(START, 'agent') .addEdge('agent', END); - Sentry.instrumentLangGraph(graph, { recordInputs: true, recordOutputs: true }); + Sentry.instrumentStateGraph(graph, { recordInputs: true, recordOutputs: true }); const compiled = graph.compile({ name: 'weather_assistant' }); diff --git a/packages/astro/src/index.server.ts b/packages/astro/src/index.server.ts index 789097ac44cb..567c5c24dc91 100644 --- a/packages/astro/src/index.server.ts +++ b/packages/astro/src/index.server.ts @@ -160,6 +160,8 @@ export { instrumentAnthropicAiClient, instrumentGoogleGenAIClient, instrumentLangChainEmbeddings, + instrumentStateGraph, + // eslint-disable-next-line typescript/no-deprecated instrumentLangGraph, instrumentStateGraphCompile, zodErrorsIntegration, diff --git a/packages/aws-serverless/src/index.ts b/packages/aws-serverless/src/index.ts index 2078044d64a8..6fd1f496adc7 100644 --- a/packages/aws-serverless/src/index.ts +++ b/packages/aws-serverless/src/index.ts @@ -142,6 +142,8 @@ export { instrumentOpenAiClient, instrumentAnthropicAiClient, instrumentGoogleGenAIClient, + instrumentStateGraph, + // eslint-disable-next-line typescript/no-deprecated instrumentLangGraph, instrumentStateGraphCompile, zodErrorsIntegration, diff --git a/packages/browser/rollup.bundle.config.mjs b/packages/browser/rollup.bundle.config.mjs index 2a70d25dac77..a3b7761f5c35 100644 --- a/packages/browser/rollup.bundle.config.mjs +++ b/packages/browser/rollup.bundle.config.mjs @@ -16,6 +16,7 @@ const reexportedPluggableIntegrationFiles = [ 'instrumentanthropicaiclient', 'instrumentopenaiclient', 'instrumentgooglegenaiclient', + 'instrumentstategraph', 'instrumentlanggraph', 'createlangchaincallbackhandler', 'instrumentlangchainembeddings', diff --git a/packages/browser/src/index.ts b/packages/browser/src/index.ts index a9e7b568ea97..b349c9c8c8d8 100644 --- a/packages/browser/src/index.ts +++ b/packages/browser/src/index.ts @@ -75,6 +75,8 @@ export { instrumentAnthropicAiClient, instrumentOpenAiClient, instrumentGoogleGenAIClient, + instrumentStateGraph, + // eslint-disable-next-line typescript/no-deprecated instrumentLangGraph, instrumentCreateReactAgent, createLangChainCallbackHandler, diff --git a/packages/browser/src/integrations-bundle/index.instrumentlanggraph.ts b/packages/browser/src/integrations-bundle/index.instrumentlanggraph.ts index e54333eed24a..f3322ba3f08a 100644 --- a/packages/browser/src/integrations-bundle/index.instrumentlanggraph.ts +++ b/packages/browser/src/integrations-bundle/index.instrumentlanggraph.ts @@ -1 +1,2 @@ +// eslint-disable-next-line typescript/no-deprecated export { instrumentLangGraph } from '@sentry/core/browser'; diff --git a/packages/browser/src/integrations-bundle/index.instrumentstategraph.ts b/packages/browser/src/integrations-bundle/index.instrumentstategraph.ts new file mode 100644 index 000000000000..4cfa5da9697a --- /dev/null +++ b/packages/browser/src/integrations-bundle/index.instrumentstategraph.ts @@ -0,0 +1 @@ +export { instrumentStateGraph } from '@sentry/core/browser'; diff --git a/packages/browser/src/utils/lazyLoadIntegration.ts b/packages/browser/src/utils/lazyLoadIntegration.ts index f348681adba5..110894de64b1 100644 --- a/packages/browser/src/utils/lazyLoadIntegration.ts +++ b/packages/browser/src/utils/lazyLoadIntegration.ts @@ -26,6 +26,7 @@ const LAZY_LOADABLE_NAMES = [ 'instrumentAnthropicAiClient', 'instrumentOpenAiClient', 'instrumentGoogleGenAIClient', + 'instrumentStateGraph', 'instrumentLangGraph', 'createLangChainCallbackHandler', 'instrumentLangChainEmbeddings', diff --git a/packages/bun/src/index.ts b/packages/bun/src/index.ts index ae98ae2aecad..04b62615b557 100644 --- a/packages/bun/src/index.ts +++ b/packages/bun/src/index.ts @@ -160,6 +160,8 @@ export { instrumentOpenAiClient, instrumentAnthropicAiClient, instrumentGoogleGenAIClient, + instrumentStateGraph, + // eslint-disable-next-line typescript/no-deprecated instrumentLangGraph, instrumentStateGraphCompile, zodErrorsIntegration, diff --git a/packages/cloudflare/src/index.ts b/packages/cloudflare/src/index.ts index 20a537c5b307..d163dd351bec 100644 --- a/packages/cloudflare/src/index.ts +++ b/packages/cloudflare/src/index.ts @@ -112,6 +112,8 @@ export { metrics, withStreamedSpan, spanStreamingIntegration, + instrumentStateGraph, + // eslint-disable-next-line typescript/no-deprecated instrumentLangGraph, instrumentCreateReactAgent, } from '@sentry/core'; diff --git a/packages/core/src/shared-exports.ts b/packages/core/src/shared-exports.ts index 983367c882f9..4c1100142fec 100644 --- a/packages/core/src/shared-exports.ts +++ b/packages/core/src/shared-exports.ts @@ -223,6 +223,8 @@ export type { LangChainOptions, LangChainIntegration } from './tracing/langchain export { instrumentStateGraphCompile, instrumentCreateReactAgent, + instrumentStateGraph, + // eslint-disable-next-line typescript/no-deprecated instrumentLangGraph, instrumentCompiledGraphInvoke, _INTERNAL_getLangGraphCreateAgentSpanOptions, diff --git a/packages/core/src/tracing/langgraph/index.ts b/packages/core/src/tracing/langgraph/index.ts index daf2f55552ea..7a78e952758a 100644 --- a/packages/core/src/tracing/langgraph/index.ts +++ b/packages/core/src/tracing/langgraph/index.ts @@ -328,7 +328,7 @@ export function instrumentCreateReactAgent( * * @example * ```typescript - * import { instrumentLangGraph } from '@sentry/cloudflare'; + * import { instrumentStateGraph } from '@sentry/cloudflare'; * import { StateGraph } from '@langchain/langgraph'; * * const graph = new StateGraph(MessagesAnnotation) @@ -336,12 +336,12 @@ export function instrumentCreateReactAgent( * .addEdge(START, 'agent') * .addEdge('agent', END); * - * instrumentLangGraph(graph, { recordInputs: true, recordOutputs: true }); + * instrumentStateGraph(graph, { recordInputs: true, recordOutputs: true }); * const compiled = graph.compile({ name: 'my_agent' }); * ``` */ // eslint-disable-next-line @typescript-eslint/no-explicit-any -export function instrumentLangGraph any }>( +export function instrumentStateGraph any }>( stateGraph: T, options?: LangGraphOptions, ): T { @@ -349,3 +349,11 @@ export function instrumentLangGraph any return stateGraph; } + +/** + * Directly instruments a StateGraph instance to add tracing spans. + * + * @deprecated This function was renamed and will be removed in a future major version. + * Use `instrumentStateGraph` instead. + */ +export const instrumentLangGraph = instrumentStateGraph; diff --git a/packages/core/test/lib/tracing/langgraph.test.ts b/packages/core/test/lib/tracing/langgraph.test.ts index 6cbd6ff2fdcb..34c859882387 100644 --- a/packages/core/test/lib/tracing/langgraph.test.ts +++ b/packages/core/test/lib/tracing/langgraph.test.ts @@ -1,5 +1,10 @@ import { describe, expect, it } from 'vitest'; -import { instrumentCreateReactAgent, instrumentStateGraphCompile } from '../../../src/tracing/langgraph'; +import { + instrumentCreateReactAgent, + instrumentLangGraph, + instrumentStateGraph, + instrumentStateGraphCompile, +} from '../../../src/tracing/langgraph'; describe('langgraph double-patch guard', () => { it('instrumentStateGraphCompile returns the same wrapper when applied twice', () => { @@ -16,3 +21,19 @@ describe('langgraph double-patch guard', () => { expect(second).toBe(first); }); }); + +describe('instrumentStateGraph', () => { + it('wraps the compile method of a StateGraph instance and returns the same instance', () => { + const originalCompile = () => ({}); + const stateGraph = { compile: originalCompile }; + + const result = instrumentStateGraph(stateGraph); + + expect(result).toBe(stateGraph); + expect(stateGraph.compile).not.toBe(originalCompile); + }); + + it('exposes instrumentLangGraph as a deprecated alias for instrumentStateGraph', () => { + expect(instrumentLangGraph).toBe(instrumentStateGraph); + }); +}); diff --git a/packages/elysia/src/index.ts b/packages/elysia/src/index.ts index abbdc9ec513d..09fa4ee52cb4 100644 --- a/packages/elysia/src/index.ts +++ b/packages/elysia/src/index.ts @@ -138,6 +138,8 @@ export { instrumentOpenAiClient, instrumentAnthropicAiClient, instrumentGoogleGenAIClient, + instrumentStateGraph, + // eslint-disable-next-line typescript/no-deprecated instrumentLangGraph, instrumentStateGraphCompile, zodErrorsIntegration, diff --git a/packages/google-cloud-serverless/src/index.ts b/packages/google-cloud-serverless/src/index.ts index 4ed627ad007e..bd14114053e8 100644 --- a/packages/google-cloud-serverless/src/index.ts +++ b/packages/google-cloud-serverless/src/index.ts @@ -140,6 +140,8 @@ export { instrumentOpenAiClient, instrumentAnthropicAiClient, instrumentGoogleGenAIClient, + instrumentStateGraph, + // eslint-disable-next-line typescript/no-deprecated instrumentLangGraph, instrumentStateGraphCompile, zodErrorsIntegration, diff --git a/packages/node/src/index.ts b/packages/node/src/index.ts index 1ad92fd21b8e..3e8a8e786c74 100644 --- a/packages/node/src/index.ts +++ b/packages/node/src/index.ts @@ -152,6 +152,8 @@ export { spanStreamingIntegration, createLangChainCallbackHandler, instrumentLangChainEmbeddings, + instrumentStateGraph, + // eslint-disable-next-line typescript/no-deprecated instrumentLangGraph, instrumentStateGraphCompile, } from '@sentry/core'; diff --git a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts index 6f091a32711e..b41bc4f16b65 100644 --- a/packages/node/src/integrations/tracing/langgraph/instrumentation.ts +++ b/packages/node/src/integrations/tracing/langgraph/instrumentation.ts @@ -6,7 +6,7 @@ import { } from '@opentelemetry/instrumentation'; import { InstrumentationNodeModuleFile } from '../InstrumentationNodeModuleFile'; import type { CompiledGraph, LangGraphOptions } from '@sentry/core'; -import { getClient, instrumentCreateReactAgent, instrumentLangGraph, SDK_VERSION } from '@sentry/core'; +import { getClient, instrumentCreateReactAgent, instrumentStateGraph, SDK_VERSION } from '@sentry/core'; const supportedVersions = ['>=0.0.0 <2.0.0']; @@ -100,7 +100,7 @@ export class SentryLangGraphInstrumentation extends InstrumentationBase unknown }, options); + instrumentStateGraph(exports.StateGraph.prototype as { compile: (...args: unknown[]) => unknown }, options); } // Patch createReactAgent to instrument agent creation and invocation diff --git a/packages/remix/src/server/index.ts b/packages/remix/src/server/index.ts index 3ce2aa4a2caf..459c0b69c039 100644 --- a/packages/remix/src/server/index.ts +++ b/packages/remix/src/server/index.ts @@ -127,6 +127,8 @@ export { instrumentOpenAiClient, instrumentAnthropicAiClient, instrumentGoogleGenAIClient, + instrumentStateGraph, + // eslint-disable-next-line typescript/no-deprecated instrumentLangGraph, instrumentStateGraphCompile, zodErrorsIntegration, diff --git a/packages/sveltekit/src/server/index.ts b/packages/sveltekit/src/server/index.ts index bfc3714a621b..4d7bfdda88dc 100644 --- a/packages/sveltekit/src/server/index.ts +++ b/packages/sveltekit/src/server/index.ts @@ -129,6 +129,8 @@ export { instrumentOpenAiClient, instrumentAnthropicAiClient, instrumentGoogleGenAIClient, + instrumentStateGraph, + // eslint-disable-next-line typescript/no-deprecated instrumentLangGraph, instrumentStateGraphCompile, zodErrorsIntegration, diff --git a/packages/vercel-edge/src/index.ts b/packages/vercel-edge/src/index.ts index b7eb963d4f6c..81da79c2877a 100644 --- a/packages/vercel-edge/src/index.ts +++ b/packages/vercel-edge/src/index.ts @@ -74,6 +74,8 @@ export { // eslint-disable-next-line typescript/no-deprecated inboundFiltersIntegration, instrumentOpenAiClient, + instrumentStateGraph, + // eslint-disable-next-line typescript/no-deprecated instrumentLangGraph, instrumentGoogleGenAIClient, instrumentAnthropicAiClient,