@depup/sentry__node 10.47.0-depup.0 → 10.48.0-depup.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.
Files changed (31) hide show
  1. package/README.md +11 -3
  2. package/build/cjs/index.js +5 -1
  3. package/build/cjs/index.js.map +1 -1
  4. package/build/cjs/integrations/tracing/express.js +50 -141
  5. package/build/cjs/integrations/tracing/express.js.map +1 -1
  6. package/build/cjs/integrations/tracing/langchain/index.js +4 -3
  7. package/build/cjs/integrations/tracing/langchain/index.js.map +1 -1
  8. package/build/cjs/integrations/tracing/langchain/instrumentation.js +37 -3
  9. package/build/cjs/integrations/tracing/langchain/instrumentation.js.map +1 -1
  10. package/build/esm/index.js +3 -3
  11. package/build/esm/integrations/tracing/express.js +51 -142
  12. package/build/esm/integrations/tracing/express.js.map +1 -1
  13. package/build/esm/integrations/tracing/langchain/index.js +4 -3
  14. package/build/esm/integrations/tracing/langchain/index.js.map +1 -1
  15. package/build/esm/integrations/tracing/langchain/instrumentation.js +38 -4
  16. package/build/esm/integrations/tracing/langchain/instrumentation.js.map +1 -1
  17. package/build/esm/package.json +1 -1
  18. package/build/types/index.d.ts +2 -2
  19. package/build/types/index.d.ts.map +1 -1
  20. package/build/types/integrations/tracing/express.d.ts +13 -68
  21. package/build/types/integrations/tracing/express.d.ts.map +1 -1
  22. package/build/types/integrations/tracing/langchain/index.d.ts +4 -3
  23. package/build/types/integrations/tracing/langchain/index.d.ts.map +1 -1
  24. package/build/types/integrations/tracing/langchain/instrumentation.d.ts +10 -1
  25. package/build/types/integrations/tracing/langchain/instrumentation.d.ts.map +1 -1
  26. package/build/types-ts3.8/index.d.ts +2 -2
  27. package/build/types-ts3.8/integrations/tracing/express.d.ts +13 -68
  28. package/build/types-ts3.8/integrations/tracing/langchain/index.d.ts +4 -3
  29. package/build/types-ts3.8/integrations/tracing/langchain/instrumentation.d.ts +10 -1
  30. package/changes.json +16 -3
  31. package/package.json +24 -12
package/README.md CHANGED
@@ -13,10 +13,18 @@ npm install @depup/sentry__node
13
13
 
14
14
  | Field | Value |
15
15
  |-------|-------|
16
- | Original | [@sentry/node](https://www.npmjs.com/package/@sentry/node) @ 10.47.0 |
17
- | Processed | 2026-03-31 |
16
+ | Original | [@sentry/node](https://www.npmjs.com/package/@sentry/node) @ 10.48.0 |
17
+ | Processed | 2026-04-09 |
18
18
  | Smoke test | passed |
19
- | Deps updated | 0 |
19
+ | Deps updated | 3 |
20
+
21
+ ## Dependency Changes
22
+
23
+ | Dependency | From | To |
24
+ |------------|------|-----|
25
+ | @fastify/otel | 0.18.0 | ^0.18.1 |
26
+ | @prisma/instrumentation | 7.6.0 | ^7.7.0 |
27
+ | import-in-the-middle | ^3.0.0 | ^3.0.1 |
20
28
 
21
29
  ---
22
30
 
@@ -49,7 +49,6 @@ const nodeCore = require('@sentry/node-core');
49
49
  exports.httpIntegration = http.httpIntegration;
50
50
  exports.nativeNodeFetchIntegration = nodeFetch.nativeNodeFetchIntegration;
51
51
  exports.fsIntegration = fs.fsIntegration;
52
- exports.expressErrorHandler = express.expressErrorHandler;
53
52
  exports.expressIntegration = express.expressIntegration;
54
53
  exports.setupExpressErrorHandler = express.setupExpressErrorHandler;
55
54
  exports.fastifyIntegration = index$1.fastifyIntegration;
@@ -126,6 +125,7 @@ exports.createTransport = core.createTransport;
126
125
  exports.dedupeIntegration = core.dedupeIntegration;
127
126
  exports.endSession = core.endSession;
128
127
  exports.eventFiltersIntegration = core.eventFiltersIntegration;
128
+ exports.expressErrorHandler = core.expressErrorHandler;
129
129
  exports.extraErrorDataIntegration = core.extraErrorDataIntegration;
130
130
  exports.featureFlagsIntegration = core.featureFlagsIntegration;
131
131
  exports.flush = core.flush;
@@ -144,6 +144,7 @@ exports.httpHeadersToSpanAttributes = core.httpHeadersToSpanAttributes;
144
144
  exports.inboundFiltersIntegration = core.inboundFiltersIntegration;
145
145
  exports.instrumentAnthropicAiClient = core.instrumentAnthropicAiClient;
146
146
  exports.instrumentGoogleGenAIClient = core.instrumentGoogleGenAIClient;
147
+ exports.instrumentLangChainEmbeddings = core.instrumentLangChainEmbeddings;
147
148
  exports.instrumentLangGraph = core.instrumentLangGraph;
148
149
  exports.instrumentOpenAiClient = core.instrumentOpenAiClient;
149
150
  exports.instrumentStateGraphCompile = core.instrumentStateGraphCompile;
@@ -166,6 +167,7 @@ exports.setMeasurement = core.setMeasurement;
166
167
  exports.setTag = core.setTag;
167
168
  exports.setTags = core.setTags;
168
169
  exports.setUser = core.setUser;
170
+ exports.spanStreamingIntegration = core.spanStreamingIntegration;
169
171
  exports.spanToBaggageHeader = core.spanToBaggageHeader;
170
172
  exports.spanToJSON = core.spanToJSON;
171
173
  exports.spanToTraceHeader = core.spanToTraceHeader;
@@ -188,6 +190,7 @@ exports.zodErrorsIntegration = core.zodErrorsIntegration;
188
190
  exports.NODE_VERSION = nodeCore.NODE_VERSION;
189
191
  exports.NodeClient = nodeCore.NodeClient;
190
192
  exports.SentryContextManager = nodeCore.SentryContextManager;
193
+ exports._INTERNAL_normalizeCollectionInterval = nodeCore._INTERNAL_normalizeCollectionInterval;
191
194
  exports.anrIntegration = nodeCore.anrIntegration;
192
195
  exports.childProcessIntegration = nodeCore.childProcessIntegration;
193
196
  exports.contextLinesIntegration = nodeCore.contextLinesIntegration;
@@ -214,4 +217,5 @@ exports.processSessionIntegration = nodeCore.processSessionIntegration;
214
217
  exports.spotlightIntegration = nodeCore.spotlightIntegration;
215
218
  exports.systemErrorIntegration = nodeCore.systemErrorIntegration;
216
219
  exports.validateOpenTelemetrySetup = nodeCore.validateOpenTelemetrySetup;
220
+ exports.withStreamedSpan = nodeCore.withStreamedSpan;
217
221
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,165 +1,74 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- const instrumentationExpress = require('@opentelemetry/instrumentation-express');
4
- const core = require('@sentry/core');
3
+ const instrumentation = require('@opentelemetry/instrumentation');
4
+ const api = require('@opentelemetry/api');
5
+ const core$1 = require('@opentelemetry/core');
5
6
  const nodeCore = require('@sentry/node-core');
7
+ const core = require('@sentry/core');
6
8
  const debugBuild = require('../../debug-build.js');
7
9
 
8
10
  const INTEGRATION_NAME = 'Express';
11
+ const SUPPORTED_VERSIONS = ['>=4.0.0 <6'];
9
12
 
10
- function requestHook(span) {
11
- nodeCore.addOriginToSpan(span, 'auto.http.otel.express');
12
-
13
- const attributes = core.spanToJSON(span).data;
14
- // this is one of: middleware, request_handler, router
15
- const type = attributes['express.type'];
16
-
17
- if (type) {
18
- span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, `${type}.express`);
19
- }
20
-
21
- // Also update the name, we don't need to "middleware - " prefix
22
- const name = attributes['express.name'];
23
- if (typeof name === 'string') {
24
- span.updateName(name);
25
- }
26
- }
27
-
28
- function spanNameHook(info, defaultName) {
29
- if (core.getIsolationScope() === core.getDefaultIsolationScope()) {
30
- debugBuild.DEBUG_BUILD && core.debug.warn('Isolation scope is still default isolation scope - skipping setting transactionName');
31
- return defaultName;
32
- }
33
- if (info.layerType === 'request_handler') {
34
- // type cast b/c Otel unfortunately types info.request as any :(
35
- const req = info.request ;
36
- const method = req.method ? req.method.toUpperCase() : 'GET';
37
- core.getIsolationScope().setTransactionName(`${method} ${info.route}`);
38
- }
39
- return defaultName;
13
+ function setupExpressErrorHandler(
14
+ //oxlint-disable-next-line no-explicit-any
15
+ app,
16
+ options,
17
+ ) {
18
+ core.setupExpressErrorHandler(app, options);
19
+ nodeCore.ensureIsWrapped(app.use, 'express');
40
20
  }
41
21
 
42
22
  const instrumentExpress = nodeCore.generateInstrumentOnce(
43
23
  INTEGRATION_NAME,
44
- () =>
45
- new instrumentationExpress.ExpressInstrumentation({
46
- requestHook: span => requestHook(span),
47
- spanNameHook: (info, defaultName) => spanNameHook(info, defaultName),
48
- }),
24
+ (options) => new ExpressInstrumentation(options),
49
25
  );
50
26
 
51
- const _expressIntegration = (() => {
27
+ class ExpressInstrumentation extends instrumentation.InstrumentationBase {
28
+ constructor(config = {}) {
29
+ super('sentry-express', core.SDK_VERSION, config);
30
+ }
31
+ init() {
32
+ const module = new instrumentation.InstrumentationNodeModuleDefinition(
33
+ 'express',
34
+ SUPPORTED_VERSIONS,
35
+ express => {
36
+ try {
37
+ core.patchExpressModule({
38
+ ...this.getConfig(),
39
+ express,
40
+ onRouteResolved(route) {
41
+ const rpcMetadata = core$1.getRPCMetadata(api.context.active());
42
+ if (route && rpcMetadata?.type === core$1.RPCType.HTTP) {
43
+ rpcMetadata.route = route;
44
+ }
45
+ },
46
+ });
47
+ } catch (e) {
48
+ debugBuild.DEBUG_BUILD && core.debug.error('Failed to patch express module:', e);
49
+ }
50
+ return express;
51
+ },
52
+ // we do not ever actually unpatch in our SDKs
53
+ express => express,
54
+ );
55
+ return module;
56
+ }
57
+ }
58
+
59
+ const _expressInstrumentation = ((options) => {
52
60
  return {
53
61
  name: INTEGRATION_NAME,
54
62
  setupOnce() {
55
- instrumentExpress();
63
+ instrumentExpress(options);
56
64
  },
57
65
  };
58
66
  }) ;
59
67
 
60
- /**
61
- * Adds Sentry tracing instrumentation for [Express](https://expressjs.com/).
62
- *
63
- * If you also want to capture errors, you need to call `setupExpressErrorHandler(app)` after you set up your Express server.
64
- *
65
- * For more information, see the [express documentation](https://docs.sentry.io/platforms/javascript/guides/express/).
66
- *
67
- * @example
68
- * ```javascript
69
- * const Sentry = require('@sentry/node');
70
- *
71
- * Sentry.init({
72
- * integrations: [Sentry.expressIntegration()],
73
- * })
74
- * ```
75
- */
76
- const expressIntegration = core.defineIntegration(_expressIntegration);
77
-
78
- /**
79
- * An Express-compatible error handler.
80
- */
81
- function expressErrorHandler(options) {
82
- return function sentryErrorMiddleware(
83
- error,
84
- request,
85
- res,
86
- next,
87
- ) {
88
- const normalizedRequest = core.httpRequestToRequestData(request);
89
- // Ensure we use the express-enhanced request here, instead of the plain HTTP one
90
- // When an error happens, the `expressRequestHandler` middleware does not run, so we set it here too
91
- core.getIsolationScope().setSDKProcessingMetadata({ normalizedRequest });
92
-
93
- const shouldHandleError = options?.shouldHandleError || defaultShouldHandleError;
94
-
95
- if (shouldHandleError(error)) {
96
- const eventId = core.captureException(error, { mechanism: { type: 'auto.middleware.express', handled: false } });
97
- (res ).sentry = eventId;
98
- }
99
-
100
- next(error);
101
- };
102
- }
103
-
104
- function expressRequestHandler() {
105
- return function sentryRequestMiddleware(
106
- request,
107
- _res,
108
- next,
109
- ) {
110
- const normalizedRequest = core.httpRequestToRequestData(request);
111
- // Ensure we use the express-enhanced request here, instead of the plain HTTP one
112
- core.getIsolationScope().setSDKProcessingMetadata({ normalizedRequest });
113
-
114
- next();
115
- };
116
- }
117
-
118
- /**
119
- * Add an Express error handler to capture errors to Sentry.
120
- *
121
- * The error handler must be before any other middleware and after all controllers.
122
- *
123
- * @param app The Express instances
124
- * @param options {ExpressHandlerOptions} Configuration options for the handler
125
- *
126
- * @example
127
- * ```javascript
128
- * const Sentry = require('@sentry/node');
129
- * const express = require("express");
130
- *
131
- * const app = express();
132
- *
133
- * // Add your routes, etc.
134
- *
135
- * // Add this after all routes,
136
- * // but before any and other error-handling middlewares are defined
137
- * Sentry.setupExpressErrorHandler(app);
138
- *
139
- * app.listen(3000);
140
- * ```
141
- */
142
- function setupExpressErrorHandler(
143
- app,
144
- options,
145
- ) {
146
- app.use(expressRequestHandler());
147
- app.use(expressErrorHandler(options));
148
- nodeCore.ensureIsWrapped(app.use, 'express');
149
- }
150
-
151
- function getStatusCodeFromResponse(error) {
152
- const statusCode = error.status || error.statusCode || error.status_code || error.output?.statusCode;
153
- return statusCode ? parseInt(statusCode , 10) : 500;
154
- }
155
-
156
- /** Returns true if response code is internal server error */
157
- function defaultShouldHandleError(error) {
158
- const status = getStatusCodeFromResponse(error);
159
- return status >= 500;
160
- }
68
+ const expressIntegration = core.defineIntegration(_expressInstrumentation);
161
69
 
162
- exports.expressErrorHandler = expressErrorHandler;
70
+ exports.expressErrorHandler = core.expressErrorHandler;
71
+ exports.ExpressInstrumentation = ExpressInstrumentation;
163
72
  exports.expressIntegration = expressIntegration;
164
73
  exports.instrumentExpress = instrumentExpress;
165
74
  exports.setupExpressErrorHandler = setupExpressErrorHandler;
@@ -1 +1 @@
1
- {"version":3,"file":"express.js","sources":["../../../../src/integrations/tracing/express.ts"],"sourcesContent":["import type * as http from 'node:http';\nimport type { Span } from '@opentelemetry/api';\nimport type { ExpressRequestInfo } from '@opentelemetry/instrumentation-express';\nimport { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';\nimport type { IntegrationFn } from '@sentry/core';\nimport {\n captureException,\n debug,\n defineIntegration,\n getDefaultIsolationScope,\n getIsolationScope,\n httpRequestToRequestData,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n spanToJSON,\n} from '@sentry/core';\nimport { addOriginToSpan, ensureIsWrapped, generateInstrumentOnce } from '@sentry/node-core';\nimport { DEBUG_BUILD } from '../../debug-build';\n\nconst INTEGRATION_NAME = 'Express';\n\nfunction requestHook(span: Span): void {\n addOriginToSpan(span, 'auto.http.otel.express');\n\n const attributes = spanToJSON(span).data;\n // this is one of: middleware, request_handler, router\n const type = attributes['express.type'];\n\n if (type) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, `${type}.express`);\n }\n\n // Also update the name, we don't need to \"middleware - \" prefix\n const name = attributes['express.name'];\n if (typeof name === 'string') {\n span.updateName(name);\n }\n}\n\nfunction spanNameHook(info: ExpressRequestInfo<unknown>, defaultName: string): string {\n if (getIsolationScope() === getDefaultIsolationScope()) {\n DEBUG_BUILD && debug.warn('Isolation scope is still default isolation scope - skipping setting transactionName');\n return defaultName;\n }\n if (info.layerType === 'request_handler') {\n // type cast b/c Otel unfortunately types info.request as any :(\n const req = info.request as { method?: string };\n const method = req.method ? req.method.toUpperCase() : 'GET';\n getIsolationScope().setTransactionName(`${method} ${info.route}`);\n }\n return defaultName;\n}\n\nexport const instrumentExpress = generateInstrumentOnce(\n INTEGRATION_NAME,\n () =>\n new ExpressInstrumentation({\n requestHook: span => requestHook(span),\n spanNameHook: (info, defaultName) => spanNameHook(info, defaultName),\n }),\n);\n\nconst _expressIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentExpress();\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for [Express](https://expressjs.com/).\n *\n * If you also want to capture errors, you need to call `setupExpressErrorHandler(app)` after you set up your Express server.\n *\n * For more information, see the [express documentation](https://docs.sentry.io/platforms/javascript/guides/express/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.expressIntegration()],\n * })\n * ```\n */\nexport const expressIntegration = defineIntegration(_expressIntegration);\n\ninterface MiddlewareError extends Error {\n status?: number | string;\n statusCode?: number | string;\n status_code?: number | string;\n output?: {\n statusCode?: number | string;\n };\n}\n\ntype ExpressMiddleware = (req: http.IncomingMessage, res: http.ServerResponse, next: () => void) => void;\n\ntype ExpressErrorMiddleware = (\n error: MiddlewareError,\n req: http.IncomingMessage,\n res: http.ServerResponse,\n next: (error: MiddlewareError) => void,\n) => void;\n\ninterface ExpressHandlerOptions {\n /**\n * Callback method deciding whether error should be captured and sent to Sentry\n * @param error Captured middleware error\n */\n shouldHandleError?(this: void, error: MiddlewareError): boolean;\n}\n\n/**\n * An Express-compatible error handler.\n */\nexport function expressErrorHandler(options?: ExpressHandlerOptions): ExpressErrorMiddleware {\n return function sentryErrorMiddleware(\n error: MiddlewareError,\n request: http.IncomingMessage,\n res: http.ServerResponse,\n next: (error: MiddlewareError) => void,\n ): void {\n const normalizedRequest = httpRequestToRequestData(request);\n // Ensure we use the express-enhanced request here, instead of the plain HTTP one\n // When an error happens, the `expressRequestHandler` middleware does not run, so we set it here too\n getIsolationScope().setSDKProcessingMetadata({ normalizedRequest });\n\n const shouldHandleError = options?.shouldHandleError || defaultShouldHandleError;\n\n if (shouldHandleError(error)) {\n const eventId = captureException(error, { mechanism: { type: 'auto.middleware.express', handled: false } });\n (res as { sentry?: string }).sentry = eventId;\n }\n\n next(error);\n };\n}\n\nfunction expressRequestHandler(): ExpressMiddleware {\n return function sentryRequestMiddleware(\n request: http.IncomingMessage,\n _res: http.ServerResponse,\n next: () => void,\n ): void {\n const normalizedRequest = httpRequestToRequestData(request);\n // Ensure we use the express-enhanced request here, instead of the plain HTTP one\n getIsolationScope().setSDKProcessingMetadata({ normalizedRequest });\n\n next();\n };\n}\n\n/**\n * Add an Express error handler to capture errors to Sentry.\n *\n * The error handler must be before any other middleware and after all controllers.\n *\n * @param app The Express instances\n * @param options {ExpressHandlerOptions} Configuration options for the handler\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n * const express = require(\"express\");\n *\n * const app = express();\n *\n * // Add your routes, etc.\n *\n * // Add this after all routes,\n * // but before any and other error-handling middlewares are defined\n * Sentry.setupExpressErrorHandler(app);\n *\n * app.listen(3000);\n * ```\n */\nexport function setupExpressErrorHandler(\n app: { use: (middleware: ExpressMiddleware | ExpressErrorMiddleware) => unknown },\n options?: ExpressHandlerOptions,\n): void {\n app.use(expressRequestHandler());\n app.use(expressErrorHandler(options));\n ensureIsWrapped(app.use, 'express');\n}\n\nfunction getStatusCodeFromResponse(error: MiddlewareError): number {\n const statusCode = error.status || error.statusCode || error.status_code || error.output?.statusCode;\n return statusCode ? parseInt(statusCode as string, 10) : 500;\n}\n\n/** Returns true if response code is internal server error */\nfunction defaultShouldHandleError(error: MiddlewareError): boolean {\n const status = getStatusCodeFromResponse(error);\n return status >= 500;\n}\n"],"names":["addOriginToSpan","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_OP","getIsolationScope","getDefaultIsolationScope","DEBUG_BUILD","debug","generateInstrumentOnce","ExpressInstrumentation","defineIntegration","httpRequestToRequestData","captureException","ensureIsWrapped"],"mappings":";;;;;;;AAkBA,MAAM,gBAAA,GAAmB,SAAS;;AAElC,SAAS,WAAW,CAAC,IAAI,EAAc;AACvC,EAAEA,wBAAe,CAAC,IAAI,EAAE,wBAAwB,CAAC;;AAEjD,EAAE,MAAM,aAAaC,eAAU,CAAC,IAAI,CAAC,CAAC,IAAI;AAC1C;AACA,EAAE,MAAM,IAAA,GAAO,UAAU,CAAC,cAAc,CAAC;;AAEzC,EAAE,IAAI,IAAI,EAAE;AACZ,IAAI,IAAI,CAAC,YAAY,CAACC,iCAA4B,EAAE,CAAC,EAAA,IAAA,CAAA,QAAA,CAAA,CAAA;AACA,EAAA;;AAEA;AACA,EAAA,MAAA,IAAA,GAAA,UAAA,CAAA,cAAA,CAAA;AACA,EAAA,IAAA,OAAA,IAAA,KAAA,QAAA,EAAA;AACA,IAAA,IAAA,CAAA,UAAA,CAAA,IAAA,CAAA;AACA,EAAA;AACA;;AAEA,SAAA,YAAA,CAAA,IAAA,EAAA,WAAA,EAAA;AACA,EAAA,IAAAC,sBAAA,EAAA,KAAAC,6BAAA,EAAA,EAAA;AACA,IAAAC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A,CAAA,WAAA,IAAA,KAAA,CAAA,MAAA,EAAA,UAAA;AACA,EAAA,OAAA,UAAA,GAAA,QAAA,CAAA,UAAA,GAAA,EAAA,CAAA,GAAA,GAAA;AACA;;AAEA;AACA,SAAA,wBAAA,CAAA,KAAA,EAAA;AACA,EAAA,MAAA,MAAA,GAAA,yBAAA,CAAA,KAAA,CAAA;AACA,EAAA,OAAA,MAAA,IAAA,GAAA;AACA;;;;;;;"}
1
+ {"version":3,"file":"express.js","sources":["../../../../src/integrations/tracing/express.ts"],"sourcesContent":["// Automatic istrumentation for Express using OTel\nimport type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';\nimport { context } from '@opentelemetry/api';\nimport { getRPCMetadata, RPCType } from '@opentelemetry/core';\n\nimport { ensureIsWrapped, generateInstrumentOnce } from '@sentry/node-core';\nimport {\n type ExpressIntegrationOptions,\n type IntegrationFn,\n debug,\n patchExpressModule,\n SDK_VERSION,\n defineIntegration,\n setupExpressErrorHandler as coreSetupExpressErrorHandler,\n type ExpressHandlerOptions,\n} from '@sentry/core';\nexport { expressErrorHandler } from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\n\nconst INTEGRATION_NAME = 'Express';\nconst SUPPORTED_VERSIONS = ['>=4.0.0 <6'];\n\nexport function setupExpressErrorHandler(\n //oxlint-disable-next-line no-explicit-any\n app: { use: (middleware: any) => unknown },\n options?: ExpressHandlerOptions,\n): void {\n coreSetupExpressErrorHandler(app, options);\n ensureIsWrapped(app.use, 'express');\n}\n\nexport type ExpressInstrumentationConfig = InstrumentationConfig &\n Omit<ExpressIntegrationOptions, 'express' | 'onRouteResolved'>;\n\nexport const instrumentExpress = generateInstrumentOnce(\n INTEGRATION_NAME,\n (options?: ExpressInstrumentationConfig) => new ExpressInstrumentation(options),\n);\n\nexport class ExpressInstrumentation extends InstrumentationBase<ExpressInstrumentationConfig> {\n public constructor(config: ExpressInstrumentationConfig = {}) {\n super('sentry-express', SDK_VERSION, config);\n }\n public init(): InstrumentationNodeModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition(\n 'express',\n SUPPORTED_VERSIONS,\n express => {\n try {\n patchExpressModule({\n ...this.getConfig(),\n express,\n onRouteResolved(route) {\n const rpcMetadata = getRPCMetadata(context.active());\n if (route && rpcMetadata?.type === RPCType.HTTP) {\n rpcMetadata.route = route;\n }\n },\n });\n } catch (e) {\n DEBUG_BUILD && debug.error('Failed to patch express module:', e);\n }\n return express;\n },\n // we do not ever actually unpatch in our SDKs\n express => express,\n );\n return module;\n }\n}\n\nconst _expressInstrumentation = ((options?: ExpressInstrumentationConfig) => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentExpress(options);\n },\n };\n}) satisfies IntegrationFn;\n\nexport const expressIntegration = defineIntegration(_expressInstrumentation);\n"],"names":["coreSetupExpressErrorHandler","ensureIsWrapped","generateInstrumentOnce","InstrumentationBase","SDK_VERSION","InstrumentationNodeModuleDefinition","patchExpressModule","getRPCMetadata","context","RPCType","DEBUG_BUILD","debug","defineIntegration"],"mappings":";;;;;;;;;AAoBA,MAAM,gBAAA,GAAmB,SAAS;AAClC,MAAM,kBAAA,GAAqB,CAAC,YAAY,CAAC;;AAElC,SAAS,wBAAwB;AACxC;AACA,EAAE,GAAG;AACL,EAAE,OAAO;AACT,EAAQ;AACR,EAAEA,6BAA4B,CAAC,GAAG,EAAE,OAAO,CAAC;AAC5C,EAAEC,wBAAe,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC;AACrC;;AAKO,MAAM,iBAAA,GAAoBC,+BAAsB;AACvD,EAAE,gBAAgB;AAClB,EAAE,CAAC,OAAO,KAAoC,IAAI,sBAAsB,CAAC,OAAO,CAAC;AACjF;;AAEO,MAAM,sBAAA,SAA+BC,mCAAmB,CAA+B;AAC9F,GAAS,WAAW,CAAC,MAAM,GAAiC,EAAE,EAAE;AAChE,IAAI,KAAK,CAAC,gBAAgB,EAAEC,gBAAW,EAAE,MAAM,CAAC;AAChD,EAAE;AACF,GAAS,IAAI,GAAwC;AACrD,IAAI,MAAM,MAAA,GAAS,IAAIC,mDAAmC;AAC1D,MAAM,SAAS;AACf,MAAM,kBAAkB;AACxB,MAAM,WAAW;AACjB,QAAQ,IAAI;AACZ,UAAUC,uBAAkB,CAAC;AAC7B,YAAY,GAAG,IAAI,CAAC,SAAS,EAAE;AAC/B,YAAY,OAAO;AACnB,YAAY,eAAe,CAAC,KAAK,EAAE;AACnC,cAAc,MAAM,WAAA,GAAcC,qBAAc,CAACC,WAAO,CAAC,MAAM,EAAE,CAAC;AAClE,cAAc,IAAI,KAAA,IAAS,WAAW,EAAE,IAAA,KAASC,cAAO,CAAC,IAAI,EAAE;AAC/D,gBAAgB,WAAW,CAAC,KAAA,GAAQ,KAAK;AACzC,cAAc;AACd,YAAY,CAAC;AACb,WAAW,CAAC;AACZ,QAAQ,CAAA,CAAE,OAAO,CAAC,EAAE;AACpB,UAAUC,sBAAA,IAAeC,UAAK,CAAC,KAAK,CAAC,iCAAiC,EAAE,CAAC,CAAC;AAC1E,QAAQ;AACR,QAAQ,OAAO,OAAO;AACtB,MAAM,CAAC;AACP;AACA,MAAM,OAAA,IAAW,OAAO;AACxB,KAAK;AACL,IAAI,OAAO,MAAM;AACjB,EAAE;AACF;;AAEA,MAAM,2BAA2B,CAAC,OAAO,KAAoC;AAC7E,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B,IAAI,SAAS,GAAG;AAChB,MAAM,iBAAiB,CAAC,OAAO,CAAC;AAChC,IAAI,CAAC;AACL,GAAG;AACH,CAAC,CAAA;;MAEY,kBAAA,GAAqBC,sBAAiB,CAAC,uBAAuB;;;;;;;;"}
@@ -104,9 +104,10 @@ const _langChainIntegration = ((options = {}) => {
104
104
  * ## Supported Events
105
105
  *
106
106
  * The integration captures the following LangChain lifecycle events:
107
- * - LLM/Chat Model: start, end, error
108
- * - Chain: start, end, error
109
- * - Tool: start, end, error
107
+ * - LLM/Chat Model: start, end, error (via callbacks)
108
+ * - Chain: start, end, error (via callbacks)
109
+ * - Tool: start, end, error (via callbacks)
110
+ * - Embeddings: embedQuery, embedDocuments (via direct method wrapping)
110
111
  *
111
112
  */
112
113
  const langChainIntegration = core.defineIntegration(_langChainIntegration);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/langchain/index.ts"],"sourcesContent":["import type { IntegrationFn, LangChainOptions } from '@sentry/core';\nimport { defineIntegration, LANGCHAIN_INTEGRATION_NAME } from '@sentry/core';\nimport { generateInstrumentOnce } from '@sentry/node-core';\nimport { SentryLangChainInstrumentation } from './instrumentation';\n\nexport const instrumentLangChain = generateInstrumentOnce<LangChainOptions>(\n LANGCHAIN_INTEGRATION_NAME,\n options => new SentryLangChainInstrumentation(options),\n);\n\nconst _langChainIntegration = ((options: LangChainOptions = {}) => {\n return {\n name: LANGCHAIN_INTEGRATION_NAME,\n setupOnce() {\n instrumentLangChain(options);\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for LangChain.\n *\n * This integration is enabled by default.\n *\n * When configured, this integration automatically instruments LangChain runnable instances\n * to capture telemetry data by injecting Sentry callback handlers into all LangChain calls.\n *\n * **Important:** This integration automatically skips wrapping the OpenAI, Anthropic, and Google GenAI\n * providers to prevent duplicate spans when using LangChain with these AI providers.\n * LangChain handles the instrumentation for all underlying AI providers.\n *\n * @example\n * ```javascript\n * import * as Sentry from '@sentry/node';\n * import { ChatOpenAI } from '@langchain/openai';\n *\n * Sentry.init({\n * integrations: [Sentry.langChainIntegration()],\n * sendDefaultPii: true, // Enable to record inputs/outputs\n * });\n *\n * // LangChain calls are automatically instrumented\n * const model = new ChatOpenAI();\n * await model.invoke(\"What is the capital of France?\");\n * ```\n *\n * ## Manual Callback Handler\n *\n * You can also manually add the Sentry callback handler alongside other callbacks:\n *\n * @example\n * ```javascript\n * import * as Sentry from '@sentry/node';\n * import { ChatOpenAI } from '@langchain/openai';\n *\n * const sentryHandler = Sentry.createLangChainCallbackHandler({\n * recordInputs: true,\n * recordOutputs: true\n * });\n *\n * const model = new ChatOpenAI();\n * await model.invoke(\n * \"What is the capital of France?\",\n * { callbacks: [sentryHandler, myOtherCallback] }\n * );\n * ```\n *\n * ## Options\n *\n * - `recordInputs`: Whether to record input messages/prompts (default: respects `sendDefaultPii` client option)\n * - `recordOutputs`: Whether to record response text (default: respects `sendDefaultPii` client option)\n *\n * ### Default Behavior\n *\n * By default, the integration will:\n * - Record inputs and outputs ONLY if `sendDefaultPii` is set to `true` in your Sentry client options\n * - Otherwise, inputs and outputs are NOT recorded unless explicitly enabled\n *\n * @example\n * ```javascript\n * // Record inputs and outputs when sendDefaultPii is false\n * Sentry.init({\n * integrations: [\n * Sentry.langChainIntegration({\n * recordInputs: true,\n * recordOutputs: true\n * })\n * ],\n * });\n *\n * // Never record inputs/outputs regardless of sendDefaultPii\n * Sentry.init({\n * sendDefaultPii: true,\n * integrations: [\n * Sentry.langChainIntegration({\n * recordInputs: false,\n * recordOutputs: false\n * })\n * ],\n * });\n * ```\n *\n * ## Supported Events\n *\n * The integration captures the following LangChain lifecycle events:\n * - LLM/Chat Model: start, end, error\n * - Chain: start, end, error\n * - Tool: start, end, error\n *\n */\nexport const langChainIntegration = defineIntegration(_langChainIntegration);\n"],"names":["generateInstrumentOnce","LANGCHAIN_INTEGRATION_NAME","SentryLangChainInstrumentation","defineIntegration"],"mappings":";;;;;;AAKO,MAAM,mBAAA,GAAsBA,+BAAsB;AACzD,EAAEC,+BAA0B;AAC5B,EAAE,WAAW,IAAIC,8CAA8B,CAAC,OAAO,CAAC;AACxD;;AAEA,MAAM,qBAAA,IAAyB,CAAC,OAAO,GAAqB,EAAE,KAAK;AACnE,EAAE,OAAO;AACT,IAAI,IAAI,EAAED,+BAA0B;AACpC,IAAI,SAAS,GAAG;AAChB,MAAM,mBAAmB,CAAC,OAAO,CAAC;AAClC,IAAI,CAAC;AACL,GAAG;AACH,CAAC,CAAA;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACa,oBAAA,GAAuBE,sBAAiB,CAAC,qBAAqB;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/langchain/index.ts"],"sourcesContent":["import type { IntegrationFn, LangChainOptions } from '@sentry/core';\nimport { defineIntegration, LANGCHAIN_INTEGRATION_NAME } from '@sentry/core';\nimport { generateInstrumentOnce } from '@sentry/node-core';\nimport { SentryLangChainInstrumentation } from './instrumentation';\n\nexport const instrumentLangChain = generateInstrumentOnce<LangChainOptions>(\n LANGCHAIN_INTEGRATION_NAME,\n options => new SentryLangChainInstrumentation(options),\n);\n\nconst _langChainIntegration = ((options: LangChainOptions = {}) => {\n return {\n name: LANGCHAIN_INTEGRATION_NAME,\n setupOnce() {\n instrumentLangChain(options);\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for LangChain.\n *\n * This integration is enabled by default.\n *\n * When configured, this integration automatically instruments LangChain runnable instances\n * to capture telemetry data by injecting Sentry callback handlers into all LangChain calls.\n *\n * **Important:** This integration automatically skips wrapping the OpenAI, Anthropic, and Google GenAI\n * providers to prevent duplicate spans when using LangChain with these AI providers.\n * LangChain handles the instrumentation for all underlying AI providers.\n *\n * @example\n * ```javascript\n * import * as Sentry from '@sentry/node';\n * import { ChatOpenAI } from '@langchain/openai';\n *\n * Sentry.init({\n * integrations: [Sentry.langChainIntegration()],\n * sendDefaultPii: true, // Enable to record inputs/outputs\n * });\n *\n * // LangChain calls are automatically instrumented\n * const model = new ChatOpenAI();\n * await model.invoke(\"What is the capital of France?\");\n * ```\n *\n * ## Manual Callback Handler\n *\n * You can also manually add the Sentry callback handler alongside other callbacks:\n *\n * @example\n * ```javascript\n * import * as Sentry from '@sentry/node';\n * import { ChatOpenAI } from '@langchain/openai';\n *\n * const sentryHandler = Sentry.createLangChainCallbackHandler({\n * recordInputs: true,\n * recordOutputs: true\n * });\n *\n * const model = new ChatOpenAI();\n * await model.invoke(\n * \"What is the capital of France?\",\n * { callbacks: [sentryHandler, myOtherCallback] }\n * );\n * ```\n *\n * ## Options\n *\n * - `recordInputs`: Whether to record input messages/prompts (default: respects `sendDefaultPii` client option)\n * - `recordOutputs`: Whether to record response text (default: respects `sendDefaultPii` client option)\n *\n * ### Default Behavior\n *\n * By default, the integration will:\n * - Record inputs and outputs ONLY if `sendDefaultPii` is set to `true` in your Sentry client options\n * - Otherwise, inputs and outputs are NOT recorded unless explicitly enabled\n *\n * @example\n * ```javascript\n * // Record inputs and outputs when sendDefaultPii is false\n * Sentry.init({\n * integrations: [\n * Sentry.langChainIntegration({\n * recordInputs: true,\n * recordOutputs: true\n * })\n * ],\n * });\n *\n * // Never record inputs/outputs regardless of sendDefaultPii\n * Sentry.init({\n * sendDefaultPii: true,\n * integrations: [\n * Sentry.langChainIntegration({\n * recordInputs: false,\n * recordOutputs: false\n * })\n * ],\n * });\n * ```\n *\n * ## Supported Events\n *\n * The integration captures the following LangChain lifecycle events:\n * - LLM/Chat Model: start, end, error (via callbacks)\n * - Chain: start, end, error (via callbacks)\n * - Tool: start, end, error (via callbacks)\n * - Embeddings: embedQuery, embedDocuments (via direct method wrapping)\n *\n */\nexport const langChainIntegration = defineIntegration(_langChainIntegration);\n"],"names":["generateInstrumentOnce","LANGCHAIN_INTEGRATION_NAME","SentryLangChainInstrumentation","defineIntegration"],"mappings":";;;;;;AAKO,MAAM,mBAAA,GAAsBA,+BAAsB;AACzD,EAAEC,+BAA0B;AAC5B,EAAE,WAAW,IAAIC,8CAA8B,CAAC,OAAO,CAAC;AACxD;;AAEA,MAAM,qBAAA,IAAyB,CAAC,OAAO,GAAqB,EAAE,KAAK;AACnE,EAAE,OAAO;AACT,IAAI,IAAI,EAAED,+BAA0B;AACpC,IAAI,SAAS,GAAG;AAChB,MAAM,mBAAmB,CAAC,OAAO,CAAC;AAClC,IAAI,CAAC;AACL,GAAG;AACH,CAAC,CAAA;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACa,oBAAA,GAAuBE,sBAAiB,CAAC,qBAAqB;;;;;"}
@@ -144,7 +144,7 @@ class SentryLangChainInstrumentation extends instrumentation.InstrumentationBase
144
144
  }
145
145
 
146
146
  /**
147
- * Core patch logic - patches chat model methods to inject Sentry callbacks
147
+ * Core patch logic - patches chat model and embedding methods
148
148
  * This is called when a LangChain provider package is loaded
149
149
  */
150
150
  _patch(exports$1) {
@@ -156,13 +156,19 @@ class SentryLangChainInstrumentation extends instrumentation.InstrumentationBase
156
156
  core.GOOGLE_GENAI_INTEGRATION_NAME,
157
157
  ]);
158
158
 
159
- // Create a shared handler instance
160
- const sentryHandler = core.createLangChainCallbackHandler(this.getConfig());
159
+ const config = this.getConfig();
160
+
161
+ // Create a shared handler instance for chat model callbacks
162
+ const sentryHandler = core.createLangChainCallbackHandler(config);
161
163
 
162
164
  // Patch Runnable methods to inject callbacks at request time
163
165
  // This directly manipulates options.callbacks that LangChain uses
164
166
  this._patchRunnableMethods(exports$1, sentryHandler);
165
167
 
168
+ // Patch embedding methods to create spans directly
169
+ // Embeddings don't use the callback system, so we wrap the methods themselves
170
+ this._patchEmbeddingsMethods(exports$1, config);
171
+
166
172
  return exports$1;
167
173
  }
168
174
 
@@ -214,6 +220,34 @@ class SentryLangChainInstrumentation extends instrumentation.InstrumentationBase
214
220
  }
215
221
  }
216
222
  }
223
+
224
+ /**
225
+ * Patches embedding class methods (embedQuery, embedDocuments) to create Sentry spans.
226
+ *
227
+ * Unlike chat models which use LangChain's callback system, the Embeddings base class
228
+ * has no callback support. We wrap the methods directly on the prototype.
229
+ *
230
+ * Instruments any exported class whose prototype has both embedQuery and embedDocuments as functions.
231
+ */
232
+ _patchEmbeddingsMethods(exports$1, options) {
233
+ const exportsToPatch = (exports$1.universal_exports ?? exports$1) ;
234
+
235
+ for (const exp of Object.values(exportsToPatch)) {
236
+ if (typeof exp !== 'function' || !exp.prototype) {
237
+ continue;
238
+ }
239
+ const proto = exp.prototype ;
240
+ if (typeof proto.embedQuery !== 'function' || typeof proto.embedDocuments !== 'function') {
241
+ continue;
242
+ }
243
+ if (proto.__sentry_patched__) {
244
+ continue;
245
+ }
246
+ proto.__sentry_patched__ = true;
247
+
248
+ core.instrumentLangChainEmbeddings(proto, options);
249
+ }
250
+ }
217
251
  }
218
252
 
219
253
  exports.SentryLangChainInstrumentation = SentryLangChainInstrumentation;
@@ -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 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 // Create a shared handler instance\n const sentryHandler = createLangChainCallbackHandler(this.getConfig());\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 // Skip if already patched (both file-level and module-level hooks resolve to the same prototype)\n if (targetProto.__sentry_patched__) {\n return;\n }\n targetProto.__sentry_patched__ = true;\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","createLangChainCallbackHandler"],"mappings":";;;;;AAiBA,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,MAA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AA;AACA,MAAA,eAAA;AACA,MAAA,cAAA;AACA,MAAA,UAAA;AACA,MAAA,mBAAA;AACA,KAAA;;AAEA,IAAA,MAAA,cAAA,IAAAA,SAAA,CAAA,iBAAA,IAAAA,SAAA,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,IAAA,IAAA,WAAA,CAAA,kBAAA,EAAA;AACA,MAAA;AACA,IAAA;AACA,IAAA,WAAA,CAAA,kBAAA,GAAA,IAAA;;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 GOOGLE_GENAI_INTEGRATION_NAME,\n instrumentLangChainEmbeddings,\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 and embedding methods\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 config = this.getConfig();\n\n // Create a shared handler instance for chat model callbacks\n const sentryHandler = createLangChainCallbackHandler(config);\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 // Patch embedding methods to create spans directly\n // Embeddings don't use the callback system, so we wrap the methods themselves\n this._patchEmbeddingsMethods(exports, config);\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 // Skip if already patched (both file-level and module-level hooks resolve to the same prototype)\n if (targetProto.__sentry_patched__) {\n return;\n }\n targetProto.__sentry_patched__ = true;\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 /**\n * Patches embedding class methods (embedQuery, embedDocuments) to create Sentry spans.\n *\n * Unlike chat models which use LangChain's callback system, the Embeddings base class\n * has no callback support. We wrap the methods directly on the prototype.\n *\n * Instruments any exported class whose prototype has both embedQuery and embedDocuments as functions.\n */\n private _patchEmbeddingsMethods(exports: PatchedLangChainExports, options: LangChainOptions): void {\n const exportsToPatch = (exports.universal_exports ?? exports) as Record<string, unknown>;\n\n for (const exp of Object.values(exportsToPatch)) {\n if (typeof exp !== 'function' || !exp.prototype) {\n continue;\n }\n const proto = exp.prototype as Record<string, unknown>;\n if (typeof proto.embedQuery !== 'function' || typeof proto.embedDocuments !== 'function') {\n continue;\n }\n if (proto.__sentry_patched__) {\n continue;\n }\n proto.__sentry_patched__ = true;\n\n instrumentLangChainEmbeddings(proto, options);\n }\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","InstrumentationNodeModuleDefinition","exports","InstrumentationNodeModuleFile","_INTERNAL_skipAiProviderWrapping","OPENAI_INTEGRATION_NAME","ANTHROPIC_AI_INTEGRATION_NAME","GOOGLE_GENAI_INTEGRATION_NAME","createLangChainCallbackHandler","instrumentLangChainEmbeddings"],"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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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;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAA,uBAAA,CAAAA,SAAA,EAAA,OAAA,EAAA;AACA,IAAA,MAAA,cAAA,IAAAA,SAAA,CAAA,iBAAA,IAAAA,SAAA,CAAA;;AAEA,IAAA,KAAA,MAAA,GAAA,IAAA,MAAA,CAAA,MAAA,CAAA,cAAA,CAAA,EAAA;AACA,MAAA,IAAA,OAAA,GAAA,KAAA,UAAA,IAAA,CAAA,GAAA,CAAA,SAAA,EAAA;AACA,QAAA;AACA,MAAA;AACA,MAAA,MAAA,KAAA,GAAA,GAAA,CAAA,SAAA;AACA,MAAA,IAAA,OAAA,KAAA,CAAA,UAAA,KAAA,UAAA,IAAA,OAAA,KAAA,CAAA,cAAA,KAAA,UAAA,EAAA;AACA,QAAA;AACA,MAAA;AACA,MAAA,IAAA,KAAA,CAAA,kBAAA,EAAA;AACA,QAAA;AACA,MAAA;AACA,MAAA,KAAA,CAAA,kBAAA,GAAA,IAAA;;AAEA,MAAAO,kCAAA,CAAA,KAAA,EAAA,OAAA,CAAA;AACA,IAAA;AACA,EAAA;AACA;;;;"}
@@ -1,7 +1,7 @@
1
1
  export { httpIntegration } from './integrations/http.js';
2
2
  export { nativeNodeFetchIntegration } from './integrations/node-fetch.js';
3
3
  export { fsIntegration } from './integrations/fs.js';
4
- export { expressErrorHandler, expressIntegration, setupExpressErrorHandler } from './integrations/tracing/express.js';
4
+ export { expressIntegration, setupExpressErrorHandler } from './integrations/tracing/express.js';
5
5
  export { fastifyIntegration, setupFastifyErrorHandler } from './integrations/tracing/fastify/index.js';
6
6
  export { graphqlIntegration } from './integrations/tracing/graphql.js';
7
7
  export { kafkaIntegration } from './integrations/tracing/kafka.js';
@@ -39,6 +39,6 @@ export { getDefaultIntegrations, getDefaultIntegrationsWithoutPerformance, init,
39
39
  export { initOpenTelemetry, preloadOpenTelemetry } from './sdk/initOtel.js';
40
40
  export { getAutoPerformanceIntegrations } from './integrations/tracing/index.js';
41
41
  export { setOpenTelemetryContextAsyncContextStrategy as setNodeAsyncContextStrategy } from '@sentry/opentelemetry';
42
- export { SDK_VERSION, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, Scope, addBreadcrumb, addEventProcessor, addIntegration, captureCheckIn, captureConsoleIntegration, captureEvent, captureException, captureFeedback, captureMessage, captureSession, close, consoleIntegration, consoleLoggingIntegration, continueTrace, createConsolaReporter, createLangChainCallbackHandler, createTransport, dedupeIntegration, endSession, eventFiltersIntegration, extraErrorDataIntegration, featureFlagsIntegration, flush, functionToStringIntegration, getActiveSpan, getClient, getCurrentScope, getGlobalScope, getIsolationScope, getRootSpan, getSpanDescendants, getSpanStatusFromHttpCode, getTraceData, getTraceMetaTags, httpHeadersToSpanAttributes, inboundFiltersIntegration, instrumentAnthropicAiClient, instrumentGoogleGenAIClient, instrumentLangGraph, instrumentOpenAiClient, instrumentStateGraphCompile, instrumentSupabaseClient, isEnabled, isInitialized, lastEventId, linkedErrorsIntegration, parameterize, profiler, requestDataIntegration, rewriteFramesIntegration, setContext, setConversationId, setCurrentClient, setExtra, setExtras, setHttpStatus, setMeasurement, setTag, setTags, setUser, spanToBaggageHeader, spanToJSON, spanToTraceHeader, startInactiveSpan, startNewTrace, startSession, startSpan, startSpanManual, supabaseIntegration, suppressTracing, trpcMiddleware, updateSpanName, winterCGHeadersToDict, withActiveSpan, withIsolationScope, withMonitor, withScope, wrapMcpServerWithSentry, zodErrorsIntegration } from '@sentry/core';
43
- export { NODE_VERSION, NodeClient, SentryContextManager, anrIntegration, childProcessIntegration, contextLinesIntegration, createGetModuleFromFilename, createSentryWinstonTransport, cron, defaultStackParser, disableAnrDetectionForCallback, generateInstrumentOnce, getSentryRelease, httpServerIntegration, httpServerSpansIntegration, localVariablesIntegration, logger, makeNodeTransport, metrics, modulesIntegration, nodeContextIntegration, nodeRuntimeMetricsIntegration, onUncaughtExceptionIntegration, onUnhandledRejectionIntegration, pinoIntegration, processSessionIntegration, spotlightIntegration, systemErrorIntegration, validateOpenTelemetrySetup } from '@sentry/node-core';
42
+ export { SDK_VERSION, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, Scope, addBreadcrumb, addEventProcessor, addIntegration, captureCheckIn, captureConsoleIntegration, captureEvent, captureException, captureFeedback, captureMessage, captureSession, close, consoleIntegration, consoleLoggingIntegration, continueTrace, createConsolaReporter, createLangChainCallbackHandler, createTransport, dedupeIntegration, endSession, eventFiltersIntegration, expressErrorHandler, extraErrorDataIntegration, featureFlagsIntegration, flush, functionToStringIntegration, getActiveSpan, getClient, getCurrentScope, getGlobalScope, getIsolationScope, getRootSpan, getSpanDescendants, getSpanStatusFromHttpCode, getTraceData, getTraceMetaTags, httpHeadersToSpanAttributes, inboundFiltersIntegration, instrumentAnthropicAiClient, instrumentGoogleGenAIClient, instrumentLangChainEmbeddings, instrumentLangGraph, instrumentOpenAiClient, instrumentStateGraphCompile, instrumentSupabaseClient, isEnabled, isInitialized, lastEventId, linkedErrorsIntegration, parameterize, profiler, requestDataIntegration, rewriteFramesIntegration, setContext, setConversationId, setCurrentClient, setExtra, setExtras, setHttpStatus, setMeasurement, setTag, setTags, setUser, spanStreamingIntegration, spanToBaggageHeader, spanToJSON, spanToTraceHeader, startInactiveSpan, startNewTrace, startSession, startSpan, startSpanManual, supabaseIntegration, suppressTracing, trpcMiddleware, updateSpanName, winterCGHeadersToDict, withActiveSpan, withIsolationScope, withMonitor, withScope, wrapMcpServerWithSentry, zodErrorsIntegration } from '@sentry/core';
43
+ export { NODE_VERSION, NodeClient, SentryContextManager, _INTERNAL_normalizeCollectionInterval, anrIntegration, childProcessIntegration, contextLinesIntegration, createGetModuleFromFilename, createSentryWinstonTransport, cron, defaultStackParser, disableAnrDetectionForCallback, generateInstrumentOnce, getSentryRelease, httpServerIntegration, httpServerSpansIntegration, localVariablesIntegration, logger, makeNodeTransport, metrics, modulesIntegration, nodeContextIntegration, nodeRuntimeMetricsIntegration, onUncaughtExceptionIntegration, onUnhandledRejectionIntegration, pinoIntegration, processSessionIntegration, spotlightIntegration, systemErrorIntegration, validateOpenTelemetrySetup, withStreamedSpan } from '@sentry/node-core';
44
44
  //# sourceMappingURL=index.js.map