@sentry/server-utils 10.63.0 → 10.64.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 (206) hide show
  1. package/build/cjs/index.js +6 -2
  2. package/build/cjs/index.js.map +1 -1
  3. package/build/cjs/integrations/tracing-channel/anthropic.js +101 -0
  4. package/build/cjs/integrations/tracing-channel/anthropic.js.map +1 -0
  5. package/build/cjs/integrations/tracing-channel/hapi-types.js +30 -0
  6. package/build/cjs/integrations/tracing-channel/hapi-types.js.map +1 -0
  7. package/build/cjs/integrations/tracing-channel/hapi-utils.js +177 -0
  8. package/build/cjs/integrations/tracing-channel/hapi-utils.js.map +1 -0
  9. package/build/cjs/integrations/tracing-channel/hapi.js +52 -0
  10. package/build/cjs/integrations/tracing-channel/hapi.js.map +1 -0
  11. package/build/cjs/integrations/tracing-channel/ioredis.js +96 -0
  12. package/build/cjs/integrations/tracing-channel/ioredis.js.map +1 -0
  13. package/build/cjs/integrations/tracing-channel/mysql.js +1 -0
  14. package/build/cjs/integrations/tracing-channel/mysql.js.map +1 -1
  15. package/build/cjs/integrations/tracing-channel/openai.js +83 -0
  16. package/build/cjs/integrations/tracing-channel/openai.js.map +1 -0
  17. package/build/cjs/integrations/tracing-channel/postgres.js +170 -0
  18. package/build/cjs/integrations/tracing-channel/postgres.js.map +1 -0
  19. package/build/cjs/integrations/tracing-channel/vercel-ai.js +25 -0
  20. package/build/cjs/integrations/tracing-channel/vercel-ai.js.map +1 -0
  21. package/build/cjs/mongoose/index.js +23 -0
  22. package/build/cjs/mongoose/index.js.map +1 -0
  23. package/build/cjs/mongoose/mongoose-dc-subscriber.js +97 -0
  24. package/build/cjs/mongoose/mongoose-dc-subscriber.js.map +1 -0
  25. package/build/cjs/orchestrion/bundler/vite.js +3 -3
  26. package/build/cjs/orchestrion/bundler/vite.js.map +1 -1
  27. package/build/cjs/orchestrion/channels.js +17 -2
  28. package/build/cjs/orchestrion/channels.js.map +1 -1
  29. package/build/cjs/orchestrion/config/anthropic-ai.js +43 -0
  30. package/build/cjs/orchestrion/config/anthropic-ai.js.map +1 -0
  31. package/build/cjs/orchestrion/config/hapi.js +26 -0
  32. package/build/cjs/orchestrion/config/hapi.js.map +1 -0
  33. package/build/cjs/orchestrion/config/index.js +35 -0
  34. package/build/cjs/orchestrion/config/index.js.map +1 -0
  35. package/build/cjs/orchestrion/config/ioredis.js +35 -0
  36. package/build/cjs/orchestrion/config/ioredis.js.map +1 -0
  37. package/build/cjs/orchestrion/config/lru-memoizer.js +17 -0
  38. package/build/cjs/orchestrion/config/lru-memoizer.js.map +1 -0
  39. package/build/cjs/orchestrion/config/mysql.js +16 -0
  40. package/build/cjs/orchestrion/config/mysql.js.map +1 -0
  41. package/build/cjs/orchestrion/config/openai.js +40 -0
  42. package/build/cjs/orchestrion/config/openai.js.map +1 -0
  43. package/build/cjs/orchestrion/config/pg.js +51 -0
  44. package/build/cjs/orchestrion/config/pg.js.map +1 -0
  45. package/build/cjs/orchestrion/config/vercel-ai.js +44 -0
  46. package/build/cjs/orchestrion/config/vercel-ai.js.map +1 -0
  47. package/build/cjs/orchestrion/detect.js +6 -1
  48. package/build/cjs/orchestrion/detect.js.map +1 -1
  49. package/build/cjs/orchestrion/index.js +27 -5
  50. package/build/cjs/orchestrion/index.js.map +1 -1
  51. package/build/cjs/orchestrion/runtime/register.js +10 -7
  52. package/build/cjs/orchestrion/runtime/register.js.map +1 -1
  53. package/build/cjs/redis/redis-statement-serializer.js +34 -0
  54. package/build/cjs/redis/redis-statement-serializer.js.map +1 -0
  55. package/build/cjs/tracing-channel.js +1 -1
  56. package/build/cjs/tracing-channel.js.map +1 -1
  57. package/build/cjs/vercel-ai/vercel-ai-dc-subscriber.js +11 -4
  58. package/build/cjs/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -1
  59. package/build/cjs/vercel-ai/vercel-ai-orchestrion-v6-subscriber.js +256 -0
  60. package/build/cjs/vercel-ai/vercel-ai-orchestrion-v6-subscriber.js.map +1 -0
  61. package/build/esm/index.js +2 -0
  62. package/build/esm/index.js.map +1 -1
  63. package/build/esm/integrations/tracing-channel/anthropic.js +99 -0
  64. package/build/esm/integrations/tracing-channel/anthropic.js.map +1 -0
  65. package/build/esm/integrations/tracing-channel/hapi-types.js +25 -0
  66. package/build/esm/integrations/tracing-channel/hapi-types.js.map +1 -0
  67. package/build/esm/integrations/tracing-channel/hapi-utils.js +172 -0
  68. package/build/esm/integrations/tracing-channel/hapi-utils.js.map +1 -0
  69. package/build/esm/integrations/tracing-channel/hapi.js +50 -0
  70. package/build/esm/integrations/tracing-channel/hapi.js.map +1 -0
  71. package/build/esm/integrations/tracing-channel/ioredis.js +94 -0
  72. package/build/esm/integrations/tracing-channel/ioredis.js.map +1 -0
  73. package/build/esm/integrations/tracing-channel/mysql.js +2 -1
  74. package/build/esm/integrations/tracing-channel/mysql.js.map +1 -1
  75. package/build/esm/integrations/tracing-channel/openai.js +81 -0
  76. package/build/esm/integrations/tracing-channel/openai.js.map +1 -0
  77. package/build/esm/integrations/tracing-channel/postgres.js +168 -0
  78. package/build/esm/integrations/tracing-channel/postgres.js.map +1 -0
  79. package/build/esm/integrations/tracing-channel/vercel-ai.js +23 -0
  80. package/build/esm/integrations/tracing-channel/vercel-ai.js.map +1 -0
  81. package/build/esm/mongoose/index.js +21 -0
  82. package/build/esm/mongoose/index.js.map +1 -0
  83. package/build/esm/mongoose/mongoose-dc-subscriber.js +89 -0
  84. package/build/esm/mongoose/mongoose-dc-subscriber.js.map +1 -0
  85. package/build/esm/orchestrion/bundler/vite.js +1 -1
  86. package/build/esm/orchestrion/channels.js +17 -2
  87. package/build/esm/orchestrion/channels.js.map +1 -1
  88. package/build/esm/orchestrion/config/anthropic-ai.js +40 -0
  89. package/build/esm/orchestrion/config/anthropic-ai.js.map +1 -0
  90. package/build/esm/orchestrion/config/hapi.js +23 -0
  91. package/build/esm/orchestrion/config/hapi.js.map +1 -0
  92. package/build/esm/orchestrion/config/index.js +31 -0
  93. package/build/esm/orchestrion/config/index.js.map +1 -0
  94. package/build/esm/orchestrion/config/ioredis.js +32 -0
  95. package/build/esm/orchestrion/config/ioredis.js.map +1 -0
  96. package/build/esm/orchestrion/config/lru-memoizer.js +14 -0
  97. package/build/esm/orchestrion/config/lru-memoizer.js.map +1 -0
  98. package/build/esm/orchestrion/config/mysql.js +13 -0
  99. package/build/esm/orchestrion/config/mysql.js.map +1 -0
  100. package/build/esm/orchestrion/config/openai.js +37 -0
  101. package/build/esm/orchestrion/config/openai.js.map +1 -0
  102. package/build/esm/orchestrion/config/pg.js +48 -0
  103. package/build/esm/orchestrion/config/pg.js.map +1 -0
  104. package/build/esm/orchestrion/config/vercel-ai.js +41 -0
  105. package/build/esm/orchestrion/config/vercel-ai.js.map +1 -0
  106. package/build/esm/orchestrion/detect.js +6 -2
  107. package/build/esm/orchestrion/detect.js.map +1 -1
  108. package/build/esm/orchestrion/index.js +21 -3
  109. package/build/esm/orchestrion/index.js.map +1 -1
  110. package/build/esm/orchestrion/runtime/register.js +8 -4
  111. package/build/esm/orchestrion/runtime/register.js.map +1 -1
  112. package/build/esm/package.json +1 -1
  113. package/build/esm/redis/redis-statement-serializer.js +32 -0
  114. package/build/esm/redis/redis-statement-serializer.js.map +1 -0
  115. package/build/esm/tracing-channel.js +2 -2
  116. package/build/esm/tracing-channel.js.map +1 -1
  117. package/build/esm/vercel-ai/vercel-ai-dc-subscriber.js +14 -8
  118. package/build/esm/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -1
  119. package/build/esm/vercel-ai/vercel-ai-orchestrion-v6-subscriber.js +254 -0
  120. package/build/esm/vercel-ai/vercel-ai-orchestrion-v6-subscriber.js.map +1 -0
  121. package/build/types/index.d.ts +2 -0
  122. package/build/types/index.d.ts.map +1 -1
  123. package/build/types/integrations/tracing-channel/anthropic.d.ts +10 -0
  124. package/build/types/integrations/tracing-channel/anthropic.d.ts.map +1 -0
  125. package/build/types/integrations/tracing-channel/hapi-types.d.ts +53 -0
  126. package/build/types/integrations/tracing-channel/hapi-types.d.ts.map +1 -0
  127. package/build/types/integrations/tracing-channel/hapi-utils.d.ts +25 -0
  128. package/build/types/integrations/tracing-channel/hapi-utils.d.ts.map +1 -0
  129. package/build/types/integrations/tracing-channel/hapi.d.ts +9 -0
  130. package/build/types/integrations/tracing-channel/hapi.d.ts.map +1 -0
  131. package/build/types/integrations/tracing-channel/ioredis.d.ts +17 -0
  132. package/build/types/integrations/tracing-channel/ioredis.d.ts.map +1 -0
  133. package/build/types/integrations/tracing-channel/mysql.d.ts.map +1 -1
  134. package/build/types/integrations/tracing-channel/openai.d.ts +10 -0
  135. package/build/types/integrations/tracing-channel/openai.d.ts.map +1 -0
  136. package/build/types/integrations/tracing-channel/postgres.d.ts +15 -0
  137. package/build/types/integrations/tracing-channel/postgres.d.ts.map +1 -0
  138. package/build/types/integrations/tracing-channel/vercel-ai.d.ts +13 -0
  139. package/build/types/integrations/tracing-channel/vercel-ai.d.ts.map +1 -0
  140. package/build/types/mongoose/index.d.ts +11 -0
  141. package/build/types/mongoose/index.d.ts.map +1 -0
  142. package/build/types/mongoose/mongoose-dc-subscriber.d.ts +63 -0
  143. package/build/types/mongoose/mongoose-dc-subscriber.d.ts.map +1 -0
  144. package/build/types/orchestrion/channels.d.ts +21 -1
  145. package/build/types/orchestrion/channels.d.ts.map +1 -1
  146. package/build/types/orchestrion/config/anthropic-ai.d.ts +31 -0
  147. package/build/types/orchestrion/config/anthropic-ai.d.ts.map +1 -0
  148. package/build/types/orchestrion/config/hapi.d.ts +17 -0
  149. package/build/types/orchestrion/config/hapi.d.ts.map +1 -0
  150. package/build/types/orchestrion/{config.d.ts → config/index.d.ts} +1 -12
  151. package/build/types/orchestrion/config/index.d.ts.map +1 -0
  152. package/build/types/orchestrion/config/ioredis.d.ts +7 -0
  153. package/build/types/orchestrion/config/ioredis.d.ts.map +1 -0
  154. package/build/types/orchestrion/config/lru-memoizer.d.ts +16 -0
  155. package/build/types/orchestrion/config/lru-memoizer.d.ts.map +1 -0
  156. package/build/types/orchestrion/config/mysql.d.ts +16 -0
  157. package/build/types/orchestrion/config/mysql.d.ts.map +1 -0
  158. package/build/types/orchestrion/config/openai.d.ts +20 -0
  159. package/build/types/orchestrion/config/openai.d.ts.map +1 -0
  160. package/build/types/orchestrion/config/pg.d.ts +33 -0
  161. package/build/types/orchestrion/config/pg.d.ts.map +1 -0
  162. package/build/types/orchestrion/config/vercel-ai.d.ts +11 -0
  163. package/build/types/orchestrion/config/vercel-ai.d.ts.map +1 -0
  164. package/build/types/orchestrion/detect.d.ts +10 -0
  165. package/build/types/orchestrion/detect.d.ts.map +1 -1
  166. package/build/types/orchestrion/index.d.ts +53 -3
  167. package/build/types/orchestrion/index.d.ts.map +1 -1
  168. package/build/types/orchestrion/runtime/register.d.ts.map +1 -1
  169. package/build/types/redis/redis-statement-serializer.d.ts +6 -0
  170. package/build/types/redis/redis-statement-serializer.d.ts.map +1 -0
  171. package/build/types/vercel-ai/vercel-ai-dc-subscriber.d.ts +10 -4
  172. package/build/types/vercel-ai/vercel-ai-dc-subscriber.d.ts.map +1 -1
  173. package/build/types/vercel-ai/vercel-ai-orchestrion-v6-subscriber.d.ts +12 -0
  174. package/build/types/vercel-ai/vercel-ai-orchestrion-v6-subscriber.d.ts.map +1 -0
  175. package/build/types-ts3.8/index.d.ts +2 -0
  176. package/build/types-ts3.8/integrations/tracing-channel/anthropic.d.ts +10 -0
  177. package/build/types-ts3.8/integrations/tracing-channel/hapi-types.d.ts +65 -0
  178. package/build/types-ts3.8/integrations/tracing-channel/hapi-utils.d.ts +25 -0
  179. package/build/types-ts3.8/integrations/tracing-channel/hapi.d.ts +9 -0
  180. package/build/types-ts3.8/integrations/tracing-channel/ioredis.d.ts +17 -0
  181. package/build/types-ts3.8/integrations/tracing-channel/openai.d.ts +10 -0
  182. package/build/types-ts3.8/integrations/tracing-channel/postgres.d.ts +15 -0
  183. package/build/types-ts3.8/integrations/tracing-channel/vercel-ai.d.ts +13 -0
  184. package/build/types-ts3.8/mongoose/index.d.ts +11 -0
  185. package/build/types-ts3.8/mongoose/mongoose-dc-subscriber.d.ts +63 -0
  186. package/build/types-ts3.8/orchestrion/channels.d.ts +21 -1
  187. package/build/types-ts3.8/orchestrion/config/anthropic-ai.d.ts +31 -0
  188. package/build/types-ts3.8/orchestrion/config/hapi.d.ts +17 -0
  189. package/build/types-ts3.8/orchestrion/{config.d.ts → config/index.d.ts} +1 -12
  190. package/build/types-ts3.8/orchestrion/config/ioredis.d.ts +7 -0
  191. package/build/types-ts3.8/orchestrion/config/lru-memoizer.d.ts +16 -0
  192. package/build/types-ts3.8/orchestrion/config/mysql.d.ts +16 -0
  193. package/build/types-ts3.8/orchestrion/config/openai.d.ts +20 -0
  194. package/build/types-ts3.8/orchestrion/config/pg.d.ts +33 -0
  195. package/build/types-ts3.8/orchestrion/config/vercel-ai.d.ts +11 -0
  196. package/build/types-ts3.8/orchestrion/detect.d.ts +10 -0
  197. package/build/types-ts3.8/orchestrion/index.d.ts +53 -3
  198. package/build/types-ts3.8/redis/redis-statement-serializer.d.ts +6 -0
  199. package/build/types-ts3.8/vercel-ai/vercel-ai-dc-subscriber.d.ts +10 -4
  200. package/build/types-ts3.8/vercel-ai/vercel-ai-orchestrion-v6-subscriber.d.ts +12 -0
  201. package/package.json +9 -9
  202. package/build/cjs/orchestrion/config.js +0 -44
  203. package/build/cjs/orchestrion/config.js.map +0 -1
  204. package/build/esm/orchestrion/config.js +0 -40
  205. package/build/esm/orchestrion/config.js.map +0 -1
  206. package/build/types/orchestrion/config.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"mysql.js","sources":["../../../../src/integrations/tracing-channel/mysql.ts"],"sourcesContent":["import * as diagnosticsChannel from 'node:diagnostics_channel';\nimport type { IntegrationFn, Scope } from '@sentry/core';\nimport {\n bindScopeToEmitter,\n debug,\n defineIntegration,\n getCurrentScope,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n startInactiveSpan,\n waitForTracingChannelBinding,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { CHANNELS } from '../../orchestrion/channels';\nimport { bindTracingChannelToSpan } from '../../tracing-channel';\n\n// NOTE: this uses the same name as the OTel integration by design.\n// When enabled, OTel 'Mysql' integration is omitted from the default set.\nconst INTEGRATION_NAME = 'Mysql' as const;\n\n// OTel \"OLD\" db/net semantic-conventions, inlined to keep this integration free of OTel deps. Matches\n// `@opentelemetry/instrumentation-mysql`'s default and the SDK's `inferDbSpanData` (which renames spans\n// off `db.statement`).\nconst ATTR_DB_SYSTEM = 'db.system';\nconst ATTR_DB_CONNECTION_STRING = 'db.connection_string';\nconst ATTR_DB_NAME = 'db.name';\nconst ATTR_DB_USER = 'db.user';\nconst ATTR_DB_STATEMENT = 'db.statement';\nconst ATTR_NET_PEER_NAME = 'net.peer.name';\nconst ATTR_NET_PEER_PORT = 'net.peer.port';\n\n/**\n * The shape orchestrion's transform attaches to the tracing-channel `context` object. Documented here\n * rather than imported because orchestrion's runtime doesn't export it.\n */\ninterface MysqlQueryChannelContext {\n // The live args array passed to the wrapped `connection.query` call; `arguments[0]` is the SQL.\n arguments: unknown[];\n self?: MysqlConnection;\n moduleVersion?: string;\n result?: unknown;\n error?: unknown;\n // The caller's scope, captured at `start` and replayed onto the streamed `Query` emitter (see below).\n _sentryCallerScope?: Scope;\n}\n\ninterface MysqlConnectionConfig {\n host?: string;\n port?: number | string;\n database?: string;\n user?: string;\n // Pool connections nest the real config one level deeper.\n connectionConfig?: MysqlConnectionConfig;\n}\n\ninterface MysqlConnection {\n config?: MysqlConnectionConfig;\n}\n\nconst _mysqlChannelIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n // `tracingChannel` is unavailable before Node 18.19 so do nothing in that case.\n if (!diagnosticsChannel.tracingChannel) {\n return;\n }\n\n DEBUG_BUILD && debug.log(`[orchestrion:mysql] subscribing to channel \"${CHANNELS.MYSQL_QUERY}\"`);\n\n waitForTracingChannelBinding(() => {\n bindTracingChannelToSpan(\n diagnosticsChannel.tracingChannel<MysqlQueryChannelContext>(CHANNELS.MYSQL_QUERY),\n data => {\n const sql = extractSql(data.arguments[0]);\n const { host, port, database, user } = getConnectionConfig(data.self);\n const portNumber = typeof port === 'string' ? parseInt(port, 10) : port;\n const portIsNumber = typeof portNumber === 'number' && !isNaN(portNumber);\n\n // For the streamed path: mysql emits the `Query` emitter's events from its socket data\n // handler with the caller's context lost. `deferSpanEnd` replays this scope onto the emitter.\n data._sentryCallerScope = getCurrentScope();\n\n return startInactiveSpan({\n name: sql ?? 'mysql.query',\n op: 'db',\n attributes: {\n [ATTR_DB_SYSTEM]: 'mysql',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.orchestrion.mysql',\n [ATTR_DB_CONNECTION_STRING]: getJDBCString(host, portIsNumber ? portNumber : undefined, database),\n ...(database ? { [ATTR_DB_NAME]: database } : {}),\n ...(user ? { [ATTR_DB_USER]: user } : {}),\n ...(sql ? { [ATTR_DB_STATEMENT]: sql } : {}),\n ...(host ? { [ATTR_NET_PEER_NAME]: host } : {}),\n ...(portIsNumber ? { [ATTR_NET_PEER_PORT]: portNumber } : {}),\n },\n });\n },\n {\n // No-callback `query(sql)` returns a streamable `Query` emitter as `result`; it settles on the\n // emitter's `'end'`/`'error'`, not the channel, so defer ending to those.\n deferSpanEnd({ data, end }) {\n const result = data.result;\n if (!result || typeof result !== 'object' || !hasOnMethod(result)) {\n return false;\n }\n\n // Replay the caller's scope so user listeners on the emitter nest under it, not a new trace.\n const callerScope = data._sentryCallerScope;\n if (callerScope) {\n bindScopeToEmitter(result, callerScope);\n }\n\n result.on('error', err => end(err));\n result.on('end', () => end());\n\n return true;\n },\n },\n );\n });\n },\n };\n}) satisfies IntegrationFn;\n\nfunction hasOnMethod(obj: object): obj is { on: (event: string, listener: (arg?: unknown) => void) => unknown } {\n return 'on' in obj && typeof (obj as { on?: unknown }).on === 'function';\n}\n\nfunction extractSql(firstArg: unknown): string | undefined {\n if (typeof firstArg === 'string') {\n return firstArg;\n }\n if (firstArg && typeof firstArg === 'object' && 'sql' in firstArg) {\n const sql = (firstArg as { sql?: unknown }).sql;\n return typeof sql === 'string' ? sql : undefined;\n }\n return undefined;\n}\n\nfunction getConnectionConfig(connection: MysqlConnection | undefined): {\n host?: string;\n port?: number | string;\n database?: string;\n user?: string;\n} {\n // Pool connections nest the real config under `.connectionConfig`; single\n // connections expose it directly. Matches `@opentelemetry/instrumentation-mysql`.\n const config = connection?.config?.connectionConfig ?? connection?.config ?? {};\n return {\n host: config.host,\n port: config.port,\n database: config.database,\n user: config.user,\n };\n}\n\nfunction getJDBCString(host: string | undefined, port: number | undefined, database: string | undefined): string {\n let s = `jdbc:mysql://${host || 'localhost'}`;\n if (typeof port === 'number') {\n s += `:${port}`;\n }\n if (database) {\n s += `/${database}`;\n }\n return s;\n}\n\n/**\n * EXPERIMENTAL — orchestrion-driven mysql integration.\n *\n * Subscribes to the `orchestrion:mysql:query` diagnostics_channel that the\n * orchestrion code transform injects into `mysql/lib/Connection.js`'s\n * `Connection.prototype.query`. Requires the orchestrion runtime hook or\n * bundler plugin to be active — wire that up via `_experimentalSetupOrchestrion`.\n */\nexport const mysqlChannelIntegration = defineIntegration(_mysqlChannelIntegration);\n"],"names":["DEBUG_BUILD","debug","CHANNELS","waitForTracingChannelBinding","bindTracingChannelToSpan","getCurrentScope","startInactiveSpan","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","bindScopeToEmitter","defineIntegration"],"mappings":";;;;;;;;AAiBA,MAAM,gBAAA,GAAmB,OAAA;AAKzB,MAAM,cAAA,GAAiB,WAAA;AACvB,MAAM,yBAAA,GAA4B,sBAAA;AAClC,MAAM,YAAA,GAAe,SAAA;AACrB,MAAM,YAAA,GAAe,SAAA;AACrB,MAAM,iBAAA,GAAoB,cAAA;AAC1B,MAAM,kBAAA,GAAqB,eAAA;AAC3B,MAAM,kBAAA,GAAqB,eAAA;AA8B3B,MAAM,4BA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QAAA,EAAU;AACjE,IAAA,MAAM,MAAO,QAAA,CAA+B,GAAA;AAC5C,IAAA,OAAO,OAAO,GAAA,KAAQ,QAAA,GAAW,GAAA,GAAM,MAAA;AAAA,EACzC;AACA,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,oBAAoB,UAAA,EAK3B;AAGA,EAAA,MAAM,SAAS,UAAA,EAAY,MAAA,EAAQ,gBAAA,IAAoB,UAAA,EAAY,UAAU,EAAC;AAC9E,EAAA,OAAO;AAAA,IACL,MAAM,MAAA,CAAO,IAAA;AAAA,IACb,MAAM,MAAA,CAAO,IAAA;AAAA,IACb,UAAU,MAAA,CAAO,QAAA;AAAA,IACjB,MAAM,MAAA,CAAO;AAAA,GACf;AACF;AAEA,SAAS,aAAA,CAAc,IAAA,EAA0B,IAAA,EAA0B,QAAA,EAAsC;AAC/G,EAAA,IAAI,CAAA,GAAI,CAAA,aAAA,EAAgB,IAAA,IAAQ,WAAW,CAAA,CAAA;AAC3C,EAAA,IAAI,OAAO,SAAS,QAAA,EAAU;AAC5B,IAAA,CAAA,IAAK,IAAI,IAAI,CAAA,CAAA;AAAA,EACf;AACA,EAAA,IAAI,QAAA,EAAU;AACZ,IAAA,CAAA,IAAK,IAAI,QAAQ,CAAA,CAAA;AAAA,EACnB;AACA,EAAA,OAAO,CAAA;AACT;AAUO,MAAM,uBAAA,GAA0BC,uBAAkB,wBAAwB;;;;"}
1
+ {"version":3,"file":"mysql.js","sources":["../../../../src/integrations/tracing-channel/mysql.ts"],"sourcesContent":["import * as diagnosticsChannel from 'node:diagnostics_channel';\nimport type { IntegrationFn, Scope } from '@sentry/core';\nimport {\n bindScopeToEmitter,\n debug,\n defineIntegration,\n getCurrentScope,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_KIND,\n startInactiveSpan,\n waitForTracingChannelBinding,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { CHANNELS } from '../../orchestrion/channels';\nimport { bindTracingChannelToSpan } from '../../tracing-channel';\n\n// NOTE: this uses the same name as the OTel integration by design.\n// When enabled, OTel 'Mysql' integration is omitted from the default set.\nconst INTEGRATION_NAME = 'Mysql' as const;\n\n// OTel \"OLD\" db/net semantic-conventions, inlined to keep this integration free of OTel deps. Matches\n// `@opentelemetry/instrumentation-mysql`'s default and the SDK's `inferDbSpanData` (which renames spans\n// off `db.statement`).\nconst ATTR_DB_SYSTEM = 'db.system';\nconst ATTR_DB_CONNECTION_STRING = 'db.connection_string';\nconst ATTR_DB_NAME = 'db.name';\nconst ATTR_DB_USER = 'db.user';\nconst ATTR_DB_STATEMENT = 'db.statement';\nconst ATTR_NET_PEER_NAME = 'net.peer.name';\nconst ATTR_NET_PEER_PORT = 'net.peer.port';\n\n/**\n * The shape orchestrion's transform attaches to the tracing-channel `context` object. Documented here\n * rather than imported because orchestrion's runtime doesn't export it.\n */\ninterface MysqlQueryChannelContext {\n // The live args array passed to the wrapped `connection.query` call; `arguments[0]` is the SQL.\n arguments: unknown[];\n self?: MysqlConnection;\n moduleVersion?: string;\n result?: unknown;\n error?: unknown;\n // The caller's scope, captured at `start` and replayed onto the streamed `Query` emitter (see below).\n _sentryCallerScope?: Scope;\n}\n\ninterface MysqlConnectionConfig {\n host?: string;\n port?: number | string;\n database?: string;\n user?: string;\n // Pool connections nest the real config one level deeper.\n connectionConfig?: MysqlConnectionConfig;\n}\n\ninterface MysqlConnection {\n config?: MysqlConnectionConfig;\n}\n\nconst _mysqlChannelIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n // `tracingChannel` is unavailable before Node 18.19 so do nothing in that case.\n if (!diagnosticsChannel.tracingChannel) {\n return;\n }\n\n DEBUG_BUILD && debug.log(`[orchestrion:mysql] subscribing to channel \"${CHANNELS.MYSQL_QUERY}\"`);\n\n waitForTracingChannelBinding(() => {\n bindTracingChannelToSpan(\n diagnosticsChannel.tracingChannel<MysqlQueryChannelContext>(CHANNELS.MYSQL_QUERY),\n data => {\n const sql = extractSql(data.arguments[0]);\n const { host, port, database, user } = getConnectionConfig(data.self);\n const portNumber = typeof port === 'string' ? parseInt(port, 10) : port;\n const portIsNumber = typeof portNumber === 'number' && !isNaN(portNumber);\n\n // For the streamed path: mysql emits the `Query` emitter's events from its socket data\n // handler with the caller's context lost. `deferSpanEnd` replays this scope onto the emitter.\n data._sentryCallerScope = getCurrentScope();\n\n return startInactiveSpan({\n name: sql ?? 'mysql.query',\n kind: SPAN_KIND.CLIENT,\n op: 'db',\n attributes: {\n [ATTR_DB_SYSTEM]: 'mysql',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.orchestrion.mysql',\n [ATTR_DB_CONNECTION_STRING]: getJDBCString(host, portIsNumber ? portNumber : undefined, database),\n ...(database ? { [ATTR_DB_NAME]: database } : {}),\n ...(user ? { [ATTR_DB_USER]: user } : {}),\n ...(sql ? { [ATTR_DB_STATEMENT]: sql } : {}),\n ...(host ? { [ATTR_NET_PEER_NAME]: host } : {}),\n ...(portIsNumber ? { [ATTR_NET_PEER_PORT]: portNumber } : {}),\n },\n });\n },\n {\n // No-callback `query(sql)` returns a streamable `Query` emitter as `result`; it settles on the\n // emitter's `'end'`/`'error'`, not the channel, so defer ending to those.\n deferSpanEnd({ data, end }) {\n const result = data.result;\n if (!result || typeof result !== 'object' || !hasOnMethod(result)) {\n return false;\n }\n\n // Replay the caller's scope so user listeners on the emitter nest under it, not a new trace.\n const callerScope = data._sentryCallerScope;\n if (callerScope) {\n bindScopeToEmitter(result, callerScope);\n }\n\n result.on('error', err => end(err));\n result.on('end', () => end());\n\n return true;\n },\n },\n );\n });\n },\n };\n}) satisfies IntegrationFn;\n\nfunction hasOnMethod(obj: object): obj is { on: (event: string, listener: (arg?: unknown) => void) => unknown } {\n return 'on' in obj && typeof (obj as { on?: unknown }).on === 'function';\n}\n\nfunction extractSql(firstArg: unknown): string | undefined {\n if (typeof firstArg === 'string') {\n return firstArg;\n }\n if (firstArg && typeof firstArg === 'object' && 'sql' in firstArg) {\n const sql = (firstArg as { sql?: unknown }).sql;\n return typeof sql === 'string' ? sql : undefined;\n }\n return undefined;\n}\n\nfunction getConnectionConfig(connection: MysqlConnection | undefined): {\n host?: string;\n port?: number | string;\n database?: string;\n user?: string;\n} {\n // Pool connections nest the real config under `.connectionConfig`; single\n // connections expose it directly. Matches `@opentelemetry/instrumentation-mysql`.\n const config = connection?.config?.connectionConfig ?? connection?.config ?? {};\n return {\n host: config.host,\n port: config.port,\n database: config.database,\n user: config.user,\n };\n}\n\nfunction getJDBCString(host: string | undefined, port: number | undefined, database: string | undefined): string {\n let s = `jdbc:mysql://${host || 'localhost'}`;\n if (typeof port === 'number') {\n s += `:${port}`;\n }\n if (database) {\n s += `/${database}`;\n }\n return s;\n}\n\n/**\n * EXPERIMENTAL — orchestrion-driven mysql integration.\n *\n * Subscribes to the `orchestrion:mysql:query` diagnostics_channel that the\n * orchestrion code transform injects into `mysql/lib/Connection.js`'s\n * `Connection.prototype.query`. Requires the orchestrion runtime hook or\n * bundler plugin to be active — wire that up via `_experimentalSetupOrchestrion`.\n */\nexport const mysqlChannelIntegration = defineIntegration(_mysqlChannelIntegration);\n"],"names":["DEBUG_BUILD","debug","CHANNELS","waitForTracingChannelBinding","bindTracingChannelToSpan","getCurrentScope","startInactiveSpan","SPAN_KIND","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","bindScopeToEmitter","defineIntegration"],"mappings":";;;;;;;;AAkBA,MAAM,gBAAA,GAAmB,OAAA;AAKzB,MAAM,cAAA,GAAiB,WAAA;AACvB,MAAM,yBAAA,GAA4B,sBAAA;AAClC,MAAM,YAAA,GAAe,SAAA;AACrB,MAAM,YAAA,GAAe,SAAA;AACrB,MAAM,iBAAA,GAAoB,cAAA;AAC1B,MAAM,kBAAA,GAAqB,eAAA;AAC3B,MAAM,kBAAA,GAAqB,eAAA;AA8B3B,MAAM,4BAA4B,MAAM;AACtC,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA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AM,MAAO,QAAA,CAA+B,GAAA;AAC5C,IAAA,OAAO,OAAO,GAAA,KAAQ,QAAA,GAAW,GAAA,GAAM,MAAA;AAAA,EACzC;AACA,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,oBAAoB,UAAA,EAK3B;AAGA,EAAA,MAAM,SAAS,UAAA,EAAY,MAAA,EAAQ,gBAAA,IAAoB,UAAA,EAAY,UAAU,EAAC;AAC9E,EAAA,OAAO;AAAA,IACL,MAAM,MAAA,CAAO,IAAA;AAAA,IACb,MAAM,MAAA,CAAO,IAAA;AAAA,IACb,UAAU,MAAA,CAAO,QAAA;AAAA,IACjB,MAAM,MAAA,CAAO;AAAA,GACf;AACF;AAEA,SAAS,aAAA,CAAc,IAAA,EAA0B,IAAA,EAA0B,QAAA,EAAsC;AAC/G,EAAA,IAAI,CAAA,GAAI,CAAA,aAAA,EAAgB,IAAA,IAAQ,WAAW,CAAA,CAAA;AAC3C,EAAA,IAAI,OAAO,SAAS,QAAA,EAAU;AAC5B,IAAA,CAAA,IAAK,IAAI,IAAI,CAAA,CAAA;AAAA,EACf;AACA,EAAA,IAAI,QAAA,EAAU;AACZ,IAAA,CAAA,IAAK,IAAI,QAAQ,CAAA,CAAA;AAAA,EACnB;AACA,EAAA,OAAO,CAAA;AACT;AAUO,MAAM,uBAAA,GAA0BC,uBAAkB,wBAAwB;;;;"}
@@ -0,0 +1,83 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const diagnosticsChannel = require('node:diagnostics_channel');
4
+ const core = require('@sentry/core');
5
+ const debugBuild = require('../../debug-build.js');
6
+ const channels = require('../../orchestrion/channels.js');
7
+ const tracingChannel = require('../../tracing-channel.js');
8
+
9
+ const INTEGRATION_NAME = "OpenAI";
10
+ const ORIGIN = "auto.ai.orchestrion.openai";
11
+ const INSTRUMENTED_CHANNELS = [
12
+ { channel: channels.CHANNELS.OPENAI_CHAT, operation: "chat" },
13
+ { channel: channels.CHANNELS.OPENAI_RESPONSES, operation: "chat" },
14
+ { channel: channels.CHANNELS.OPENAI_EMBEDDINGS, operation: "embeddings" },
15
+ { channel: channels.CHANNELS.OPENAI_CONVERSATIONS, operation: "chat" }
16
+ ];
17
+ let subscribed = false;
18
+ const _openaiChannelIntegration = ((options = {}) => {
19
+ return {
20
+ name: INTEGRATION_NAME,
21
+ setupOnce() {
22
+ if (!diagnosticsChannel.tracingChannel || subscribed) {
23
+ return;
24
+ }
25
+ subscribed = true;
26
+ core.waitForTracingChannelBinding(() => {
27
+ for (const { channel, operation } of INSTRUMENTED_CHANNELS) {
28
+ debugBuild.DEBUG_BUILD && core.debug.log(`[orchestrion:openai] subscribing to channel "${channel}"`);
29
+ tracingChannel.bindTracingChannelToSpan(
30
+ diagnosticsChannel.tracingChannel(channel),
31
+ (data) => createGenAiSpan(data, operation, options),
32
+ {
33
+ beforeSpanEnd: (span, data) => {
34
+ core.addOpenAiResponseAttributes(span, data.result, core.resolveAIRecordingOptions(options).recordOutputs);
35
+ },
36
+ // Streaming: the result is a `Stream` consumed later, so instrument it and let it end the span.
37
+ deferSpanEnd: ({ span, data }) => wrapStreamResult(span, data, options)
38
+ }
39
+ );
40
+ }
41
+ });
42
+ }
43
+ };
44
+ });
45
+ function createGenAiSpan(data, operation, options) {
46
+ if (core._INTERNAL_shouldSkipAiProviderWrapping(INTEGRATION_NAME)) {
47
+ return void 0;
48
+ }
49
+ const args = data.arguments ?? [];
50
+ const params = args[0];
51
+ const { recordInputs } = core.resolveAIRecordingOptions(options);
52
+ const enableTruncation = core.shouldEnableTruncation(options.enableTruncation);
53
+ const attributes = core.extractOpenAiRequestAttributes(args, operation);
54
+ attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] = ORIGIN;
55
+ const model = params?.model || "unknown";
56
+ const span = core.startInactiveSpan({
57
+ name: `${operation} ${model}`,
58
+ op: `gen_ai.${operation}`,
59
+ attributes
60
+ });
61
+ if (recordInputs && params) {
62
+ core.addOpenAiRequestAttributes(span, params, operation, enableTruncation);
63
+ }
64
+ return span;
65
+ }
66
+ function isAsyncIterable(value) {
67
+ return !!value && typeof value[Symbol.asyncIterator] === "function";
68
+ }
69
+ function wrapStreamResult(span, data, options) {
70
+ const result = data.result;
71
+ if (!isAsyncIterable(result)) {
72
+ return false;
73
+ }
74
+ const { recordOutputs } = core.resolveAIRecordingOptions(options);
75
+ const iterate = result[Symbol.asyncIterator].bind(result);
76
+ const instrumented = core.instrumentOpenAiStream({ [Symbol.asyncIterator]: iterate }, span, recordOutputs ?? false);
77
+ result[Symbol.asyncIterator] = () => instrumented;
78
+ return true;
79
+ }
80
+ const openaiChannelIntegration = core.defineIntegration(_openaiChannelIntegration);
81
+
82
+ exports.openaiChannelIntegration = openaiChannelIntegration;
83
+ //# sourceMappingURL=openai.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.js","sources":["../../../../src/integrations/tracing-channel/openai.ts"],"sourcesContent":["import * as diagnosticsChannel from 'node:diagnostics_channel';\nimport type { IntegrationFn, OpenAiOptions, Span, SpanAttributeValue } from '@sentry/core';\nimport {\n _INTERNAL_shouldSkipAiProviderWrapping,\n addOpenAiRequestAttributes,\n addOpenAiResponseAttributes,\n debug,\n defineIntegration,\n extractOpenAiRequestAttributes,\n instrumentOpenAiStream,\n resolveAIRecordingOptions,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n shouldEnableTruncation,\n startInactiveSpan,\n waitForTracingChannelBinding,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { CHANNELS } from '../../orchestrion/channels';\nimport { bindTracingChannelToSpan } from '../../tracing-channel';\n\n// Same name as the OTel integration by design: when enabled, the OTel 'OpenAI'\n// integration is dropped from the default set (see the Node opt-in loader).\nconst INTEGRATION_NAME = 'OpenAI' as const;\n\n// Distinct from the proxy's `auto.ai.openai` so spans from the orchestrion path\n// are attributable separately from the OTel/proxy one.\nconst ORIGIN = 'auto.ai.orchestrion.openai';\n\n// Each instrumented `create` method maps to the gen_ai operation its span reports.\nconst INSTRUMENTED_CHANNELS = [\n { channel: CHANNELS.OPENAI_CHAT, operation: 'chat' },\n { channel: CHANNELS.OPENAI_RESPONSES, operation: 'chat' },\n { channel: CHANNELS.OPENAI_EMBEDDINGS, operation: 'embeddings' },\n { channel: CHANNELS.OPENAI_CONVERSATIONS, operation: 'chat' },\n] as const;\n\n/**\n * The context object orchestrion shares across the tracing-channel lifecycle hooks: `arguments` is the\n * live args array passed to `Completions.create(body, options)`, and Node's `tracingChannel` attaches\n * `result` when the returned promise settles.\n */\ninterface OpenAiChatChannelContext {\n arguments: unknown[];\n result?: unknown;\n}\n\nlet subscribed = false;\n\nconst _openaiChannelIntegration = ((options: OpenAiOptions = {}) => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n // `tracingChannel` is unavailable before Node 18.19, and a second `init()` would double-subscribe.\n if (!diagnosticsChannel.tracingChannel || subscribed) {\n return;\n }\n subscribed = true;\n\n // `bindTracingChannelToSpan` needs the async-context binding that `initOpenTelemetry()` registers\n // after `setupOnce` runs, so wait for it before subscribing.\n waitForTracingChannelBinding(() => {\n for (const { channel, operation } of INSTRUMENTED_CHANNELS) {\n DEBUG_BUILD && debug.log(`[orchestrion:openai] subscribing to channel \"${channel}\"`);\n bindTracingChannelToSpan(\n diagnosticsChannel.tracingChannel<OpenAiChatChannelContext>(channel),\n data => createGenAiSpan(data, operation, options),\n {\n beforeSpanEnd: (span, data) => {\n addOpenAiResponseAttributes(span, data.result, resolveAIRecordingOptions(options).recordOutputs);\n },\n // Streaming: the result is a `Stream` consumed later, so instrument it and let it end the span.\n deferSpanEnd: ({ span, data }) => wrapStreamResult(span, data, options),\n },\n );\n }\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Build the span for an instrumented `create` call.\n * Returning `undefined` opts the payload out so no span is opened.\n */\nfunction createGenAiSpan(data: OpenAiChatChannelContext, operation: string, options: OpenAiOptions): Span | undefined {\n // langchain drives the openai SDK itself and instruments at its own layer; skip here to avoid double spans.\n if (_INTERNAL_shouldSkipAiProviderWrapping(INTEGRATION_NAME)) {\n return undefined;\n }\n\n const args = data.arguments ?? [];\n const params = args[0] as Record<string, unknown> | undefined;\n\n const { recordInputs } = resolveAIRecordingOptions(options);\n const enableTruncation = shouldEnableTruncation(options.enableTruncation);\n\n const attributes = extractOpenAiRequestAttributes(args, operation);\n attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] = ORIGIN;\n const model = (params?.model as string) || 'unknown';\n\n const span = startInactiveSpan({\n name: `${operation} ${model}`,\n op: `gen_ai.${operation}`,\n attributes: attributes as Record<string, SpanAttributeValue>,\n });\n\n if (recordInputs && params) {\n addOpenAiRequestAttributes(span, params, operation, enableTruncation);\n }\n\n return span;\n}\n\ntype AsyncIterableStream = { [Symbol.asyncIterator]: () => AsyncIterator<unknown> };\n\nfunction isAsyncIterable(value: unknown): value is AsyncIterableStream {\n return !!value && typeof (value as AsyncIterableStream)[Symbol.asyncIterator] === 'function';\n}\n\n/**\n * For a streaming `create({ stream: true })` the result is a `Stream` the caller consumes later. We can't\n * swap what `create` returns, but the `Stream` in `data.result` is the same instance the caller holds and\n * `asyncEnd` fires before the caller iterates — so we patch its async iterator in place to run through\n * `instrumentOpenAiStream`, which accumulates the streamed attributes and ends the span when iteration finishes.\n * Only a streaming call resolves to an async-iterable, so that check alone distinguishes it. Returns `true`\n * to hand span-ending ownership to `instrumentOpenAiStream`; `false` for non-streaming/errored results, which end\n * via the normal `beforeSpanEnd` path.\n */\nfunction wrapStreamResult(span: Span, data: OpenAiChatChannelContext, options: OpenAiOptions): boolean {\n const result = data.result;\n if (!isAsyncIterable(result)) {\n return false;\n }\n\n const { recordOutputs } = resolveAIRecordingOptions(options);\n const iterate = result[Symbol.asyncIterator].bind(result);\n const instrumented = instrumentOpenAiStream({ [Symbol.asyncIterator]: iterate }, span, recordOutputs ?? false);\n result[Symbol.asyncIterator] = () => instrumented;\n\n return true;\n}\n\n/**\n * EXPERIMENTAL — orchestrion-driven OpenAI integration. Subscribes to the `orchestrion:openai:*`\n * diagnostics_channels injected into `openai`'s `create` methods (chat completions, responses, embeddings,\n * conversations), so it requires the orchestrion runtime hook or bundler plugin.\n */\nexport const openaiChannelIntegration = defineIntegration(_openaiChannelIntegration);\n"],"names":["CHANNELS","waitForTracingChannelBinding","DEBUG_BUILD","debug","bindTracingChannelToSpan","addOpenAiResponseAttributes","resolveAIRecordingOptions","_INTERNAL_shouldSkipAiProviderWrapping","shouldEnableTruncation","extractOpenAiRequestAttributes","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","startInactiveSpan","addOpenAiRequestAttributes","instrumentOpenAiStream","defineIntegration"],"mappings":";;;;;;;;AAsBA,MAAM,gBAAA,GAAmB,QAAA;AAIzB,MAAM,MAAA,GAAS,4BAAA;AAGf,MAAM,qBAAA,GAAwB;AAAA,EAC5B,EAAE,OAAA,EAASA,iBAAA,CAAS,WAAA,EAAa,WAAW,MAAA,EAAO;AAAA,EACnD,EAAE,OAAA,EAASA,iBAAA,CAAS,gBAAA,EAAkB,WAAW,MAAA,EAAO;AAAA,EACxD,EAAE,OAAA,EAASA,iBAAA,CAAS,iBAAA,EAAmB,WAAW,YAAA,EAAa;AAAA,EAC/D,EAAE,OAAA,EAASA,iBAAA,CAAS,oBAAA,EAAsB,WAAW,MAAA;AACvD,CAAA;AAYA,IAAI,UAAA,GAAa,KAAA;AAEjB,MAAM,yBAAA,IAA6B,CAAC,OAAA,GAAyB,EAAC,KAAM;AAClE,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,GAAY;AAEV,MAAA,IAAI,CAAC,kBAAA,CAAmB,cAAA,IAAkB,UAAA,EAAY;AACpD,QAAA;AAAA,MACF;AACA,MAAA,UAAA,GAAa,IAAA;AAIb,MAAAC,iCAAA,CAA6B,MAAM;AACjC,QAAA,KAAA,MAAW,EAAE,OAAA,EAAS,SAAA,EAAU,IAAK,qBAAA,EAAuB;AAC1D,UAAA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OC,sBAAA,CAAkB;AAAA,IAC7B,IAAA,EAAM,CAAA,EAAG,SAAS,CAAA,CAAA,EAAI,KAAK,CAAA,CAAA;AAAA,IAC3B,EAAA,EAAI,UAAU,SAAS,CAAA,CAAA;AAAA,IACvB;AAAA,GACD,CAAA;AAED,EAAA,IAAI,gBAAgB,MAAA,EAAQ;AAC1B,IAAAC,+BAAA,CAA2B,IAAA,EAAM,MAAA,EAAQ,SAAA,EAAW,gBAAgB,CAAA;AAAA,EACtE;AAEA,EAAA,OAAO,IAAA;AACT;AAIA,SAAS,gBAAgB,KAAA,EAA8C;AACrE,EAAA,OAAO,CAAC,CAAC,KAAA,IAAS,OAAQ,KAAA,CAA8B,MAAA,CAAO,aAAa,CAAA,KAAM,UAAA;AACpF;AAWA,SAAS,gBAAA,CAAiB,IAAA,EAAY,IAAA,EAAgC,OAAA,EAAiC;AACrG,EAAA,MAAM,SAAS,IAAA,CAAK,MAAA;AACpB,EAAA,IAAI,CAAC,eAAA,CAAgB,MAAM,CAAA,EAAG;AAC5B,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,MAAM,EAAE,aAAA,EAAc,GAAIN,8BAAA,CAA0B,OAAO,CAAA;AAC3D,EAAA,MAAM,UAAU,MAAA,CAAO,MAAA,CAAO,aAAa,CAAA,CAAE,KAAK,MAAM,CAAA;AACxD,EAAA,MAAM,YAAA,GAAeO,2BAAA,CAAuB,EAAE,CAAC,MAAA,CAAO,aAAa,GAAG,OAAA,EAAQ,EAAG,IAAA,EAAM,aAAA,IAAiB,KAAK,CAAA;AAC7G,EAAA,MAAA,CAAO,MAAA,CAAO,aAAa,CAAA,GAAI,MAAM,YAAA;AAErC,EAAA,OAAO,IAAA;AACT;AAOO,MAAM,wBAAA,GAA2BC,uBAAkB,yBAAyB;;;;"}
@@ -0,0 +1,170 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const diagnosticsChannel = require('node:diagnostics_channel');
4
+ const core = require('@sentry/core');
5
+ const debugBuild = require('../../debug-build.js');
6
+ const channels = require('../../orchestrion/channels.js');
7
+ const tracingChannel = require('../../tracing-channel.js');
8
+
9
+ const INTEGRATION_NAME = "Postgres";
10
+ const ORIGIN = "auto.db.orchestrion.postgres";
11
+ const ATTR_DB_SYSTEM = "db.system";
12
+ const ATTR_DB_NAME = "db.name";
13
+ const ATTR_DB_CONNECTION_STRING = "db.connection_string";
14
+ const ATTR_DB_USER = "db.user";
15
+ const ATTR_DB_STATEMENT = "db.statement";
16
+ const ATTR_NET_PEER_NAME = "net.peer.name";
17
+ const ATTR_NET_PEER_PORT = "net.peer.port";
18
+ const ATTR_PG_PLAN = "db.postgresql.plan";
19
+ const ATTR_PG_IDLE_TIMEOUT = "db.postgresql.idle.timeout.millis";
20
+ const ATTR_PG_MAX_CLIENT = "db.postgresql.max.client";
21
+ const DB_SYSTEM_POSTGRESQL = "postgresql";
22
+ const SPAN_QUERY_FALLBACK = "pg.query";
23
+ const SPAN_CONNECT = "pg.connect";
24
+ const SPAN_POOL_CONNECT = "pg-pool.connect";
25
+ const _postgresChannelIntegration = ((options = {}) => {
26
+ return {
27
+ name: INTEGRATION_NAME,
28
+ setupOnce() {
29
+ if (!diagnosticsChannel.tracingChannel) {
30
+ return;
31
+ }
32
+ core.waitForTracingChannelBinding(() => {
33
+ subscribeQueryLikeChannel(channels.CHANNELS.PG_QUERY, querySpanOptions, { deferStreamedResult: true });
34
+ if (!options.ignoreConnectSpans) {
35
+ subscribeQueryLikeChannel(channels.CHANNELS.PG_CONNECT, connectSpanOptions);
36
+ subscribeQueryLikeChannel(channels.CHANNELS.PGPOOL_CONNECT, poolConnectSpanOptions);
37
+ }
38
+ });
39
+ }
40
+ };
41
+ });
42
+ function subscribeQueryLikeChannel(channelName, getSpanOptions, { deferStreamedResult = false } = {}) {
43
+ debugBuild.DEBUG_BUILD && core.debug.log(`[orchestrion:pg] subscribing to channel "${channelName}"`);
44
+ tracingChannel.bindTracingChannelToSpan(
45
+ diagnosticsChannel.tracingChannel(channelName),
46
+ (data) => {
47
+ if (!core.getActiveSpan()) {
48
+ return void 0;
49
+ }
50
+ data._sentryCallerScope = core.getCurrentScope();
51
+ return core.startInactiveSpan({ ...getSpanOptions(data), kind: core.SPAN_KIND.CLIENT });
52
+ },
53
+ // `connect`/`pool-connect` resolve with a persistent `Client` (itself an
54
+ // `EventEmitter`), which is NOT a streamed result. Deferring their span
55
+ // to that emitter's `'end'`/`'error'` would keep it open for the whole
56
+ // connection lifetime, so it never ends in time and is dropped. Only
57
+ // `query` can return a streamable `Submittable`, so only it defers.
58
+ deferStreamedResult ? {
59
+ // Streamable `Submittable` (e.g. `client.query(new Query())`)
60
+ // returns an emitter that orchestrion stores on `ctx.result` while
61
+ // firing no async events; the query isn't done until the emitter
62
+ // emits `'end'`/`'error'`. Defer ending to those events for that
63
+ // path; the callback, promise, and sync-throw paths carry no
64
+ // emitter, so the helper ends the span as usual.
65
+ deferSpanEnd({ data, end }) {
66
+ const result = data.result;
67
+ if (!result || typeof result !== "object" || !hasOnMethod(result)) {
68
+ return false;
69
+ }
70
+ const callerScope = data._sentryCallerScope;
71
+ if (callerScope) {
72
+ core.bindScopeToEmitter(result, callerScope);
73
+ }
74
+ result.on("error", (err) => end(err));
75
+ result.on("end", () => end());
76
+ return true;
77
+ }
78
+ } : void 0
79
+ );
80
+ }
81
+ function querySpanOptions(ctx) {
82
+ const params = ctx.self?.connectionParameters ?? {};
83
+ const queryConfig = extractQueryConfig(ctx.arguments);
84
+ return {
85
+ // The description is the SQL statement
86
+ name: queryConfig?.text ?? SPAN_QUERY_FALLBACK,
87
+ op: "db",
88
+ attributes: {
89
+ ...getConnectionAttributes(params),
90
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
91
+ [ATTR_DB_STATEMENT]: queryConfig?.text || void 0,
92
+ [ATTR_PG_PLAN]: typeof queryConfig?.name === "string" ? queryConfig.name : void 0
93
+ }
94
+ };
95
+ }
96
+ function connectSpanOptions(ctx) {
97
+ const params = ctx.self?.connectionParameters ?? {};
98
+ return { name: SPAN_CONNECT, op: "db", attributes: getConnectionAttributes(params) };
99
+ }
100
+ function poolConnectSpanOptions(ctx) {
101
+ const opts = ctx.self?.options ?? {};
102
+ return { name: SPAN_POOL_CONNECT, op: "db", attributes: getPoolConnectionAttributes(opts) };
103
+ }
104
+ function hasOnMethod(obj) {
105
+ return "on" in obj && typeof obj.on === "function";
106
+ }
107
+ function extractQueryConfig(args) {
108
+ const arg0 = args[0];
109
+ if (typeof arg0 === "string") {
110
+ return { text: arg0 };
111
+ }
112
+ if (arg0 && typeof arg0 === "object" && typeof arg0.text === "string") {
113
+ const obj = arg0;
114
+ return { text: obj.text, name: obj.name };
115
+ }
116
+ return void 0;
117
+ }
118
+ function getConnectionAttributes(params) {
119
+ return {
120
+ [ATTR_DB_SYSTEM]: DB_SYSTEM_POSTGRESQL,
121
+ [ATTR_DB_CONNECTION_STRING]: getConnectionString(params),
122
+ [ATTR_DB_NAME]: params.database,
123
+ [ATTR_DB_USER]: params.user,
124
+ [ATTR_NET_PEER_NAME]: params.host,
125
+ [ATTR_NET_PEER_PORT]: Number.isInteger(params.port) ? params.port : void 0
126
+ };
127
+ }
128
+ function getPoolConnectionAttributes(opts) {
129
+ let url;
130
+ try {
131
+ url = opts.connectionString ? new URL(opts.connectionString) : void 0;
132
+ } catch {
133
+ url = void 0;
134
+ }
135
+ const database = url?.pathname.slice(1) || opts.database;
136
+ const host = url?.hostname || opts.host;
137
+ const port = Number(url?.port) || (Number.isInteger(opts.port) ? opts.port : void 0);
138
+ const user = url?.username || opts.user;
139
+ return {
140
+ [ATTR_DB_SYSTEM]: DB_SYSTEM_POSTGRESQL,
141
+ [ATTR_DB_CONNECTION_STRING]: getConnectionString(opts),
142
+ [ATTR_PG_IDLE_TIMEOUT]: opts.idleTimeoutMillis,
143
+ [ATTR_PG_MAX_CLIENT]: opts.max,
144
+ [ATTR_DB_NAME]: database,
145
+ [ATTR_NET_PEER_PORT]: port,
146
+ // these two come from a url parse and slice, can be ''
147
+ [ATTR_NET_PEER_NAME]: host || void 0,
148
+ [ATTR_DB_USER]: user || void 0
149
+ };
150
+ }
151
+ function getConnectionString(params) {
152
+ if (params.connectionString) {
153
+ try {
154
+ const url = new URL(params.connectionString);
155
+ url.username = "";
156
+ url.password = "";
157
+ return url.toString();
158
+ } catch {
159
+ return "postgresql://localhost:5432/";
160
+ }
161
+ }
162
+ const host = params.host || "localhost";
163
+ const port = params.port || 5432;
164
+ const database = params.database || "";
165
+ return `postgresql://${host}:${port}/${database}`;
166
+ }
167
+ const postgresChannelIntegration = core.defineIntegration(_postgresChannelIntegration);
168
+
169
+ exports.postgresChannelIntegration = postgresChannelIntegration;
170
+ //# sourceMappingURL=postgres.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres.js","sources":["../../../../src/integrations/tracing-channel/postgres.ts"],"sourcesContent":["import * as diagnosticsChannel from 'node:diagnostics_channel';\nimport type { IntegrationFn, Scope, SpanAttributes } from '@sentry/core';\nimport {\n bindScopeToEmitter,\n debug,\n defineIntegration,\n getActiveSpan,\n getCurrentScope,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_KIND,\n startInactiveSpan,\n waitForTracingChannelBinding,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { CHANNELS } from '../../orchestrion/channels';\nimport { bindTracingChannelToSpan } from '../../tracing-channel';\n\n// NOTE: this uses the same name as the OTel integration by design.\n// When enabled, the OTel 'Postgres' integration is omitted from the default set.\nconst INTEGRATION_NAME = 'Postgres' as const;\n\n// Only the query span carries an origin (the connect/pool-connect spans don't,\n// so they default to 'manual').\nconst ORIGIN = 'auto.db.orchestrion.postgres';\n\n// OpenTelemetry \"OLD\" db/net semantic-conventions, inlined to keep this\n// integration free of `@opentelemetry/*` deps.\nconst ATTR_DB_SYSTEM = 'db.system';\nconst ATTR_DB_NAME = 'db.name';\nconst ATTR_DB_CONNECTION_STRING = 'db.connection_string';\nconst ATTR_DB_USER = 'db.user';\nconst ATTR_DB_STATEMENT = 'db.statement';\nconst ATTR_NET_PEER_NAME = 'net.peer.name';\nconst ATTR_NET_PEER_PORT = 'net.peer.port';\nconst ATTR_PG_PLAN = 'db.postgresql.plan';\nconst ATTR_PG_IDLE_TIMEOUT = 'db.postgresql.idle.timeout.millis';\nconst ATTR_PG_MAX_CLIENT = 'db.postgresql.max.client';\nconst DB_SYSTEM_POSTGRESQL = 'postgresql';\n\n// We set `op: 'db'` and the SQL description directly here (same as mysql\n// orchestrion) rather than relying on the OTel pipeline's `inferDbSpanData`\n// processor, which only runs in the node SDK, so setting them here is what\n// makes the spans correct on the other runtimes\n//\n// The user-visible span is identical to OTel: query spans are named after\n// `db.statement`; connect/pool-connect spans keep these names.\nconst SPAN_QUERY_FALLBACK = 'pg.query';\nconst SPAN_CONNECT = 'pg.connect';\nconst SPAN_POOL_CONNECT = 'pg-pool.connect';\n\n/**\n * The shape orchestrion's transform attaches to the tracing-channel `context`. Documented here rather\n * than imported because orchestrion's runtime doesn't export it.\n */\ninterface PgChannelContext {\n // The live args array passed to the wrapped `query`/`connect` call.\n arguments: unknown[];\n self?: unknown;\n result?: unknown;\n error?: unknown;\n // The caller's scope, captured at `start` and replayed onto a streamed `Submittable` emitter (see below).\n _sentryCallerScope?: Scope;\n}\n\ninterface PgConnectionParams {\n database?: string;\n host?: string;\n port?: number;\n user?: string;\n connectionString?: string;\n}\n\ninterface PgPoolOptions extends PgConnectionParams {\n idleTimeoutMillis?: number;\n // pg-pool stores the max pool size as `max` (defaulting it to 10 in its\n // constructor). The OTel pg instrumentation reads a `maxClient` field that\n // pg-pool never sets, so its `db.postgresql.max.client` attribute is always\n // dropped; we read the real `max` so the attribute is actually populated.\n max?: number;\n}\n\nconst _postgresChannelIntegration = ((options: { ignoreConnectSpans?: boolean } = {}) => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n // `tracingChannel` is unavailable before Node 18.19 so do nothing in that case.\n if (!diagnosticsChannel.tracingChannel) {\n return;\n }\n\n waitForTracingChannelBinding(() => {\n // Query spans: `pg`/native `Client.prototype.query`. Only this channel can return a streamable\n // `Submittable` result, so it's the only one that defers span-ending to the emitter (see below).\n subscribeQueryLikeChannel(CHANNELS.PG_QUERY, querySpanOptions, { deferStreamedResult: true });\n\n // Connect spans, gated by `ignoreConnectSpans` (same as OTel pg).\n // `Client.prototype.connect` (pg + native)\n // and `Pool.prototype.connect` (pg-pool).\n if (!options.ignoreConnectSpans) {\n subscribeQueryLikeChannel(CHANNELS.PG_CONNECT, connectSpanOptions);\n subscribeQueryLikeChannel(CHANNELS.PGPOOL_CONNECT, poolConnectSpanOptions);\n }\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Subscribe to a pg tracing-channel and manage a span across its lifecycle.\n * Shared by the query/connect/pool-connect channels. They differ only in how\n * the span's name + attributes are built (`getSpanOptions`), and whether the\n * result can be a streamable emitter (`deferStreamedResult`, query-only).\n */\nfunction subscribeQueryLikeChannel(\n channelName: string,\n getSpanOptions: (ctx: PgChannelContext) => { name: string; op: string; attributes: SpanAttributes },\n { deferStreamedResult = false }: { deferStreamedResult?: boolean } = {},\n): void {\n DEBUG_BUILD && debug.log(`[orchestrion:pg] subscribing to channel \"${channelName}\"`);\n\n bindTracingChannelToSpan(\n diagnosticsChannel.tracingChannel<PgChannelContext>(channelName),\n data => {\n // Only instrument when there's an active span; returning `undefined` opts this call out entirely,\n // leaving the active context untouched (e.g. connects issued during app startup).\n if (!getActiveSpan()) {\n return undefined;\n }\n\n // Capture the caller's scope while still synchronously inside the call, for the streamed path:\n // pg dispatches a `Submittable` emitter's events outside the original async scope, so `deferSpanEnd`\n // replays this scope onto that emitter.\n data._sentryCallerScope = getCurrentScope();\n\n // `kind: CLIENT` mirrors the OTel pg instrumentation, so the emitted\n // `otel.kind` matches across the OTel and diagnostics-channel paths.\n return startInactiveSpan({ ...getSpanOptions(data), kind: SPAN_KIND.CLIENT });\n },\n // `connect`/`pool-connect` resolve with a persistent `Client` (itself an\n // `EventEmitter`), which is NOT a streamed result. Deferring their span\n // to that emitter's `'end'`/`'error'` would keep it open for the whole\n // connection lifetime, so it never ends in time and is dropped. Only\n // `query` can return a streamable `Submittable`, so only it defers.\n deferStreamedResult\n ? {\n // Streamable `Submittable` (e.g. `client.query(new Query())`)\n // returns an emitter that orchestrion stores on `ctx.result` while\n // firing no async events; the query isn't done until the emitter\n // emits `'end'`/`'error'`. Defer ending to those events for that\n // path; the callback, promise, and sync-throw paths carry no\n // emitter, so the helper ends the span as usual.\n deferSpanEnd({ data, end }) {\n const result = data.result;\n if (!result || typeof result !== 'object' || !hasOnMethod(result)) {\n return false;\n }\n\n // Replay the caller's scope onto the emitter so listeners theu\n // user attaches after the call returns (and any spans they start)\n // nest under the caller, not a fresh root trace.\n const callerScope = data._sentryCallerScope;\n if (callerScope) {\n bindScopeToEmitter(result, callerScope);\n }\n\n result.on('error', err => end(err));\n result.on('end', () => end());\n\n return true;\n },\n }\n : undefined,\n );\n}\n\nfunction querySpanOptions(ctx: PgChannelContext): { name: string; op: string; attributes: SpanAttributes } {\n const params = (ctx.self as { connectionParameters?: PgConnectionParams } | undefined)?.connectionParameters ?? {};\n const queryConfig = extractQueryConfig(ctx.arguments);\n return {\n // The description is the SQL statement\n name: queryConfig?.text ?? SPAN_QUERY_FALLBACK,\n op: 'db',\n attributes: {\n ...getConnectionAttributes(params),\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [ATTR_DB_STATEMENT]: queryConfig?.text || undefined,\n [ATTR_PG_PLAN]: typeof queryConfig?.name === 'string' ? queryConfig.name : undefined,\n },\n };\n}\n\nfunction connectSpanOptions(ctx: PgChannelContext): { name: string; op: string; attributes: SpanAttributes } {\n const params = (ctx.self as { connectionParameters?: PgConnectionParams } | undefined)?.connectionParameters ?? {};\n // No origin set -> defaults to 'manual'\n return { name: SPAN_CONNECT, op: 'db', attributes: getConnectionAttributes(params) };\n}\n\nfunction poolConnectSpanOptions(ctx: PgChannelContext): { name: string; op: string; attributes: SpanAttributes } {\n const opts = (ctx.self as { options?: PgPoolOptions } | undefined)?.options ?? {};\n return { name: SPAN_POOL_CONNECT, op: 'db', attributes: getPoolConnectionAttributes(opts) };\n}\n\nfunction hasOnMethod(obj: object): obj is { on: (event: string, listener: (arg?: unknown) => void) => unknown } {\n return 'on' in obj && typeof (obj as { on?: unknown }).on === 'function';\n}\n\n// `client.query(text, cb?)`, `client.query(text, values, cb?)`, and\n// `client.query(configObj, cb?)` are all valid; normalize to `{ text, name }`\n// (the only fields the span needs). Returns undefined for invalid args.\nfunction extractQueryConfig(args: unknown[]): { text: string; name?: unknown } | undefined {\n const arg0 = args[0];\n if (typeof arg0 === 'string') {\n return { text: arg0 };\n }\n if (arg0 && typeof arg0 === 'object' && typeof (arg0 as { text?: unknown }).text === 'string') {\n const obj = arg0 as { text: string; name?: unknown };\n return { text: obj.text, name: obj.name };\n }\n return undefined;\n}\n\nfunction getConnectionAttributes(params: PgConnectionParams): SpanAttributes {\n return {\n [ATTR_DB_SYSTEM]: DB_SYSTEM_POSTGRESQL,\n [ATTR_DB_CONNECTION_STRING]: getConnectionString(params),\n [ATTR_DB_NAME]: params.database,\n [ATTR_DB_USER]: params.user,\n [ATTR_NET_PEER_NAME]: params.host,\n [ATTR_NET_PEER_PORT]: Number.isInteger(params.port) ? params.port : undefined,\n };\n}\n\nfunction getPoolConnectionAttributes(opts: PgPoolOptions): SpanAttributes {\n let url: URL | undefined;\n try {\n url = opts.connectionString ? new URL(opts.connectionString) : undefined;\n } catch {\n url = undefined;\n }\n const database = url?.pathname.slice(1) || opts.database;\n const host = url?.hostname || opts.host;\n // Mirror OTel's `getSemanticAttributesFromPoolConnection`: prefer the URL's\n // port, but fall back to an explicit `opts.port` when the connection string\n // omits it (`Number('')` / `Number(undefined)` -> falsy).\n const port = Number(url?.port) || (Number.isInteger(opts.port) ? opts.port : undefined);\n const user = url?.username || opts.user;\n return {\n [ATTR_DB_SYSTEM]: DB_SYSTEM_POSTGRESQL,\n [ATTR_DB_CONNECTION_STRING]: getConnectionString(opts),\n [ATTR_PG_IDLE_TIMEOUT]: opts.idleTimeoutMillis,\n [ATTR_PG_MAX_CLIENT]: opts.max,\n [ATTR_DB_NAME]: database,\n [ATTR_NET_PEER_PORT]: port,\n // these two come from a url parse and slice, can be ''\n [ATTR_NET_PEER_NAME]: host || undefined,\n [ATTR_DB_USER]: user || undefined,\n };\n}\n\n// Builds `postgresql://host:port/database`, masking credentials when a raw\n// connection string was provided.\nfunction getConnectionString(params: PgConnectionParams): string {\n if (params.connectionString) {\n try {\n const url = new URL(params.connectionString);\n url.username = '';\n url.password = '';\n return url.toString();\n } catch {\n return 'postgresql://localhost:5432/';\n }\n }\n const host = params.host || 'localhost';\n const port = params.port || 5432;\n const database = params.database || '';\n return `postgresql://${host}:${port}/${database}`;\n}\n\n/**\n * EXPERIMENTAL: orchestrion-driven `pg` (node-postgres) integration.\n *\n * Subscribes to the `orchestrion:pg:query`/`:connect` and\n * `orchestrion:pg-pool:connect` diagnostics_channels that the orchestrion code\n * transform injects into `pg`'s `Client.prototype.query`/`connect`\n * and `pg-pool`'s `Pool.prototype.connect`. Requires the orchestrion runtime\n * hook or bundler plugin to be active.\n */\nexport const postgresChannelIntegration = defineIntegration(_postgresChannelIntegration);\n"],"names":["waitForTracingChannelBinding","CHANNELS","DEBUG_BUILD","debug","bindTracingChannelToSpan","getActiveSpan","getCurrentScope","startInactiveSpan","SPAN_KIND","bindScopeToEmitter","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","defineIntegration"],"mappings":";;;;;;;;AAmBA,MAAM,gBAAA,GAAmB,UAAA;AAIzB,MAAM,MAAA,GAAS,8BAAA;AAIf,MAAM,cAAA,GAAiB,WAAA;AACvB,MAAM,YAAA,GAAe,SAAA;AACrB,MAAM,yBAAA,GAA4B,sBAAA;AAClC,MAAM,YAAA,GAAe,SAAA;AACrB,MAAM,iBAAA,GAAoB,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kB,GAAG,IAAA,CAAK,GAAA;AAAA,IAC3B,CAAC,YAAY,GAAG,QAAA;AAAA,IAChB,CAAC,kBAAkB,GAAG,IAAA;AAAA;AAAA,IAEtB,CAAC,kBAAkB,GAAG,IAAA,IAAQ,MAAA;AAAA,IAC9B,CAAC,YAAY,GAAG,IAAA,IAAQ;AAAA,GAC1B;AACF;AAIA,SAAS,oBAAoB,MAAA,EAAoC;AAC/D,EAAA,IAAI,OAAO,gBAAA,EAAkB;AAC3B,IAAA,IAAI;AACF,MAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,MAAA,CAAO,gBAAgB,CAAA;AAC3C,MAAA,GAAA,CAAI,QAAA,GAAW,EAAA;AACf,MAAA,GAAA,CAAI,QAAA,GAAW,EAAA;AACf,MAAA,OAAO,IAAI,QAAA,EAAS;AAAA,IACtB,CAAA,CAAA,MAAQ;AACN,MAAA,OAAO,8BAAA;AAAA,IACT;AAAA,EACF;AACA,EAAA,MAAM,IAAA,GAAO,OAAO,IAAA,IAAQ,WAAA;AAC5B,EAAA,MAAM,IAAA,GAAO,OAAO,IAAA,IAAQ,IAAA;AAC5B,EAAA,MAAM,QAAA,GAAW,OAAO,QAAA,IAAY,EAAA;AACpC,EAAA,OAAO,CAAA,aAAA,EAAgB,IAAI,CAAA,CAAA,EAAI,IAAI,IAAI,QAAQ,CAAA,CAAA;AACjD;AAWO,MAAM,0BAAA,GAA6BC,uBAAkB,2BAA2B;;;;"}
@@ -0,0 +1,25 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const core = require('@sentry/core');
4
+ const index = require('../../vercel-ai/index.js');
5
+ const diagnosticsChannel = require('node:diagnostics_channel');
6
+ const vercelAiOrchestrionV6Subscriber = require('../../vercel-ai/vercel-ai-orchestrion-v6-subscriber.js');
7
+
8
+ const _vercelAiChannelIntegration = ((options = {}) => {
9
+ const parentIntegration = index.vercelAiIntegration(options);
10
+ return core.extendIntegration(parentIntegration, {
11
+ options,
12
+ setupOnce() {
13
+ if (!diagnosticsChannel.tracingChannel) {
14
+ return;
15
+ }
16
+ core.waitForTracingChannelBinding(() => {
17
+ vercelAiOrchestrionV6Subscriber.subscribeVercelAiOrchestrionChannels(diagnosticsChannel.tracingChannel, options);
18
+ });
19
+ }
20
+ });
21
+ });
22
+ const vercelAiChannelIntegration = core.defineIntegration(_vercelAiChannelIntegration);
23
+
24
+ exports.vercelAiChannelIntegration = vercelAiChannelIntegration;
25
+ //# sourceMappingURL=vercel-ai.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vercel-ai.js","sources":["../../../../src/integrations/tracing-channel/vercel-ai.ts"],"sourcesContent":["import type { IntegrationFn } from '@sentry/core';\nimport { defineIntegration, extendIntegration, waitForTracingChannelBinding } from '@sentry/core';\nimport { vercelAiIntegration as baseVercelAiIntegration } from '../../vercel-ai';\nimport * as dc from 'node:diagnostics_channel';\nimport { subscribeVercelAiOrchestrionChannels } from '../../vercel-ai/vercel-ai-orchestrion-v6-subscriber';\n\ntype VercelAiOptions = Parameters<typeof baseVercelAiIntegration>[0];\n\n// In channel-based (orchestrion) mode we emit our own `gen_ai.*` spans from the\n// diagnostics channels. The `ai` SDK would otherwise emit its own native\n// OpenTelemetry spans whenever the user enables `experimental_telemetry`, which\n// would be duplicates. Rather than dropping those after the fact, the v6\n// subscriber suppresses them at the source: it flips the wrapped call's\n// `experimental_telemetry.isEnabled` to `false`, so `ai` falls back to its\n// internal no-op tracer and never creates the native spans in the first place.\n// See `subscribeVercelAiOrchestrionChannels`.\nconst _vercelAiChannelIntegration = ((options: VercelAiOptions = {}) => {\n const parentIntegration = baseVercelAiIntegration(options);\n\n return extendIntegration(parentIntegration, {\n options,\n setupOnce() {\n // Bail if this is not available\n if (!dc.tracingChannel) {\n return;\n }\n\n waitForTracingChannelBinding(() => {\n subscribeVercelAiOrchestrionChannels(dc.tracingChannel, options);\n });\n },\n });\n}) satisfies IntegrationFn;\n\n/**\n * Auto-instrument the `ai` SDK. Supported are:\n * - v7 via native `ai:telemetry` tracing channel\n * - v6 via orchestrion `orchestrion:ai:*` channels\n */\nexport const vercelAiChannelIntegration = defineIntegration(_vercelAiChannelIntegration);\n"],"names":["baseVercelAiIntegration","extendIntegration","dc","waitForTracingChannelBinding","subscribeVercelAiOrchestrionChannels","defineIntegration"],"mappings":";;;;;;;AAgBA,MAAM,2BAAA,IAA+B,CAAC,OAAA,GAA2B,EAAC,KAAM;AACtE,EAAA,MAAM,iBAAA,GAAoBA,0BAAwB,OAAO,CAAA;AAEzD,EAAA,OAAOC,uBAAkB,iBAAA,EAAmB;AAAA,IAC1C,OAAA;AAAA,IACA,SAAA,GAAY;AAEV,MAAA,IAAI,CAACC,mBAAG,cAAA,EAAgB;AACtB,QAAA;AAAA,MACF;AAEA,MAAAC,iCAAA,CAA6B,MAAM;AACjC,QAAAC,oEAAA,CAAqCF,kBAAA,CAAG,gBAAgB,OAAO,CAAA;AAAA,MACjE,CAAC,CAAA;AAAA,IACH;AAAA,GACD,CAAA;AACH,CAAA,CAAA;AAOO,MAAM,0BAAA,GAA6BG,uBAAkB,2BAA2B;;;;"}
@@ -0,0 +1,23 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const core = require('@sentry/core');
4
+ const diagnosticsChannel = require('node:diagnostics_channel');
5
+ const mongooseDcSubscriber = require('./mongoose-dc-subscriber.js');
6
+
7
+ const _mongooseIntegration = (() => {
8
+ return {
9
+ name: "Mongoose",
10
+ setupOnce() {
11
+ if (!diagnosticsChannel.tracingChannel) {
12
+ return;
13
+ }
14
+ core.waitForTracingChannelBinding(() => {
15
+ mongooseDcSubscriber.subscribeMongooseDiagnosticChannels(diagnosticsChannel.tracingChannel);
16
+ });
17
+ }
18
+ };
19
+ });
20
+ const mongooseIntegration = core.defineIntegration(_mongooseIntegration);
21
+
22
+ exports.mongooseIntegration = mongooseIntegration;
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/mongoose/index.ts"],"sourcesContent":["import { defineIntegration, type IntegrationFn, waitForTracingChannelBinding } from '@sentry/core';\nimport * as dc from 'node:diagnostics_channel';\nimport { subscribeMongooseDiagnosticChannels } from './mongoose-dc-subscriber';\n\nconst _mongooseIntegration = (() => {\n return {\n name: 'Mongoose',\n setupOnce() {\n // Bail on Node <= 18.18.0, where `tracingChannel` does not exist.\n if (!dc.tracingChannel) {\n return;\n }\n\n // Subscribe to mongoose's native tracing channels (mongoose >= 9.7).\n // This is a no-op on versions that don't publish to the channels, so it is always safe to call.\n waitForTracingChannelBinding(() => {\n subscribeMongooseDiagnosticChannels(dc.tracingChannel);\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Auto-instrument the [mongoose](https://www.npmjs.com/package/mongoose) library via its native\n * `node:diagnostics_channel` tracing channels (mongoose >= 9.7).\n *\n * On older mongoose versions the channels are never published to, so this integration is inert and\n * the IITM-based patcher (gated to `< 9.7.0`) handles instrumentation instead.\n */\nexport const mongooseIntegration = defineIntegration(_mongooseIntegration);\n"],"names":["dc","waitForTracingChannelBinding","subscribeMongooseDiagnosticChannels","defineIntegration"],"mappings":";;;;;;AAIA,MAAM,wBAAwB,MAAM;AAClC,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,UAAA;AAAA,IACN,SAAA,GAAY;AAEV,MAAA,IAAI,CAACA,mBAAG,cAAA,EAAgB;AACtB,QAAA;AAAA,MACF;AAIA,MAAAC,iCAAA,CAA6B,MAAM;AACjC,QAAAC,wDAAA,CAAoCF,mBAAG,cAAc,CAAA;AAAA,MACvD,CAAC,CAAA;AAAA,IACH;AAAA,GACF;AACF,CAAA,CAAA;AASO,MAAM,mBAAA,GAAsBG,uBAAkB,oBAAoB;;;;"}
@@ -0,0 +1,97 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const attributes = require('@sentry/conventions/attributes');
4
+ const core = require('@sentry/core');
5
+ const debugBuild = require('../debug-build.js');
6
+ const tracingChannel = require('../tracing-channel.js');
7
+
8
+ const MONGOOSE_DC_CHANNEL_QUERY = "mongoose:query";
9
+ const MONGOOSE_DC_CHANNEL_AGGREGATE = "mongoose:aggregate";
10
+ const MONGOOSE_DC_CHANNEL_MODEL_SAVE = "mongoose:model:save";
11
+ const MONGOOSE_DC_CHANNEL_MODEL_INSERT_MANY = "mongoose:model:insertMany";
12
+ const MONGOOSE_DC_CHANNEL_MODEL_BULK_WRITE = "mongoose:model:bulkWrite";
13
+ const MONGOOSE_DC_CHANNEL_CURSOR_NEXT = "mongoose:cursor:next";
14
+ const ORIGIN = "auto.db.mongoose.diagnostic_channel";
15
+ const DB_SYSTEM_NAME_VALUE_MONGODB = "mongodb";
16
+ const MAX_REDACTION_DEPTH = 10;
17
+ let subscribed = false;
18
+ function subscribeMongooseDiagnosticChannels(tracingChannel) {
19
+ if (subscribed) {
20
+ return;
21
+ }
22
+ subscribed = true;
23
+ try {
24
+ setupChannel(tracingChannel, MONGOOSE_DC_CHANNEL_QUERY);
25
+ setupChannel(tracingChannel, MONGOOSE_DC_CHANNEL_AGGREGATE);
26
+ setupChannel(tracingChannel, MONGOOSE_DC_CHANNEL_MODEL_SAVE);
27
+ setupChannel(tracingChannel, MONGOOSE_DC_CHANNEL_MODEL_INSERT_MANY);
28
+ setupChannel(tracingChannel, MONGOOSE_DC_CHANNEL_MODEL_BULK_WRITE);
29
+ setupChannel(tracingChannel, MONGOOSE_DC_CHANNEL_CURSOR_NEXT);
30
+ } catch {
31
+ debugBuild.DEBUG_BUILD && core.debug.log("Mongoose node:diagnostics_channel subscription failed.");
32
+ }
33
+ }
34
+ function setupChannel(tracingChannel$1, channelName) {
35
+ tracingChannel.bindTracingChannelToSpan(tracingChannel$1(channelName), (data) => {
36
+ const collection = data.collection;
37
+ const queryText = redactMongoQuery(data.args?.pipeline ?? data.args?.filter);
38
+ const batchSize = getBatchSize(data);
39
+ return core.startInactiveSpan({
40
+ name: collection ? `mongoose.${collection}.${data.operation}` : `mongoose.${data.operation}`,
41
+ attributes: {
42
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
43
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: "db",
44
+ [attributes.DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_MONGODB,
45
+ [attributes.DB_OPERATION_NAME]: data.operation,
46
+ [attributes.DB_COLLECTION_NAME]: collection ?? void 0,
47
+ [attributes.DB_NAMESPACE]: data.database ?? void 0,
48
+ [attributes.DB_QUERY_TEXT]: queryText ?? void 0,
49
+ [attributes.DB_OPERATION_BATCH_SIZE]: batchSize ?? void 0,
50
+ [attributes.SERVER_ADDRESS]: data.serverAddress ?? void 0,
51
+ [attributes.SERVER_PORT]: data.serverPort ?? void 0
52
+ }
53
+ });
54
+ });
55
+ }
56
+ function getBatchSize(data) {
57
+ const args = data.args;
58
+ const batch = data.operation === "insertMany" ? args?.docs : data.operation === "bulkWrite" ? args?.ops : void 0;
59
+ return Array.isArray(batch) && batch.length > 1 ? batch.length : void 0;
60
+ }
61
+ function redactMongoQuery(value) {
62
+ if (value == null) {
63
+ return void 0;
64
+ }
65
+ try {
66
+ const redacted = redactValue(value, 0);
67
+ const text = JSON.stringify(redacted);
68
+ return text == null || text === "{}" || text === "[]" ? void 0 : text;
69
+ } catch {
70
+ return void 0;
71
+ }
72
+ }
73
+ function redactValue(value, depth) {
74
+ if (depth > MAX_REDACTION_DEPTH) {
75
+ return "?";
76
+ }
77
+ if (Array.isArray(value)) {
78
+ return value.map((item) => redactValue(item, depth + 1));
79
+ }
80
+ if (value && typeof value === "object") {
81
+ const out = {};
82
+ for (const key of Object.keys(value)) {
83
+ out[key] = redactValue(value[key], depth + 1);
84
+ }
85
+ return out;
86
+ }
87
+ return "?";
88
+ }
89
+
90
+ exports.MONGOOSE_DC_CHANNEL_AGGREGATE = MONGOOSE_DC_CHANNEL_AGGREGATE;
91
+ exports.MONGOOSE_DC_CHANNEL_CURSOR_NEXT = MONGOOSE_DC_CHANNEL_CURSOR_NEXT;
92
+ exports.MONGOOSE_DC_CHANNEL_MODEL_BULK_WRITE = MONGOOSE_DC_CHANNEL_MODEL_BULK_WRITE;
93
+ exports.MONGOOSE_DC_CHANNEL_MODEL_INSERT_MANY = MONGOOSE_DC_CHANNEL_MODEL_INSERT_MANY;
94
+ exports.MONGOOSE_DC_CHANNEL_MODEL_SAVE = MONGOOSE_DC_CHANNEL_MODEL_SAVE;
95
+ exports.MONGOOSE_DC_CHANNEL_QUERY = MONGOOSE_DC_CHANNEL_QUERY;
96
+ exports.subscribeMongooseDiagnosticChannels = subscribeMongooseDiagnosticChannels;
97
+ //# sourceMappingURL=mongoose-dc-subscriber.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoose-dc-subscriber.js","sources":["../../../src/mongoose/mongoose-dc-subscriber.ts"],"sourcesContent":["import type { TracingChannel } from 'node:diagnostics_channel';\nimport {\n DB_COLLECTION_NAME,\n DB_NAMESPACE,\n DB_OPERATION_BATCH_SIZE,\n DB_OPERATION_NAME,\n DB_QUERY_TEXT,\n DB_SYSTEM_NAME,\n SERVER_ADDRESS,\n SERVER_PORT,\n} from '@sentry/conventions/attributes';\nimport { debug, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startInactiveSpan } from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { bindTracingChannelToSpan } from '../tracing-channel';\n\n// Channel names published by mongoose >= 9.7.0 (see mongoose `lib/tracing.js`,\n// `lib/query.js`, `lib/aggregate.js`, `lib/model.js` and `lib/cursor/*`).\n// Hardcoded so the subscriber does not have to import mongoose — the channels\n// just have to be subscribed to before the user's mongoose code publishes.\nexport const MONGOOSE_DC_CHANNEL_QUERY = 'mongoose:query';\nexport const MONGOOSE_DC_CHANNEL_AGGREGATE = 'mongoose:aggregate';\nexport const MONGOOSE_DC_CHANNEL_MODEL_SAVE = 'mongoose:model:save';\nexport const MONGOOSE_DC_CHANNEL_MODEL_INSERT_MANY = 'mongoose:model:insertMany';\nexport const MONGOOSE_DC_CHANNEL_MODEL_BULK_WRITE = 'mongoose:model:bulkWrite';\nexport const MONGOOSE_DC_CHANNEL_CURSOR_NEXT = 'mongoose:cursor:next';\n\nconst ORIGIN = 'auto.db.mongoose.diagnostic_channel';\nconst DB_SYSTEM_NAME_VALUE_MONGODB = 'mongodb';\n\n// Cap recursion so a self-referential or pathologically deep query can never\n// stall (or blow the stack in) instrumentation.\nconst MAX_REDACTION_DEPTH = 10;\n\n/**\n * Shape of the context object mongoose >= 9.7.0 publishes on its tracing\n * channels (mongoose's `TracingContext`, see `types/tracing.d.ts`).\n *\n * Node's `tracePromise` mutates this same object with `result`/`error` once the\n * operation settles, which `bindTracingChannelToSpan` reads in its lifecycle\n * handlers — hence both are declared optional here.\n *\n * Unlike redis/ioredis, mongoose does NOT pre-sanitize the payload, so `args`\n * carries the raw user query. We redact it before emitting `db.query.text`.\n */\nexport interface MongooseTracingData {\n operation: string;\n /** Absent for connection-level `aggregate()` calls, which have no model/collection. */\n collection?: string;\n database?: string;\n serverAddress?: string;\n serverPort?: number;\n /** Cursor channels only: the cursor's fetch batch size and tailable flag. */\n batchSize?: number;\n tailable?: boolean;\n /**\n * Operation-specific arguments. `filter` (queries/cursors) and `pipeline`\n * (aggregations) carry the query shape; `docs`/`ops` carry batch payloads.\n */\n args?: {\n filter?: unknown;\n pipeline?: unknown;\n docs?: unknown;\n ops?: unknown;\n [key: string]: unknown;\n };\n result?: unknown;\n error?: Error;\n}\n\n/**\n * Platform-provided factory that creates a native tracing channel for the given name. The\n * subscriber binds the span and its lifecycle onto the channel via `bindTracingChannelToSpan`,\n * which propagates the active span through the runtime's async context.\n *\n * Node passes `node:diagnostics_channel`'s `tracingChannel` directly.\n */\nexport type MongooseTracingChannelFactory = <T extends object>(name: string) => TracingChannel<T, T>;\n\nlet subscribed = false;\n\n/**\n * Subscribe Sentry span handlers to mongoose's diagnostics-channel events\n * (`mongoose:query`, `:aggregate`, `:model:save`, `:model:insertMany`,\n * `:model:bulkWrite`, `:cursor:next`), published by mongoose >= 9.7.0.\n *\n * On older mongoose versions the channels are never published to, so the\n * subscribers are inert — there is no double-instrumentation against the\n * IITM-based vendored patcher, which is gated to `< 9.7.0`.\n *\n * Idempotent: subsequent calls are a no-op.\n */\nexport function subscribeMongooseDiagnosticChannels(tracingChannel: MongooseTracingChannelFactory): void {\n if (subscribed) {\n return;\n }\n subscribed = true;\n\n try {\n setupChannel(tracingChannel, MONGOOSE_DC_CHANNEL_QUERY);\n setupChannel(tracingChannel, MONGOOSE_DC_CHANNEL_AGGREGATE);\n setupChannel(tracingChannel, MONGOOSE_DC_CHANNEL_MODEL_SAVE);\n setupChannel(tracingChannel, MONGOOSE_DC_CHANNEL_MODEL_INSERT_MANY);\n setupChannel(tracingChannel, MONGOOSE_DC_CHANNEL_MODEL_BULK_WRITE);\n setupChannel(tracingChannel, MONGOOSE_DC_CHANNEL_CURSOR_NEXT);\n } catch {\n // The factory relies on `node:diagnostics_channel`, which isn't always\n // available. Fail closed; the SDK simply won't emit mongoose spans here.\n DEBUG_BUILD && debug.log('Mongoose node:diagnostics_channel subscription failed.');\n }\n}\n\nfunction setupChannel(tracingChannel: MongooseTracingChannelFactory, channelName: string): void {\n bindTracingChannelToSpan(tracingChannel<MongooseTracingData>(channelName), data => {\n const collection = data.collection;\n const queryText = redactMongoQuery(data.args?.pipeline ?? data.args?.filter);\n const batchSize = getBatchSize(data);\n\n return startInactiveSpan({\n name: collection ? `mongoose.${collection}.${data.operation}` : `mongoose.${data.operation}`,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'db',\n [DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_MONGODB,\n [DB_OPERATION_NAME]: data.operation,\n [DB_COLLECTION_NAME]: collection ?? undefined,\n [DB_NAMESPACE]: data.database ?? undefined,\n [DB_QUERY_TEXT]: queryText ?? undefined,\n [DB_OPERATION_BATCH_SIZE]: batchSize ?? undefined,\n [SERVER_ADDRESS]: data.serverAddress ?? undefined,\n [SERVER_PORT]: data.serverPort ?? undefined,\n },\n });\n });\n}\n\n/**\n * `db.operation.batch.size` is only meaningful for genuine batch operations.\n * Mongoose's cursor `batchSize` is a fetch-tuning option, not a batch operation\n * size, so it is intentionally excluded here.\n */\nfunction getBatchSize(data: MongooseTracingData): number | undefined {\n const args = data.args;\n const batch = data.operation === 'insertMany' ? args?.docs : data.operation === 'bulkWrite' ? args?.ops : undefined;\n\n return Array.isArray(batch) && batch.length > 1 ? batch.length : undefined;\n}\n\n/**\n * Serialize a mongoose filter/pipeline into `db.query.text` while stripping every\n * value: keys and Mongo operators (`$gt`, `$in`, …) are preserved, leaf values\n * become `'?'`. Mongoose does not sanitize its channel payload, so this prevents\n * raw user data (potential PII) from leaving the process. Returns `undefined`\n * (rather than throwing) on anything it cannot serialize.\n */\nfunction redactMongoQuery(value: unknown): string | undefined {\n if (value == null) {\n return undefined;\n }\n\n try {\n const redacted = redactValue(value, 0);\n const text = JSON.stringify(redacted);\n\n // Skip empty/uninformative shapes (e.g. a `findOne()` with no filter).\n return text == null || text === '{}' || text === '[]' ? undefined : text;\n } catch {\n return undefined;\n }\n}\n\nfunction redactValue(value: unknown, depth: number): unknown {\n if (depth > MAX_REDACTION_DEPTH) {\n return '?';\n }\n\n if (Array.isArray(value)) {\n return value.map(item => redactValue(item, depth + 1));\n }\n\n if (value && typeof value === 'object') {\n const out: Record<string, unknown> = {};\n for (const key of Object.keys(value as Record<string, unknown>)) {\n out[key] = redactValue((value as Record<string, unknown>)[key], depth + 1);\n }\n\n return out;\n }\n\n return '?';\n}\n"],"names":["DEBUG_BUILD","debug","tracingChannel","bindTracingChannelToSpan","startInactiveSpan","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_OP","DB_SYSTEM_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;AAAA,EACT;AAEA,EAAA,IAAI;AACF,IAAA,MAAM,QAAA,GAAW,WAAA,CAAY,KAAA,EAAO,CAAC,CAAA;AACrC,IAAA,MAAM,IAAA,GAAO,IAAA,CAAK,SAAA,CAAU,QAAQ,CAAA;AAGpC,IAAA,OAAO,QAAQ,IAAA,IAAQ,IAAA,KAAS,IAAA,IAAQ,IAAA,KAAS,OAAO,KAAA,CAAA,GAAY,IAAA;AAAA,EACtE,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,MAAA;AAAA,EACT;AACF;AAEA,SAAS,WAAA,CAAY,OAAgB,KAAA,EAAwB;AAC3D,EAAA,IAAI,QAAQ,mBAAA,EAAqB;AAC/B,IAAA,OAAO,GAAA;AAAA,EACT;AAEA,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACxB,IAAA,OAAO,MAAM,GAAA,CAAI,CAAA,IAAA,KAAQ,YAAY,IAAA,EAAM,KAAA,GAAQ,CAAC,CAAC,CAAA;AAAA,EACvD;AAEA,EAAA,IAAI,KAAA,IAAS,OAAO,KAAA,KAAU,QAAA,EAAU;AACtC,IAAA,MAAM,MAA+B,EAAC;AACtC,IAAA,KAAA,MAAW,GAAA,IAAO,MAAA,CAAO,IAAA,CAAK,KAAgC,CAAA,EAAG;AAC/D,MAAA,GAAA,CAAI,GAAG,CAAA,GAAI,WAAA,CAAa,MAAkC,GAAG,CAAA,EAAG,QAAQ,CAAC,CAAA;AAAA,IAC3E;AAEA,IAAA,OAAO,GAAA;AAAA,EACT;AAEA,EAAA,OAAO,GAAA;AACT;;;;;;;;;;"}
@@ -2,10 +2,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
3
  const codeTransformer = require('@apm-js-collab/code-transformer-bundler-plugins/vite');
4
4
  const MagicString = require('magic-string');
5
- const config = require('../config.js');
5
+ const index = require('../config/index.js');
6
6
 
7
7
  function sentryOrchestrionPlugin() {
8
- const codeTransformerPlugins = codeTransformer.default({ instrumentations: config.SENTRY_INSTRUMENTATIONS });
8
+ const codeTransformerPlugins = codeTransformer.default({ instrumentations: index.SENTRY_INSTRUMENTATIONS });
9
9
  const codeTransformerArray = Array.isArray(codeTransformerPlugins) ? codeTransformerPlugins : [codeTransformerPlugins];
10
10
  return [bundlerMarkerPlugin(), ...codeTransformerArray];
11
11
  }
@@ -19,7 +19,7 @@ function bundlerMarkerPlugin() {
19
19
  name: "sentry-orchestrion-marker",
20
20
  enforce: "pre",
21
21
  config() {
22
- return { ssr: { noExternal: config.INSTRUMENTED_MODULE_NAMES } };
22
+ return { ssr: { noExternal: index.INSTRUMENTED_MODULE_NAMES } };
23
23
  },
24
24
  renderChunk(code, chunk) {
25
25
  if (!chunk.isEntry) return null;
@@ -1 +1 @@
1
- {"version":3,"file":"vite.js","sources":["../../../../src/orchestrion/bundler/vite.ts"],"sourcesContent":["// EXPERIMENTAL — Vite plugin that runs the orchestrion code transform at build\n// time, injecting `diagnostics_channel.tracingChannel` calls into the libraries\n// listed in `SENTRY_INSTRUMENTATIONS`.\n//\n// This file is published ESM-only via the `@sentry/server-utils/orchestrion/vite`\n// subpath export. `@apm-js-collab/code-transformer-bundler-plugins` is\n// `\"type\": \"module\"`, so consuming it from a CJS build is intentionally\n// unsupported — vite.config.ts is almost always ESM in practice. The CJS\n// rollup variant still emits this file, but `package.json` only exposes the\n// ESM entry, so attempts to `require('@sentry/server-utils/orchestrion/vite')` will\n// fail at resolution time rather than producing a half-broken plugin.\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype UnknownPlugin = any;\n\nimport codeTransformer from '@apm-js-collab/code-transformer-bundler-plugins/vite';\nimport MagicString from 'magic-string';\nimport { INSTRUMENTED_MODULE_NAMES, SENTRY_INSTRUMENTATIONS } from '../config';\n\n// `vite` types live in the package's ESM-only subpath; under Node16 module\n// resolution with TS treating @sentry/server-utils as CJS, importing them produces a\n// false positive. We don't need the runtime value for typing — `UnknownPlugin`\n// is sufficient — so we omit the import entirely.\n\n/**\n * Vite plugin that runs the orchestrion code transform on the bundled output.\n *\n * Use when bundling a Node app with Vite (e.g. Vite SSR builds, Nuxt's Nitro\n * pipeline, SvelteKit). For unbundled Node processes use the runtime hook\n * instead (`node --import @sentry/node/orchestrion app.js`).\n *\n * Returns two plugins:\n * 1. `sentry-orchestrion-marker` — a `renderChunk` hook that prepends a\n * single-line banner to entry chunks. The banner sets\n * `globalThis.__SENTRY_ORCHESTRION__.bundler = true` at app boot, so the\n * `_experimentalSetupOrchestrion()` detector can confirm the bundler path\n * ran (rather than relying on a build-time flag that wouldn't be visible\n * to the runtime).\n * Also injects every instrumented package name into `ssr.noExternal` via\n * the `config` hook, since externalized deps are `require()`d at runtime\n * from `node_modules` and never pass through the transform.\n * 2. The upstream `@apm-js-collab/code-transformer-bundler-plugins/vite`\n * plugin, fed our central `SENTRY_INSTRUMENTATIONS` config.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import { sentryOrchestrionPlugin } from '@sentry/node/orchestrion/vite';\n * export default { plugins: [sentryOrchestrionPlugin()] };\n * ```\n */\nexport function sentryOrchestrionPlugin(): UnknownPlugin[] {\n const codeTransformerPlugins = codeTransformer({ instrumentations: SENTRY_INSTRUMENTATIONS });\n const codeTransformerArray: UnknownPlugin[] = Array.isArray(codeTransformerPlugins)\n ? codeTransformerPlugins\n : [codeTransformerPlugins];\n return [bundlerMarkerPlugin(), ...codeTransformerArray];\n}\n\nfunction bundlerMarkerPlugin(): UnknownPlugin {\n const banner = [\n 'globalThis.__SENTRY_ORCHESTRION__ = (globalThis.__SENTRY_ORCHESTRION__ || {});',\n 'globalThis.__SENTRY_ORCHESTRION__.bundler = true;',\n '',\n ].join('\\n');\n\n return {\n name: 'sentry-orchestrion-marker',\n enforce: 'pre' as const,\n config(): { ssr: { noExternal: string[] } } {\n // Force-bundle every instrumented package so the code transform actually\n // sees its source. Vite externalizes dependencies in SSR builds by\n // default, leaving them as bare `require()`/`import` calls resolved from\n // `node_modules` at runtime — those copies are untouched and the\n // diagnostics_channel calls never get injected. Vite merges array\n // `noExternal` entries with the user's config, so we don't overwrite\n // their additions.\n return { ssr: { noExternal: INSTRUMENTED_MODULE_NAMES } };\n },\n renderChunk(code: string, chunk: { isEntry: boolean }): { code: string; map: unknown } | null {\n if (!chunk.isEntry) return null;\n // Prepend via magic-string so the entry chunk's sourcemap stays aligned —\n // returning `map: null` here would shift every mapping by the banner's\n // line count and misattribute server stack traces.\n const ms = new MagicString(code);\n ms.prepend(banner);\n return { code: ms.toString(), map: ms.generateMap({ hires: true }) };\n },\n };\n}\n"],"names":["codeTransformer","SENTRY_INSTRUMENTATIONS","INSTRUMENTED_MODULE_NAMES","MagicString"],"mappings":";;;;;;AAmDO,SAAS,uBAAA,GAA2C;AACzD,EAAA,MAAM,sBAAA,GAAyBA,uBAAA,CAAgB,EAAE,gBAAA,EAAkBC,gCAAyB,CAAA;AAC5F,EAAA,MAAM,uBAAwC,KAAA,CAAM,OAAA,CAAQ,sBAAsB,CAAA,GAC9E,sBAAA,GACA,CAAC,sBAAsB,CAAA;AAC3B,EAAA,OAAO,CAAC,mBAAA,EAAoB,EAAG,GAAG,oBAAoB,CAAA;AACxD;AAEA,SAAS,mBAAA,GAAqC;AAC5C,EAAA,MAAM,MAAA,GAAS;AAAA,IACb,gFAAA;AAAA,IACA,mDAAA;AAAA,IACA;AAAA,GACF,CAAE,KAAK,IAAI,CAAA;AAEX,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,2BAAA;AAAA,IACN,OAAA,EAAS,KAAA;AAAA,IACT,MAAA,GAA4C;AAQ1C,MAAA,OAAO,EAAE,GAAA,EAAK,EAAE,UAAA,EAAYC,kCAA0B,EAAE;AAAA,IAC1D,CAAA;AAAA,IACA,WAAA,CAAY,MAAc,KAAA,EAAoE;AAC5F,MAAA,IAAI,CAAC,KAAA,CAAM,OAAA,EAAS,OAAO,IAAA;AAI3B,MAAA,MAAM,EAAA,GAAK,IAAIC,mBAAA,CAAY,IAAI,CAAA;AAC/B,MAAA,EAAA,CAAG,QAAQ,MAAM,CAAA;AACjB,MAAA,OAAO,EAAE,IAAA,EAAM,EAAA,CAAG,QAAA,EAAS,EAAG,GAAA,EAAK,EAAA,CAAG,WAAA,CAAY,EAAE,KAAA,EAAO,IAAA,EAAM,CAAA,EAAE;AAAA,IACrE;AAAA,GACF;AACF;;;;"}
1
+ {"version":3,"file":"vite.js","sources":["../../../../src/orchestrion/bundler/vite.ts"],"sourcesContent":["// EXPERIMENTAL — Vite plugin that runs the orchestrion code transform at build\n// time, injecting `diagnostics_channel.tracingChannel` calls into the libraries\n// listed in `SENTRY_INSTRUMENTATIONS`.\n//\n// This file is published ESM-only via the `@sentry/server-utils/orchestrion/vite`\n// subpath export. `@apm-js-collab/code-transformer-bundler-plugins` is\n// `\"type\": \"module\"`, so consuming it from a CJS build is intentionally\n// unsupported — vite.config.ts is almost always ESM in practice. The CJS\n// rollup variant still emits this file, but `package.json` only exposes the\n// ESM entry, so attempts to `require('@sentry/server-utils/orchestrion/vite')` will\n// fail at resolution time rather than producing a half-broken plugin.\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype UnknownPlugin = any;\n\nimport codeTransformer from '@apm-js-collab/code-transformer-bundler-plugins/vite';\nimport MagicString from 'magic-string';\nimport { INSTRUMENTED_MODULE_NAMES, SENTRY_INSTRUMENTATIONS } from '../config';\n\n// `vite` types live in the package's ESM-only subpath; under Node16 module\n// resolution with TS treating @sentry/server-utils as CJS, importing them produces a\n// false positive. We don't need the runtime value for typing — `UnknownPlugin`\n// is sufficient — so we omit the import entirely.\n\n/**\n * Vite plugin that runs the orchestrion code transform on the bundled output.\n *\n * Use when bundling a Node app with Vite (e.g. Vite SSR builds, Nuxt's Nitro\n * pipeline, SvelteKit). For unbundled Node processes use the runtime hook\n * instead (`node --import @sentry/node/orchestrion app.js`).\n *\n * Returns two plugins:\n * 1. `sentry-orchestrion-marker` — a `renderChunk` hook that prepends a\n * single-line banner to entry chunks. The banner sets\n * `globalThis.__SENTRY_ORCHESTRION__.bundler = true` at app boot, so the\n * `_experimentalSetupOrchestrion()` detector can confirm the bundler path\n * ran (rather than relying on a build-time flag that wouldn't be visible\n * to the runtime).\n * Also injects every instrumented package name into `ssr.noExternal` via\n * the `config` hook, since externalized deps are `require()`d at runtime\n * from `node_modules` and never pass through the transform.\n * 2. The upstream `@apm-js-collab/code-transformer-bundler-plugins/vite`\n * plugin, fed our central `SENTRY_INSTRUMENTATIONS` config.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import { sentryOrchestrionPlugin } from '@sentry/node/orchestrion/vite';\n * export default { plugins: [sentryOrchestrionPlugin()] };\n * ```\n */\nexport function sentryOrchestrionPlugin(): UnknownPlugin[] {\n const codeTransformerPlugins = codeTransformer({ instrumentations: SENTRY_INSTRUMENTATIONS });\n const codeTransformerArray: UnknownPlugin[] = Array.isArray(codeTransformerPlugins)\n ? codeTransformerPlugins\n : [codeTransformerPlugins];\n return [bundlerMarkerPlugin(), ...codeTransformerArray];\n}\n\nfunction bundlerMarkerPlugin(): UnknownPlugin {\n const banner = [\n 'globalThis.__SENTRY_ORCHESTRION__ = (globalThis.__SENTRY_ORCHESTRION__ || {});',\n 'globalThis.__SENTRY_ORCHESTRION__.bundler = true;',\n '',\n ].join('\\n');\n\n return {\n name: 'sentry-orchestrion-marker',\n enforce: 'pre' as const,\n config(): { ssr: { noExternal: string[] } } {\n // Force-bundle every instrumented package so the code transform actually\n // sees its source. Vite externalizes dependencies in SSR builds by\n // default, leaving them as bare `require()`/`import` calls resolved from\n // `node_modules` at runtime — those copies are untouched and the\n // diagnostics_channel calls never get injected. Vite merges array\n // `noExternal` entries with the user's config, so we don't overwrite\n // their additions.\n return { ssr: { noExternal: INSTRUMENTED_MODULE_NAMES } };\n },\n renderChunk(code: string, chunk: { isEntry: boolean }): { code: string; map: unknown } | null {\n if (!chunk.isEntry) return null;\n // Prepend via magic-string so the entry chunk's sourcemap stays aligned —\n // returning `map: null` here would shift every mapping by the banner's\n // line count and misattribute server stack traces.\n const ms = new MagicString(code);\n ms.prepend(banner);\n return { code: ms.toString(), map: ms.generateMap({ hires: true }) };\n },\n };\n}\n"],"names":["codeTransformer","SENTRY_INSTRUMENTATIONS","INSTRUMENTED_MODULE_NAMES","MagicString"],"mappings":";;;;;;AAmDO,SAAS,uBAAA,GAA2C;AACzD,EAAA,MAAM,sBAAA,GAAyBA,uBAAA,CAAgB,EAAE,gBAAA,EAAkBC,+BAAyB,CAAA;AAC5F,EAAA,MAAM,uBAAwC,KAAA,CAAM,OAAA,CAAQ,sBAAsB,CAAA,GAC9E,sBAAA,GACA,CAAC,sBAAsB,CAAA;AAC3B,EAAA,OAAO,CAAC,mBAAA,EAAoB,EAAG,GAAG,oBAAoB,CAAA;AACxD;AAEA,SAAS,mBAAA,GAAqC;AAC5C,EAAA,MAAM,MAAA,GAAS;AAAA,IACb,gFAAA;AAAA,IACA,mDAAA;AAAA,IACA;AAAA,GACF,CAAE,KAAK,IAAI,CAAA;AAEX,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,2BAAA;AAAA,IACN,OAAA,EAAS,KAAA;AAAA,IACT,MAAA,GAA4C;AAQ1C,MAAA,OAAO,EAAE,GAAA,EAAK,EAAE,UAAA,EAAYC,iCAA0B,EAAE;AAAA,IAC1D,CAAA;AAAA,IACA,WAAA,CAAY,MAAc,KAAA,EAAoE;AAC5F,MAAA,IAAI,CAAC,KAAA,CAAM,OAAA,EAAS,OAAO,IAAA;AAI3B,MAAA,MAAM,EAAA,GAAK,IAAIC,mBAAA,CAAY,IAAI,CAAA;AAC/B,MAAA,EAAA,CAAG,QAAQ,MAAM,CAAA;AACjB,MAAA,OAAO,EAAE,IAAA,EAAM,EAAA,CAAG,QAAA,EAAS,EAAG,GAAA,EAAK,EAAA,CAAG,WAAA,CAAY,EAAE,KAAA,EAAO,IAAA,EAAM,CAAA,EAAE;AAAA,IACrE;AAAA,GACF;AACF;;;;"}