@sentry/node 10.37.0 → 10.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/index.js +28 -24
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/integrations/tracing/anthropic-ai/instrumentation.js +8 -8
- package/build/cjs/integrations/tracing/anthropic-ai/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/google-genai/instrumentation.js +9 -9
- package/build/cjs/integrations/tracing/google-genai/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/langchain/instrumentation.js +9 -9
- package/build/cjs/integrations/tracing/langchain/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/langgraph/instrumentation.js +6 -6
- package/build/cjs/integrations/tracing/langgraph/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/openai/instrumentation.js +11 -11
- package/build/cjs/integrations/tracing/openai/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/postgresjs.js +10 -10
- package/build/cjs/integrations/tracing/postgresjs.js.map +1 -1
- package/build/esm/index.js +1 -1
- package/build/esm/integrations/tracing/anthropic-ai/instrumentation.js +8 -8
- package/build/esm/integrations/tracing/anthropic-ai/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/google-genai/instrumentation.js +9 -9
- package/build/esm/integrations/tracing/google-genai/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/langchain/instrumentation.js +9 -9
- package/build/esm/integrations/tracing/langchain/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/langgraph/instrumentation.js +6 -6
- package/build/esm/integrations/tracing/langgraph/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/openai/instrumentation.js +11 -11
- package/build/esm/integrations/tracing/openai/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/postgresjs.js +10 -10
- package/build/esm/integrations/tracing/postgresjs.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/types/index.d.ts +1 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types-ts3.8/index.d.ts +1 -1
- package/package.json +5 -5
package/build/cjs/index.js
CHANGED
|
@@ -4,7 +4,7 @@ const http = require('./integrations/http.js');
|
|
|
4
4
|
const nodeFetch = require('./integrations/node-fetch.js');
|
|
5
5
|
const fs = require('./integrations/fs.js');
|
|
6
6
|
const express = require('./integrations/tracing/express.js');
|
|
7
|
-
const index = require('./integrations/tracing/fastify/index.js');
|
|
7
|
+
const index$1 = require('./integrations/tracing/fastify/index.js');
|
|
8
8
|
const graphql = require('./integrations/tracing/graphql.js');
|
|
9
9
|
const kafka = require('./integrations/tracing/kafka.js');
|
|
10
10
|
const lrumemoizer = require('./integrations/tracing/lrumemoizer.js');
|
|
@@ -16,8 +16,8 @@ const redis = require('./integrations/tracing/redis.js');
|
|
|
16
16
|
const postgres = require('./integrations/tracing/postgres.js');
|
|
17
17
|
const postgresjs = require('./integrations/tracing/postgresjs.js');
|
|
18
18
|
const prisma = require('./integrations/tracing/prisma.js');
|
|
19
|
-
const index$
|
|
20
|
-
const index$
|
|
19
|
+
const index$5 = require('./integrations/tracing/hapi/index.js');
|
|
20
|
+
const index$6 = require('./integrations/tracing/hono/index.js');
|
|
21
21
|
const koa = require('./integrations/tracing/koa.js');
|
|
22
22
|
const connect = require('./integrations/tracing/connect.js');
|
|
23
23
|
const knex = require('./integrations/tracing/knex.js');
|
|
@@ -25,10 +25,10 @@ const tedious = require('./integrations/tracing/tedious.js');
|
|
|
25
25
|
const genericPool = require('./integrations/tracing/genericPool.js');
|
|
26
26
|
const dataloader = require('./integrations/tracing/dataloader.js');
|
|
27
27
|
const amqplib = require('./integrations/tracing/amqplib.js');
|
|
28
|
-
const index$
|
|
29
|
-
const index$
|
|
30
|
-
const index
|
|
31
|
-
const index$
|
|
28
|
+
const index$a = require('./integrations/tracing/vercelai/index.js');
|
|
29
|
+
const index$9 = require('./integrations/tracing/openai/index.js');
|
|
30
|
+
const index = require('./integrations/tracing/anthropic-ai/index.js');
|
|
31
|
+
const index$4 = require('./integrations/tracing/google-genai/index.js');
|
|
32
32
|
const index$7 = require('./integrations/tracing/langchain/index.js');
|
|
33
33
|
const index$8 = require('./integrations/tracing/langgraph/index.js');
|
|
34
34
|
const launchDarkly = require('./integrations/featureFlagShims/launchDarkly.js');
|
|
@@ -37,9 +37,9 @@ const statsig = require('./integrations/featureFlagShims/statsig.js');
|
|
|
37
37
|
const unleash = require('./integrations/featureFlagShims/unleash.js');
|
|
38
38
|
const growthbook = require('./integrations/featureFlagShims/growthbook.js');
|
|
39
39
|
const firebase = require('./integrations/tracing/firebase/firebase.js');
|
|
40
|
-
const index$
|
|
40
|
+
const index$3 = require('./sdk/index.js');
|
|
41
41
|
const initOtel = require('./sdk/initOtel.js');
|
|
42
|
-
const index$
|
|
42
|
+
const index$2 = require('./integrations/tracing/index.js');
|
|
43
43
|
const opentelemetry = require('@sentry/opentelemetry');
|
|
44
44
|
const core = require('@sentry/core');
|
|
45
45
|
const nodeCore = require('@sentry/node-core');
|
|
@@ -52,8 +52,8 @@ exports.fsIntegration = fs.fsIntegration;
|
|
|
52
52
|
exports.expressErrorHandler = express.expressErrorHandler;
|
|
53
53
|
exports.expressIntegration = express.expressIntegration;
|
|
54
54
|
exports.setupExpressErrorHandler = express.setupExpressErrorHandler;
|
|
55
|
-
exports.fastifyIntegration = index.fastifyIntegration;
|
|
56
|
-
exports.setupFastifyErrorHandler = index.setupFastifyErrorHandler;
|
|
55
|
+
exports.fastifyIntegration = index$1.fastifyIntegration;
|
|
56
|
+
exports.setupFastifyErrorHandler = index$1.setupFastifyErrorHandler;
|
|
57
57
|
exports.graphqlIntegration = graphql.graphqlIntegration;
|
|
58
58
|
exports.kafkaIntegration = kafka.kafkaIntegration;
|
|
59
59
|
exports.lruMemoizerIntegration = lrumemoizer.lruMemoizerIntegration;
|
|
@@ -65,10 +65,10 @@ exports.redisIntegration = redis.redisIntegration;
|
|
|
65
65
|
exports.postgresIntegration = postgres.postgresIntegration;
|
|
66
66
|
exports.postgresJsIntegration = postgresjs.postgresJsIntegration;
|
|
67
67
|
exports.prismaIntegration = prisma.prismaIntegration;
|
|
68
|
-
exports.hapiIntegration = index$
|
|
69
|
-
exports.setupHapiErrorHandler = index$
|
|
70
|
-
exports.honoIntegration = index$
|
|
71
|
-
exports.setupHonoErrorHandler = index$
|
|
68
|
+
exports.hapiIntegration = index$5.hapiIntegration;
|
|
69
|
+
exports.setupHapiErrorHandler = index$5.setupHapiErrorHandler;
|
|
70
|
+
exports.honoIntegration = index$6.honoIntegration;
|
|
71
|
+
exports.setupHonoErrorHandler = index$6.setupHonoErrorHandler;
|
|
72
72
|
exports.koaIntegration = koa.koaIntegration;
|
|
73
73
|
exports.setupKoaErrorHandler = koa.setupKoaErrorHandler;
|
|
74
74
|
exports.connectIntegration = connect.connectIntegration;
|
|
@@ -78,10 +78,10 @@ exports.tediousIntegration = tedious.tediousIntegration;
|
|
|
78
78
|
exports.genericPoolIntegration = genericPool.genericPoolIntegration;
|
|
79
79
|
exports.dataloaderIntegration = dataloader.dataloaderIntegration;
|
|
80
80
|
exports.amqplibIntegration = amqplib.amqplibIntegration;
|
|
81
|
-
exports.vercelAIIntegration = index$
|
|
82
|
-
exports.openAIIntegration = index$
|
|
83
|
-
exports.anthropicAIIntegration = index
|
|
84
|
-
exports.googleGenAIIntegration = index$
|
|
81
|
+
exports.vercelAIIntegration = index$a.vercelAIIntegration;
|
|
82
|
+
exports.openAIIntegration = index$9.openAIIntegration;
|
|
83
|
+
exports.anthropicAIIntegration = index.anthropicAIIntegration;
|
|
84
|
+
exports.googleGenAIIntegration = index$4.googleGenAIIntegration;
|
|
85
85
|
exports.langChainIntegration = index$7.langChainIntegration;
|
|
86
86
|
exports.langGraphIntegration = index$8.langGraphIntegration;
|
|
87
87
|
exports.buildLaunchDarklyFlagUsedHandler = launchDarkly.buildLaunchDarklyFlagUsedHandlerShim;
|
|
@@ -92,13 +92,13 @@ exports.statsigIntegration = statsig.statsigIntegrationShim;
|
|
|
92
92
|
exports.unleashIntegration = unleash.unleashIntegrationShim;
|
|
93
93
|
exports.growthbookIntegration = growthbook.growthbookIntegrationShim;
|
|
94
94
|
exports.firebaseIntegration = firebase.firebaseIntegration;
|
|
95
|
-
exports.getDefaultIntegrations = index$
|
|
96
|
-
exports.getDefaultIntegrationsWithoutPerformance = index$
|
|
97
|
-
exports.init = index$
|
|
98
|
-
exports.initWithoutDefaultIntegrations = index$
|
|
95
|
+
exports.getDefaultIntegrations = index$3.getDefaultIntegrations;
|
|
96
|
+
exports.getDefaultIntegrationsWithoutPerformance = index$3.getDefaultIntegrationsWithoutPerformance;
|
|
97
|
+
exports.init = index$3.init;
|
|
98
|
+
exports.initWithoutDefaultIntegrations = index$3.initWithoutDefaultIntegrations;
|
|
99
99
|
exports.initOpenTelemetry = initOtel.initOpenTelemetry;
|
|
100
100
|
exports.preloadOpenTelemetry = initOtel.preloadOpenTelemetry;
|
|
101
|
-
exports.getAutoPerformanceIntegrations = index$
|
|
101
|
+
exports.getAutoPerformanceIntegrations = index$2.getAutoPerformanceIntegrations;
|
|
102
102
|
exports.setNodeAsyncContextStrategy = opentelemetry.setOpenTelemetryContextAsyncContextStrategy;
|
|
103
103
|
exports.SDK_VERSION = core.SDK_VERSION;
|
|
104
104
|
exports.SEMANTIC_ATTRIBUTE_SENTRY_OP = core.SEMANTIC_ATTRIBUTE_SENTRY_OP;
|
|
@@ -142,7 +142,11 @@ exports.getTraceData = core.getTraceData;
|
|
|
142
142
|
exports.getTraceMetaTags = core.getTraceMetaTags;
|
|
143
143
|
exports.httpHeadersToSpanAttributes = core.httpHeadersToSpanAttributes;
|
|
144
144
|
exports.inboundFiltersIntegration = core.inboundFiltersIntegration;
|
|
145
|
+
exports.instrumentAnthropicAiClient = core.instrumentAnthropicAiClient;
|
|
146
|
+
exports.instrumentGoogleGenAIClient = core.instrumentGoogleGenAIClient;
|
|
147
|
+
exports.instrumentLangGraph = core.instrumentLangGraph;
|
|
145
148
|
exports.instrumentOpenAiClient = core.instrumentOpenAiClient;
|
|
149
|
+
exports.instrumentStateGraphCompile = core.instrumentStateGraphCompile;
|
|
146
150
|
exports.instrumentSupabaseClient = core.instrumentSupabaseClient;
|
|
147
151
|
exports.isEnabled = core.isEnabled;
|
|
148
152
|
exports.isInitialized = core.isInitialized;
|
package/build/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -28,8 +28,8 @@ class SentryAnthropicAiInstrumentation extends instrumentation.InstrumentationBa
|
|
|
28
28
|
/**
|
|
29
29
|
* Core patch logic applying instrumentation to the Anthropic AI client constructor.
|
|
30
30
|
*/
|
|
31
|
-
_patch(exports) {
|
|
32
|
-
const Original = exports.Anthropic;
|
|
31
|
+
_patch(exports$1) {
|
|
32
|
+
const Original = exports$1.Anthropic;
|
|
33
33
|
|
|
34
34
|
const config = this.getConfig();
|
|
35
35
|
|
|
@@ -68,10 +68,10 @@ class SentryAnthropicAiInstrumentation extends instrumentation.InstrumentationBa
|
|
|
68
68
|
// Constructor replacement - handle read-only properties
|
|
69
69
|
// The Anthropic property might have only a getter, so use defineProperty
|
|
70
70
|
try {
|
|
71
|
-
exports.Anthropic = WrappedAnthropic;
|
|
71
|
+
exports$1.Anthropic = WrappedAnthropic;
|
|
72
72
|
} catch (error) {
|
|
73
73
|
// If direct assignment fails, override the property descriptor
|
|
74
|
-
Object.defineProperty(exports, 'Anthropic', {
|
|
74
|
+
Object.defineProperty(exports$1, 'Anthropic', {
|
|
75
75
|
value: WrappedAnthropic,
|
|
76
76
|
writable: true,
|
|
77
77
|
configurable: true,
|
|
@@ -82,12 +82,12 @@ class SentryAnthropicAiInstrumentation extends instrumentation.InstrumentationBa
|
|
|
82
82
|
// Wrap the default export if it points to the original constructor
|
|
83
83
|
// Constructor replacement - handle read-only properties
|
|
84
84
|
// The Anthropic property might have only a getter, so use defineProperty
|
|
85
|
-
if (exports.default === Original) {
|
|
85
|
+
if (exports$1.default === Original) {
|
|
86
86
|
try {
|
|
87
|
-
exports.default = WrappedAnthropic;
|
|
87
|
+
exports$1.default = WrappedAnthropic;
|
|
88
88
|
} catch (error) {
|
|
89
89
|
// If direct assignment fails, override the property descriptor
|
|
90
|
-
Object.defineProperty(exports, 'default', {
|
|
90
|
+
Object.defineProperty(exports$1, 'default', {
|
|
91
91
|
value: WrappedAnthropic,
|
|
92
92
|
writable: true,
|
|
93
93
|
configurable: true,
|
|
@@ -95,7 +95,7 @@ class SentryAnthropicAiInstrumentation extends instrumentation.InstrumentationBa
|
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
return exports;
|
|
98
|
+
return exports$1;
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sources":["../../../../../src/integrations/tracing/anthropic-ai/instrumentation.ts"],"sourcesContent":["import {\n InstrumentationBase,\n type InstrumentationConfig,\n type InstrumentationModuleDefinition,\n InstrumentationNodeModuleDefinition,\n} from '@opentelemetry/instrumentation';\nimport type { AnthropicAiClient, AnthropicAiOptions } from '@sentry/core';\nimport {\n _INTERNAL_shouldSkipAiProviderWrapping,\n ANTHROPIC_AI_INTEGRATION_NAME,\n getClient,\n instrumentAnthropicAiClient,\n SDK_VERSION,\n} from '@sentry/core';\n\nconst supportedVersions = ['>=0.19.2 <1.0.0'];\n\ntype AnthropicAiInstrumentationOptions = InstrumentationConfig & AnthropicAiOptions;\n\n/**\n * Represents the patched shape of the Anthropic AI module export.\n */\ninterface PatchedModuleExports {\n [key: string]: unknown;\n Anthropic: abstract new (...args: unknown[]) => AnthropicAiClient;\n}\n\n/**\n * Sentry Anthropic AI instrumentation using OpenTelemetry.\n */\nexport class SentryAnthropicAiInstrumentation extends InstrumentationBase<AnthropicAiInstrumentationOptions> {\n public constructor(config: AnthropicAiInstrumentationOptions = {}) {\n super('@sentry/instrumentation-anthropic-ai', SDK_VERSION, config);\n }\n\n /**\n * Initializes the instrumentation by defining the modules to be patched.\n */\n public init(): InstrumentationModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition(\n '@anthropic-ai/sdk',\n supportedVersions,\n this._patch.bind(this),\n );\n return module;\n }\n\n /**\n * Core patch logic applying instrumentation to the Anthropic AI client constructor.\n */\n private _patch(exports: PatchedModuleExports): PatchedModuleExports | void {\n const Original = exports.Anthropic;\n\n const config = this.getConfig();\n\n const WrappedAnthropic = function (this: unknown, ...args: unknown[]) {\n // Check if wrapping should be skipped (e.g., when LangChain is handling instrumentation)\n if (_INTERNAL_shouldSkipAiProviderWrapping(ANTHROPIC_AI_INTEGRATION_NAME)) {\n return Reflect.construct(Original, args) as AnthropicAiClient;\n }\n\n const instance = Reflect.construct(Original, args);\n const client = getClient();\n const defaultPii = Boolean(client?.getOptions().sendDefaultPii);\n\n const recordInputs = config.recordInputs ?? defaultPii;\n const recordOutputs = config.recordOutputs ?? defaultPii;\n\n return instrumentAnthropicAiClient(instance as AnthropicAiClient, {\n recordInputs,\n recordOutputs,\n });\n } as unknown as abstract new (...args: unknown[]) => AnthropicAiClient;\n\n // Preserve static and prototype chains\n Object.setPrototypeOf(WrappedAnthropic, Original);\n Object.setPrototypeOf(WrappedAnthropic.prototype, Original.prototype);\n\n for (const key of Object.getOwnPropertyNames(Original)) {\n if (!['length', 'name', 'prototype'].includes(key)) {\n const descriptor = Object.getOwnPropertyDescriptor(Original, key);\n if (descriptor) {\n Object.defineProperty(WrappedAnthropic, key, descriptor);\n }\n }\n }\n\n // Constructor replacement - handle read-only properties\n // The Anthropic property might have only a getter, so use defineProperty\n try {\n exports.Anthropic = WrappedAnthropic;\n } catch (error) {\n // If direct assignment fails, override the property descriptor\n Object.defineProperty(exports, 'Anthropic', {\n value: WrappedAnthropic,\n writable: true,\n configurable: true,\n enumerable: true,\n });\n }\n\n // Wrap the default export if it points to the original constructor\n // Constructor replacement - handle read-only properties\n // The Anthropic property might have only a getter, so use defineProperty\n if (exports.default === Original) {\n try {\n exports.default = WrappedAnthropic;\n } catch (error) {\n // If direct assignment fails, override the property descriptor\n Object.defineProperty(exports, 'default', {\n value: WrappedAnthropic,\n writable: true,\n configurable: true,\n enumerable: true,\n });\n }\n }\n return exports;\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","InstrumentationNodeModuleDefinition","_INTERNAL_shouldSkipAiProviderWrapping","ANTHROPIC_AI_INTEGRATION_NAME","getClient","instrumentAnthropicAiClient"],"mappings":";;;;;AAeA,MAAM,iBAAA,GAAoB,CAAC,iBAAiB,CAAC;;AAY7C;AACA;AACA;AACO,MAAM,gCAAA,SAAyCA,mCAAmB,CAAoC;AAC7G,GAAS,WAAW,CAAC,MAAM,GAAsC,EAAE,EAAE;AACrE,IAAI,KAAK,CAAC,sCAAsC,EAAEC,gBAAW,EAAE,MAAM,CAAC;AACtE,EAAE;;AAEF;AACA;AACA;AACA,GAAS,IAAI,GAAoC;AACjD,IAAI,MAAM,MAAA,GAAS,IAAIC,mDAAmC;AAC1D,MAAM,mBAAmB;AACzB,MAAM,iBAAiB;AACvB,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;AAC5B,KAAK;AACL,IAAI,OAAO,MAAM;AACjB,EAAE;;AAEF;AACA;AACA;AACA,GAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sources":["../../../../../src/integrations/tracing/anthropic-ai/instrumentation.ts"],"sourcesContent":["import {\n InstrumentationBase,\n type InstrumentationConfig,\n type InstrumentationModuleDefinition,\n InstrumentationNodeModuleDefinition,\n} from '@opentelemetry/instrumentation';\nimport type { AnthropicAiClient, AnthropicAiOptions } from '@sentry/core';\nimport {\n _INTERNAL_shouldSkipAiProviderWrapping,\n ANTHROPIC_AI_INTEGRATION_NAME,\n getClient,\n instrumentAnthropicAiClient,\n SDK_VERSION,\n} from '@sentry/core';\n\nconst supportedVersions = ['>=0.19.2 <1.0.0'];\n\ntype AnthropicAiInstrumentationOptions = InstrumentationConfig & AnthropicAiOptions;\n\n/**\n * Represents the patched shape of the Anthropic AI module export.\n */\ninterface PatchedModuleExports {\n [key: string]: unknown;\n Anthropic: abstract new (...args: unknown[]) => AnthropicAiClient;\n}\n\n/**\n * Sentry Anthropic AI instrumentation using OpenTelemetry.\n */\nexport class SentryAnthropicAiInstrumentation extends InstrumentationBase<AnthropicAiInstrumentationOptions> {\n public constructor(config: AnthropicAiInstrumentationOptions = {}) {\n super('@sentry/instrumentation-anthropic-ai', SDK_VERSION, config);\n }\n\n /**\n * Initializes the instrumentation by defining the modules to be patched.\n */\n public init(): InstrumentationModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition(\n '@anthropic-ai/sdk',\n supportedVersions,\n this._patch.bind(this),\n );\n return module;\n }\n\n /**\n * Core patch logic applying instrumentation to the Anthropic AI client constructor.\n */\n private _patch(exports: PatchedModuleExports): PatchedModuleExports | void {\n const Original = exports.Anthropic;\n\n const config = this.getConfig();\n\n const WrappedAnthropic = function (this: unknown, ...args: unknown[]) {\n // Check if wrapping should be skipped (e.g., when LangChain is handling instrumentation)\n if (_INTERNAL_shouldSkipAiProviderWrapping(ANTHROPIC_AI_INTEGRATION_NAME)) {\n return Reflect.construct(Original, args) as AnthropicAiClient;\n }\n\n const instance = Reflect.construct(Original, args);\n const client = getClient();\n const defaultPii = Boolean(client?.getOptions().sendDefaultPii);\n\n const recordInputs = config.recordInputs ?? defaultPii;\n const recordOutputs = config.recordOutputs ?? defaultPii;\n\n return instrumentAnthropicAiClient(instance as AnthropicAiClient, {\n recordInputs,\n recordOutputs,\n });\n } as unknown as abstract new (...args: unknown[]) => AnthropicAiClient;\n\n // Preserve static and prototype chains\n Object.setPrototypeOf(WrappedAnthropic, Original);\n Object.setPrototypeOf(WrappedAnthropic.prototype, Original.prototype);\n\n for (const key of Object.getOwnPropertyNames(Original)) {\n if (!['length', 'name', 'prototype'].includes(key)) {\n const descriptor = Object.getOwnPropertyDescriptor(Original, key);\n if (descriptor) {\n Object.defineProperty(WrappedAnthropic, key, descriptor);\n }\n }\n }\n\n // Constructor replacement - handle read-only properties\n // The Anthropic property might have only a getter, so use defineProperty\n try {\n exports.Anthropic = WrappedAnthropic;\n } catch (error) {\n // If direct assignment fails, override the property descriptor\n Object.defineProperty(exports, 'Anthropic', {\n value: WrappedAnthropic,\n writable: true,\n configurable: true,\n enumerable: true,\n });\n }\n\n // Wrap the default export if it points to the original constructor\n // Constructor replacement - handle read-only properties\n // The Anthropic property might have only a getter, so use defineProperty\n if (exports.default === Original) {\n try {\n exports.default = WrappedAnthropic;\n } catch (error) {\n // If direct assignment fails, override the property descriptor\n Object.defineProperty(exports, 'default', {\n value: WrappedAnthropic,\n writable: true,\n configurable: true,\n enumerable: true,\n });\n }\n }\n return exports;\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","InstrumentationNodeModuleDefinition","exports","_INTERNAL_shouldSkipAiProviderWrapping","ANTHROPIC_AI_INTEGRATION_NAME","getClient","instrumentAnthropicAiClient"],"mappings":";;;;;AAeA,MAAM,iBAAA,GAAoB,CAAC,iBAAiB,CAAC;;AAY7C;AACA;AACA;AACO,MAAM,gCAAA,SAAyCA,mCAAmB,CAAoC;AAC7G,GAAS,WAAW,CAAC,MAAM,GAAsC,EAAE,EAAE;AACrE,IAAI,KAAK,CAAC,sCAAsC,EAAEC,gBAAW,EAAE,MAAM,CAAC;AACtE,EAAE;;AAEF;AACA;AACA;AACA,GAAS,IAAI,GAAoC;AACj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const module = new instrumentation.InstrumentationNodeModuleDefinition(
|
|
25
25
|
'@google/genai',
|
|
26
26
|
supportedVersions,
|
|
27
|
-
exports => this._patch(exports),
|
|
28
|
-
exports => exports,
|
|
27
|
+
exports$1 => this._patch(exports$1),
|
|
28
|
+
exports$1 => exports$1,
|
|
29
29
|
// In CJS, @google/genai re-exports from (dist/node/index.cjs) file.
|
|
30
30
|
// Patching only the root module sometimes misses the real implementation or
|
|
31
31
|
// gets overwritten when that file is loaded. We add a file-level patch so that
|
|
@@ -34,8 +34,8 @@ class SentryGoogleGenAiInstrumentation extends instrumentation.InstrumentationBa
|
|
|
34
34
|
new instrumentation.InstrumentationNodeModuleFile(
|
|
35
35
|
'@google/genai/dist/node/index.cjs',
|
|
36
36
|
supportedVersions,
|
|
37
|
-
exports => this._patch(exports),
|
|
38
|
-
exports => exports,
|
|
37
|
+
exports$1 => this._patch(exports$1),
|
|
38
|
+
exports$1 => exports$1,
|
|
39
39
|
),
|
|
40
40
|
],
|
|
41
41
|
);
|
|
@@ -45,12 +45,12 @@ class SentryGoogleGenAiInstrumentation extends instrumentation.InstrumentationBa
|
|
|
45
45
|
/**
|
|
46
46
|
* Core patch logic applying instrumentation to the Google GenAI client constructor.
|
|
47
47
|
*/
|
|
48
|
-
_patch(exports) {
|
|
49
|
-
const Original = exports.GoogleGenAI;
|
|
48
|
+
_patch(exports$1) {
|
|
49
|
+
const Original = exports$1.GoogleGenAI;
|
|
50
50
|
const config = this.getConfig();
|
|
51
51
|
|
|
52
52
|
if (typeof Original !== 'function') {
|
|
53
|
-
return exports;
|
|
53
|
+
return exports$1;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
const WrappedGoogleGenAI = function ( ...args) {
|
|
@@ -87,9 +87,9 @@ class SentryGoogleGenAiInstrumentation extends instrumentation.InstrumentationBa
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
// Replace google genai exports with the wrapped constructor
|
|
90
|
-
core.replaceExports(exports, 'GoogleGenAI', WrappedGoogleGenAI);
|
|
90
|
+
core.replaceExports(exports$1, 'GoogleGenAI', WrappedGoogleGenAI);
|
|
91
91
|
|
|
92
|
-
return exports;
|
|
92
|
+
return exports$1;
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sources":["../../../../../src/integrations/tracing/google-genai/instrumentation.ts"],"sourcesContent":["import type { InstrumentationConfig, InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n} from '@opentelemetry/instrumentation';\nimport type { GoogleGenAIClient, GoogleGenAIOptions } from '@sentry/core';\nimport {\n _INTERNAL_shouldSkipAiProviderWrapping,\n getClient,\n GOOGLE_GENAI_INTEGRATION_NAME,\n instrumentGoogleGenAIClient,\n replaceExports,\n SDK_VERSION,\n} from '@sentry/core';\n\nconst supportedVersions = ['>=0.10.0 <2'];\n\n/**\n * Represents the patched shape of the Google GenAI module export.\n */\ninterface PatchedModuleExports {\n [key: string]: unknown;\n GoogleGenAI?: unknown;\n}\n\ntype GoogleGenAIInstrumentationOptions = GoogleGenAIOptions & InstrumentationConfig;\n\n/**\n * Sentry Google GenAI instrumentation using OpenTelemetry.\n */\nexport class SentryGoogleGenAiInstrumentation extends InstrumentationBase<GoogleGenAIInstrumentationOptions> {\n public constructor(config: GoogleGenAIInstrumentationOptions = {}) {\n super('@sentry/instrumentation-google-genai', SDK_VERSION, config);\n }\n\n /**\n * Initializes the instrumentation by defining the modules to be patched.\n */\n public init(): InstrumentationModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition(\n '@google/genai',\n supportedVersions,\n exports => this._patch(exports),\n exports => exports,\n // In CJS, @google/genai re-exports from (dist/node/index.cjs) file.\n // Patching only the root module sometimes misses the real implementation or\n // gets overwritten when that file is loaded. We add a file-level patch so that\n // _patch runs again on the concrete implementation\n [\n new InstrumentationNodeModuleFile(\n '@google/genai/dist/node/index.cjs',\n supportedVersions,\n exports => this._patch(exports),\n exports => exports,\n ),\n ],\n );\n return module;\n }\n\n /**\n * Core patch logic applying instrumentation to the Google GenAI client constructor.\n */\n private _patch(exports: PatchedModuleExports): PatchedModuleExports | void {\n const Original = exports.GoogleGenAI;\n const config = this.getConfig();\n\n if (typeof Original !== 'function') {\n return exports;\n }\n\n const WrappedGoogleGenAI = function (this: unknown, ...args: unknown[]): GoogleGenAIClient {\n // Check if wrapping should be skipped (e.g., when LangChain is handling instrumentation)\n if (_INTERNAL_shouldSkipAiProviderWrapping(GOOGLE_GENAI_INTEGRATION_NAME)) {\n return Reflect.construct(Original, args) as GoogleGenAIClient;\n }\n\n const instance = Reflect.construct(Original, args);\n const client = getClient();\n const defaultPii = Boolean(client?.getOptions().sendDefaultPii);\n\n const typedConfig = config;\n const recordInputs = typedConfig?.recordInputs ?? defaultPii;\n const recordOutputs = typedConfig?.recordOutputs ?? defaultPii;\n\n return instrumentGoogleGenAIClient(instance, {\n recordInputs,\n recordOutputs,\n });\n };\n\n // Preserve static and prototype chains\n Object.setPrototypeOf(WrappedGoogleGenAI, Original);\n Object.setPrototypeOf(WrappedGoogleGenAI.prototype, Original.prototype);\n\n for (const key of Object.getOwnPropertyNames(Original)) {\n if (!['length', 'name', 'prototype'].includes(key)) {\n const descriptor = Object.getOwnPropertyDescriptor(Original, key);\n if (descriptor) {\n Object.defineProperty(WrappedGoogleGenAI, key, descriptor);\n }\n }\n }\n\n // Replace google genai exports with the wrapped constructor\n replaceExports(exports, 'GoogleGenAI', WrappedGoogleGenAI);\n\n return exports;\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","InstrumentationNodeModuleDefinition","InstrumentationNodeModuleFile","_INTERNAL_shouldSkipAiProviderWrapping","GOOGLE_GENAI_INTEGRATION_NAME","getClient","instrumentGoogleGenAIClient","replaceExports"],"mappings":";;;;;AAgBA,MAAM,iBAAA,GAAoB,CAAC,aAAa,CAAC;;AAEzC;AACA;AACA;;AAQA;AACA;AACA;AACO,MAAM,gCAAA,SAAyCA,mCAAmB,CAAoC;AAC7G,GAAS,WAAW,CAAC,MAAM,GAAsC,EAAE,EAAE;AACrE,IAAI,KAAK,CAAC,sCAAsC,EAAEC,gBAAW,EAAE,MAAM,CAAC;AACtE,EAAE;;AAEF;AACA;AACA;AACA,GAAS,IAAI,GAAoC;AACjD,IAAI,MAAM,MAAA,GAAS,IAAIC,mDAAmC;AAC1D,MAAM,eAAe;AACrB,MAAM,iBAAiB;AACvB,
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sources":["../../../../../src/integrations/tracing/google-genai/instrumentation.ts"],"sourcesContent":["import type { InstrumentationConfig, InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n} from '@opentelemetry/instrumentation';\nimport type { GoogleGenAIClient, GoogleGenAIOptions } from '@sentry/core';\nimport {\n _INTERNAL_shouldSkipAiProviderWrapping,\n getClient,\n GOOGLE_GENAI_INTEGRATION_NAME,\n instrumentGoogleGenAIClient,\n replaceExports,\n SDK_VERSION,\n} from '@sentry/core';\n\nconst supportedVersions = ['>=0.10.0 <2'];\n\n/**\n * Represents the patched shape of the Google GenAI module export.\n */\ninterface PatchedModuleExports {\n [key: string]: unknown;\n GoogleGenAI?: unknown;\n}\n\ntype GoogleGenAIInstrumentationOptions = GoogleGenAIOptions & InstrumentationConfig;\n\n/**\n * Sentry Google GenAI instrumentation using OpenTelemetry.\n */\nexport class SentryGoogleGenAiInstrumentation extends InstrumentationBase<GoogleGenAIInstrumentationOptions> {\n public constructor(config: GoogleGenAIInstrumentationOptions = {}) {\n super('@sentry/instrumentation-google-genai', SDK_VERSION, config);\n }\n\n /**\n * Initializes the instrumentation by defining the modules to be patched.\n */\n public init(): InstrumentationModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition(\n '@google/genai',\n supportedVersions,\n exports => this._patch(exports),\n exports => exports,\n // In CJS, @google/genai re-exports from (dist/node/index.cjs) file.\n // Patching only the root module sometimes misses the real implementation or\n // gets overwritten when that file is loaded. We add a file-level patch so that\n // _patch runs again on the concrete implementation\n [\n new InstrumentationNodeModuleFile(\n '@google/genai/dist/node/index.cjs',\n supportedVersions,\n exports => this._patch(exports),\n exports => exports,\n ),\n ],\n );\n return module;\n }\n\n /**\n * Core patch logic applying instrumentation to the Google GenAI client constructor.\n */\n private _patch(exports: PatchedModuleExports): PatchedModuleExports | void {\n const Original = exports.GoogleGenAI;\n const config = this.getConfig();\n\n if (typeof Original !== 'function') {\n return exports;\n }\n\n const WrappedGoogleGenAI = function (this: unknown, ...args: unknown[]): GoogleGenAIClient {\n // Check if wrapping should be skipped (e.g., when LangChain is handling instrumentation)\n if (_INTERNAL_shouldSkipAiProviderWrapping(GOOGLE_GENAI_INTEGRATION_NAME)) {\n return Reflect.construct(Original, args) as GoogleGenAIClient;\n }\n\n const instance = Reflect.construct(Original, args);\n const client = getClient();\n const defaultPii = Boolean(client?.getOptions().sendDefaultPii);\n\n const typedConfig = config;\n const recordInputs = typedConfig?.recordInputs ?? defaultPii;\n const recordOutputs = typedConfig?.recordOutputs ?? defaultPii;\n\n return instrumentGoogleGenAIClient(instance, {\n recordInputs,\n recordOutputs,\n });\n };\n\n // Preserve static and prototype chains\n Object.setPrototypeOf(WrappedGoogleGenAI, Original);\n Object.setPrototypeOf(WrappedGoogleGenAI.prototype, Original.prototype);\n\n for (const key of Object.getOwnPropertyNames(Original)) {\n if (!['length', 'name', 'prototype'].includes(key)) {\n const descriptor = Object.getOwnPropertyDescriptor(Original, key);\n if (descriptor) {\n Object.defineProperty(WrappedGoogleGenAI, key, descriptor);\n }\n }\n }\n\n // Replace google genai exports with the wrapped constructor\n replaceExports(exports, 'GoogleGenAI', WrappedGoogleGenAI);\n\n return exports;\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","InstrumentationNodeModuleDefinition","exports","InstrumentationNodeModuleFile","_INTERNAL_sh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 @@ class SentryLangChainInstrumentation extends instrumentation.InstrumentationBase
|
|
|
108
108
|
packageName,
|
|
109
109
|
supportedVersions,
|
|
110
110
|
this._patch.bind(this),
|
|
111
|
-
exports => exports,
|
|
111
|
+
exports$1 => exports$1,
|
|
112
112
|
[
|
|
113
113
|
new instrumentation.InstrumentationNodeModuleFile(
|
|
114
114
|
`${packageName}/dist/index.cjs`,
|
|
115
115
|
supportedVersions,
|
|
116
116
|
this._patch.bind(this),
|
|
117
|
-
exports => exports,
|
|
117
|
+
exports$1 => exports$1,
|
|
118
118
|
),
|
|
119
119
|
],
|
|
120
120
|
),
|
|
@@ -127,14 +127,14 @@ class SentryLangChainInstrumentation extends instrumentation.InstrumentationBase
|
|
|
127
127
|
'langchain',
|
|
128
128
|
supportedVersions,
|
|
129
129
|
this._patch.bind(this),
|
|
130
|
-
exports => exports,
|
|
130
|
+
exports$1 => exports$1,
|
|
131
131
|
[
|
|
132
132
|
// To catch the CJS build that contains ConfigurableModel / initChatModel for v1
|
|
133
133
|
new instrumentation.InstrumentationNodeModuleFile(
|
|
134
134
|
'langchain/dist/chat_models/universal.cjs',
|
|
135
135
|
supportedVersions,
|
|
136
136
|
this._patch.bind(this),
|
|
137
|
-
exports => exports,
|
|
137
|
+
exports$1 => exports$1,
|
|
138
138
|
),
|
|
139
139
|
],
|
|
140
140
|
),
|
|
@@ -147,7 +147,7 @@ class SentryLangChainInstrumentation extends instrumentation.InstrumentationBase
|
|
|
147
147
|
* Core patch logic - patches chat model methods to inject Sentry callbacks
|
|
148
148
|
* This is called when a LangChain provider package is loaded
|
|
149
149
|
*/
|
|
150
|
-
_patch(exports) {
|
|
150
|
+
_patch(exports$1) {
|
|
151
151
|
// Skip AI provider wrapping now that LangChain is actually being used
|
|
152
152
|
// This prevents duplicate spans from Anthropic/OpenAI/GoogleGenAI standalone integrations
|
|
153
153
|
core._INTERNAL_skipAiProviderWrapping([
|
|
@@ -172,16 +172,16 @@ class SentryLangChainInstrumentation extends instrumentation.InstrumentationBase
|
|
|
172
172
|
|
|
173
173
|
// Patch Runnable methods to inject callbacks at request time
|
|
174
174
|
// This directly manipulates options.callbacks that LangChain uses
|
|
175
|
-
this._patchRunnableMethods(exports, sentryHandler);
|
|
175
|
+
this._patchRunnableMethods(exports$1, sentryHandler);
|
|
176
176
|
|
|
177
|
-
return exports;
|
|
177
|
+
return exports$1;
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
/**
|
|
181
181
|
* Patches chat model methods (invoke, stream, batch) to inject Sentry callbacks
|
|
182
182
|
* Finds a chat model class from the provider package exports and patches its prototype methods
|
|
183
183
|
*/
|
|
184
|
-
_patchRunnableMethods(exports, sentryHandler) {
|
|
184
|
+
_patchRunnableMethods(exports$1, sentryHandler) {
|
|
185
185
|
// Known chat model class names for each provider
|
|
186
186
|
const knownChatModelNames = [
|
|
187
187
|
'ChatAnthropic',
|
|
@@ -193,7 +193,7 @@ class SentryLangChainInstrumentation extends instrumentation.InstrumentationBase
|
|
|
193
193
|
'ConfigurableModel',
|
|
194
194
|
];
|
|
195
195
|
|
|
196
|
-
const exportsToPatch = (exports.universal_exports ?? exports) ;
|
|
196
|
+
const exportsToPatch = (exports$1.universal_exports ?? exports$1) ;
|
|
197
197
|
|
|
198
198
|
const chatModelClass = Object.values(exportsToPatch).find(exp => {
|
|
199
199
|
return typeof exp === 'function' && knownChatModelNames.includes(exp.name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sources":["../../../../../src/integrations/tracing/langchain/instrumentation.ts"],"sourcesContent":["import {\n InstrumentationBase,\n type InstrumentationConfig,\n type InstrumentationModuleDefinition,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n} from '@opentelemetry/instrumentation';\nimport type { LangChainOptions } from '@sentry/core';\nimport {\n _INTERNAL_skipAiProviderWrapping,\n ANTHROPIC_AI_INTEGRATION_NAME,\n createLangChainCallbackHandler,\n getClient,\n GOOGLE_GENAI_INTEGRATION_NAME,\n OPENAI_INTEGRATION_NAME,\n SDK_VERSION,\n} from '@sentry/core';\n\nconst supportedVersions = ['>=0.1.0 <2.0.0'];\n\ntype LangChainInstrumentationOptions = InstrumentationConfig & LangChainOptions;\n\n/**\n * Represents the patched shape of LangChain provider package exports\n */\ninterface PatchedLangChainExports {\n [key: string]: unknown;\n}\n\n/**\n * Augments a callback handler list with Sentry's handler if not already present\n */\nfunction augmentCallbackHandlers(handlers: unknown, sentryHandler: unknown): unknown {\n // Handle null/undefined - return array with just our handler\n if (!handlers) {\n return [sentryHandler];\n }\n\n // If handlers is already an array\n if (Array.isArray(handlers)) {\n // Check if our handler is already in the list\n if (handlers.includes(sentryHandler)) {\n return handlers;\n }\n // Add our handler to the list\n return [...handlers, sentryHandler];\n }\n\n // If it's a single handler object, convert to array\n if (typeof handlers === 'object') {\n return [handlers, sentryHandler];\n }\n\n // Unknown type - return original\n return handlers;\n}\n\n/**\n * Wraps Runnable methods (invoke, stream, batch) to inject Sentry callbacks at request time\n * Uses a Proxy to intercept method calls and augment the options.callbacks\n */\nfunction wrapRunnableMethod(\n originalMethod: (...args: unknown[]) => unknown,\n sentryHandler: unknown,\n _methodName: string,\n): (...args: unknown[]) => unknown {\n return new Proxy(originalMethod, {\n apply(target, thisArg, args: unknown[]): unknown {\n // LangChain Runnable method signatures:\n // invoke(input, options?) - options contains callbacks\n // stream(input, options?) - options contains callbacks\n // batch(inputs, options?) - options contains callbacks\n\n // Options is typically the second argument\n const optionsIndex = 1;\n let options = args[optionsIndex] as Record<string, unknown> | undefined;\n\n // If options don't exist or aren't an object, create them\n if (!options || typeof options !== 'object' || Array.isArray(options)) {\n options = {};\n args[optionsIndex] = options;\n }\n\n // Inject our callback handler into options.callbacks (request time callbacks)\n const existingCallbacks = options.callbacks;\n const augmentedCallbacks = augmentCallbackHandlers(existingCallbacks, sentryHandler);\n options.callbacks = augmentedCallbacks;\n\n // Call original method with augmented options\n return Reflect.apply(target, thisArg, args);\n },\n }) as (...args: unknown[]) => unknown;\n}\n\n/**\n * Sentry LangChain instrumentation using OpenTelemetry.\n */\nexport class SentryLangChainInstrumentation extends InstrumentationBase<LangChainInstrumentationOptions> {\n public constructor(config: LangChainInstrumentationOptions = {}) {\n super('@sentry/instrumentation-langchain', SDK_VERSION, config);\n }\n\n /**\n * Initializes the instrumentation by defining the modules to be patched.\n * We patch the BaseChatModel class methods to inject callbacks\n *\n * We hook into provider packages (@langchain/anthropic, @langchain/openai, etc.)\n * because @langchain/core is often bundled and not loaded as a separate module\n */\n public init(): InstrumentationModuleDefinition | InstrumentationModuleDefinition[] {\n const modules: InstrumentationModuleDefinition[] = [];\n\n // Hook into common LangChain provider packages\n const providerPackages = [\n '@langchain/anthropic',\n '@langchain/openai',\n '@langchain/google-genai',\n '@langchain/mistralai',\n '@langchain/google-vertexai',\n '@langchain/groq',\n ];\n\n for (const packageName of providerPackages) {\n // In CJS, LangChain packages re-export from dist/index.cjs files.\n // Patching only the root module sometimes misses the real implementation or\n // gets overwritten when that file is loaded. We add a file-level patch so that\n // _patch runs again on the concrete implementation\n modules.push(\n new InstrumentationNodeModuleDefinition(\n packageName,\n supportedVersions,\n this._patch.bind(this),\n exports => exports,\n [\n new InstrumentationNodeModuleFile(\n `${packageName}/dist/index.cjs`,\n supportedVersions,\n this._patch.bind(this),\n exports => exports,\n ),\n ],\n ),\n );\n }\n\n // Hook into main 'langchain' package to catch initChatModel (v1+)\n modules.push(\n new InstrumentationNodeModuleDefinition(\n 'langchain',\n supportedVersions,\n this._patch.bind(this),\n exports => exports,\n [\n // To catch the CJS build that contains ConfigurableModel / initChatModel for v1\n new InstrumentationNodeModuleFile(\n 'langchain/dist/chat_models/universal.cjs',\n supportedVersions,\n this._patch.bind(this),\n exports => exports,\n ),\n ],\n ),\n );\n\n return modules;\n }\n\n /**\n * Core patch logic - patches chat model methods to inject Sentry callbacks\n * This is called when a LangChain provider package is loaded\n */\n private _patch(exports: PatchedLangChainExports): PatchedLangChainExports | void {\n // Skip AI provider wrapping now that LangChain is actually being used\n // This prevents duplicate spans from Anthropic/OpenAI/GoogleGenAI standalone integrations\n _INTERNAL_skipAiProviderWrapping([\n OPENAI_INTEGRATION_NAME,\n ANTHROPIC_AI_INTEGRATION_NAME,\n GOOGLE_GENAI_INTEGRATION_NAME,\n ]);\n\n const client = getClient();\n const defaultPii = Boolean(client?.getOptions().sendDefaultPii);\n\n const config = this.getConfig();\n\n const recordInputs = config?.recordInputs ?? defaultPii;\n const recordOutputs = config?.recordOutputs ?? defaultPii;\n\n // Create a shared handler instance\n const sentryHandler = createLangChainCallbackHandler({\n recordInputs,\n recordOutputs,\n });\n\n // Patch Runnable methods to inject callbacks at request time\n // This directly manipulates options.callbacks that LangChain uses\n this._patchRunnableMethods(exports, sentryHandler);\n\n return exports;\n }\n\n /**\n * Patches chat model methods (invoke, stream, batch) to inject Sentry callbacks\n * Finds a chat model class from the provider package exports and patches its prototype methods\n */\n private _patchRunnableMethods(exports: PatchedLangChainExports, sentryHandler: unknown): void {\n // Known chat model class names for each provider\n const knownChatModelNames = [\n 'ChatAnthropic',\n 'ChatOpenAI',\n 'ChatGoogleGenerativeAI',\n 'ChatMistralAI',\n 'ChatVertexAI',\n 'ChatGroq',\n 'ConfigurableModel',\n ];\n\n const exportsToPatch = (exports.universal_exports ?? exports) as Record<string, unknown>;\n\n const chatModelClass = Object.values(exportsToPatch).find(exp => {\n return typeof exp === 'function' && knownChatModelNames.includes(exp.name);\n }) as { prototype: unknown; name: string } | undefined;\n\n if (!chatModelClass) {\n return;\n }\n\n // Patch directly on chatModelClass.prototype\n const targetProto = chatModelClass.prototype as Record<string, unknown>;\n\n // Patch the methods (invoke, stream, batch)\n // All chat model instances will inherit these patched methods\n const methodsToPatch = ['invoke', 'stream', 'batch'] as const;\n\n for (const methodName of methodsToPatch) {\n const method = targetProto[methodName];\n if (typeof method === 'function') {\n targetProto[methodName] = wrapRunnableMethod(\n method as (...args: unknown[]) => unknown,\n sentryHandler,\n methodName,\n );\n }\n }\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","InstrumentationNodeModuleDefinition","InstrumentationNodeModuleFile","_INTERNAL_skipAiProviderWrapping","OPENAI_INTEGRATION_NAME","ANTHROPIC_AI_INTEGRATION_NAME","GOOGLE_GENAI_INTEGRATION_NAME","getClient","createLangChainCallbackHandler"],"mappings":";;;;;AAkBA,MAAM,iBAAA,GAAoB,CAAC,gBAAgB,CAAC;;AAW5C;AACA;AACA;AACA,SAAS,uBAAuB,CAAC,QAAQ,EAAW,aAAa,EAAoB;AACrF;AACA,EAAE,IAAI,CAAC,QAAQ,EAAE;AACjB,IAAI,OAAO,CAAC,aAAa,CAAC;AAC1B,EAAE;;AAEF;AACA,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;AAC/B;AACA,IAAI,IAAI,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE;AAC1C,MAAM,OAAO,QAAQ;AACrB,IAAI;AACJ;AACA,IAAI,OAAO,CAAC,GAAG,QAAQ,EAAE,aAAa,CAAC;AACvC,EAAE;;AAEF;AACA,EAAE,IAAI,OAAO,QAAA,KAAa,QAAQ,EAAE;AACpC,IAAI,OAAO,CAAC,QAAQ,EAAE,aAAa,CAAC;AACpC,EAAE;;AAEF;AACA,EAAE,OAAO,QAAQ;AACjB;;AAEA;AACA;AACA;AACA;AACA,SAAS,kBAAkB;AAC3B,EAAE,cAAc;AAChB,EAAE,aAAa;AACf,EAAE,WAAW;AACb,EAAmC;AACnC,EAAE,OAAO,IAAI,KAAK,CAAC,cAAc,EAAE;AACnC,IAAI,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAsB;AACrD;AACA;AACA;AACA;;AAEA;AACA,MAAM,MAAM,YAAA,GAAe,CAAC;AAC5B,MAAM,IAAI,OAAA,GAAU,IAAI,CAAC,YAAY,CAAA;;AAErC;AACA,MAAM,IAAI,CAAC,OAAA,IAAW,OAAO,OAAA,KAAY,QAAA,IAAY,KAAK,CAAC,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AAA,OAAA,OAAA;AACA,EAAA;;AAEA;AACA;AACA;AACA;AACA,GAAA,qBAAA,CAAA,OAAA,EAAA,aAAA,EAAA;AACA;AACA,IAAA,MAAA,mBAAA,GAAA;AACA,MAAA,eAAA;AACA,MAAA,YAAA;AACA,MAAA,wBAAA;AACA,MAAA,eAAA;AACA,MAAA,cAAA;AACA,MAAA,UAAA;AACA,MAAA,mBAAA;AACA,KAAA;;AAEA,IAAA,MAAA,cAAA,IAAA,OAAA,CAAA,iBAAA,IAAA,OAAA,CAAA;;AAEA,IAAA,MAAA,cAAA,GAAA,MAAA,CAAA,MAAA,CAAA,cAAA,CAAA,CAAA,IAAA,CAAA,GAAA,IAAA;AACA,MAAA,OAAA,OAAA,GAAA,KAAA,UAAA,IAAA,mBAAA,CAAA,QAAA,CAAA,GAAA,CAAA,IAAA,CAAA;AACA,IAAA,CAAA,CAAA;;AAEA,IAAA,IAAA,CAAA,cAAA,EAAA;AACA,MAAA;AACA,IAAA;;AAEA;AACA,IAAA,MAAA,WAAA,GAAA,cAAA,CAAA,SAAA;;AAEA;AACA;AACA,IAAA,MAAA,cAAA,GAAA,CAAA,QAAA,EAAA,QAAA,EAAA,OAAA,CAAA;;AAEA,IAAA,KAAA,MAAA,UAAA,IAAA,cAAA,EAAA;AACA,MAAA,MAAA,MAAA,GAAA,WAAA,CAAA,UAAA,CAAA;AACA,MAAA,IAAA,OAAA,MAAA,KAAA,UAAA,EAAA;AACA,QAAA,WAAA,CAAA,UAAA,CAAA,GAAA,kBAAA;AACA,UAAA,MAAA;AACA,UAAA,aAEA,CAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sources":["../../../../../src/integrations/tracing/langchain/instrumentation.ts"],"sourcesContent":["import {\n InstrumentationBase,\n type InstrumentationConfig,\n type InstrumentationModuleDefinition,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n} from '@opentelemetry/instrumentation';\nimport type { LangChainOptions } from '@sentry/core';\nimport {\n _INTERNAL_skipAiProviderWrapping,\n ANTHROPIC_AI_INTEGRATION_NAME,\n createLangChainCallbackHandler,\n getClient,\n GOOGLE_GENAI_INTEGRATION_NAME,\n OPENAI_INTEGRATION_NAME,\n SDK_VERSION,\n} from '@sentry/core';\n\nconst supportedVersions = ['>=0.1.0 <2.0.0'];\n\ntype LangChainInstrumentationOptions = InstrumentationConfig & LangChainOptions;\n\n/**\n * Represents the patched shape of LangChain provider package exports\n */\ninterface PatchedLangChainExports {\n [key: string]: unknown;\n}\n\n/**\n * Augments a callback handler list with Sentry's handler if not already present\n */\nfunction augmentCallbackHandlers(handlers: unknown, sentryHandler: unknown): unknown {\n // Handle null/undefined - return array with just our handler\n if (!handlers) {\n return [sentryHandler];\n }\n\n // If handlers is already an array\n if (Array.isArray(handlers)) {\n // Check if our handler is already in the list\n if (handlers.includes(sentryHandler)) {\n return handlers;\n }\n // Add our handler to the list\n return [...handlers, sentryHandler];\n }\n\n // If it's a single handler object, convert to array\n if (typeof handlers === 'object') {\n return [handlers, sentryHandler];\n }\n\n // Unknown type - return original\n return handlers;\n}\n\n/**\n * Wraps Runnable methods (invoke, stream, batch) to inject Sentry callbacks at request time\n * Uses a Proxy to intercept method calls and augment the options.callbacks\n */\nfunction wrapRunnableMethod(\n originalMethod: (...args: unknown[]) => unknown,\n sentryHandler: unknown,\n _methodName: string,\n): (...args: unknown[]) => unknown {\n return new Proxy(originalMethod, {\n apply(target, thisArg, args: unknown[]): unknown {\n // LangChain Runnable method signatures:\n // invoke(input, options?) - options contains callbacks\n // stream(input, options?) - options contains callbacks\n // batch(inputs, options?) - options contains callbacks\n\n // Options is typically the second argument\n const optionsIndex = 1;\n let options = args[optionsIndex] as Record<string, unknown> | undefined;\n\n // If options don't exist or aren't an object, create them\n if (!options || typeof options !== 'object' || Array.isArray(options)) {\n options = {};\n args[optionsIndex] = options;\n }\n\n // Inject our callback handler into options.callbacks (request time callbacks)\n const existingCallbacks = options.callbacks;\n const augmentedCallbacks = augmentCallbackHandlers(existingCallbacks, sentryHandler);\n options.callbacks = augmentedCallbacks;\n\n // Call original method with augmented options\n return Reflect.apply(target, thisArg, args);\n },\n }) as (...args: unknown[]) => unknown;\n}\n\n/**\n * Sentry LangChain instrumentation using OpenTelemetry.\n */\nexport class SentryLangChainInstrumentation extends InstrumentationBase<LangChainInstrumentationOptions> {\n public constructor(config: LangChainInstrumentationOptions = {}) {\n super('@sentry/instrumentation-langchain', SDK_VERSION, config);\n }\n\n /**\n * Initializes the instrumentation by defining the modules to be patched.\n * We patch the BaseChatModel class methods to inject callbacks\n *\n * We hook into provider packages (@langchain/anthropic, @langchain/openai, etc.)\n * because @langchain/core is often bundled and not loaded as a separate module\n */\n public init(): InstrumentationModuleDefinition | InstrumentationModuleDefinition[] {\n const modules: InstrumentationModuleDefinition[] = [];\n\n // Hook into common LangChain provider packages\n const providerPackages = [\n '@langchain/anthropic',\n '@langchain/openai',\n '@langchain/google-genai',\n '@langchain/mistralai',\n '@langchain/google-vertexai',\n '@langchain/groq',\n ];\n\n for (const packageName of providerPackages) {\n // In CJS, LangChain packages re-export from dist/index.cjs files.\n // Patching only the root module sometimes misses the real implementation or\n // gets overwritten when that file is loaded. We add a file-level patch so that\n // _patch runs again on the concrete implementation\n modules.push(\n new InstrumentationNodeModuleDefinition(\n packageName,\n supportedVersions,\n this._patch.bind(this),\n exports => exports,\n [\n new InstrumentationNodeModuleFile(\n `${packageName}/dist/index.cjs`,\n supportedVersions,\n this._patch.bind(this),\n exports => exports,\n ),\n ],\n ),\n );\n }\n\n // Hook into main 'langchain' package to catch initChatModel (v1+)\n modules.push(\n new InstrumentationNodeModuleDefinition(\n 'langchain',\n supportedVersions,\n this._patch.bind(this),\n exports => exports,\n [\n // To catch the CJS build that contains ConfigurableModel / initChatModel for v1\n new InstrumentationNodeModuleFile(\n 'langchain/dist/chat_models/universal.cjs',\n supportedVersions,\n this._patch.bind(this),\n exports => exports,\n ),\n ],\n ),\n );\n\n return modules;\n }\n\n /**\n * Core patch logic - patches chat model methods to inject Sentry callbacks\n * This is called when a LangChain provider package is loaded\n */\n private _patch(exports: PatchedLangChainExports): PatchedLangChainExports | void {\n // Skip AI provider wrapping now that LangChain is actually being used\n // This prevents duplicate spans from Anthropic/OpenAI/GoogleGenAI standalone integrations\n _INTERNAL_skipAiProviderWrapping([\n OPENAI_INTEGRATION_NAME,\n ANTHROPIC_AI_INTEGRATION_NAME,\n GOOGLE_GENAI_INTEGRATION_NAME,\n ]);\n\n const client = getClient();\n const defaultPii = Boolean(client?.getOptions().sendDefaultPii);\n\n const config = this.getConfig();\n\n const recordInputs = config?.recordInputs ?? defaultPii;\n const recordOutputs = config?.recordOutputs ?? defaultPii;\n\n // Create a shared handler instance\n const sentryHandler = createLangChainCallbackHandler({\n recordInputs,\n recordOutputs,\n });\n\n // Patch Runnable methods to inject callbacks at request time\n // This directly manipulates options.callbacks that LangChain uses\n this._patchRunnableMethods(exports, sentryHandler);\n\n return exports;\n }\n\n /**\n * Patches chat model methods (invoke, stream, batch) to inject Sentry callbacks\n * Finds a chat model class from the provider package exports and patches its prototype methods\n */\n private _patchRunnableMethods(exports: PatchedLangChainExports, sentryHandler: unknown): void {\n // Known chat model class names for each provider\n const knownChatModelNames = [\n 'ChatAnthropic',\n 'ChatOpenAI',\n 'ChatGoogleGenerativeAI',\n 'ChatMistralAI',\n 'ChatVertexAI',\n 'ChatGroq',\n 'ConfigurableModel',\n ];\n\n const exportsToPatch = (exports.universal_exports ?? exports) as Record<string, unknown>;\n\n const chatModelClass = Object.values(exportsToPatch).find(exp => {\n return typeof exp === 'function' && knownChatModelNames.includes(exp.name);\n }) as { prototype: unknown; name: string } | undefined;\n\n if (!chatModelClass) {\n return;\n }\n\n // Patch directly on chatModelClass.prototype\n const targetProto = chatModelClass.prototype as Record<string, unknown>;\n\n // Patch the methods (invoke, stream, batch)\n // All chat model instances will inherit these patched methods\n const methodsToPatch = ['invoke', 'stream', 'batch'] as const;\n\n for (const methodName of methodsToPatch) {\n const method = targetProto[methodName];\n if (typeof method === 'function') {\n targetProto[methodName] = wrapRunnableMethod(\n method as (...args: unknown[]) => unknown,\n sentryHandler,\n methodName,\n );\n }\n }\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","InstrumentationNodeModuleDefinition","exports","InstrumentationNodeModuleFile","_INTERNAL_skipAiProviderWrapping","OPENAI_INTEGRATION_NAME","ANTHROPIC_AI_INTEGRATION_NAME","GOOGLE_GENAI_INTEGRATION_NAME","getClient","createLangChainCallbackHandler"],"mappings":";;;;;AAkBA,MAAM,iBAAA,GAAoB,CAAC,gBAAgB,CAAC;;AAW5C;AACA;AACA;AACA,SAAS,uBAAuB,CAAC,QAAQ,EAAW,aAAa,EAAoB;AACrF;AACA,EAAE,IAAI,CAAC,QAAQ,EAAE;AACjB,IAAI,OAAO,CAAC,aAAa,CAAC;AAC1B,EAAE;;AAEF;AACA,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;AAC/B;AACA,IAAI,IAAI,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE;AAC1C,MAAM,OAAO,QAAQ;AACrB,IAAI;AACJ;AACA,IAAI,OAAO,CAAC,GAAG,QAAQ,EAAE,aAAa,CAAC;AACvC,EAAE;;AAEF;AACA,EAAE,IAAI,OAAO,QAAA,KAAa,QAAQ,EAAE;AACpC,IAAI,OAAO,CAAC,QAAQ,EAAE,aAAa,CAAC;AACpC,EAAE;;AAEF;AACA,EAAE,OAAO,QAAQ;AACjB;;AAEA;AACA;AACA;AACA;AACA,SAAS,kBAAkB;AAC3B,EAAE,cAAc;AAChB,EAAE,aAAa;AACf,EAAE,WAAW;AACb,EAAmC;AACnC,EAAE,OAAO,IAAI,KAAK,CAAC,cAAc,EAAE;AACnC,IAAI,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAsB;AACrD;AACA;AACA;AACA;;AAEA;AACA,MAAM,MAAM,YAAA,GA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entation extends instrumentation.InstrumentationBase
|
|
|
21
21
|
'@langchain/langgraph',
|
|
22
22
|
supportedVersions,
|
|
23
23
|
this._patch.bind(this),
|
|
24
|
-
exports => exports,
|
|
24
|
+
exports$1 => exports$1,
|
|
25
25
|
[
|
|
26
26
|
new instrumentation.InstrumentationNodeModuleFile(
|
|
27
27
|
/**
|
|
@@ -33,7 +33,7 @@ class SentryLangGraphInstrumentation extends instrumentation.InstrumentationBase
|
|
|
33
33
|
'@langchain/langgraph/dist/index.cjs',
|
|
34
34
|
supportedVersions,
|
|
35
35
|
this._patch.bind(this),
|
|
36
|
-
exports => exports,
|
|
36
|
+
exports$1 => exports$1,
|
|
37
37
|
),
|
|
38
38
|
],
|
|
39
39
|
);
|
|
@@ -43,7 +43,7 @@ class SentryLangGraphInstrumentation extends instrumentation.InstrumentationBase
|
|
|
43
43
|
/**
|
|
44
44
|
* Core patch logic applying instrumentation to the LangGraph module.
|
|
45
45
|
*/
|
|
46
|
-
_patch(exports) {
|
|
46
|
+
_patch(exports$1) {
|
|
47
47
|
const client = core.getClient();
|
|
48
48
|
const defaultPii = Boolean(client?.getOptions().sendDefaultPii);
|
|
49
49
|
|
|
@@ -57,8 +57,8 @@ class SentryLangGraphInstrumentation extends instrumentation.InstrumentationBase
|
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
// Patch StateGraph.compile to instrument both compile() and invoke()
|
|
60
|
-
if (exports.StateGraph && typeof exports.StateGraph === 'function') {
|
|
61
|
-
const StateGraph = exports.StateGraph
|
|
60
|
+
if (exports$1.StateGraph && typeof exports$1.StateGraph === 'function') {
|
|
61
|
+
const StateGraph = exports$1.StateGraph
|
|
62
62
|
|
|
63
63
|
;
|
|
64
64
|
|
|
@@ -68,7 +68,7 @@ class SentryLangGraphInstrumentation extends instrumentation.InstrumentationBase
|
|
|
68
68
|
);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
return exports;
|
|
71
|
+
return exports$1;
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sources":["../../../../../src/integrations/tracing/langgraph/instrumentation.ts"],"sourcesContent":["import {\n InstrumentationBase,\n type InstrumentationConfig,\n type InstrumentationModuleDefinition,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n} from '@opentelemetry/instrumentation';\nimport type { CompiledGraph, LangGraphOptions } from '@sentry/core';\nimport { getClient, instrumentStateGraphCompile, SDK_VERSION } from '@sentry/core';\n\nconst supportedVersions = ['>=0.0.0 <2.0.0'];\n\ntype LangGraphInstrumentationOptions = InstrumentationConfig & LangGraphOptions;\n\n/**\n * Represents the patched shape of the LangGraph module export.\n */\ninterface PatchedModuleExports {\n [key: string]: unknown;\n StateGraph?: abstract new (...args: unknown[]) => unknown;\n}\n\n/**\n * Sentry LangGraph instrumentation using OpenTelemetry.\n */\nexport class SentryLangGraphInstrumentation extends InstrumentationBase<LangGraphInstrumentationOptions> {\n public constructor(config: LangGraphInstrumentationOptions = {}) {\n super('@sentry/instrumentation-langgraph', SDK_VERSION, config);\n }\n\n /**\n * Initializes the instrumentation by defining the modules to be patched.\n */\n public init(): InstrumentationModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition(\n '@langchain/langgraph',\n supportedVersions,\n this._patch.bind(this),\n exports => exports,\n [\n new InstrumentationNodeModuleFile(\n /**\n * In CJS, LangGraph packages re-export from dist/index.cjs files.\n * Patching only the root module sometimes misses the real implementation or\n * gets overwritten when that file is loaded. We add a file-level patch so that\n * _patch runs again on the concrete implementation\n */\n '@langchain/langgraph/dist/index.cjs',\n supportedVersions,\n this._patch.bind(this),\n exports => exports,\n ),\n ],\n );\n return module;\n }\n\n /**\n * Core patch logic applying instrumentation to the LangGraph module.\n */\n private _patch(exports: PatchedModuleExports): PatchedModuleExports | void {\n const client = getClient();\n const defaultPii = Boolean(client?.getOptions().sendDefaultPii);\n\n const config = this.getConfig();\n const recordInputs = config.recordInputs ?? defaultPii;\n const recordOutputs = config.recordOutputs ?? defaultPii;\n\n const options: LangGraphOptions = {\n recordInputs,\n recordOutputs,\n };\n\n // Patch StateGraph.compile to instrument both compile() and invoke()\n if (exports.StateGraph && typeof exports.StateGraph === 'function') {\n const StateGraph = exports.StateGraph as {\n prototype: Record<string, unknown>;\n };\n\n StateGraph.prototype.compile = instrumentStateGraphCompile(\n StateGraph.prototype.compile as (...args: unknown[]) => CompiledGraph,\n options,\n );\n }\n\n return exports;\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","InstrumentationNodeModuleDefinition","InstrumentationNodeModuleFile","getClient","instrumentStateGraphCompile"],"mappings":";;;;;AAUA,MAAM,iBAAA,GAAoB,CAAC,gBAAgB,CAAC;;AAY5C;AACA;AACA;AACO,MAAM,8BAAA,SAAuCA,mCAAmB,CAAkC;AACzG,GAAS,WAAW,CAAC,MAAM,GAAoC,EAAE,EAAE;AACnE,IAAI,KAAK,CAAC,mCAAmC,EAAEC,gBAAW,EAAE,MAAM,CAAC;AACnE,EAAE;;AAEF;AACA;AACA;AACA,GAAS,IAAI,GAAoC;AACjD,IAAI,MAAM,MAAA,GAAS,IAAIC,mDAAmC;AAC1D,MAAM,sBAAsB;AAC5B,MAAM,iBAAiB;AACvB,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;AAC5B,
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sources":["../../../../../src/integrations/tracing/langgraph/instrumentation.ts"],"sourcesContent":["import {\n InstrumentationBase,\n type InstrumentationConfig,\n type InstrumentationModuleDefinition,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n} from '@opentelemetry/instrumentation';\nimport type { CompiledGraph, LangGraphOptions } from '@sentry/core';\nimport { getClient, instrumentStateGraphCompile, SDK_VERSION } from '@sentry/core';\n\nconst supportedVersions = ['>=0.0.0 <2.0.0'];\n\ntype LangGraphInstrumentationOptions = InstrumentationConfig & LangGraphOptions;\n\n/**\n * Represents the patched shape of the LangGraph module export.\n */\ninterface PatchedModuleExports {\n [key: string]: unknown;\n StateGraph?: abstract new (...args: unknown[]) => unknown;\n}\n\n/**\n * Sentry LangGraph instrumentation using OpenTelemetry.\n */\nexport class SentryLangGraphInstrumentation extends InstrumentationBase<LangGraphInstrumentationOptions> {\n public constructor(config: LangGraphInstrumentationOptions = {}) {\n super('@sentry/instrumentation-langgraph', SDK_VERSION, config);\n }\n\n /**\n * Initializes the instrumentation by defining the modules to be patched.\n */\n public init(): InstrumentationModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition(\n '@langchain/langgraph',\n supportedVersions,\n this._patch.bind(this),\n exports => exports,\n [\n new InstrumentationNodeModuleFile(\n /**\n * In CJS, LangGraph packages re-export from dist/index.cjs files.\n * Patching only the root module sometimes misses the real implementation or\n * gets overwritten when that file is loaded. We add a file-level patch so that\n * _patch runs again on the concrete implementation\n */\n '@langchain/langgraph/dist/index.cjs',\n supportedVersions,\n this._patch.bind(this),\n exports => exports,\n ),\n ],\n );\n return module;\n }\n\n /**\n * Core patch logic applying instrumentation to the LangGraph module.\n */\n private _patch(exports: PatchedModuleExports): PatchedModuleExports | void {\n const client = getClient();\n const defaultPii = Boolean(client?.getOptions().sendDefaultPii);\n\n const config = this.getConfig();\n const recordInputs = config.recordInputs ?? defaultPii;\n const recordOutputs = config.recordOutputs ?? defaultPii;\n\n const options: LangGraphOptions = {\n recordInputs,\n recordOutputs,\n };\n\n // Patch StateGraph.compile to instrument both compile() and invoke()\n if (exports.StateGraph && typeof exports.StateGraph === 'function') {\n const StateGraph = exports.StateGraph as {\n prototype: Record<string, unknown>;\n };\n\n StateGraph.prototype.compile = instrumentStateGraphCompile(\n StateGraph.prototype.compile as (...args: unknown[]) => CompiledGraph,\n options,\n );\n }\n\n return exports;\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","InstrumentationNodeModuleDefinition","exports","InstrumentationNodeModuleFile","getClient","instrumentStateGraphCompile"],"mappings":";;;;;AAUA,MAAM,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,UAAA,KAAe,UAAU,EAAE;AACxE,MAAM,MAAM,UAAA,GAAaA,SAAO,CAAC;;AAE3B;;AAEN,MAAM,UAAU,CAAC,SAAS,CAAC,OAAA,GAAUG,gCAA2B;AAChE,QAAQ,UAAU,CAAC,SAAS,CAAC,OAAA;AAC7B,QAAQ,OAAO;AACf,OAAO;AACP,IAAI;;AAEJ,IAAI,OAAOH,SAAO;AAClB,EAAE;AACF;;;;"}
|
|
@@ -24,8 +24,8 @@ class SentryOpenAiInstrumentation extends instrumentation.InstrumentationBase {
|
|
|
24
24
|
/**
|
|
25
25
|
* Core patch logic applying instrumentation to the OpenAI and AzureOpenAI client constructors.
|
|
26
26
|
*/
|
|
27
|
-
_patch(exports) {
|
|
28
|
-
let result = exports;
|
|
27
|
+
_patch(exports$1) {
|
|
28
|
+
let result = exports$1;
|
|
29
29
|
result = this._patchClient(result, 'OpenAI');
|
|
30
30
|
result = this._patchClient(result, 'AzureOpenAI');
|
|
31
31
|
return result;
|
|
@@ -34,10 +34,10 @@ class SentryOpenAiInstrumentation extends instrumentation.InstrumentationBase {
|
|
|
34
34
|
/**
|
|
35
35
|
* Patch logic applying instrumentation to the specified client constructor.
|
|
36
36
|
*/
|
|
37
|
-
_patchClient(exports, exportKey) {
|
|
38
|
-
const Original = exports[exportKey];
|
|
37
|
+
_patchClient(exports$1, exportKey) {
|
|
38
|
+
const Original = exports$1[exportKey];
|
|
39
39
|
if (!Original) {
|
|
40
|
-
return exports;
|
|
40
|
+
return exports$1;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
const config = this.getConfig();
|
|
@@ -77,10 +77,10 @@ class SentryOpenAiInstrumentation extends instrumentation.InstrumentationBase {
|
|
|
77
77
|
// Constructor replacement - handle read-only properties
|
|
78
78
|
// The OpenAI property might have only a getter, so use defineProperty
|
|
79
79
|
try {
|
|
80
|
-
exports[exportKey] = WrappedOpenAI;
|
|
80
|
+
exports$1[exportKey] = WrappedOpenAI;
|
|
81
81
|
} catch (error) {
|
|
82
82
|
// If direct assignment fails, override the property descriptor
|
|
83
|
-
Object.defineProperty(exports, exportKey, {
|
|
83
|
+
Object.defineProperty(exports$1, exportKey, {
|
|
84
84
|
value: WrappedOpenAI,
|
|
85
85
|
writable: true,
|
|
86
86
|
configurable: true,
|
|
@@ -91,12 +91,12 @@ class SentryOpenAiInstrumentation extends instrumentation.InstrumentationBase {
|
|
|
91
91
|
// Wrap the default export if it points to the original constructor
|
|
92
92
|
// Constructor replacement - handle read-only properties
|
|
93
93
|
// The OpenAI property might have only a getter, so use defineProperty
|
|
94
|
-
if (exports.default === Original) {
|
|
94
|
+
if (exports$1.default === Original) {
|
|
95
95
|
try {
|
|
96
|
-
exports.default = WrappedOpenAI;
|
|
96
|
+
exports$1.default = WrappedOpenAI;
|
|
97
97
|
} catch (error) {
|
|
98
98
|
// If direct assignment fails, override the property descriptor
|
|
99
|
-
Object.defineProperty(exports, 'default', {
|
|
99
|
+
Object.defineProperty(exports$1, 'default', {
|
|
100
100
|
value: WrappedOpenAI,
|
|
101
101
|
writable: true,
|
|
102
102
|
configurable: true,
|
|
@@ -104,7 +104,7 @@ class SentryOpenAiInstrumentation extends instrumentation.InstrumentationBase {
|
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
return exports;
|
|
107
|
+
return exports$1;
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sources":["../../../../../src/integrations/tracing/openai/instrumentation.ts"],"sourcesContent":["import {\n InstrumentationBase,\n type InstrumentationConfig,\n type InstrumentationModuleDefinition,\n InstrumentationNodeModuleDefinition,\n} from '@opentelemetry/instrumentation';\nimport type { Integration, OpenAiClient, OpenAiOptions } from '@sentry/core';\nimport {\n _INTERNAL_shouldSkipAiProviderWrapping,\n getClient,\n instrumentOpenAiClient,\n OPENAI_INTEGRATION_NAME,\n SDK_VERSION,\n} from '@sentry/core';\n\nconst supportedVersions = ['>=4.0.0 <7'];\n\nexport interface OpenAiIntegration extends Integration {\n options: OpenAiOptions;\n}\n\ntype OpenAiInstrumentationOptions = InstrumentationConfig & OpenAiOptions;\n\n/**\n * Represents the patched shape of the OpenAI module export.\n */\ninterface PatchedModuleExports {\n [key: string]: unknown;\n OpenAI: abstract new (...args: unknown[]) => OpenAiClient;\n AzureOpenAI?: abstract new (...args: unknown[]) => OpenAiClient;\n}\n\n/**\n * Sentry OpenAI instrumentation using OpenTelemetry.\n */\nexport class SentryOpenAiInstrumentation extends InstrumentationBase<OpenAiInstrumentationOptions> {\n public constructor(config: OpenAiInstrumentationOptions = {}) {\n super('@sentry/instrumentation-openai', SDK_VERSION, config);\n }\n\n /**\n * Initializes the instrumentation by defining the modules to be patched.\n */\n public init(): InstrumentationModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition('openai', supportedVersions, this._patch.bind(this));\n return module;\n }\n\n /**\n * Core patch logic applying instrumentation to the OpenAI and AzureOpenAI client constructors.\n */\n private _patch(exports: PatchedModuleExports): PatchedModuleExports | void {\n let result = exports;\n result = this._patchClient(result, 'OpenAI');\n result = this._patchClient(result, 'AzureOpenAI');\n return result;\n }\n\n /**\n * Patch logic applying instrumentation to the specified client constructor.\n */\n private _patchClient(exports: PatchedModuleExports, exportKey: 'OpenAI' | 'AzureOpenAI'): PatchedModuleExports {\n const Original = exports[exportKey];\n if (!Original) {\n return exports;\n }\n\n const config = this.getConfig();\n\n const WrappedOpenAI = function (this: unknown, ...args: unknown[]) {\n // Check if wrapping should be skipped (e.g., when LangChain is handling instrumentation)\n if (_INTERNAL_shouldSkipAiProviderWrapping(OPENAI_INTEGRATION_NAME)) {\n return Reflect.construct(Original, args) as OpenAiClient;\n }\n\n const instance = Reflect.construct(Original, args);\n const client = getClient();\n const defaultPii = Boolean(client?.getOptions().sendDefaultPii);\n\n const recordInputs = config.recordInputs ?? defaultPii;\n const recordOutputs = config.recordOutputs ?? defaultPii;\n\n return instrumentOpenAiClient(instance as OpenAiClient, {\n recordInputs,\n recordOutputs,\n });\n } as unknown as abstract new (...args: unknown[]) => OpenAiClient;\n\n // Preserve static and prototype chains\n Object.setPrototypeOf(WrappedOpenAI, Original);\n Object.setPrototypeOf(WrappedOpenAI.prototype, Original.prototype);\n\n for (const key of Object.getOwnPropertyNames(Original)) {\n if (!['length', 'name', 'prototype'].includes(key)) {\n const descriptor = Object.getOwnPropertyDescriptor(Original, key);\n if (descriptor) {\n Object.defineProperty(WrappedOpenAI, key, descriptor);\n }\n }\n }\n\n // Constructor replacement - handle read-only properties\n // The OpenAI property might have only a getter, so use defineProperty\n try {\n exports[exportKey] = WrappedOpenAI;\n } catch (error) {\n // If direct assignment fails, override the property descriptor\n Object.defineProperty(exports, exportKey, {\n value: WrappedOpenAI,\n writable: true,\n configurable: true,\n enumerable: true,\n });\n }\n\n // Wrap the default export if it points to the original constructor\n // Constructor replacement - handle read-only properties\n // The OpenAI property might have only a getter, so use defineProperty\n if (exports.default === Original) {\n try {\n exports.default = WrappedOpenAI;\n } catch (error) {\n // If direct assignment fails, override the property descriptor\n Object.defineProperty(exports, 'default', {\n value: WrappedOpenAI,\n writable: true,\n configurable: true,\n enumerable: true,\n });\n }\n }\n return exports;\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","InstrumentationNodeModuleDefinition","_INTERNAL_shouldSkipAiProviderWrapping","OPENAI_INTEGRATION_NAME","getClient","instrumentOpenAiClient"],"mappings":";;;;;AAeA,MAAM,iBAAA,GAAoB,CAAC,YAAY,CAAC;;AAiBxC;AACA;AACA;AACO,MAAM,2BAAA,SAAoCA,mCAAmB,CAA+B;AACnG,GAAS,WAAW,CAAC,MAAM,GAAiC,EAAE,EAAE;AAChE,IAAI,KAAK,CAAC,gCAAgC,EAAEC,gBAAW,EAAE,MAAM,CAAC;AAChE,EAAE;;AAEF;AACA;AACA;AACA,GAAS,IAAI,GAAoC;AACjD,IAAI,MAAM,MAAA,GAAS,IAAIC,mDAAmC,CAAC,QAAQ,EAAE,iBAAiB,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC/G,IAAI,OAAO,MAAM;AACjB,EAAE;;AAEF;AACA;AACA;AACA,GAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sources":["../../../../../src/integrations/tracing/openai/instrumentation.ts"],"sourcesContent":["import {\n InstrumentationBase,\n type InstrumentationConfig,\n type InstrumentationModuleDefinition,\n InstrumentationNodeModuleDefinition,\n} from '@opentelemetry/instrumentation';\nimport type { Integration, OpenAiClient, OpenAiOptions } from '@sentry/core';\nimport {\n _INTERNAL_shouldSkipAiProviderWrapping,\n getClient,\n instrumentOpenAiClient,\n OPENAI_INTEGRATION_NAME,\n SDK_VERSION,\n} from '@sentry/core';\n\nconst supportedVersions = ['>=4.0.0 <7'];\n\nexport interface OpenAiIntegration extends Integration {\n options: OpenAiOptions;\n}\n\ntype OpenAiInstrumentationOptions = InstrumentationConfig & OpenAiOptions;\n\n/**\n * Represents the patched shape of the OpenAI module export.\n */\ninterface PatchedModuleExports {\n [key: string]: unknown;\n OpenAI: abstract new (...args: unknown[]) => OpenAiClient;\n AzureOpenAI?: abstract new (...args: unknown[]) => OpenAiClient;\n}\n\n/**\n * Sentry OpenAI instrumentation using OpenTelemetry.\n */\nexport class SentryOpenAiInstrumentation extends InstrumentationBase<OpenAiInstrumentationOptions> {\n public constructor(config: OpenAiInstrumentationOptions = {}) {\n super('@sentry/instrumentation-openai', SDK_VERSION, config);\n }\n\n /**\n * Initializes the instrumentation by defining the modules to be patched.\n */\n public init(): InstrumentationModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition('openai', supportedVersions, this._patch.bind(this));\n return module;\n }\n\n /**\n * Core patch logic applying instrumentation to the OpenAI and AzureOpenAI client constructors.\n */\n private _patch(exports: PatchedModuleExports): PatchedModuleExports | void {\n let result = exports;\n result = this._patchClient(result, 'OpenAI');\n result = this._patchClient(result, 'AzureOpenAI');\n return result;\n }\n\n /**\n * Patch logic applying instrumentation to the specified client constructor.\n */\n private _patchClient(exports: PatchedModuleExports, exportKey: 'OpenAI' | 'AzureOpenAI'): PatchedModuleExports {\n const Original = exports[exportKey];\n if (!Original) {\n return exports;\n }\n\n const config = this.getConfig();\n\n const WrappedOpenAI = function (this: unknown, ...args: unknown[]) {\n // Check if wrapping should be skipped (e.g., when LangChain is handling instrumentation)\n if (_INTERNAL_shouldSkipAiProviderWrapping(OPENAI_INTEGRATION_NAME)) {\n return Reflect.construct(Original, args) as OpenAiClient;\n }\n\n const instance = Reflect.construct(Original, args);\n const client = getClient();\n const defaultPii = Boolean(client?.getOptions().sendDefaultPii);\n\n const recordInputs = config.recordInputs ?? defaultPii;\n const recordOutputs = config.recordOutputs ?? defaultPii;\n\n return instrumentOpenAiClient(instance as OpenAiClient, {\n recordInputs,\n recordOutputs,\n });\n } as unknown as abstract new (...args: unknown[]) => OpenAiClient;\n\n // Preserve static and prototype chains\n Object.setPrototypeOf(WrappedOpenAI, Original);\n Object.setPrototypeOf(WrappedOpenAI.prototype, Original.prototype);\n\n for (const key of Object.getOwnPropertyNames(Original)) {\n if (!['length', 'name', 'prototype'].includes(key)) {\n const descriptor = Object.getOwnPropertyDescriptor(Original, key);\n if (descriptor) {\n Object.defineProperty(WrappedOpenAI, key, descriptor);\n }\n }\n }\n\n // Constructor replacement - handle read-only properties\n // The OpenAI property might have only a getter, so use defineProperty\n try {\n exports[exportKey] = WrappedOpenAI;\n } catch (error) {\n // If direct assignment fails, override the property descriptor\n Object.defineProperty(exports, exportKey, {\n value: WrappedOpenAI,\n writable: true,\n configurable: true,\n enumerable: true,\n });\n }\n\n // Wrap the default export if it points to the original constructor\n // Constructor replacement - handle read-only properties\n // The OpenAI property might have only a getter, so use defineProperty\n if (exports.default === Original) {\n try {\n exports.default = WrappedOpenAI;\n } catch (error) {\n // If direct assignment fails, override the property descriptor\n Object.defineProperty(exports, 'default', {\n value: WrappedOpenAI,\n writable: true,\n configurable: true,\n enumerable: true,\n });\n }\n }\n return exports;\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","InstrumentationNodeModuleDefinition","exports","_INTERNAL_shouldSkipAiProviderWrapping","OPENAI_INTEGRATION_NAME","getClient","instrumentOpenAiClient"],"mappings":";;;;;AAeA,MAAM,iBAAA,GAAoB,CAAC,YAAY,CAAC;;AAiBxC;AACA;AACA;AACO,MAAM,2BAAA,SAAoCA,mCAAmB,CAA+B;AACnG,GAAS,WAAW,CAAC,MAAM,GAAiC,EAAE,EAAE;AAChE,IAAI,KAAK,CAAC,gCAAgC,EAAEC,gBAAW,EAAE,MAAM,CAAC;AAChE,EAAE;;AAEF;AACA;AACA;AACA,GAAS,IAAI,GAAoC;AACjD,IAAI,MAAM,MAAA,GAAS,IAAIC,mDAAmC,CAAC,QAAQ,EAAE,iBAAiB,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC/G,IAAI,OAAO,MAAM;AACjB,EAAE;;AAEF;AACA;AACA;AACA,GAAU,MAAM,CAACC,SAAO,EAAqD;AAC7E,IAAI,IAAI,MAAA,GAASA,SAAO;AACxB,IAAI,MAAA,GAAS,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC;AAChD,IAAI,MAAA,GAAS,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,aAAa,CAAC;AACrD,IAAI,OAAO,MAAM;AACjB,EAAE;;AAEF;AACA;AACA;AACA,GAAU,YAAY,CAACA,SAAO,EAAwB,SAAS,EAAkD;AACjH,IAAI,MAAM,QAAA,GAAWA,SAAO,CAAC,SAAS,CAAC;AACvC,IAAI,IAAI,CAAC,QAAQ,EAAE;AACnB,MAAM,OAAOA,SAAO;AACpB,IAAI;;AAEJ,IAAI,MAAM,MAAA,GAAS,IAAI,CAAC,SAAS,EAAE;;AAEnC,IAAI,MAAM,gBAAgB,WAAyB,GAAG,IAAI,EAAa;AACvE;AACA,MAAM,IAAIC,2CAAsC,CAACC,4BAAuB,CAA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