@sentry/server-utils 11.21.0 → 11.23.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 (261) hide show
  1. package/build/THIRD-PARTY-LICENSES.txt +10 -10
  2. package/build/cjs/chunks/config.js +4 -2
  3. package/build/cjs/chunks/config.js.map +1 -1
  4. package/build/cjs/chunks/core.js +0 -1
  5. package/build/cjs/chunks/exports.js +76 -28
  6. package/build/cjs/chunks/exports.js.map +1 -1
  7. package/build/cjs/chunks/module-details-from-path.js +427 -428
  8. package/build/cjs/chunks/module-details-from-path.js.map +1 -1
  9. package/build/cjs/chunks/moduleInjectedTransform.js +419 -421
  10. package/build/cjs/chunks/moduleInjectedTransform.js.map +1 -1
  11. package/build/cjs/chunks/rolldown-runtime.js +8 -6
  12. package/build/cjs/index.js +95 -41
  13. package/build/cjs/index.js.map +1 -1
  14. package/build/cjs/index.request-handler.js +2 -2
  15. package/build/cjs/orchestrion/bundler/bun.js +1 -1
  16. package/build/cjs/orchestrion/bundler/esbuild.js +1 -1
  17. package/build/cjs/orchestrion/bundler/rollup.js +1 -1
  18. package/build/cjs/orchestrion/bundler/vite.js +2 -2
  19. package/build/cjs/orchestrion/bundler/webpack-loader.js +2 -2
  20. package/build/cjs/orchestrion/bundler/webpack.js +4 -4
  21. package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/defineProperty.js +1 -1
  22. package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/assertClassBrand.js +1 -1
  23. package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/checkPrivateRedeclaration.js +1 -1
  24. package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/classPrivateFieldGet2.js +1 -1
  25. package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/classPrivateFieldInitSpec.js +1 -1
  26. package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/classPrivateFieldSet2.js +1 -1
  27. package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/classPrivateMethodInitSpec.js +1 -1
  28. package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/defineProperty.js +1 -1
  29. package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/toPrimitive.js +1 -1
  30. package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/toPropertyKey.js +1 -1
  31. package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/typeof.js +1 -1
  32. package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/toPrimitive.js +1 -1
  33. package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/toPropertyKey.js +1 -1
  34. package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/typeof.js +1 -1
  35. package/build/esm/_virtual/_rolldown/runtime.js +8 -6
  36. package/build/esm/ai/anthropic-ai/index.js +2 -2
  37. package/build/esm/ai/anthropic-ai/streaming.js +11 -2
  38. package/build/esm/ai/anthropic-ai/streaming.js.map +1 -1
  39. package/build/esm/ai/anthropic-ai/tool-runner.js +3 -3
  40. package/build/esm/ai/anthropic-ai/utils.js +2 -2
  41. package/build/esm/ai/core/span-hooks.js +1 -1
  42. package/build/esm/ai/core/time-to-first-chunk.js +1 -1
  43. package/build/esm/ai/core/utils.js +2 -2
  44. package/build/esm/ai/flue/index.js +2 -2
  45. package/build/esm/ai/flue/utils.js +2 -2
  46. package/build/esm/ai/google-genai/decisions.js +1 -1
  47. package/build/esm/ai/google-genai/index.js +2 -2
  48. package/build/esm/ai/google-genai/streaming.js +9 -2
  49. package/build/esm/ai/google-genai/streaming.js.map +1 -1
  50. package/build/esm/ai/google-genai/utils.js +1 -1
  51. package/build/esm/ai/langchain/embeddings.js +3 -3
  52. package/build/esm/ai/langchain/index.js +15 -9
  53. package/build/esm/ai/langchain/index.js.map +1 -1
  54. package/build/esm/ai/langchain/typesafe-classifier.js +2 -2
  55. package/build/esm/ai/langchain/utils.js +3 -4
  56. package/build/esm/ai/langchain/utils.js.map +1 -1
  57. package/build/esm/ai/langgraph/agent-span.js +3 -3
  58. package/build/esm/ai/langgraph/index.js +1 -1
  59. package/build/esm/ai/langgraph/stream.js +2 -2
  60. package/build/esm/ai/langgraph/utils.js +3 -3
  61. package/build/esm/ai/mastra/index.js +2 -2
  62. package/build/esm/ai/mastra/span-registry.js +1 -1
  63. package/build/esm/ai/mastra/utils.js +2 -2
  64. package/build/esm/ai/mistral/index.js +2 -2
  65. package/build/esm/ai/mistral/streaming.js +18 -9
  66. package/build/esm/ai/mistral/streaming.js.map +1 -1
  67. package/build/esm/ai/openai/index.js +2 -2
  68. package/build/esm/ai/openai/mapping.js +1 -1
  69. package/build/esm/ai/openai/streaming.js +15 -2
  70. package/build/esm/ai/openai/streaming.js.map +1 -1
  71. package/build/esm/ai/openai/utils.js +2 -2
  72. package/build/esm/ai/pi-ai/chat.js +12 -4
  73. package/build/esm/ai/pi-ai/chat.js.map +1 -1
  74. package/build/esm/ai/pi-ai/providers.js +1 -1
  75. package/build/esm/ai/pi-ai/recording.js +1 -1
  76. package/build/esm/ai/pi-durable/index.js +2 -2
  77. package/build/esm/ai/pi-durable/runs.js +3 -3
  78. package/build/esm/ai/pi-durable/tools.js +3 -3
  79. package/build/esm/ai/tanstack-ai/index.js +2 -2
  80. package/build/esm/ai/tanstack-ai/utils.js +2 -2
  81. package/build/esm/ai/typesafe/index.js +3 -3
  82. package/build/esm/ai/workers-ai/index.js +2 -2
  83. package/build/esm/ai/workers-ai/streaming.js +7 -5
  84. package/build/esm/ai/workers-ai/streaming.js.map +1 -1
  85. package/build/esm/ai/workers-ai/utils.js +7 -4
  86. package/build/esm/ai/workers-ai/utils.js.map +1 -1
  87. package/build/esm/async-context.js +1 -1
  88. package/build/esm/cron/common.js +1 -1
  89. package/build/esm/cron/cron.js +1 -1
  90. package/build/esm/cron/node-cron.js +1 -1
  91. package/build/esm/cron/node-schedule.js +1 -1
  92. package/build/esm/eve.js +1 -1
  93. package/build/esm/integrations/amqplib.js +3 -3
  94. package/build/esm/integrations/anthropic.js +3 -4
  95. package/build/esm/integrations/anthropic.js.map +1 -1
  96. package/build/esm/integrations/aws-sdk/index.js +3 -3
  97. package/build/esm/integrations/aws-sdk/services/MessageAttributes.js +1 -1
  98. package/build/esm/integrations/aws-sdk/services/bedrock-runtime-content.js +2 -2
  99. package/build/esm/integrations/aws-sdk/services/bedrock-runtime.js +3 -3
  100. package/build/esm/integrations/aws-sdk/services/dynamodb.js +1 -1
  101. package/build/esm/integrations/aws-sdk/services/lambda.js +2 -2
  102. package/build/esm/integrations/aws-sdk/services/sns.js +3 -3
  103. package/build/esm/integrations/aws-sdk/services/sqs.js +2 -2
  104. package/build/esm/integrations/bullmq/meter.js +2 -2
  105. package/build/esm/integrations/bullmq/tracer.js +2 -2
  106. package/build/esm/integrations/clickhouse.js +3 -3
  107. package/build/esm/integrations/cron.js +1 -1
  108. package/build/esm/integrations/dataloader.js +3 -3
  109. package/build/esm/integrations/express/error-handler.js +1 -1
  110. package/build/esm/integrations/express/index.js +1 -1
  111. package/build/esm/integrations/express/instrumentation.js +3 -3
  112. package/build/esm/integrations/fastify/errors.js +1 -1
  113. package/build/esm/integrations/fastify/index.js +1 -1
  114. package/build/esm/integrations/fastify/instrumentation.js +8 -4
  115. package/build/esm/integrations/fastify/instrumentation.js.map +1 -1
  116. package/build/esm/integrations/firebase/firestore.js +2 -2
  117. package/build/esm/integrations/firebase/functions.js +1 -1
  118. package/build/esm/integrations/firebase/index.js +1 -1
  119. package/build/esm/integrations/flue.js +1 -1
  120. package/build/esm/integrations/generic-pool.js +3 -3
  121. package/build/esm/integrations/google-genai.js +2 -2
  122. package/build/esm/integrations/graphql/graphql-dc-subscriber.js +3 -3
  123. package/build/esm/integrations/graphql/index.js +1 -1
  124. package/build/esm/integrations/graphql/resolvers.js +2 -2
  125. package/build/esm/integrations/graphql/spans.js +3 -3
  126. package/build/esm/integrations/groq.js +1 -1
  127. package/build/esm/integrations/hapi/hapi-error-handler.js +1 -1
  128. package/build/esm/integrations/hapi/hapi-utils.js +4 -5
  129. package/build/esm/integrations/hapi/hapi-utils.js.map +1 -1
  130. package/build/esm/integrations/hapi/index.js +1 -1
  131. package/build/esm/integrations/hono/applyPatches.js +1 -1
  132. package/build/esm/integrations/hono/createHonoMiddleware.js +1 -1
  133. package/build/esm/integrations/hono/honoIntegration.js +3 -3
  134. package/build/esm/integrations/hono/matchResult.js +1 -1
  135. package/build/esm/integrations/hono/middlewareHandlers.js +2 -2
  136. package/build/esm/integrations/hono/patchAppRequest.js +3 -3
  137. package/build/esm/integrations/hono/patchAppUse.js +1 -1
  138. package/build/esm/integrations/hono/patchRoute.js +1 -1
  139. package/build/esm/integrations/hono/wrapMiddlewareSpan.js +3 -3
  140. package/build/esm/integrations/kafkajs/consumer.js +2 -2
  141. package/build/esm/integrations/kafkajs/index.js +1 -1
  142. package/build/esm/integrations/kafkajs/spans.js +2 -2
  143. package/build/esm/integrations/knex.js +3 -3
  144. package/build/esm/integrations/koa/index.js +3 -3
  145. package/build/esm/integrations/langchain.js +1 -1
  146. package/build/esm/integrations/langgraph.js +1 -1
  147. package/build/esm/integrations/lru-memoizer.js +1 -1
  148. package/build/esm/integrations/mastra-classifier.js +2 -2
  149. package/build/esm/integrations/mastra.js +4 -4
  150. package/build/esm/integrations/mcp-server.js +2 -2
  151. package/build/esm/integrations/mistral.js +2 -2
  152. package/build/esm/integrations/mongodb/index.js +1 -1
  153. package/build/esm/integrations/mongodb/mongodb-span.js +1 -1
  154. package/build/esm/integrations/mongoose/index.js +1 -1
  155. package/build/esm/integrations/mongoose/mongoose-dc-subscriber.js +3 -3
  156. package/build/esm/integrations/mongoose/mongoose-legacy-span.js +1 -1
  157. package/build/esm/integrations/mysql.js +3 -3
  158. package/build/esm/integrations/mysql2/index.js +1 -1
  159. package/build/esm/integrations/mysql2/mysql2-dc-subscriber.js +3 -3
  160. package/build/esm/integrations/neon.js +13 -5
  161. package/build/esm/integrations/neon.js.map +1 -1
  162. package/build/esm/integrations/nitro/captureStorageEvents.js +3 -3
  163. package/build/esm/integrations/nitro/captureTracingEvents.js +3 -3
  164. package/build/esm/integrations/nitro/index.js +1 -1
  165. package/build/esm/integrations/nitro/setServerTimingHeaders.js +1 -1
  166. package/build/esm/integrations/node-cron.js +1 -1
  167. package/build/esm/integrations/node-schedule.js +1 -1
  168. package/build/esm/integrations/openai-compatible.js +2 -2
  169. package/build/esm/integrations/openai.js +2 -2
  170. package/build/esm/integrations/pg.js +43 -16
  171. package/build/esm/integrations/pg.js.map +1 -1
  172. package/build/esm/integrations/pi-ai.js +1 -1
  173. package/build/esm/integrations/pi-durable.js +1 -1
  174. package/build/esm/integrations/pino.js +1 -1
  175. package/build/esm/integrations/pino.js.map +1 -1
  176. package/build/esm/integrations/postgresjs/index.js +3 -3
  177. package/build/esm/integrations/postgresjs/postgresjs-dc-subscriber.js +3 -3
  178. package/build/esm/integrations/postgresjs-wrapper.js +1 -1
  179. package/build/esm/integrations/prisma/index.js +1 -1
  180. package/build/esm/integrations/prisma/orchestrion.js +8 -12
  181. package/build/esm/integrations/prisma/orchestrion.js.map +1 -1
  182. package/build/esm/integrations/prisma/tracing-helper.js +2 -2
  183. package/build/esm/integrations/redis/index.js +3 -3
  184. package/build/esm/integrations/redis/ioredis-channel-subscriber.js +3 -3
  185. package/build/esm/integrations/redis/redis-cache.js +1 -1
  186. package/build/esm/integrations/redis/redis-dc-subscriber.js +3 -3
  187. package/build/esm/integrations/serveTunnel.js +2 -2
  188. package/build/esm/integrations/tanstack-ai.js +1 -1
  189. package/build/esm/integrations/tedious.js +4 -4
  190. package/build/esm/integrations/together-ai.js +1 -1
  191. package/build/esm/integrations/typesafe.js +1 -1
  192. package/build/esm/integrations/vercel-ai/extract.js +2 -3
  193. package/build/esm/integrations/vercel-ai/extract.js.map +1 -1
  194. package/build/esm/integrations/vercel-ai/index.js +1 -1
  195. package/build/esm/integrations/vercel-ai/util.js +21 -2
  196. package/build/esm/integrations/vercel-ai/util.js.map +1 -1
  197. package/build/esm/integrations/vercel-ai/vercel-ai-dc-subscriber.js +3 -3
  198. package/build/esm/integrations/vercel-ai/vercel-ai-orchestrion-subscriber.js +1 -1
  199. package/build/esm/integrations/vercel-ai/vercel-ai-tool-telemetry.js +3 -3
  200. package/build/esm/integrations/winston.js +1 -1
  201. package/build/esm/opentelemetry.js +1 -1
  202. package/build/esm/orchestrion/bundler/esbuild.js +1 -1
  203. package/build/esm/orchestrion/bundler/externalRequire.js +1 -1
  204. package/build/esm/orchestrion/bundler/rollup.js +1 -1
  205. package/build/esm/orchestrion/bundler/webpack-loader.js +1 -1
  206. package/build/esm/orchestrion/bundler/webpack.js +1 -1
  207. package/build/esm/orchestrion/config/index.js +1 -1
  208. package/build/esm/orchestrion/config/mistral.js +1 -1
  209. package/build/esm/orchestrion/config/mistral.js.map +1 -1
  210. package/build/esm/orchestrion/config/prisma.js +2 -0
  211. package/build/esm/orchestrion/config/prisma.js.map +1 -1
  212. package/build/esm/orchestrion/detect.js +1 -1
  213. package/build/esm/orchestrion/instrumentation.js +1 -1
  214. package/build/esm/package.json +1 -1
  215. package/build/esm/tracing-channel.js +1 -2
  216. package/build/esm/tracing-channel.js.map +1 -1
  217. package/build/esm/utils/cronMonitoring.js +1 -1
  218. package/build/esm/utils/diagnosticsChannel.js +1 -1
  219. package/build/esm/utils/module.js +2 -2
  220. package/build/esm/utils/module.js.map +1 -1
  221. package/build/esm/utils/monitorStream.js +1 -1
  222. package/build/esm/utils/serverTimingTraceHeader.js +1 -1
  223. package/build/esm/utils/tunnelServer.js +1 -1
  224. package/build/esm/utils/wrapServerRequestHandler.js +4 -4
  225. package/build/esm/vendored/@apm-js-collab/code-transformer/lib/matcher.js +3 -3
  226. package/build/esm/vendored/@apm-js-collab/code-transformer/lib/transformer.js +5 -5
  227. package/build/esm/vendored/@apm-js-collab/code-transformer-bundler-plugins/dist/esm/core-BiWIBBjf.js +1 -1
  228. package/build/esm/vendored/@apm-js-collab/code-transformer-bundler-plugins/dist/esm/webpack-loader-factory.js +1 -1
  229. package/build/esm/vendored/esquery/dist/esquery.min.js +1 -0
  230. package/build/esm/vendored/esquery/dist/esquery.min.js.map +1 -1
  231. package/build/esm/vendored/meriyah/dist/meriyah.js +416 -418
  232. package/build/esm/vendored/meriyah/dist/meriyah.js.map +1 -1
  233. package/build/esm/vendored/meriyah/dist/meriyah2.js +416 -418
  234. package/build/esm/vendored/meriyah/dist/meriyah2.js.map +1 -1
  235. package/build/esm/vendored/source-map/lib/base64-vlq.js +1 -1
  236. package/build/esm/vendored/source-map/lib/base64-vlq.js.map +1 -1
  237. package/build/types/ai/anthropic-ai/streaming.d.ts.map +1 -1
  238. package/build/types/ai/anthropic-ai/types.d.ts +1 -0
  239. package/build/types/ai/anthropic-ai/types.d.ts.map +1 -1
  240. package/build/types/ai/google-genai/streaming.d.ts.map +1 -1
  241. package/build/types/ai/langchain/index.d.ts.map +1 -1
  242. package/build/types/ai/mistral/streaming.d.ts.map +1 -1
  243. package/build/types/ai/openai/streaming.d.ts.map +1 -1
  244. package/build/types/ai/pi-ai/chat.d.ts.map +1 -1
  245. package/build/types/ai/workers-ai/streaming.d.ts.map +1 -1
  246. package/build/types/ai/workers-ai/utils.d.ts.map +1 -1
  247. package/build/types/integrations/fastify/instrumentation.d.ts.map +1 -1
  248. package/build/types/integrations/neon.d.ts.map +1 -1
  249. package/build/types/integrations/pg.d.ts +6 -1
  250. package/build/types/integrations/pg.d.ts.map +1 -1
  251. package/build/types/integrations/pino.d.ts.map +1 -1
  252. package/build/types/integrations/vercel-ai/extract.d.ts +2 -5
  253. package/build/types/integrations/vercel-ai/extract.d.ts.map +1 -1
  254. package/build/types/integrations/vercel-ai/util.d.ts.map +1 -1
  255. package/build/types/orchestrion/channels.d.ts +1 -0
  256. package/build/types/orchestrion/channels.d.ts.map +1 -1
  257. package/build/types/orchestrion/config/mistral.d.ts +3 -3
  258. package/build/types/orchestrion/config/prisma.d.ts +2 -1
  259. package/build/types/orchestrion/config/prisma.d.ts.map +1 -1
  260. package/build/types/tracing-channel.d.ts.map +1 -1
  261. package/package.json +4 -4
@@ -1,10 +1,10 @@
1
+ import { GEN_AI_INPUT_MESSAGES, GEN_AI_OUTPUT_MESSAGES } from "@sentry/conventions/attributes";
2
+ import { isObjectLike } from "@sentry/core";
1
3
  import { processClassifierEvaluationData, setStartingClassifierEvaluation } from "../ai/mastra/classifier-evaluation.js";
2
4
  import { getEvaluationInputMessages, getEvaluationOutputMessages } from "../ai/core/utils.js";
3
5
  import { CHANNELS } from "../orchestrion/channels.js";
4
6
  import { safeChannelCallback } from "../tracing-channel.js";
5
7
  import { tracingChannel } from "../utils/diagnosticsChannel.js";
6
- import { GEN_AI_INPUT_MESSAGES, GEN_AI_OUTPUT_MESSAGES } from "@sentry/conventions/attributes";
7
- import { isObjectLike } from "@sentry/core";
8
8
  // src/integrations/mastra-classifier.ts
9
9
  /**
10
10
  * Add the evaluated state, questions and answers of a `Classifier.evaluate()` call to the exporter's
@@ -1,4 +1,8 @@
1
1
  import { tracingChannel } from "../utils/diagnosticsChannel.js";
2
+ import { createRequire } from "node:module";
3
+ import { join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { GLOBAL_OBJ, captureException, consoleSandbox, debug, defineIntegration, isObjectLike, withActiveSpan } from "@sentry/core";
2
6
  import { MASTRA_EXPORTER_BRAND, MASTRA_INTEGRATION_NAME } from "../ai/mastra/constants.js";
3
7
  import { SentryMastraExporter } from "../ai/mastra/index.js";
4
8
  import { getSentrySpanForMastraId } from "../ai/mastra/span-registry.js";
@@ -8,10 +12,6 @@ import { mastraModuleNames } from "../orchestrion/config/mastra.js";
8
12
  import { recordClassifierEvaluations } from "./mastra-classifier.js";
9
13
  import { invokeOrchestrionInstrumentation } from "../orchestrion/instrumentation.js";
10
14
  import { bindSpanToChannelStore, safeChannelCallback } from "../tracing-channel.js";
11
- import { GLOBAL_OBJ, captureException, consoleSandbox, debug, defineIntegration, isObjectLike, withActiveSpan } from "@sentry/core";
12
- import { createRequire } from "node:module";
13
- import { join } from "node:path";
14
- import { fileURLToPath } from "node:url";
15
15
  // src/integrations/mastra.ts
16
16
  /** Mastra AISpan → the id the exporter keys its Sentry span on. */
17
17
  function mastraSpanId(span) {
@@ -1,10 +1,10 @@
1
1
  import { tracingChannel } from "../utils/diagnosticsChannel.js";
2
+ import { defineIntegration } from "@sentry/core";
3
+ import { wrapMcpServerWithSentry } from "@sentry/core/server";
2
4
  import { CHANNELS } from "../orchestrion/channels.js";
3
5
  import { mcpServerModuleNames } from "../orchestrion/config/mcp-server.js";
4
6
  import { invokeOrchestrionInstrumentation } from "../orchestrion/instrumentation.js";
5
7
  import { safeChannelCallback } from "../tracing-channel.js";
6
- import { defineIntegration } from "@sentry/core";
7
- import { wrapMcpServerWithSentry } from "@sentry/core/server";
8
8
  // src/integrations/mcp-server.ts
9
9
  const INTEGRATION_NAME = "McpServer";
10
10
  const _mcpServerIntegration = (() => {
@@ -1,4 +1,6 @@
1
+ import { SENTRY_ORIGIN } from "@sentry/conventions/attributes";
1
2
  import { tracingChannel } from "../utils/diagnosticsChannel.js";
3
+ import { defineIntegration, startInactiveSpan } from "@sentry/core";
2
4
  import { getGenAiSpanOp, markCancelledIfAborted, resolveGenAiCallRecording } from "../ai/core/utils.js";
3
5
  import { runGenAiSpanEnd, runGenAiSpanStart } from "../ai/core/span-hooks.js";
4
6
  import { addRequestAttributes, extractRequestAttributes } from "../ai/mistral/index.js";
@@ -10,8 +12,6 @@ import { CHANNELS } from "../orchestrion/channels.js";
10
12
  import { mistralModuleNames } from "../orchestrion/config/mistral.js";
11
13
  import { invokeOrchestrionInstrumentation } from "../orchestrion/instrumentation.js";
12
14
  import { bindTracingChannelToSpan } from "../tracing-channel.js";
13
- import { SENTRY_ORIGIN } from "@sentry/conventions/attributes";
14
- import { defineIntegration, startInactiveSpan } from "@sentry/core";
15
15
  // src/integrations/mistral.ts
16
16
  const INTEGRATION_NAME = MISTRAL_INTEGRATION_NAME;
17
17
  const INSTRUMENTED_CHANNELS = [
@@ -1,10 +1,10 @@
1
1
  import { tracingChannel } from "../../utils/diagnosticsChannel.js";
2
+ import { defineIntegration } from "@sentry/core";
2
3
  import { getV3CommandOperation, getV3SpanAttributes, getV4SpanAttributes, startMongoSpan } from "./mongodb-span.js";
3
4
  import { CHANNELS } from "../../orchestrion/channels.js";
4
5
  import { bindTracingChannelToSpan } from "../../tracing-channel.js";
5
6
  import { mongodbModuleNames } from "../../orchestrion/config/mongodb.js";
6
7
  import { invokeOrchestrionInstrumentation } from "../../orchestrion/instrumentation.js";
7
- import { defineIntegration } from "@sentry/core";
8
8
  // src/integrations/mongodb/index.ts
9
9
  const INTEGRATION_NAME = "Mongo";
10
10
  const ORIGIN = "auto.db.mongo";
@@ -1,6 +1,6 @@
1
1
  import { DB_COLLECTION_NAME, DB_CONNECTION_STRING, DB_NAMESPACE, DB_OPERATION_NAME, DB_QUERY_TEXT, DB_SYSTEM_NAME, SENTRY_KIND, SENTRY_OP, SENTRY_ORIGIN, SERVER_ADDRESS, SERVER_PORT } from "@sentry/conventions/attributes";
2
- import { getActiveSpan, getClient, hasSpanStreamingEnabled, isObjectLike, startInactiveSpan } from "@sentry/core";
3
2
  import { DB } from "@sentry/conventions/op";
3
+ import { getActiveSpan, getClient, hasSpanStreamingEnabled, isObjectLike, startInactiveSpan } from "@sentry/core";
4
4
  // src/integrations/mongodb/mongodb-span.ts
5
5
  const DB_SYSTEM_VALUE_MONGODB = "mongodb";
6
6
  /**
@@ -1,11 +1,11 @@
1
1
  import { tracingChannel } from "../../utils/diagnosticsChannel.js";
2
+ import { defineIntegration, getActiveSpan, waitForTracingChannelBinding } from "@sentry/core";
2
3
  import { subscribeMongooseDiagnosticChannels } from "./mongoose-dc-subscriber.js";
3
4
  import { startMongooseLegacySpan } from "./mongoose-legacy-span.js";
4
5
  import { CHANNELS } from "../../orchestrion/channels.js";
5
6
  import { MONGOOSE_CONTEXT_CAPTURE_CHANNELS, mongooseModuleNames } from "../../orchestrion/config/mongoose.js";
6
7
  import { bindTracingChannelToSpan } from "../../tracing-channel.js";
7
8
  import { invokeOrchestrionInstrumentation } from "../../orchestrion/instrumentation.js";
8
- import { defineIntegration, getActiveSpan, waitForTracingChannelBinding } from "@sentry/core";
9
9
  // src/integrations/mongoose/index.ts
10
10
  const INTEGRATION_NAME = "Mongoose";
11
11
  const ORIGIN = "auto.db.mongoose";
@@ -1,8 +1,8 @@
1
- import { DEBUG_BUILD } from "../../debug-build.js";
2
- import { bindTracingChannelToSpan } from "../../tracing-channel.js";
3
1
  import { DB_COLLECTION_NAME, DB_NAMESPACE, DB_OPERATION_BATCH_SIZE, DB_OPERATION_NAME, DB_QUERY_TEXT, DB_SYSTEM_NAME, SENTRY_OP, SENTRY_ORIGIN, SERVER_ADDRESS, SERVER_PORT } from "@sentry/conventions/attributes";
4
- import { debug, getClient, hasSpanStreamingEnabled, isObjectLike, startInactiveSpan } from "@sentry/core";
5
2
  import { DB } from "@sentry/conventions/op";
3
+ import { debug, getClient, hasSpanStreamingEnabled, isObjectLike, startInactiveSpan } from "@sentry/core";
4
+ import { DEBUG_BUILD } from "../../debug-build.js";
5
+ import { bindTracingChannelToSpan } from "../../tracing-channel.js";
6
6
  // src/integrations/mongoose/mongoose-dc-subscriber.ts
7
7
  const MONGOOSE_DC_CHANNEL_QUERY = "mongoose:query";
8
8
  const MONGOOSE_DC_CHANNEL_AGGREGATE = "mongoose:aggregate";
@@ -1,6 +1,6 @@
1
1
  import { DB_COLLECTION_NAME, DB_NAMESPACE, DB_OPERATION_NAME, DB_SYSTEM_NAME, DB_USER, SENTRY_KIND, SENTRY_OP, SENTRY_ORIGIN, SERVER_ADDRESS, SERVER_PORT } from "@sentry/conventions/attributes";
2
- import { getClient, hasSpanStreamingEnabled, startInactiveSpan } from "@sentry/core";
3
2
  import { DB } from "@sentry/conventions/op";
3
+ import { getClient, hasSpanStreamingEnabled, startInactiveSpan } from "@sentry/core";
4
4
  // src/integrations/mongoose/mongoose-legacy-span.ts
5
5
  const DB_SYSTEM_NAME_VALUE_MONGODB = "mongodb";
6
6
  /**
@@ -1,12 +1,12 @@
1
1
  import { tracingChannel } from "../utils/diagnosticsChannel.js";
2
+ import { DB_CONNECTION_STRING, DB_NAMESPACE, DB_SYSTEM_NAME, DB_USER, SENTRY_KIND, SENTRY_OP, SENTRY_ORIGIN, SERVER_ADDRESS, SERVER_PORT } from "@sentry/conventions/attributes";
3
+ import { DB } from "@sentry/conventions/op";
4
+ import { bindScopeToEmitter, defineIntegration, getCurrentScope, isObjectLike, startInactiveSpan } from "@sentry/core";
2
5
  import { getSqlQueryAttributes, getSqlSpanName } from "../utils/sql.js";
3
6
  import { CHANNELS } from "../orchestrion/channels.js";
4
7
  import { bindTracingChannelToSpan } from "../tracing-channel.js";
5
8
  import { mysqlModuleNames } from "../orchestrion/config/mysql.js";
6
9
  import { invokeOrchestrionInstrumentation } from "../orchestrion/instrumentation.js";
7
- import { DB_CONNECTION_STRING, DB_NAMESPACE, DB_SYSTEM_NAME, DB_USER, SENTRY_KIND, SENTRY_OP, SENTRY_ORIGIN, SERVER_ADDRESS, SERVER_PORT } from "@sentry/conventions/attributes";
8
- import { bindScopeToEmitter, defineIntegration, getCurrentScope, isObjectLike, startInactiveSpan } from "@sentry/core";
9
- import { DB } from "@sentry/conventions/op";
10
10
  // src/integrations/mysql.ts
11
11
  const INTEGRATION_NAME = "Mysql";
12
12
  const DB_SYSTEM_NAME_VALUE_MYSQL = "mysql";
@@ -1,4 +1,5 @@
1
1
  import { tracingChannel } from "../../utils/diagnosticsChannel.js";
2
+ import { defineIntegration, isObjectLike, startInactiveSpan, waitForTracingChannelBinding } from "@sentry/core";
2
3
  import { getSqlQueryAttributes, getSqlSpanName } from "../../utils/sql.js";
3
4
  import { subscribeMysql2DiagnosticChannels } from "./mysql2-dc-subscriber.js";
4
5
  import { CHANNELS } from "../../orchestrion/channels.js";
@@ -6,7 +7,6 @@ import { bindTracingChannelToSpan } from "../../tracing-channel.js";
6
7
  import { mysql2ModuleNames } from "../../orchestrion/config/mysql2.js";
7
8
  import { invokeOrchestrionInstrumentation } from "../../orchestrion/instrumentation.js";
8
9
  import { DB_NAMESPACE, DB_SYSTEM_NAME, DB_USER, SENTRY_KIND, SENTRY_OP, SENTRY_ORIGIN, SERVER_ADDRESS, SERVER_PORT } from "@sentry/conventions/attributes";
9
- import { defineIntegration, isObjectLike, startInactiveSpan, waitForTracingChannelBinding } from "@sentry/core";
10
10
  import { DB } from "@sentry/conventions/op";
11
11
  // src/integrations/mysql2/index.ts
12
12
  const INTEGRATION_NAME = "Mysql2";
@@ -1,8 +1,8 @@
1
- import { bindTracingChannelToSpan } from "../../tracing-channel.js";
2
- import { getSqlQueryAttributes, getSqlSpanName } from "../../utils/sql.js";
3
1
  import { DB_NAMESPACE, DB_SYSTEM_NAME, SENTRY_OP, SENTRY_ORIGIN, SERVER_ADDRESS, SERVER_PORT } from "@sentry/conventions/attributes";
4
- import { startInactiveSpan } from "@sentry/core";
5
2
  import { DB } from "@sentry/conventions/op";
3
+ import { startInactiveSpan } from "@sentry/core";
4
+ import { bindTracingChannelToSpan } from "../../tracing-channel.js";
5
+ import { getSqlQueryAttributes, getSqlSpanName } from "../../utils/sql.js";
6
6
  // src/integrations/mysql2/mysql2-dc-subscriber.ts
7
7
  const MYSQL2_DC_CHANNEL_QUERY = "mysql2:query";
8
8
  const MYSQL2_DC_CHANNEL_EXECUTE = "mysql2:execute";
@@ -1,13 +1,13 @@
1
1
  import { tracingChannel } from "../utils/diagnosticsChannel.js";
2
+ import { DB_OPERATION_BATCH_SIZE, DB_OPERATION_NAME, DB_QUERY_SUMMARY, DB_QUERY_TEXT, DB_SYSTEM_NAME, SENTRY_KIND, SENTRY_OP, SENTRY_ORIGIN } from "@sentry/conventions/attributes";
3
+ import { DB } from "@sentry/conventions/op";
4
+ import { defineIntegration, getActiveSpan, startInactiveSpan } from "@sentry/core";
2
5
  import { getLowCardinalitySqlSpanName, getSqlQueryAttributes } from "../utils/sql.js";
3
6
  import { CHANNELS } from "../orchestrion/channels.js";
4
7
  import { neonModuleNames } from "../orchestrion/config/neon.js";
5
8
  import { invokeOrchestrionInstrumentation } from "../orchestrion/instrumentation.js";
6
9
  import { bindTracingChannelToSpan } from "../tracing-channel.js";
7
- import { bindPgQueryChannel, getConnectionAttributes } from "./pg.js";
8
- import { DB_OPERATION_BATCH_SIZE, DB_OPERATION_NAME, DB_QUERY_SUMMARY, DB_QUERY_TEXT, DB_SYSTEM_NAME, SENTRY_KIND, SENTRY_OP, SENTRY_ORIGIN } from "@sentry/conventions/attributes";
9
- import { defineIntegration, getActiveSpan, startInactiveSpan } from "@sentry/core";
10
- import { DB } from "@sentry/conventions/op";
10
+ import { bindPgQueryChannel, getConnectionAttributes, setReturnedRows } from "./pg.js";
11
11
  // src/integrations/neon.ts
12
12
  const INTEGRATION_NAME = "Neon";
13
13
  const ORIGIN = "auto.db.neon";
@@ -29,7 +29,12 @@ function instrumentNeon() {
29
29
  const span = startInactiveSpan(httpQuerySpanOptions(data.arguments));
30
30
  httpQuerySpans.add(span);
31
31
  return span;
32
- });
32
+ }, { beforeSpanEnd(span, data) {
33
+ if ("error" in data) return;
34
+ const { result } = data;
35
+ const isBatch = Array.isArray(data.arguments[0]);
36
+ setReturnedRows(span, isBatch && Array.isArray(result) ? result.map(toPgResult) : toPgResult(result));
37
+ } });
33
38
  tracingChannel(CHANNELS.NEON_RESOLVE_CONNECTION).subscribe({
34
39
  start: NOOP,
35
40
  end: NOOP,
@@ -71,6 +76,9 @@ function httpQuerySpanOptions(args) {
71
76
  attributes
72
77
  };
73
78
  }
79
+ function toPgResult(result) {
80
+ return Array.isArray(result) ? { rows: result } : result;
81
+ }
74
82
  function getBatchOperationName(statements) {
75
83
  const operations = new Set(statements.map((s) => s[DB_OPERATION_NAME]?.toUpperCase()));
76
84
  const [operation] = operations;
@@ -1 +1 @@
1
- {"version":3,"file":"neon.js","names":["diagnosticsChannel.tracingChannel"],"sources":["../../../src/integrations/neon.ts"],"sourcesContent":["import * as diagnosticsChannel from '../utils/diagnosticsChannel';\nimport {\n DB_OPERATION_BATCH_SIZE,\n DB_OPERATION_NAME,\n DB_QUERY_SUMMARY,\n DB_QUERY_TEXT,\n DB_SYSTEM_NAME,\n SENTRY_KIND,\n SENTRY_OP,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport { DB } from '@sentry/conventions/op';\nimport type { IntegrationFn, Span, SpanAttributes } from '@sentry/core';\nimport { defineIntegration, getActiveSpan, startInactiveSpan } from '@sentry/core';\nimport { getLowCardinalitySqlSpanName, getSqlQueryAttributes } from '../utils/sql';\nimport { CHANNELS } from '../orchestrion/channels';\nimport { neonModuleNames } from '../orchestrion/config/neon';\nimport { invokeOrchestrionInstrumentation } from '../orchestrion/instrumentation';\nimport { bindTracingChannelToSpan } from '../tracing-channel';\nimport { bindPgQueryChannel, getConnectionAttributes } from './pg';\n\nconst INTEGRATION_NAME = 'Neon' as const;\nconst ORIGIN = 'auto.db.neon';\nconst DB_SYSTEM_POSTGRESQL = 'postgresql';\nconst DEFAULT_PORT = 5432;\nconst NOOP = (): void => {};\n\n// `sql.query(text, params)` builds the first shape, a tagged-template call the second.\ntype NeonQueryData = { query: string; params?: unknown[] } | NeonSqlTemplate;\n\ninterface NeonSqlTemplate {\n strings: readonly string[];\n values: unknown[];\n toParameterizedQuery?: () => { query: string };\n}\n\ninterface NeonHttpQueryContext {\n // `[queryData, opts]` for a single query, `[queryData[], opts[]]` for a `transaction()` batch.\n arguments: unknown[];\n}\n\ninterface NeonResolveConnectionContext {\n result?: { resolvedURL?: URL };\n}\n\n// The HTTP query spans this integration started, so the connection-resolver subscriber only\n// enriches those and never a user's own active span.\nconst httpQuerySpans = new WeakSet<Span>();\n\nconst _neonIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setup(client) {\n invokeOrchestrionInstrumentation(client, neonModuleNames, instrumentNeon, []);\n },\n };\n}) satisfies IntegrationFn;\n\nfunction instrumentNeon(): void {\n // The WebSocket driver is pg's `Client`, bundled into the package, so its query channel gets\n // the pg span shape.\n bindPgQueryChannel(CHANNELS.NEON_QUERY, { origin: ORIGIN });\n\n bindTracingChannelToSpan(diagnosticsChannel.tracingChannel<NeonHttpQueryContext>(CHANNELS.NEON_HTTP_QUERY), data => {\n const span = startInactiveSpan(httpQuerySpanOptions(data.arguments));\n httpQuerySpans.add(span);\n return span;\n });\n\n // The connection string is resolved inside the HTTP executor, so the query span is active\n // when this settles. The executor's own context never sees the string.\n diagnosticsChannel.tracingChannel<NeonResolveConnectionContext>(CHANNELS.NEON_RESOLVE_CONNECTION).subscribe({\n start: NOOP,\n end: NOOP,\n asyncStart: NOOP,\n error: NOOP,\n asyncEnd(data) {\n const span = getActiveSpan();\n const url = data.result?.resolvedURL;\n if (!span || !httpQuerySpans.has(span) || !url) {\n return;\n }\n span.setAttributes(\n getConnectionAttributes({\n host: url.hostname,\n port: Number(url.port) || DEFAULT_PORT,\n database: url.pathname.slice(1),\n user: url.username || undefined,\n }),\n );\n },\n });\n}\n\nfunction httpQuerySpanOptions(args: unknown[]): Parameters<typeof startInactiveSpan>[0] {\n const queryData = args[0] as NeonQueryData | NeonQueryData[] | undefined;\n const batchSize = Array.isArray(queryData) ? queryData.length : undefined;\n // A batch gets one span whose text and summary list every statement, in order.\n const statements = (Array.isArray(queryData) ? queryData : [queryData])\n .map(getQueryText)\n .filter((text): text is string => !!text)\n .map(text => getSqlQueryAttributes(text));\n const queryText = joinDefined(statements.map(s => s[DB_QUERY_TEXT]));\n const querySummary = joinDefined(statements.map(s => s[DB_QUERY_SUMMARY]));\n const operationName =\n batchSize === undefined ? statements[0]?.[DB_OPERATION_NAME] : getBatchOperationName(statements);\n const attributes: SpanAttributes = {\n [SENTRY_OP]: DB,\n [SENTRY_ORIGIN]: ORIGIN,\n [SENTRY_KIND]: 'client',\n [DB_SYSTEM_NAME]: DB_SYSTEM_POSTGRESQL,\n [DB_QUERY_TEXT]: queryText || undefined,\n [DB_QUERY_SUMMARY]: querySummary,\n [DB_OPERATION_NAME]: operationName,\n [DB_OPERATION_BATCH_SIZE]: batchSize,\n };\n\n return { name: getLowCardinalitySqlSpanName(attributes, DB_SYSTEM_POSTGRESQL), onlyIfParent: true, attributes };\n}\n\n// OTel names a batch `BATCH <op>` when every statement shares one operation, plain `BATCH` otherwise.\nfunction getBatchOperationName(statements: ReturnType<typeof getSqlQueryAttributes>[]): string {\n const operations = new Set(statements.map(s => s[DB_OPERATION_NAME]?.toUpperCase()));\n const [operation] = operations;\n return operations.size === 1 && operation ? `BATCH ${operation}` : 'BATCH';\n}\n\nfunction joinDefined(parts: (string | undefined)[]): string | undefined {\n const defined = parts.filter((part): part is string => !!part);\n return defined.length ? defined.join('; ') : undefined;\n}\n\nfunction getQueryText(data: NeonQueryData | undefined): string | undefined {\n if (!data || typeof data !== 'object') {\n return undefined;\n }\n if ('query' in data && typeof data.query === 'string') {\n return data.query;\n }\n if (!('strings' in data) || !Array.isArray(data.strings)) {\n return undefined;\n }\n if (typeof data.toParameterizedQuery === 'function') {\n try {\n // Neon's own rendering also inlines `sql.unsafe()` fragments and nested templates.\n return data.toParameterizedQuery().query;\n } catch {\n // fall through to the plain placeholder rendering\n }\n }\n return data.strings.reduce((text, part, i) => `${text}$${i}${part}`);\n}\n\n/**\n * Diagnostics-channel-based `@neondatabase/serverless` integration.\n *\n * Subscribes to the channels Sentry's code transform injects into the package's bundled pg\n * `Client.prototype.query` (WebSocket driver) and into the HTTP executor behind `neon()`, so both\n * drivers emit `db` spans with the same shape as the `pg` integration. Requires the Sentry runtime\n * hook or bundler plugin to be active.\n */\nexport const neonIntegration = defineIntegration(_neonIntegration);\n"],"mappings":";;;;;;;;;;;AAqBA,MAAM,mBAAmB;AACzB,MAAM,SAAS;AACf,MAAM,uBAAuB;AAC7B,MAAM,eAAe;AACrB,MAAM,aAAmB,CAAC;AAsB1B,MAAM,iCAAiB,IAAI,QAAc;AAEzC,MAAM,0BAA0B;CAC9B,OAAO;EACL,MAAM;EACN,MAAM,QAAQ;GACZ,iCAAiC,QAAQ,iBAAiB,gBAAgB,CAAC,CAAC;EAC9E;CACF;AACF;AAEA,SAAS,iBAAuB;CAG9B,mBAAmB,SAAS,YAAY,EAAE,QAAQ,OAAO,CAAC;CAE1D,yBAAyBA,eAAwD,SAAS,eAAe,IAAG,SAAQ;EAClH,MAAM,OAAO,kBAAkB,qBAAqB,KAAK,SAAS,CAAC;EACnE,eAAe,IAAI,IAAI;EACvB,OAAO;CACT,CAAC;CAIDA,eAAgE,SAAS,uBAAuB,CAAC,CAAC,UAAU;EAC1G,OAAO;EACP,KAAK;EACL,YAAY;EACZ,OAAO;EACP,SAAS,MAAM;GACb,MAAM,OAAO,cAAc;GAC3B,MAAM,MAAM,KAAK,QAAQ;GACzB,IAAI,CAAC,QAAQ,CAAC,eAAe,IAAI,IAAI,KAAK,CAAC,KACzC;GAEF,KAAK,cACH,wBAAwB;IACtB,MAAM,IAAI;IACV,MAAM,OAAO,IAAI,IAAI,KAAK;IAC1B,UAAU,IAAI,SAAS,MAAM,CAAC;IAC9B,MAAM,IAAI,YAAY,KAAA;GACxB,CAAC,CACH;EACF;CACF,CAAC;AACH;AAEA,SAAS,qBAAqB,MAA0D;CACtF,MAAM,YAAY,KAAK;CACvB,MAAM,YAAY,MAAM,QAAQ,SAAS,IAAI,UAAU,SAAS,KAAA;CAEhE,MAAM,cAAc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F,OAAO,KAAK,QAAQ,QAAQ,MAAM,MAAM,MAAM,GAAG,KAAK,GAAG,IAAI,MAAM;AACrE;;;;;;;;;AAUA,MAAa,kBAAkB,kBAAkB,gBAAgB"}
1
+ {"version":3,"file":"neon.js","names":["diagnosticsChannel.tracingChannel"],"sources":["../../../src/integrations/neon.ts"],"sourcesContent":["import * as diagnosticsChannel from '../utils/diagnosticsChannel';\nimport {\n DB_OPERATION_BATCH_SIZE,\n DB_OPERATION_NAME,\n DB_QUERY_SUMMARY,\n DB_QUERY_TEXT,\n DB_SYSTEM_NAME,\n SENTRY_KIND,\n SENTRY_OP,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport { DB } from '@sentry/conventions/op';\nimport type { IntegrationFn, Span, SpanAttributes } from '@sentry/core';\nimport { defineIntegration, getActiveSpan, startInactiveSpan } from '@sentry/core';\nimport { getLowCardinalitySqlSpanName, getSqlQueryAttributes } from '../utils/sql';\nimport { CHANNELS } from '../orchestrion/channels';\nimport { neonModuleNames } from '../orchestrion/config/neon';\nimport { invokeOrchestrionInstrumentation } from '../orchestrion/instrumentation';\nimport { bindTracingChannelToSpan } from '../tracing-channel';\nimport { bindPgQueryChannel, getConnectionAttributes, setReturnedRows } from './pg';\n\nconst INTEGRATION_NAME = 'Neon' as const;\nconst ORIGIN = 'auto.db.neon';\nconst DB_SYSTEM_POSTGRESQL = 'postgresql';\nconst DEFAULT_PORT = 5432;\nconst NOOP = (): void => {};\n\n// `sql.query(text, params)` builds the first shape, a tagged-template call the second.\ntype NeonQueryData = { query: string; params?: unknown[] } | NeonSqlTemplate;\n\ninterface NeonSqlTemplate {\n strings: readonly string[];\n values: unknown[];\n toParameterizedQuery?: () => { query: string };\n}\n\ninterface NeonHttpQueryContext {\n // `[queryData, opts]` for a single query, `[queryData[], opts[]]` for a `transaction()` batch.\n arguments: unknown[];\n // Per statement: the rows array, or `{ rowCount, rows, ... }` with `fullResults`. A batch resolves to an array of these.\n result?: unknown;\n}\n\ninterface NeonResolveConnectionContext {\n result?: { resolvedURL?: URL };\n}\n\n// The HTTP query spans this integration started, so the connection-resolver subscriber only\n// enriches those and never a user's own active span.\nconst httpQuerySpans = new WeakSet<Span>();\n\nconst _neonIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setup(client) {\n invokeOrchestrionInstrumentation(client, neonModuleNames, instrumentNeon, []);\n },\n };\n}) satisfies IntegrationFn;\n\nfunction instrumentNeon(): void {\n // The WebSocket driver is pg's `Client`, bundled into the package, so its query channel gets\n // the pg span shape.\n bindPgQueryChannel(CHANNELS.NEON_QUERY, { origin: ORIGIN });\n\n bindTracingChannelToSpan(\n diagnosticsChannel.tracingChannel<NeonHttpQueryContext>(CHANNELS.NEON_HTTP_QUERY),\n data => {\n const span = startInactiveSpan(httpQuerySpanOptions(data.arguments));\n httpQuerySpans.add(span);\n return span;\n },\n {\n beforeSpanEnd(span, data) {\n if ('error' in data) {\n return;\n }\n const { result } = data;\n const isBatch = Array.isArray(data.arguments[0]);\n setReturnedRows(span, isBatch && Array.isArray(result) ? result.map(toPgResult) : toPgResult(result));\n },\n },\n );\n\n // The connection string is resolved inside the HTTP executor, so the query span is active\n // when this settles. The executor's own context never sees the string.\n diagnosticsChannel.tracingChannel<NeonResolveConnectionContext>(CHANNELS.NEON_RESOLVE_CONNECTION).subscribe({\n start: NOOP,\n end: NOOP,\n asyncStart: NOOP,\n error: NOOP,\n asyncEnd(data) {\n const span = getActiveSpan();\n const url = data.result?.resolvedURL;\n if (!span || !httpQuerySpans.has(span) || !url) {\n return;\n }\n span.setAttributes(\n getConnectionAttributes({\n host: url.hostname,\n port: Number(url.port) || DEFAULT_PORT,\n database: url.pathname.slice(1),\n user: url.username || undefined,\n }),\n );\n },\n });\n}\n\nfunction httpQuerySpanOptions(args: unknown[]): Parameters<typeof startInactiveSpan>[0] {\n const queryData = args[0] as NeonQueryData | NeonQueryData[] | undefined;\n const batchSize = Array.isArray(queryData) ? queryData.length : undefined;\n // A batch gets one span whose text and summary list every statement, in order.\n const statements = (Array.isArray(queryData) ? queryData : [queryData])\n .map(getQueryText)\n .filter((text): text is string => !!text)\n .map(text => getSqlQueryAttributes(text));\n const queryText = joinDefined(statements.map(s => s[DB_QUERY_TEXT]));\n const querySummary = joinDefined(statements.map(s => s[DB_QUERY_SUMMARY]));\n const operationName =\n batchSize === undefined ? statements[0]?.[DB_OPERATION_NAME] : getBatchOperationName(statements);\n const attributes: SpanAttributes = {\n [SENTRY_OP]: DB,\n [SENTRY_ORIGIN]: ORIGIN,\n [SENTRY_KIND]: 'client',\n [DB_SYSTEM_NAME]: DB_SYSTEM_POSTGRESQL,\n [DB_QUERY_TEXT]: queryText || undefined,\n [DB_QUERY_SUMMARY]: querySummary,\n [DB_OPERATION_NAME]: operationName,\n [DB_OPERATION_BATCH_SIZE]: batchSize,\n };\n\n return { name: getLowCardinalitySqlSpanName(attributes, DB_SYSTEM_POSTGRESQL), onlyIfParent: true, attributes };\n}\n\nfunction toPgResult(result: unknown): unknown {\n return Array.isArray(result) ? { rows: result } : result;\n}\n\n// OTel names a batch `BATCH <op>` when every statement shares one operation, plain `BATCH` otherwise.\nfunction getBatchOperationName(statements: ReturnType<typeof getSqlQueryAttributes>[]): string {\n const operations = new Set(statements.map(s => s[DB_OPERATION_NAME]?.toUpperCase()));\n const [operation] = operations;\n return operations.size === 1 && operation ? `BATCH ${operation}` : 'BATCH';\n}\n\nfunction joinDefined(parts: (string | undefined)[]): string | undefined {\n const defined = parts.filter((part): part is string => !!part);\n return defined.length ? defined.join('; ') : undefined;\n}\n\nfunction getQueryText(data: NeonQueryData | undefined): string | undefined {\n if (!data || typeof data !== 'object') {\n return undefined;\n }\n if ('query' in data && typeof data.query === 'string') {\n return data.query;\n }\n if (!('strings' in data) || !Array.isArray(data.strings)) {\n return undefined;\n }\n if (typeof data.toParameterizedQuery === 'function') {\n try {\n // Neon's own rendering also inlines `sql.unsafe()` fragments and nested templates.\n return data.toParameterizedQuery().query;\n } catch {\n // fall through to the plain placeholder rendering\n }\n }\n return data.strings.reduce((text, part, i) => `${text}$${i}${part}`);\n}\n\n/**\n * Diagnostics-channel-based `@neondatabase/serverless` integration.\n *\n * Subscribes to the channels Sentry's code transform injects into the package's bundled pg\n * `Client.prototype.query` (WebSocket driver) and into the HTTP executor behind `neon()`, so both\n * drivers emit `db` spans with the same shape as the `pg` integration. Requires the Sentry runtime\n * hook or bundler plugin to be active.\n */\nexport const neonIntegration = defineIntegration(_neonIntegration);\n"],"mappings":";;;;;;;;;;;AAqBA,MAAM,mBAAmB;AACzB,MAAM,SAAS;AACf,MAAM,uBAAuB;AAC7B,MAAM,eAAe;AACrB,MAAM,aAAmB,CAAC;AAwB1B,MAAM,iCAAiB,IAAI,QAAc;AAEzC,MAAM,0BAA0B;CAC9B,OAAO;EACL,MAAM;EACN,MAAM,QAAQ;GACZ,iCAAiC,QAAQ,iBAAiB,gBAAgB,CAAC,CAAC;EAC9E;CACF;AACF;AAEA,SAAS,iBAAuB;CAG9B,mBAAmB,SAAS,YAAY,EAAE,QAAQ,OAAO,CAAC;CAE1D,yBACEA,eAAwD,SAAS,eAAe,IAChF,SAAQ;EACN,MAAM,OAAO,kBAAkB,qBAAqB,KAAK,SAAS,CAAC;EACnE,eAAe,IAAI,IAAI;EACvB,OAAO;CACT,GACA,EACE,cAAc,MAAM,MAAM;EACxB,IAAI,WAAW,MACb;EAEF,MAAM,EAAE,WAAW;EACnB,MAAM,UAAU,MAAM,QAAQ,KAAK,UAAU,EAAE;EAC/C,gBAAgB,MAAM,WAAW,MAAM,QAAQ,MAAM,IAAI,OAAO,IAAI,UAAU,IAAI,WAAW,MAAM,CAAC;CACtG,EACF,CACF;CAIAA,eAAgE,SAAS,uBAAuB,CAAC,CAAC,UAAU;EAC1G,OAAO;EACP,KAAK;EACL,YAAY;EACZ,OAAO;EACP,SAAS,MAAM;GACb,MAAM,OAAO,cAAc;GAC3B,MAAM,MAAM,KAAK,QAAQ;GACzB,IAAI,CAAC,QAAQ,CAAC,eAAe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,YAAY,OAAmD;CACtE,MAAM,UAAU,MAAM,QAAQ,SAAyB,CAAC,CAAC,IAAI;CAC7D,OAAO,QAAQ,SAAS,QAAQ,KAAK,IAAI,IAAI,KAAA;AAC/C;AAEA,SAAS,aAAa,MAAqD;CACzE,IAAI,CAAC,QAAQ,OAAO,SAAS,UAC3B;CAEF,IAAI,WAAW,QAAQ,OAAO,KAAK,UAAU,UAC3C,OAAO,KAAK;CAEd,IAAI,EAAE,aAAa,SAAS,CAAC,MAAM,QAAQ,KAAK,OAAO,GACrD;CAEF,IAAI,OAAO,KAAK,yBAAyB,YACvC,IAAI;EAEF,OAAO,KAAK,qBAAqB,CAAC,CAAC;CACrC,QAAQ,CAER;CAEF,OAAO,KAAK,QAAQ,QAAQ,MAAM,MAAM,MAAM,GAAG,KAAK,GAAG,IAAI,MAAM;AACrE;;;;;;;;;AAUA,MAAa,kBAAkB,kBAAkB,gBAAgB"}
@@ -1,9 +1,9 @@
1
- import { bindTracingChannelToSpan } from "../../tracing-channel.js";
2
- import { tracingChannel } from "../../utils/diagnosticsChannel.js";
3
1
  import { CACHE_HIT, CACHE_KEY, CACHE_OPERATION, DB_COLLECTION_NAME, DB_OPERATION_NAME, DB_SYSTEM_NAME, SENTRY_OP, SENTRY_ORIGIN } from "@sentry/conventions/attributes";
4
- import { CACHE_OPERATION_NAMES, GLOBAL_OBJ, _INTERNAL_safeDateNow, getClient, hasSpanStreamingEnabled, isObjectLike, startInactiveSpan } from "@sentry/core";
5
2
  import { CACHE_GET, CACHE_PUT, CACHE_REMOVE } from "@sentry/conventions/op";
3
+ import { CACHE_OPERATION_NAMES, GLOBAL_OBJ, _INTERNAL_safeDateNow, getClient, hasSpanStreamingEnabled, isObjectLike, startInactiveSpan } from "@sentry/core";
6
4
  import { flushIfServerless } from "@sentry/core/server";
5
+ import { bindTracingChannelToSpan } from "../../tracing-channel.js";
6
+ import { tracingChannel } from "../../utils/diagnosticsChannel.js";
7
7
  // src/integrations/nitro/captureStorageEvents.ts
8
8
  const ORIGIN = "auto.cache.nitro";
9
9
  const TRACED_OPERATIONS = [
@@ -1,9 +1,9 @@
1
+ import { SENTRY_OP, SENTRY_ORIGIN, SENTRY_SEGMENT_NAME_SOURCE, SERVER_PORT } from "@sentry/conventions/attributes";
2
+ import { HANDLER, HTTP_SERVER, MIDDLEWARE } from "@sentry/conventions/op";
3
+ import { GLOBAL_OBJ, HTTP_SPAN_NAME_FALLBACK, getActiveSpan, getClient, getHttpSpanDetailsFromUrlObject, getRootSpan, hasSpanStreamingEnabled, httpHeadersToSpanAttributes, isObjectLike, parseStringToURLObject, setHttpStatus, spanToJSON, startInactiveSpan } from "@sentry/core";
1
4
  import { bindTracingChannelToSpan } from "../../tracing-channel.js";
2
5
  import { tracingChannel } from "../../utils/diagnosticsChannel.js";
3
6
  import { setHttpServerSpanRouteAttribute } from "../../utils/setHttpServerSpanRouteAttribute.js";
4
- import { SENTRY_OP, SENTRY_ORIGIN, SENTRY_SEGMENT_NAME_SOURCE, SERVER_PORT } from "@sentry/conventions/attributes";
5
- import { GLOBAL_OBJ, HTTP_SPAN_NAME_FALLBACK, getActiveSpan, getClient, getHttpSpanDetailsFromUrlObject, getRootSpan, hasSpanStreamingEnabled, httpHeadersToSpanAttributes, isObjectLike, parseStringToURLObject, setHttpStatus, spanToJSON, startInactiveSpan } from "@sentry/core";
6
- import { HANDLER, HTTP_SERVER, MIDDLEWARE } from "@sentry/conventions/op";
7
7
  // src/integrations/nitro/captureTracingEvents.ts
8
8
  /**
9
9
  * Captures tracing events emitted by Nitro tracing channels.
@@ -1,7 +1,7 @@
1
+ import { defineIntegration } from "@sentry/core";
1
2
  import { captureStorageEvents } from "./captureStorageEvents.js";
2
3
  import { captureTracingEvents } from "./captureTracingEvents.js";
3
4
  import { captureServerTimingHeaders } from "./setServerTimingHeaders.js";
4
- import { defineIntegration } from "@sentry/core";
5
5
  // src/integrations/nitro/index.ts
6
6
  const INTEGRATION_NAME = "Nitro";
7
7
  const _nitroIntegration = ((options = {}) => {
@@ -1,5 +1,5 @@
1
- import { tracingChannel } from "../../utils/diagnosticsChannel.js";
2
1
  import { GLOBAL_OBJ, getTraceData } from "@sentry/core";
2
+ import { tracingChannel } from "../../utils/diagnosticsChannel.js";
3
3
  // src/integrations/nitro/setServerTimingHeaders.ts
4
4
  /**
5
5
  * Subscribes to the h3 request tracing channel to set Server-Timing trace headers on every response.
@@ -1,8 +1,8 @@
1
+ import { defineIntegration } from "@sentry/core";
1
2
  import { CHANNELS } from "../orchestrion/channels.js";
2
3
  import { nodeCronModuleNames } from "../orchestrion/config/node-cron.js";
3
4
  import { invokeOrchestrionInstrumentation } from "../orchestrion/instrumentation.js";
4
5
  import { cronExpressionToMonitorConfig, shouldMonitorJob, subscribeToJobCreation, wrapScheduledJob } from "../utils/cronMonitoring.js";
5
- import { defineIntegration } from "@sentry/core";
6
6
  // src/integrations/node-cron.ts
7
7
  const INTEGRATION_NAME = "NodeCron";
8
8
  const _nodeCronIntegration = ((options = {}) => {
@@ -1,8 +1,8 @@
1
+ import { defineIntegration } from "@sentry/core";
1
2
  import { CHANNELS } from "../orchestrion/channels.js";
2
3
  import { nodeScheduleModuleNames } from "../orchestrion/config/node-schedule.js";
3
4
  import { invokeOrchestrionInstrumentation } from "../orchestrion/instrumentation.js";
4
5
  import { cronExpressionToMonitorConfig, shouldMonitorJob, subscribeToScheduleChange, updateMonitorConfig, wrapScheduledJob } from "../utils/cronMonitoring.js";
5
- import { defineIntegration } from "@sentry/core";
6
6
  // src/integrations/node-schedule.ts
7
7
  const INTEGRATION_NAME = "NodeSchedule";
8
8
  const _nodeScheduleIntegration = ((options = {}) => {
@@ -1,4 +1,6 @@
1
1
  import { tracingChannel } from "../utils/diagnosticsChannel.js";
2
+ import { _INTERNAL_shouldSkipAiProviderWrapping, getClient, hasSpanStreamingEnabled, startInactiveSpan } from "@sentry/core";
3
+ import { GEN_AI_PROVIDER_NAME, SENTRY_ORIGIN } from "@sentry/conventions/attributes";
2
4
  import { getGenAiSpanOp, getRequestSignal, markCancelledIfAborted, resolveGenAiCallRecording } from "../ai/core/utils.js";
3
5
  import { wrapApiPromiseResponse } from "../ai/core/apiPromise.js";
4
6
  import { runGenAiSpanEnd, runGenAiSpanStart } from "../ai/core/span-hooks.js";
@@ -7,8 +9,6 @@ import { instrumentStream } from "../ai/openai/streaming.js";
7
9
  import { addResponseAttributes } from "../ai/openai/utils.js";
8
10
  import { invokeOrchestrionInstrumentation } from "../orchestrion/instrumentation.js";
9
11
  import { bindTracingChannelToSpan } from "../tracing-channel.js";
10
- import { GEN_AI_PROVIDER_NAME, SENTRY_ORIGIN } from "@sentry/conventions/attributes";
11
- import { _INTERNAL_shouldSkipAiProviderWrapping, getClient, hasSpanStreamingEnabled, startInactiveSpan } from "@sentry/core";
12
12
  // src/integrations/openai-compatible.ts
13
13
  /**
14
14
  * Builds a diagnostics-channel integration for an OpenAI-compatible provider SDK. It subscribes to the
@@ -1,4 +1,6 @@
1
+ import { SENTRY_ORIGIN } from "@sentry/conventions/attributes";
1
2
  import { tracingChannel } from "../utils/diagnosticsChannel.js";
3
+ import { defineIntegration, getClient, hasSpanStreamingEnabled, startInactiveSpan } from "@sentry/core";
2
4
  import { getGenAiSpanOp, getRequestSignal, markCancelledIfAborted, resolveGenAiCallRecording } from "../ai/core/utils.js";
3
5
  import { addRequestAttributes, extractRequestAttributes } from "../ai/openai/index.js";
4
6
  import { wrapApiPromiseResponse } from "../ai/core/apiPromise.js";
@@ -10,8 +12,6 @@ import { CHANNELS } from "../orchestrion/channels.js";
10
12
  import { bindTracingChannelToSpan } from "../tracing-channel.js";
11
13
  import { openaiModuleNames } from "../orchestrion/config/openai.js";
12
14
  import { invokeOrchestrionInstrumentation } from "../orchestrion/instrumentation.js";
13
- import { SENTRY_ORIGIN } from "@sentry/conventions/attributes";
14
- import { defineIntegration, getClient, hasSpanStreamingEnabled, startInactiveSpan } from "@sentry/core";
15
15
  // src/integrations/openai.ts
16
16
  const INTEGRATION_NAME = "OpenAI";
17
17
  const ORIGIN = "auto.ai.openai";
@@ -1,12 +1,12 @@
1
1
  import { tracingChannel } from "../utils/diagnosticsChannel.js";
2
+ import { DB_CONNECTION_STRING, DB_NAMESPACE, DB_RESPONSE_RETURNED_ROWS, DB_SYSTEM_NAME, DB_USER, SENTRY_KIND, SENTRY_OP, SENTRY_ORIGIN, SERVER_ADDRESS, SERVER_PORT } from "@sentry/conventions/attributes";
3
+ import { DB } from "@sentry/conventions/op";
4
+ import { bindScopeToEmitter, defineIntegration, getCurrentScope, isObjectLike, startInactiveSpan } from "@sentry/core";
2
5
  import { getSqlQueryAttributes, getSqlSpanName } from "../utils/sql.js";
3
6
  import { CHANNELS } from "../orchestrion/channels.js";
4
7
  import { bindTracingChannelToSpan } from "../tracing-channel.js";
5
8
  import { pgModuleNames } from "../orchestrion/config/pg.js";
6
9
  import { invokeOrchestrionInstrumentation } from "../orchestrion/instrumentation.js";
7
- import { DB_CONNECTION_STRING, DB_NAMESPACE, DB_SYSTEM_NAME, DB_USER, SENTRY_KIND, SENTRY_OP, SENTRY_ORIGIN, SERVER_ADDRESS, SERVER_PORT } from "@sentry/conventions/attributes";
8
- import { bindScopeToEmitter, defineIntegration, getCurrentScope, isObjectLike, startInactiveSpan } from "@sentry/core";
9
- import { DB } from "@sentry/conventions/op";
10
10
  // src/integrations/pg.ts
11
11
  const INTEGRATION_NAME = "Postgres";
12
12
  const ORIGIN = "auto.db.postgres";
@@ -41,15 +41,16 @@ function instrumentPostgres(options) {
41
41
  * streamable `Submittable` result, so it's the only one that defers span-ending to the emitter.
42
42
  */
43
43
  function bindPgQueryChannel(channelName, options) {
44
- subscribeQueryLikeChannel(channelName, (ctx) => querySpanOptions(ctx, options), { deferStreamedResult: true });
44
+ subscribeQueryLikeChannel(channelName, (ctx) => querySpanOptions(ctx, options), { isQuery: true });
45
45
  }
46
46
  /**
47
47
  * Subscribe to a pg tracing-channel and manage a span across its lifecycle.
48
48
  * Shared by the query/connect/pool-connect channels. They differ only in how
49
49
  * the span's name + attributes are built (`getSpanOptions`), and whether the
50
- * result can be a streamable emitter (`deferStreamedResult`, query-only).
50
+ * result is a query result that can be a streamable emitter and carries a row
51
+ * count (`isQuery`).
51
52
  */
52
- function subscribeQueryLikeChannel(channelName, getSpanOptions, { deferStreamedResult = false } = {}) {
53
+ function subscribeQueryLikeChannel(channelName, getSpanOptions, { isQuery = false } = {}) {
53
54
  bindTracingChannelToSpan(tracingChannel(channelName), (data) => {
54
55
  data._sentryCallerScope = getCurrentScope();
55
56
  const spanOptions = getSpanOptions(data);
@@ -61,15 +62,24 @@ function subscribeQueryLikeChannel(channelName, getSpanOptions, { deferStreamedR
61
62
  [SENTRY_KIND]: "client"
62
63
  }
63
64
  });
64
- }, deferStreamedResult ? { deferSpanEnd({ data, end }) {
65
- const result = data.result;
66
- if (!result || typeof result !== "object" || !hasOnMethod(result)) return false;
67
- const callerScope = data._sentryCallerScope;
68
- if (callerScope) bindScopeToEmitter(result, callerScope);
69
- result.on("error", (err) => end(err));
70
- result.on("end", () => end());
71
- return true;
72
- } } : void 0);
65
+ }, isQuery ? {
66
+ beforeSpanEnd(span, data) {
67
+ if ("error" in data || isObjectLike(data.result) && hasOnMethod(data.result)) return;
68
+ setReturnedRows(span, data.result);
69
+ },
70
+ deferSpanEnd({ span, data, end }) {
71
+ const result = data.result;
72
+ if (!result || typeof result !== "object" || !hasOnMethod(result)) return false;
73
+ const callerScope = data._sentryCallerScope;
74
+ if (callerScope) bindScopeToEmitter(result, callerScope);
75
+ result.on("error", (err) => end(err));
76
+ result.on("end", (endResult) => {
77
+ if (!hasReadMethod(result)) setReturnedRows(span, endResult);
78
+ end();
79
+ });
80
+ return true;
81
+ }
82
+ } : void 0);
73
83
  }
74
84
  function querySpanOptions(ctx, { origin, connectionString }) {
75
85
  const params = ctx.self?.connectionParameters ?? {};
@@ -109,6 +119,23 @@ function poolConnectSpanOptions(ctx) {
109
119
  function hasOnMethod(obj) {
110
120
  return "on" in obj && typeof obj.on === "function";
111
121
  }
122
+ function hasReadMethod(obj) {
123
+ return "read" in obj && typeof obj.read === "function";
124
+ }
125
+ /**
126
+ * Sets `db.response.returned_rows` from a pg-style result (`{ rowCount, rows }`), or an array of them
127
+ * (one per statement of a multi-statement query), summed. Sets nothing when no count is known.
128
+ */
129
+ function setReturnedRows(span, results) {
130
+ const counts = (Array.isArray(results) ? results : [results]).map(getRowCount).filter((count) => count !== void 0);
131
+ if (counts.length) span.setAttribute(DB_RESPONSE_RETURNED_ROWS, counts.reduce((sum, count) => sum + count, 0));
132
+ }
133
+ function getRowCount(result) {
134
+ if (!isObjectLike(result)) return;
135
+ const { rowCount, rows } = result;
136
+ if (typeof rowCount === "number") return rowCount;
137
+ return Array.isArray(rows) ? rows.length : void 0;
138
+ }
112
139
  function extractQueryConfig(args) {
113
140
  const arg0 = args[0];
114
141
  if (typeof arg0 === "string") return { text: arg0 };
@@ -179,6 +206,6 @@ function getConnectionString(params) {
179
206
  * hook or bundler plugin to be active.
180
207
  */
181
208
  const postgresIntegration = defineIntegration(_postgresIntegration);
182
- export { bindPgQueryChannel, getConnectionAttributes, postgresIntegration };
209
+ export { bindPgQueryChannel, getConnectionAttributes, postgresIntegration, setReturnedRows };
183
210
 
184
211
  //# sourceMappingURL=pg.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pg.js","names":["diagnosticsChannel.tracingChannel"],"sources":["../../../src/integrations/pg.ts"],"sourcesContent":["import * as diagnosticsChannel from '../utils/diagnosticsChannel';\nimport {\n DB_NAMESPACE,\n DB_SYSTEM_NAME,\n DB_USER,\n SENTRY_KIND,\n SENTRY_OP,\n SERVER_ADDRESS,\n SERVER_PORT,\n SENTRY_ORIGIN,\n DB_CONNECTION_STRING,\n} from '@sentry/conventions/attributes';\nimport { DB } from '@sentry/conventions/op';\nimport type { IntegrationFn, Scope, SpanAttributes } from '@sentry/core';\nimport { isObjectLike, bindScopeToEmitter, defineIntegration, getCurrentScope, startInactiveSpan } from '@sentry/core';\nimport { getSqlQueryAttributes, getSqlSpanName } from '../utils/sql';\nimport type { OrchestrionChannelContext } from '../orchestrion/types';\nimport { CHANNELS } from '../orchestrion/channels';\nimport { bindTracingChannelToSpan } from '../tracing-channel';\nimport { pgModuleNames } from '../orchestrion/config/pg';\nimport { invokeOrchestrionInstrumentation } from '../orchestrion/instrumentation';\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.postgres';\n\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 the `db` op 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 the\n// SQL 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 extends OrchestrionChannelContext {\n // The caller's scope, captured at `start` and replayed onto a streamed `Submittable` emitter (see below).\n _sentryCallerScope?: Scope;\n}\n\nexport interface 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 _postgresIntegration = ((options: { ignoreConnectSpans?: boolean } = {}) => {\n return {\n name: INTEGRATION_NAME,\n setup(client) {\n invokeOrchestrionInstrumentation(client, pgModuleNames, instrumentPostgres, [options]);\n },\n };\n}) satisfies IntegrationFn;\n\nfunction instrumentPostgres(options: { ignoreConnectSpans?: boolean }): void {\n bindPgQueryChannel(CHANNELS.PG_QUERY, { origin: ORIGIN, connectionString: 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\nexport interface PgQuerySpanOptions {\n origin: string;\n // `db.connection_string` is deprecated in favor of `server.address`/`server.port`. Only the pg\n // integration keeps emitting it, for parity with its OTel predecessor.\n connectionString?: boolean;\n}\n\n/**\n * Query spans for a channel carrying `pg` `Client.prototype.query` calls, from `pg` itself or from\n * a copy bundled into another driver (`@neondatabase/serverless`). Only this call can return a\n * streamable `Submittable` result, so it's the only one that defers span-ending to the emitter.\n */\nexport function bindPgQueryChannel(channelName: string, options: PgQuerySpanOptions): void {\n subscribeQueryLikeChannel(channelName, ctx => querySpanOptions(ctx, options), { deferStreamedResult: true });\n}\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; attributes: SpanAttributes },\n { deferStreamedResult = false }: { deferStreamedResult?: boolean } = {},\n): void {\n bindTracingChannelToSpan(\n diagnosticsChannel.tracingChannel<PgChannelContext>(channelName),\n data => {\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 // `sentry.kind: 'client'` mirrors the OTel pg instrumentation, so the emitted\n // `sentry.kind` matches across the OTel and diagnostics-channel paths.\n const spanOptions = getSpanOptions(data);\n return startInactiveSpan({\n ...spanOptions,\n onlyIfParent: true,\n attributes: { ...spanOptions.attributes, [SENTRY_KIND]: 'client' },\n });\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(\n ctx: PgChannelContext,\n { origin, connectionString }: PgQuerySpanOptions,\n): { name: string; attributes: SpanAttributes } {\n const params = (ctx.self as { connectionParameters?: PgConnectionParams } | undefined)?.connectionParameters ?? {};\n const queryConfig = extractQueryConfig(ctx.arguments);\n const attributes: SpanAttributes = {\n [SENTRY_OP]: DB,\n ...(connectionString ? getPgConnectionAttributes(params) : getConnectionAttributes(params)),\n [SENTRY_ORIGIN]: origin,\n ...getSqlQueryAttributes(queryConfig?.text),\n [ATTR_PG_PLAN]: typeof queryConfig?.name === 'string' ? queryConfig.name : undefined,\n };\n\n return { name: getSqlSpanName(attributes, SPAN_QUERY_FALLBACK), attributes };\n}\n\nfunction connectSpanOptions(ctx: PgChannelContext): { name: 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, attributes: { [SENTRY_OP]: DB, ...getPgConnectionAttributes(params) } };\n}\n\nfunction poolConnectSpanOptions(ctx: PgChannelContext): { name: string; attributes: SpanAttributes } {\n const opts = (ctx.self as { options?: PgPoolOptions } | undefined)?.options ?? {};\n return { name: SPAN_POOL_CONNECT, attributes: { [SENTRY_OP]: DB, ...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 (isObjectLike(arg0) && 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\n/** The `db.*`/`server.*` attributes for a pg-style set of connection parameters. */\nexport function getConnectionAttributes(params: PgConnectionParams): SpanAttributes {\n return {\n [DB_SYSTEM_NAME]: DB_SYSTEM_POSTGRESQL,\n [DB_NAMESPACE]: params.database,\n [DB_USER]: params.user,\n [SERVER_ADDRESS]: params.host,\n [SERVER_PORT]: Number.isInteger(params.port) ? params.port : undefined,\n };\n}\n\nfunction getPgConnectionAttributes(params: PgConnectionParams): SpanAttributes {\n // oxlint-disable-next-line typescript/no-deprecated -- Preserve the existing attribute name.\n return { ...getConnectionAttributes(params), [DB_CONNECTION_STRING]: getConnectionString(params) };\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 [DB_SYSTEM_NAME]: DB_SYSTEM_POSTGRESQL,\n // oxlint-disable-next-line typescript/no-deprecated -- Preserve the existing attribute name.\n [DB_CONNECTION_STRING]: getConnectionString(opts),\n [ATTR_PG_IDLE_TIMEOUT]: opts.idleTimeoutMillis,\n [ATTR_PG_MAX_CLIENT]: opts.max,\n [DB_NAMESPACE]: database,\n [SERVER_PORT]: port,\n // these two come from a url parse and slice, can be ''\n [SERVER_ADDRESS]: host || undefined,\n [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 * Diagnostics-channel-based `pg` (node-postgres) integration.\n *\n * Subscribes to the `orchestrion:pg:query`/`:connect` and\n * `orchestrion:pg-pool:connect` diagnostics_channels that Sentry's code\n * transform injects into `pg`'s `Client.prototype.query`/`connect`\n * and `pg-pool`'s `Pool.prototype.connect`. Requires the Sentry runtime\n * hook or bundler plugin to be active.\n */\nexport const postgresIntegration = defineIntegration(_postgresIntegration);\n"],"mappings":";;;;;;;;;;AAwBA,MAAM,mBAAmB;AAIzB,MAAM,SAAS;AAEf,MAAM,eAAe;AACrB,MAAM,uBAAuB;AAC7B,MAAM,qBAAqB;AAC3B,MAAM,uBAAuB;AAS7B,MAAM,sBAAsB;AAC5B,MAAM,eAAe;AACrB,MAAM,oBAAoB;AA4B1B,MAAM,yBAAyB,UAA4C,CAAC,MAAM;CAChF,OAAO;EACL,MAAM;EACN,MAAM,QAAQ;GACZ,iCAAiC,QAAQ,eAAe,oBAAoB,CAAC,OAAO,CAAC;EACvF;CACF;AACF;AAEA,SAAS,mBAAmB,SAAiD;CAC3E,mBAAmB,SAAS,UAAU;EAAE,QAAQ;EAAQ,kBAAkB;CAAK,CAAC;CAKhF,IAAI,CAAC,QAAQ,oBAAoB;EAC/B,0BAA0B,SAAS,YAAY,kBAAkB;EACjE,0BAA0B,SAAS,gBAAgB,sBAAsB;CAC3E;AACF;;;;;;AAcA,SAAgB,mBAAmB,aAAqB,SAAmC;CACzF,0BAA0B,cAAa,QAAO,iBAAiB,KAAK,OAAO,GAAG,EAAE,qBAAqB,KAAK,CAAC;AAC7G;;;;;;;AAQA,SAAS,0BACP,aACA,gBACA,EAAE,sBAAsB,UAA6C,CAAC,GAChE;CACN,yBACEA,eAAoD,WAAW,IAC/D,SAAQ;EAIN,KAAK,qBAAqB,gBAAgB;EAI1C,MAAM,cAAc,eAAe,IAAI;EACvC,OAAO,kBAAkB;GACvB,GAAG;GACH,cAAc;GACd,YAAY;IAAE,GAAG,YAAY;KAAa,cAAc;GAAS;EACnE,CAAC;CACH,GAMA,sBACI,EAOE,aAAa,EAAE,MAAM,OAAO;EAC1B,MAAM,SAAS,KAAK;EACpB,IAAI,CAAC,UAAU,OAAO,WAAW,YAAY,CAAC,YAAY,MAAM,GAC9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annel.tracingChannel"],"sources":["../../../src/integrations/pg.ts"],"sourcesContent":["import * as diagnosticsChannel from '../utils/diagnosticsChannel';\nimport {\n DB_NAMESPACE,\n DB_RESPONSE_RETURNED_ROWS,\n DB_SYSTEM_NAME,\n DB_USER,\n SENTRY_KIND,\n SENTRY_OP,\n SERVER_ADDRESS,\n SERVER_PORT,\n SENTRY_ORIGIN,\n DB_CONNECTION_STRING,\n} from '@sentry/conventions/attributes';\nimport { DB } from '@sentry/conventions/op';\nimport type { IntegrationFn, Scope, Span, SpanAttributes } from '@sentry/core';\nimport { isObjectLike, bindScopeToEmitter, defineIntegration, getCurrentScope, startInactiveSpan } from '@sentry/core';\nimport { getSqlQueryAttributes, getSqlSpanName } from '../utils/sql';\nimport type { OrchestrionChannelContext } from '../orchestrion/types';\nimport { CHANNELS } from '../orchestrion/channels';\nimport { bindTracingChannelToSpan } from '../tracing-channel';\nimport { pgModuleNames } from '../orchestrion/config/pg';\nimport { invokeOrchestrionInstrumentation } from '../orchestrion/instrumentation';\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.postgres';\n\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 the `db` op 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 the\n// SQL 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 extends OrchestrionChannelContext {\n // The caller's scope, captured at `start` and replayed onto a streamed `Submittable` emitter (see below).\n _sentryCallerScope?: Scope;\n}\n\nexport interface 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 _postgresIntegration = ((options: { ignoreConnectSpans?: boolean } = {}) => {\n return {\n name: INTEGRATION_NAME,\n setup(client) {\n invokeOrchestrionInstrumentation(client, pgModuleNames, instrumentPostgres, [options]);\n },\n };\n}) satisfies IntegrationFn;\n\nfunction instrumentPostgres(options: { ignoreConnectSpans?: boolean }): void {\n bindPgQueryChannel(CHANNELS.PG_QUERY, { origin: ORIGIN, connectionString: 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\nexport interface PgQuerySpanOptions {\n origin: string;\n // `db.connection_string` is deprecated in favor of `server.address`/`server.port`. Only the pg\n // integration keeps emitting it, for parity with its OTel predecessor.\n connectionString?: boolean;\n}\n\n/**\n * Query spans for a channel carrying `pg` `Client.prototype.query` calls, from `pg` itself or from\n * a copy bundled into another driver (`@neondatabase/serverless`). Only this call can return a\n * streamable `Submittable` result, so it's the only one that defers span-ending to the emitter.\n */\nexport function bindPgQueryChannel(channelName: string, options: PgQuerySpanOptions): void {\n subscribeQueryLikeChannel(channelName, ctx => querySpanOptions(ctx, options), { isQuery: true });\n}\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 is a query result that can be a streamable emitter and carries a row\n * count (`isQuery`).\n */\nfunction subscribeQueryLikeChannel(\n channelName: string,\n getSpanOptions: (ctx: PgChannelContext) => { name: string; attributes: SpanAttributes },\n { isQuery = false }: { isQuery?: boolean } = {},\n): void {\n bindTracingChannelToSpan(\n diagnosticsChannel.tracingChannel<PgChannelContext>(channelName),\n data => {\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 // `sentry.kind: 'client'` mirrors the OTel pg instrumentation, so the emitted\n // `sentry.kind` matches across the OTel and diagnostics-channel paths.\n const spanOptions = getSpanOptions(data);\n return startInactiveSpan({\n ...spanOptions,\n onlyIfParent: true,\n attributes: { ...spanOptions.attributes, [SENTRY_KIND]: 'client' },\n });\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 isQuery\n ? {\n beforeSpanEnd(span, data) {\n // A streamed `Submittable` reports its rows on its own `'end'` event (see `deferSpanEnd`).\n if ('error' in data || (isObjectLike(data.result) && hasOnMethod(data.result))) {\n return;\n }\n setReturnedRows(span, data.result);\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({ span, 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', (endResult?: unknown) => {\n // A `Query` ends with its full result(s). A cursor (`pg-cursor`, `pg-query-stream`) is read in\n // batches and ends with only the last batch, so its count would be wrong.\n if (!hasReadMethod(result)) {\n setReturnedRows(span, endResult);\n }\n end();\n });\n\n return true;\n },\n }\n : undefined,\n );\n}\n\nfunction querySpanOptions(\n ctx: PgChannelContext,\n { origin, connectionString }: PgQuerySpanOptions,\n): { name: string; attributes: SpanAttributes } {\n const params = (ctx.self as { connectionParameters?: PgConnectionParams } | undefined)?.connectionParameters ?? {};\n const queryConfig = extractQueryConfig(ctx.arguments);\n const attributes: SpanAttributes = {\n [SENTRY_OP]: DB,\n ...(connectionString ? getPgConnectionAttributes(params) : getConnectionAttributes(params)),\n [SENTRY_ORIGIN]: origin,\n ...getSqlQueryAttributes(queryConfig?.text),\n [ATTR_PG_PLAN]: typeof queryConfig?.name === 'string' ? queryConfig.name : undefined,\n };\n\n return { name: getSqlSpanName(attributes, SPAN_QUERY_FALLBACK), attributes };\n}\n\nfunction connectSpanOptions(ctx: PgChannelContext): { name: 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, attributes: { [SENTRY_OP]: DB, ...getPgConnectionAttributes(params) } };\n}\n\nfunction poolConnectSpanOptions(ctx: PgChannelContext): { name: string; attributes: SpanAttributes } {\n const opts = (ctx.self as { options?: PgPoolOptions } | undefined)?.options ?? {};\n return { name: SPAN_POOL_CONNECT, attributes: { [SENTRY_OP]: DB, ...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\nfunction hasReadMethod(obj: object): boolean {\n return 'read' in obj && typeof (obj as { read?: unknown }).read === 'function';\n}\n\n/**\n * Sets `db.response.returned_rows` from a pg-style result (`{ rowCount, rows }`), or an array of them\n * (one per statement of a multi-statement query), summed. Sets nothing when no count is known.\n */\nexport function setReturnedRows(span: Span, results: unknown): void {\n const counts = (Array.isArray(results) ? results : [results])\n .map(getRowCount)\n .filter((count): count is number => count !== undefined);\n if (counts.length) {\n span.setAttribute(\n DB_RESPONSE_RETURNED_ROWS,\n counts.reduce((sum, count) => sum + count, 0),\n );\n }\n}\n\nfunction getRowCount(result: unknown): number | undefined {\n if (!isObjectLike(result)) {\n return undefined;\n }\n const { rowCount, rows } = result as { rowCount?: unknown; rows?: unknown };\n if (typeof rowCount === 'number') {\n return rowCount;\n }\n return Array.isArray(rows) ? rows.length : undefined;\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 (isObjectLike(arg0) && 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\n/** The `db.*`/`server.*` attributes for a pg-style set of connection parameters. */\nexport function getConnectionAttributes(params: PgConnectionParams): SpanAttributes {\n return {\n [DB_SYSTEM_NAME]: DB_SYSTEM_POSTGRESQL,\n [DB_NAMESPACE]: params.database,\n [DB_USER]: params.user,\n [SERVER_ADDRESS]: params.host,\n [SERVER_PORT]: Number.isInteger(params.port) ? params.port : undefined,\n };\n}\n\nfunction getPgConnectionAttributes(params: PgConnectionParams): SpanAttributes {\n // oxlint-disable-next-line typescript/no-deprecated -- Preserve the existing attribute name.\n return { ...getConnectionAttributes(params), [DB_CONNECTION_STRING]: getConnectionString(params) };\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 [DB_SYSTEM_NAME]: DB_SYSTEM_POSTGRESQL,\n // oxlint-disable-next-line typescript/no-deprecated -- Preserve the existing attribute name.\n [DB_CONNECTION_STRING]: getConnectionString(opts),\n [ATTR_PG_IDLE_TIMEOUT]: opts.idleTimeoutMillis,\n [ATTR_PG_MAX_CLIENT]: opts.max,\n [DB_NAMESPACE]: database,\n [SERVER_PORT]: port,\n // these two come from a url parse and slice, can be ''\n [SERVER_ADDRESS]: host || undefined,\n [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 * Diagnostics-channel-based `pg` (node-postgres) integration.\n *\n * Subscribes to the `orchestrion:pg:query`/`:connect` and\n * `orchestrion:pg-pool:connect` diagnostics_channels that Sentry's code\n * transform injects into `pg`'s `Client.prototype.query`/`connect`\n * and `pg-pool`'s `Pool.prototype.connect`. Requires the Sentry runtime\n * hook or bundler plugin to be active.\n */\nexport const postgresIntegration = defineIntegration(_postgresIntegration);\n"],"mappings":";;;;;;;;;;AAyBA,MAAM,mBAAmB;AAIzB,MAAM,SAAS;AAEf,MAAM,eAAe;AACrB,MAAM,uBAAuB;AAC7B,MAAM,qBAAqB;AAC3B,MAAM,uBAAuB;AAS7B,MAAM,sBAAsB;AAC5B,MAAM,eAAe;AACrB,MAAM,oBAAoB;AA4B1B,MAAM,yBAAyB,UAA4C,CAAC,MAAM;CAChF,OAAO;EACL,MAAM;EACN,MAAM,QAAQ;GACZ,iCAAiC,QAAQ,eAAe,oBAAoB,CAAC,OAAO,CAAC;EACvF;CACF;AACF;AAEA,SAAS,mBAAmB,SAAiD;CAC3E,mBAAmB,SAAS,UAAU;EAAE,QAAQ;EAAQ,kBAAkB;CAAK,CAAC;CAKhF,IAAI,CAAC,QAAQ,oBAAoB;EAC/B,0BAA0B,SAAS,YAAY,kBAAkB;EACjE,0BAA0B,SAAS,gBAAgB,sBAAsB;CAC3E;AACF;;;;;;AAcA,SAAgB,mBAAmB,aAAqB,SAAmC;CACzF,0BAA0B,cAAa,QAAO,iBAAiB,KAAK,OAAO,GAAG,EAAE,SAAS,KAAK,CAAC;AACjG;;;;;;;;AASA,SAAS,0BACP,aACA,gBACA,EAAE,UAAU,UAAiC,CAAC,GACxC;CACN,yBACEA,eAAoD,WAAW,IAC/D,SAAQ;EAIN,KAAK,qBAAqB,gBAAgB;EAI1C,MAAM,cAAc,eAAe,IAAI;EACvC,OAAO,kBAAkB;GACvB,GAAG;GACH,cAAc;GACd,YAAY;IAAE,GAAG,YAAY;KAAa,cAAc;GAAS;EACnE,CAAC;CACH,GAMA,UACI;EACE,cAAc,MAAM,MAAM;GAExB,IAAI,WAAW,QAAS,aAAa,KAAK,MAAM,KAAK,YAAY,KAAK,MAAM,GAC1E;GAEF,gBAAgB,MAAM,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KAAK,SAAS,MAAM,CAAC,KAAK,KAAK;CAChD,MAAM,OAAO,KAAK,YAAY,KAAK;CAInC,MAAM,OAAO,OAAO,KAAK,IAAI,MAAM,OAAO,UAAU,KAAK,IAAI,IAAI,KAAK,OAAO,KAAA;CAC7E,MAAM,OAAO,KAAK,YAAY,KAAK;CACnC,OAAO;GACJ,iBAAiB;GAEjB,uBAAuB,oBAAoB,IAAI;GAC/C,uBAAuB,KAAK;GAC5B,qBAAqB,KAAK;GAC1B,eAAe;GACf,cAAc;GAEd,iBAAiB,QAAQ,KAAA;GACzB,UAAU,QAAQ,KAAA;CACrB;AACF;AAIA,SAAS,oBAAoB,QAAoC;CAC/D,IAAI,OAAO,kBACT,IAAI;EACF,MAAM,MAAM,IAAI,IAAI,OAAO,gBAAgB;EAC3C,IAAI,WAAW;EACf,IAAI,WAAW;EACf,OAAO,IAAI,SAAS;CACtB,QAAQ;EACN,OAAO;CACT;CAKF,OAAO,gBAHM,OAAO,QAAQ,YAGA,GAFf,OAAO,QAAQ,KAEQ,GADnB,OAAO,YAAY;AAEtC;;;;;;;;;;AAWA,MAAa,sBAAsB,kBAAkB,oBAAoB"}
@@ -1,4 +1,5 @@
1
1
  import { tracingChannel } from "../utils/diagnosticsChannel.js";
2
+ import { defineIntegration, isThenable, startInactiveSpan } from "@sentry/core";
2
3
  import { runGenAiSpanEnd, runGenAiSpanStart } from "../ai/core/span-hooks.js";
3
4
  import { getPiAiChatSpanOptions, observePiAiFirstChunk, setPiAiResponseAttributes } from "../ai/pi-ai/chat.js";
4
5
  import { PI_AI_INTEGRATION_NAME } from "../ai/pi-ai/constants.js";
@@ -8,7 +9,6 @@ import { CHANNELS } from "../orchestrion/channels.js";
8
9
  import { piAiModuleNames } from "../orchestrion/config/pi-ai.js";
9
10
  import { invokeOrchestrionInstrumentation } from "../orchestrion/instrumentation.js";
10
11
  import { bindTracingChannelToSpan } from "../tracing-channel.js";
11
- import { defineIntegration, isThenable, startInactiveSpan } from "@sentry/core";
12
12
  // src/integrations/pi-ai.ts
13
13
  const _piAiIntegration = ((options = {}) => {
14
14
  return {
@@ -1,4 +1,5 @@
1
1
  import { tracingChannel } from "../utils/diagnosticsChannel.js";
2
+ import { debug, defineIntegration, isObjectLike } from "@sentry/core";
2
3
  import { endRunsOnClose, instrumentPiDurableHarnessOptions } from "../ai/pi-durable/index.js";
3
4
  import { PI_DURABLE_INTEGRATION_NAME } from "../ai/pi-durable/constants.js";
4
5
  import { markBuiltInTool } from "../ai/pi-durable/tools.js";
@@ -6,7 +7,6 @@ import { DEBUG_BUILD } from "../debug-build.js";
6
7
  import { CHANNELS } from "../orchestrion/channels.js";
7
8
  import { piDurableModuleNames } from "../orchestrion/config/pi-durable.js";
8
9
  import { invokeOrchestrionInstrumentation } from "../orchestrion/instrumentation.js";
9
- import { debug, defineIntegration, isObjectLike } from "@sentry/core";
10
10
  // src/integrations/pi-durable.ts
11
11
  const _piDurableIntegration = ((options = {}) => {
12
12
  return {
@@ -1,6 +1,6 @@
1
- import { tracingChannel } from "../utils/diagnosticsChannel.js";
2
1
  import { SENTRY_ORIGIN } from "@sentry/conventions/attributes";
3
2
  import { addExceptionMechanism, captureException, captureLogEvent, captureMessage, defineIntegration, isObjectLike, severityLevelFromString, withScope } from "@sentry/core";
3
+ import { tracingChannel } from "../utils/diagnosticsChannel.js";
4
4
  // src/integrations/pino.ts
5
5
  const SENTRY_TRACK_SYMBOL = Symbol("sentry-track-pino-logger");
6
6
  /**