@sentry/core 10.51.0 → 10.53.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 (361) hide show
  1. package/browser.js +3 -0
  2. package/build/cjs/browser.js +529 -0
  3. package/build/cjs/browser.js.map +1 -0
  4. package/build/cjs/client.js +15 -2
  5. package/build/cjs/client.js.map +1 -1
  6. package/build/cjs/fetch.js +7 -4
  7. package/build/cjs/fetch.js.map +1 -1
  8. package/build/cjs/index.js +82 -62
  9. package/build/cjs/index.js.map +1 -1
  10. package/build/cjs/instrument/console.js +43 -3
  11. package/build/cjs/instrument/console.js.map +1 -1
  12. package/build/cjs/integrations/captureconsole.js +2 -2
  13. package/build/cjs/integrations/captureconsole.js.map +1 -1
  14. package/build/cjs/integrations/console.js +5 -1
  15. package/build/cjs/integrations/console.js.map +1 -1
  16. package/build/cjs/integrations/express/index.js +4 -6
  17. package/build/cjs/integrations/express/index.js.map +1 -1
  18. package/build/cjs/integrations/express/utils.js +0 -7
  19. package/build/cjs/integrations/express/utils.js.map +1 -1
  20. package/build/cjs/integrations/http/add-outgoing-request-breadcrumb.js +43 -0
  21. package/build/cjs/integrations/http/add-outgoing-request-breadcrumb.js.map +1 -0
  22. package/build/cjs/integrations/http/client-patch.js +113 -0
  23. package/build/cjs/integrations/http/client-patch.js.map +1 -0
  24. package/build/cjs/integrations/http/client-subscriptions.js +166 -0
  25. package/build/cjs/integrations/http/client-subscriptions.js.map +1 -0
  26. package/build/cjs/integrations/http/constants.js +10 -0
  27. package/build/cjs/integrations/http/constants.js.map +1 -0
  28. package/build/cjs/integrations/http/double-wrap-warning.js +29 -0
  29. package/build/cjs/integrations/http/double-wrap-warning.js.map +1 -0
  30. package/build/cjs/integrations/http/get-outgoing-span-data.js +88 -0
  31. package/build/cjs/integrations/http/get-outgoing-span-data.js.map +1 -0
  32. package/build/cjs/integrations/http/get-request-url.js +54 -0
  33. package/build/cjs/integrations/http/get-request-url.js.map +1 -0
  34. package/build/cjs/integrations/http/inject-trace-propagation-headers.js +81 -0
  35. package/build/cjs/integrations/http/inject-trace-propagation-headers.js.map +1 -0
  36. package/build/cjs/integrations/mcp-server/errorCapture.js +2 -2
  37. package/build/cjs/integrations/mcp-server/errorCapture.js.map +1 -1
  38. package/build/cjs/integrations/mcp-server/handlers.js +72 -0
  39. package/build/cjs/integrations/mcp-server/handlers.js.map +1 -1
  40. package/build/cjs/integrations/mcp-server/index.js +10 -1
  41. package/build/cjs/integrations/mcp-server/index.js.map +1 -1
  42. package/build/cjs/integrations/requestdata.js +85 -3
  43. package/build/cjs/integrations/requestdata.js.map +1 -1
  44. package/build/cjs/integrations/supabase.js +4 -4
  45. package/build/cjs/integrations/supabase.js.map +1 -1
  46. package/build/cjs/logs/envelope.js +12 -2
  47. package/build/cjs/logs/envelope.js.map +1 -1
  48. package/build/cjs/logs/internal.js +7 -1
  49. package/build/cjs/logs/internal.js.map +1 -1
  50. package/build/cjs/metrics/envelope.js +15 -2
  51. package/build/cjs/metrics/envelope.js.map +1 -1
  52. package/build/cjs/metrics/internal.js +7 -1
  53. package/build/cjs/metrics/internal.js.map +1 -1
  54. package/build/cjs/server.js +563 -0
  55. package/build/cjs/server.js.map +1 -0
  56. package/build/cjs/tracing/ai/utils.js +2 -2
  57. package/build/cjs/tracing/ai/utils.js.map +1 -1
  58. package/build/cjs/tracing/anthropic-ai/index.js +3 -3
  59. package/build/cjs/tracing/anthropic-ai/index.js.map +1 -1
  60. package/build/cjs/tracing/anthropic-ai/streaming.js +3 -3
  61. package/build/cjs/tracing/anthropic-ai/streaming.js.map +1 -1
  62. package/build/cjs/tracing/anthropic-ai/utils.js +2 -2
  63. package/build/cjs/tracing/anthropic-ai/utils.js.map +1 -1
  64. package/build/cjs/tracing/google-genai/index.js +3 -3
  65. package/build/cjs/tracing/google-genai/index.js.map +1 -1
  66. package/build/cjs/tracing/google-genai/streaming.js +2 -2
  67. package/build/cjs/tracing/google-genai/streaming.js.map +1 -1
  68. package/build/cjs/tracing/langchain/embeddings.js +2 -2
  69. package/build/cjs/tracing/langchain/embeddings.js.map +1 -1
  70. package/build/cjs/tracing/langchain/index.js +4 -4
  71. package/build/cjs/tracing/langchain/index.js.map +1 -1
  72. package/build/cjs/tracing/langgraph/index.js +3 -3
  73. package/build/cjs/tracing/langgraph/index.js.map +1 -1
  74. package/build/cjs/tracing/langgraph/utils.js +2 -2
  75. package/build/cjs/tracing/langgraph/utils.js.map +1 -1
  76. package/build/cjs/tracing/openai/index.js +3 -3
  77. package/build/cjs/tracing/openai/index.js.map +1 -1
  78. package/build/cjs/tracing/openai/streaming.js +2 -2
  79. package/build/cjs/tracing/openai/streaming.js.map +1 -1
  80. package/build/cjs/tracing/sentrySpan.js +5 -0
  81. package/build/cjs/tracing/sentrySpan.js.map +1 -1
  82. package/build/cjs/tracing/spans/captureSpan.js +58 -23
  83. package/build/cjs/tracing/spans/captureSpan.js.map +1 -1
  84. package/build/cjs/tracing/spans/extractGenAiSpans.js +60 -0
  85. package/build/cjs/tracing/spans/extractGenAiSpans.js.map +1 -0
  86. package/build/cjs/tracing/spans/spanJsonToStreamedSpan.js +26 -0
  87. package/build/cjs/tracing/spans/spanJsonToStreamedSpan.js.map +1 -0
  88. package/build/cjs/tracing/trace.js +1 -0
  89. package/build/cjs/tracing/trace.js.map +1 -1
  90. package/build/cjs/tracing/vercel-ai/constants.js +8 -0
  91. package/build/cjs/tracing/vercel-ai/constants.js.map +1 -1
  92. package/build/cjs/tracing/vercel-ai/index.js +99 -15
  93. package/build/cjs/tracing/vercel-ai/index.js.map +1 -1
  94. package/build/cjs/trpc.js +3 -3
  95. package/build/cjs/trpc.js.map +1 -1
  96. package/build/cjs/utils/baggage.js +73 -0
  97. package/build/cjs/utils/baggage.js.map +1 -1
  98. package/build/cjs/utils/chain-and-copy-promiselike.js +1 -0
  99. package/build/cjs/utils/chain-and-copy-promiselike.js.map +1 -1
  100. package/build/cjs/utils/exports.js +7 -7
  101. package/build/cjs/utils/exports.js.map +1 -1
  102. package/build/cjs/utils/flushIfServerless.js +2 -2
  103. package/build/cjs/utils/flushIfServerless.js.map +1 -1
  104. package/build/cjs/utils/get-default-export.js +32 -0
  105. package/build/cjs/utils/get-default-export.js.map +1 -0
  106. package/build/cjs/utils/request.js +129 -0
  107. package/build/cjs/utils/request.js.map +1 -1
  108. package/build/cjs/utils/spanUtils.js +1 -1
  109. package/build/cjs/utils/spanUtils.js.map +1 -1
  110. package/build/cjs/utils/string.js +9 -2
  111. package/build/cjs/utils/string.js.map +1 -1
  112. package/build/cjs/utils/traceData.js +2 -2
  113. package/build/cjs/utils/traceData.js.map +1 -1
  114. package/build/cjs/utils/version.js +1 -1
  115. package/build/esm/browser.js +142 -0
  116. package/build/esm/browser.js.map +1 -0
  117. package/build/esm/client.js +15 -2
  118. package/build/esm/client.js.map +1 -1
  119. package/build/esm/fetch.js +7 -4
  120. package/build/esm/fetch.js.map +1 -1
  121. package/build/esm/index.js +20 -15
  122. package/build/esm/index.js.map +1 -1
  123. package/build/esm/instrument/console.js +44 -5
  124. package/build/esm/instrument/console.js.map +1 -1
  125. package/build/esm/integrations/console.js +6 -2
  126. package/build/esm/integrations/console.js.map +1 -1
  127. package/build/esm/integrations/express/index.js +3 -5
  128. package/build/esm/integrations/express/index.js.map +1 -1
  129. package/build/esm/integrations/express/utils.js +1 -7
  130. package/build/esm/integrations/express/utils.js.map +1 -1
  131. package/build/esm/integrations/http/add-outgoing-request-breadcrumb.js +41 -0
  132. package/build/esm/integrations/http/add-outgoing-request-breadcrumb.js.map +1 -0
  133. package/build/esm/integrations/http/client-patch.js +111 -0
  134. package/build/esm/integrations/http/client-patch.js.map +1 -0
  135. package/build/esm/integrations/http/client-subscriptions.js +164 -0
  136. package/build/esm/integrations/http/client-subscriptions.js.map +1 -0
  137. package/build/esm/integrations/http/constants.js +6 -0
  138. package/build/esm/integrations/http/constants.js.map +1 -0
  139. package/build/esm/integrations/http/double-wrap-warning.js +26 -0
  140. package/build/esm/integrations/http/double-wrap-warning.js.map +1 -0
  141. package/build/esm/integrations/http/get-outgoing-span-data.js +85 -0
  142. package/build/esm/integrations/http/get-outgoing-span-data.js.map +1 -0
  143. package/build/esm/integrations/http/get-request-url.js +49 -0
  144. package/build/esm/integrations/http/get-request-url.js.map +1 -0
  145. package/build/esm/integrations/http/inject-trace-propagation-headers.js +79 -0
  146. package/build/esm/integrations/http/inject-trace-propagation-headers.js.map +1 -0
  147. package/build/esm/integrations/mcp-server/handlers.js +72 -1
  148. package/build/esm/integrations/mcp-server/handlers.js.map +1 -1
  149. package/build/esm/integrations/mcp-server/index.js +11 -2
  150. package/build/esm/integrations/mcp-server/index.js.map +1 -1
  151. package/build/esm/integrations/requestdata.js +85 -3
  152. package/build/esm/integrations/requestdata.js.map +1 -1
  153. package/build/esm/logs/envelope.js +12 -2
  154. package/build/esm/logs/envelope.js.map +1 -1
  155. package/build/esm/logs/internal.js +7 -1
  156. package/build/esm/logs/internal.js.map +1 -1
  157. package/build/esm/metrics/envelope.js +15 -2
  158. package/build/esm/metrics/envelope.js.map +1 -1
  159. package/build/esm/metrics/internal.js +7 -1
  160. package/build/esm/metrics/internal.js.map +1 -1
  161. package/build/esm/package.json +1 -1
  162. package/build/esm/server.js +157 -0
  163. package/build/esm/server.js.map +1 -0
  164. package/build/esm/tracing/sentrySpan.js +5 -0
  165. package/build/esm/tracing/sentrySpan.js.map +1 -1
  166. package/build/esm/tracing/spans/captureSpan.js +58 -23
  167. package/build/esm/tracing/spans/captureSpan.js.map +1 -1
  168. package/build/esm/tracing/spans/extractGenAiSpans.js +58 -0
  169. package/build/esm/tracing/spans/extractGenAiSpans.js.map +1 -0
  170. package/build/esm/tracing/spans/spanJsonToStreamedSpan.js +24 -0
  171. package/build/esm/tracing/spans/spanJsonToStreamedSpan.js.map +1 -0
  172. package/build/esm/tracing/trace.js +1 -1
  173. package/build/esm/tracing/trace.js.map +1 -1
  174. package/build/esm/tracing/vercel-ai/constants.js +8 -1
  175. package/build/esm/tracing/vercel-ai/constants.js.map +1 -1
  176. package/build/esm/tracing/vercel-ai/index.js +101 -18
  177. package/build/esm/tracing/vercel-ai/index.js.map +1 -1
  178. package/build/esm/utils/baggage.js +73 -1
  179. package/build/esm/utils/baggage.js.map +1 -1
  180. package/build/esm/utils/chain-and-copy-promiselike.js +1 -0
  181. package/build/esm/utils/chain-and-copy-promiselike.js.map +1 -1
  182. package/build/esm/utils/exports.js +7 -7
  183. package/build/esm/utils/exports.js.map +1 -1
  184. package/build/esm/utils/get-default-export.js +30 -0
  185. package/build/esm/utils/get-default-export.js.map +1 -0
  186. package/build/esm/utils/request.js +127 -1
  187. package/build/esm/utils/request.js.map +1 -1
  188. package/build/esm/utils/spanUtils.js +1 -1
  189. package/build/esm/utils/spanUtils.js.map +1 -1
  190. package/build/esm/utils/string.js +9 -2
  191. package/build/esm/utils/string.js.map +1 -1
  192. package/build/esm/utils/version.js +1 -1
  193. package/build/types/browser-exports.d.ts +11 -0
  194. package/build/types/browser-exports.d.ts.map +1 -0
  195. package/build/types/browser.d.ts +3 -0
  196. package/build/types/browser.d.ts.map +1 -0
  197. package/build/types/build-time-plugins/buildTimeOptionsBase.d.ts +8 -0
  198. package/build/types/build-time-plugins/buildTimeOptionsBase.d.ts.map +1 -1
  199. package/build/types/carrier.d.ts +1 -1
  200. package/build/types/carrier.d.ts.map +1 -1
  201. package/build/types/client.d.ts.map +1 -1
  202. package/build/types/fetch.d.ts.map +1 -1
  203. package/build/types/index.d.ts +3 -223
  204. package/build/types/index.d.ts.map +1 -1
  205. package/build/types/instrument/console.d.ts +7 -0
  206. package/build/types/instrument/console.d.ts.map +1 -1
  207. package/build/types/integrations/captureconsole.d.ts +1 -1
  208. package/build/types/integrations/captureconsole.d.ts.map +1 -1
  209. package/build/types/integrations/console.d.ts +5 -0
  210. package/build/types/integrations/console.d.ts.map +1 -1
  211. package/build/types/integrations/conversationId.d.ts +1 -1
  212. package/build/types/integrations/conversationId.d.ts.map +1 -1
  213. package/build/types/integrations/dedupe.d.ts +1 -1
  214. package/build/types/integrations/dedupe.d.ts.map +1 -1
  215. package/build/types/integrations/eventFilters.d.ts +2 -2
  216. package/build/types/integrations/eventFilters.d.ts.map +1 -1
  217. package/build/types/integrations/express/index.d.ts.map +1 -1
  218. package/build/types/integrations/express/utils.d.ts +1 -5
  219. package/build/types/integrations/express/utils.d.ts.map +1 -1
  220. package/build/types/integrations/extraerrordata.d.ts +1 -1
  221. package/build/types/integrations/extraerrordata.d.ts.map +1 -1
  222. package/build/types/integrations/functiontostring.d.ts +1 -1
  223. package/build/types/integrations/functiontostring.d.ts.map +1 -1
  224. package/build/types/integrations/http/add-outgoing-request-breadcrumb.d.ts +6 -0
  225. package/build/types/integrations/http/add-outgoing-request-breadcrumb.d.ts.map +1 -0
  226. package/build/types/integrations/http/client-patch.d.ts +46 -0
  227. package/build/types/integrations/http/client-patch.d.ts.map +1 -0
  228. package/build/types/integrations/http/client-subscriptions.d.ts +21 -0
  229. package/build/types/integrations/http/client-subscriptions.d.ts.map +1 -0
  230. package/build/types/integrations/http/constants.d.ts +6 -0
  231. package/build/types/integrations/http/constants.d.ts.map +1 -0
  232. package/build/types/integrations/http/double-wrap-warning.d.ts +4 -0
  233. package/build/types/integrations/http/double-wrap-warning.d.ts.map +1 -0
  234. package/build/types/integrations/http/get-outgoing-span-data.d.ts +13 -0
  235. package/build/types/integrations/http/get-outgoing-span-data.d.ts.map +1 -0
  236. package/build/types/integrations/http/get-request-url.d.ts +10 -0
  237. package/build/types/integrations/http/get-request-url.d.ts.map +1 -0
  238. package/build/types/integrations/http/index.d.ts +4 -0
  239. package/build/types/integrations/http/index.d.ts.map +1 -0
  240. package/build/types/integrations/http/inject-trace-propagation-headers.d.ts +12 -0
  241. package/build/types/integrations/http/inject-trace-propagation-headers.d.ts.map +1 -0
  242. package/build/types/integrations/http/types.d.ts +249 -0
  243. package/build/types/integrations/http/types.d.ts.map +1 -0
  244. package/build/types/integrations/linkederrors.d.ts +1 -1
  245. package/build/types/integrations/linkederrors.d.ts.map +1 -1
  246. package/build/types/integrations/mcp-server/handlers.d.ts +18 -0
  247. package/build/types/integrations/mcp-server/handlers.d.ts.map +1 -1
  248. package/build/types/integrations/mcp-server/index.d.ts +8 -1
  249. package/build/types/integrations/mcp-server/index.d.ts.map +1 -1
  250. package/build/types/integrations/requestdata.d.ts +1 -1
  251. package/build/types/integrations/requestdata.d.ts.map +1 -1
  252. package/build/types/integrations/spanStreaming.d.ts +1 -1
  253. package/build/types/integrations/spanStreaming.d.ts.map +1 -1
  254. package/build/types/integrations/supabase.d.ts +1 -1
  255. package/build/types/integrations/supabase.d.ts.map +1 -1
  256. package/build/types/integrations/zoderrors.d.ts +1 -1
  257. package/build/types/integrations/zoderrors.d.ts.map +1 -1
  258. package/build/types/logs/console-integration.d.ts +1 -1
  259. package/build/types/logs/console-integration.d.ts.map +1 -1
  260. package/build/types/logs/envelope.d.ts +5 -2
  261. package/build/types/logs/envelope.d.ts.map +1 -1
  262. package/build/types/logs/internal.d.ts.map +1 -1
  263. package/build/types/metrics/envelope.d.ts +5 -2
  264. package/build/types/metrics/envelope.d.ts.map +1 -1
  265. package/build/types/metrics/internal.d.ts.map +1 -1
  266. package/build/types/server-exports.d.ts +26 -0
  267. package/build/types/server-exports.d.ts.map +1 -0
  268. package/build/types/server.d.ts +10 -0
  269. package/build/types/server.d.ts.map +1 -0
  270. package/build/types/shared-exports.d.ts +215 -0
  271. package/build/types/shared-exports.d.ts.map +1 -0
  272. package/build/types/tracing/index.d.ts +1 -1
  273. package/build/types/tracing/index.d.ts.map +1 -1
  274. package/build/types/tracing/sentrySpan.d.ts.map +1 -1
  275. package/build/types/tracing/spans/captureSpan.d.ts +4 -4
  276. package/build/types/tracing/spans/captureSpan.d.ts.map +1 -1
  277. package/build/types/tracing/spans/extractGenAiSpans.d.ts +15 -0
  278. package/build/types/tracing/spans/extractGenAiSpans.d.ts.map +1 -0
  279. package/build/types/tracing/spans/spanJsonToStreamedSpan.d.ts +6 -0
  280. package/build/types/tracing/spans/spanJsonToStreamedSpan.d.ts.map +1 -0
  281. package/build/types/tracing/trace.d.ts +1 -0
  282. package/build/types/tracing/trace.d.ts.map +1 -1
  283. package/build/types/tracing/vercel-ai/constants.d.ts +1 -0
  284. package/build/types/tracing/vercel-ai/constants.d.ts.map +1 -1
  285. package/build/types/tracing/vercel-ai/index.d.ts +9 -0
  286. package/build/types/tracing/vercel-ai/index.d.ts.map +1 -1
  287. package/build/types/types-hoist/envelope.d.ts +1 -1
  288. package/build/types/types-hoist/envelope.d.ts.map +1 -1
  289. package/build/types/types-hoist/log.d.ts +5 -0
  290. package/build/types/types-hoist/log.d.ts.map +1 -1
  291. package/build/types/types-hoist/metric.d.ts +5 -0
  292. package/build/types/types-hoist/metric.d.ts.map +1 -1
  293. package/build/types/types-hoist/options.d.ts +8 -0
  294. package/build/types/types-hoist/options.d.ts.map +1 -1
  295. package/build/types/types-hoist/webfetchapi.d.ts +2 -0
  296. package/build/types/types-hoist/webfetchapi.d.ts.map +1 -1
  297. package/build/types/utils/baggage.d.ts +13 -0
  298. package/build/types/utils/baggage.d.ts.map +1 -1
  299. package/build/types/utils/get-default-export.d.ts +22 -0
  300. package/build/types/utils/get-default-export.d.ts.map +1 -0
  301. package/build/types/utils/request.d.ts +30 -0
  302. package/build/types/utils/request.d.ts.map +1 -1
  303. package/build/types/utils/spanUtils.d.ts +1 -1
  304. package/build/types/utils/string.d.ts +1 -1
  305. package/build/types/utils/string.d.ts.map +1 -1
  306. package/build/types-ts3.8/browser-exports.d.ts +11 -0
  307. package/build/types-ts3.8/browser.d.ts +3 -0
  308. package/build/types-ts3.8/build-time-plugins/buildTimeOptionsBase.d.ts +8 -0
  309. package/build/types-ts3.8/carrier.d.ts +1 -1
  310. package/build/types-ts3.8/index.d.ts +3 -225
  311. package/build/types-ts3.8/instrument/console.d.ts +7 -0
  312. package/build/types-ts3.8/integrations/captureconsole.d.ts +1 -1
  313. package/build/types-ts3.8/integrations/console.d.ts +5 -0
  314. package/build/types-ts3.8/integrations/conversationId.d.ts +1 -1
  315. package/build/types-ts3.8/integrations/dedupe.d.ts +1 -1
  316. package/build/types-ts3.8/integrations/eventFilters.d.ts +2 -2
  317. package/build/types-ts3.8/integrations/express/utils.d.ts +1 -5
  318. package/build/types-ts3.8/integrations/extraerrordata.d.ts +1 -1
  319. package/build/types-ts3.8/integrations/functiontostring.d.ts +1 -1
  320. package/build/types-ts3.8/integrations/http/add-outgoing-request-breadcrumb.d.ts +6 -0
  321. package/build/types-ts3.8/integrations/http/client-patch.d.ts +46 -0
  322. package/build/types-ts3.8/integrations/http/client-subscriptions.d.ts +21 -0
  323. package/build/types-ts3.8/integrations/http/constants.d.ts +6 -0
  324. package/build/types-ts3.8/integrations/http/double-wrap-warning.d.ts +4 -0
  325. package/build/types-ts3.8/integrations/http/get-outgoing-span-data.d.ts +13 -0
  326. package/build/types-ts3.8/integrations/http/get-request-url.d.ts +10 -0
  327. package/build/types-ts3.8/integrations/http/index.d.ts +4 -0
  328. package/build/types-ts3.8/integrations/http/inject-trace-propagation-headers.d.ts +12 -0
  329. package/build/types-ts3.8/integrations/http/types.d.ts +252 -0
  330. package/build/types-ts3.8/integrations/linkederrors.d.ts +1 -1
  331. package/build/types-ts3.8/integrations/mcp-server/handlers.d.ts +18 -0
  332. package/build/types-ts3.8/integrations/mcp-server/index.d.ts +8 -1
  333. package/build/types-ts3.8/integrations/requestdata.d.ts +1 -1
  334. package/build/types-ts3.8/integrations/spanStreaming.d.ts +1 -1
  335. package/build/types-ts3.8/integrations/supabase.d.ts +1 -1
  336. package/build/types-ts3.8/integrations/zoderrors.d.ts +1 -1
  337. package/build/types-ts3.8/logs/console-integration.d.ts +1 -1
  338. package/build/types-ts3.8/logs/envelope.d.ts +5 -2
  339. package/build/types-ts3.8/metrics/envelope.d.ts +5 -2
  340. package/build/types-ts3.8/server-exports.d.ts +21 -0
  341. package/build/types-ts3.8/server.d.ts +10 -0
  342. package/build/types-ts3.8/shared-exports.d.ts +214 -0
  343. package/build/types-ts3.8/tracing/index.d.ts +1 -1
  344. package/build/types-ts3.8/tracing/spans/captureSpan.d.ts +4 -4
  345. package/build/types-ts3.8/tracing/spans/extractGenAiSpans.d.ts +15 -0
  346. package/build/types-ts3.8/tracing/spans/spanJsonToStreamedSpan.d.ts +6 -0
  347. package/build/types-ts3.8/tracing/trace.d.ts +1 -0
  348. package/build/types-ts3.8/tracing/vercel-ai/constants.d.ts +1 -0
  349. package/build/types-ts3.8/tracing/vercel-ai/index.d.ts +9 -0
  350. package/build/types-ts3.8/types-hoist/envelope.d.ts +1 -1
  351. package/build/types-ts3.8/types-hoist/log.d.ts +5 -0
  352. package/build/types-ts3.8/types-hoist/metric.d.ts +5 -0
  353. package/build/types-ts3.8/types-hoist/options.d.ts +8 -0
  354. package/build/types-ts3.8/types-hoist/webfetchapi.d.ts +2 -0
  355. package/build/types-ts3.8/utils/baggage.d.ts +13 -0
  356. package/build/types-ts3.8/utils/get-default-export.d.ts +22 -0
  357. package/build/types-ts3.8/utils/request.d.ts +30 -0
  358. package/build/types-ts3.8/utils/spanUtils.d.ts +1 -1
  359. package/build/types-ts3.8/utils/string.d.ts +1 -1
  360. package/package.json +24 -2
  361. package/server.js +3 -0
@@ -1 +1 @@
1
- {"version":3,"file":"handlers.js","sources":["../../../../src/integrations/mcp-server/handlers.ts"],"sourcesContent":["/**\n * Handler method wrapping for MCP server instrumentation\n *\n * Provides automatic error capture and span correlation for tool, resource,\n * and prompt handlers.\n */\n\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { debug } from '../../utils/debug-logger';\nimport { fill } from '../../utils/object';\nimport { captureError } from './errorCapture';\nimport type { MCPHandler, MCPServerInstance } from './types';\n\n/**\n * Generic function to wrap MCP server method handlers\n * @internal\n * @param serverInstance - MCP server instance\n * @param methodName - Method name to wrap (tool, resource, prompt)\n */\nfunction wrapMethodHandler(serverInstance: MCPServerInstance, methodName: keyof MCPServerInstance): void {\n fill(serverInstance, methodName, originalMethod => {\n return function (this: MCPServerInstance, name: string, ...args: unknown[]) {\n const handler = args[args.length - 1];\n\n if (typeof handler !== 'function') {\n return (originalMethod as (...args: unknown[]) => unknown).call(this, name, ...args);\n }\n\n const wrappedHandler = createWrappedHandler(handler as MCPHandler, methodName, name);\n return (originalMethod as (...args: unknown[]) => unknown).call(this, name, ...args.slice(0, -1), wrappedHandler);\n };\n });\n}\n\n/**\n * Creates a wrapped handler with span correlation and error capture\n * @internal\n * @param originalHandler - Original handler function\n * @param methodName - MCP method name\n * @param handlerName - Handler identifier\n * @returns Wrapped handler function\n */\nfunction createWrappedHandler(originalHandler: MCPHandler, methodName: keyof MCPServerInstance, handlerName: string) {\n return function (this: unknown, ...handlerArgs: unknown[]): unknown {\n try {\n return createErrorCapturingHandler.call(this, originalHandler, methodName, handlerName, handlerArgs);\n } catch (error) {\n DEBUG_BUILD && debug.warn('MCP handler wrapping failed:', error);\n return originalHandler.apply(this, handlerArgs);\n }\n };\n}\n\n/**\n * Creates an error-capturing wrapper for handler execution\n * @internal\n * @param originalHandler - Original handler function\n * @param methodName - MCP method name\n * @param handlerName - Handler identifier\n * @param handlerArgs - Handler arguments\n * @param extraHandlerData - Additional handler context\n * @returns Handler execution result\n */\nfunction createErrorCapturingHandler(\n this: MCPServerInstance,\n originalHandler: MCPHandler,\n methodName: keyof MCPServerInstance,\n handlerName: string,\n handlerArgs: unknown[],\n): unknown {\n try {\n const result = originalHandler.apply(this, handlerArgs);\n\n if (result && typeof result === 'object' && typeof (result as { then?: unknown }).then === 'function') {\n return Promise.resolve(result).catch(error => {\n captureHandlerError(error, methodName, handlerName);\n throw error;\n });\n }\n\n return result;\n } catch (error) {\n captureHandlerError(error as Error, methodName, handlerName);\n throw error;\n }\n}\n\n/**\n * Captures handler execution errors based on handler type\n * @internal\n * @param error - Error to capture\n * @param methodName - MCP method name\n * @param handlerName - Handler identifier\n */\nfunction captureHandlerError(error: Error, methodName: keyof MCPServerInstance, handlerName: string): void {\n try {\n const extraData: Record<string, unknown> = {};\n\n if (methodName === 'tool' || methodName === 'registerTool') {\n extraData.tool_name = handlerName;\n\n if (\n error.name === 'ProtocolValidationError' ||\n error.message.includes('validation') ||\n error.message.includes('protocol')\n ) {\n captureError(error, 'validation', extraData);\n } else if (\n error.name === 'ServerTimeoutError' ||\n error.message.includes('timed out') ||\n error.message.includes('timeout')\n ) {\n captureError(error, 'timeout', extraData);\n } else {\n captureError(error, 'tool_execution', extraData);\n }\n } else if (methodName === 'resource' || methodName === 'registerResource') {\n extraData.resource_uri = handlerName;\n captureError(error, 'resource_execution', extraData);\n } else if (methodName === 'prompt' || methodName === 'registerPrompt') {\n extraData.prompt_name = handlerName;\n captureError(error, 'prompt_execution', extraData);\n }\n } catch (_captureErr) {\n // noop\n }\n}\n\n/**\n * Wraps tool handlers to associate them with request spans.\n * Instruments both `tool` (legacy API) and `registerTool` (new API) if present.\n * @param serverInstance - MCP server instance\n */\nexport function wrapToolHandlers(serverInstance: MCPServerInstance): void {\n if (typeof serverInstance.tool === 'function') wrapMethodHandler(serverInstance, 'tool');\n if (typeof serverInstance.registerTool === 'function') wrapMethodHandler(serverInstance, 'registerTool');\n}\n\n/**\n * Wraps resource handlers to associate them with request spans.\n * Instruments both `resource` (legacy API) and `registerResource` (new API) if present.\n * @param serverInstance - MCP server instance\n */\nexport function wrapResourceHandlers(serverInstance: MCPServerInstance): void {\n if (typeof serverInstance.resource === 'function') wrapMethodHandler(serverInstance, 'resource');\n if (typeof serverInstance.registerResource === 'function') wrapMethodHandler(serverInstance, 'registerResource');\n}\n\n/**\n * Wraps prompt handlers to associate them with request spans.\n * Instruments both `prompt` (legacy API) and `registerPrompt` (new API) if present.\n * @param serverInstance - MCP server instance\n */\nexport function wrapPromptHandlers(serverInstance: MCPServerInstance): void {\n if (typeof serverInstance.prompt === 'function') wrapMethodHandler(serverInstance, 'prompt');\n if (typeof serverInstance.registerPrompt === 'function') wrapMethodHandler(serverInstance, 'registerPrompt');\n}\n\n/**\n * Wraps all MCP handler types for span correlation.\n * Supports both the legacy API (`tool`, `resource`, `prompt`) and the newer API\n * (`registerTool`, `registerResource`, `registerPrompt`), instrumenting whichever methods are present.\n * @param serverInstance - MCP server instance\n */\nexport function wrapAllMCPHandlers(serverInstance: MCPServerInstance): void {\n wrapToolHandlers(serverInstance);\n wrapResourceHandlers(serverInstance);\n wrapPromptHandlers(serverInstance);\n}\n"],"names":[],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,iBAAiB,CAAC,cAAc,EAAqB,UAAU,EAAiC;AACzG,EAAE,IAAI,CAAC,cAAc,EAAE,UAAU,EAAE,kBAAkB;AACrD,IAAI,OAAO,WAAmC,IAAI,EAAU,GAAG,IAAI,EAAa;AAChF,MAAM,MAAM,OAAA,GAAU,IAAI,CAAC,IAAI,CAAC,MAAA,GAAS,CAAC,CAAC;;AAE3C,MAAM,IAAI,OAAO,OAAA,KAAY,UAAU,EAAE;AACzC,QAAQ,OAAO,CAAC,cAAA,GAAmD,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;AAC5F,MAAM;;AAEN,MAAM,MAAM,cAAA,GAAiB,oBAAoB,CAAC,UAAuB,UAAU,EAAE,IAAI,CAAC;AAC1F,MAAM,OAAO,CAAC,cAAA,GAAmD,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,cAAc,CAAC;AACvH,IAAI,CAAC;AACL,EAAE,CAAC,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,oBAAoB,CAAC,eAAe,EAAc,UAAU,EAA2B,WAAW,EAAU;AACrH,EAAE,OAAO,WAAyB,GAAG,WAAW,EAAsB;AACtE,IAAI,IAAI;AACR,MAAM,OAAO,2BAA2B,CAAC,IAAI,CAAC,IAAI,EAAE,eAAe,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW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AO,cAAc,CAAC,YAAA,KAAiB,UAAU,EAAE,iBAAiB,CAAC,cAAc,EAAE,cAAc,CAAC;AAC1G;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,oBAAoB,CAAC,cAAc,EAA2B;AAC9E,EAAE,IAAI,OAAO,cAAc,CAAC,QAAA,KAAa,UAAU,EAAE,iBAAiB,CAAC,cAAc,EAAE,UAAU,CAAC;AAClG,EAAE,IAAI,OAAO,cAAc,CAAC,gBAAA,KAAqB,UAAU,EAAE,iBAAiB,CAAC,cAAc,EAAE,kBAAkB,CAAC;AAClH;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,cAAc,EAA2B;AAC5E,EAAE,IAAI,OAAO,cAAc,CAAC,MAAA,KAAW,UAAU,EAAE,iBAAiB,CAAC,cAAc,EAAE,QAAQ,CAAC;AAC9F,EAAE,IAAI,OAAO,cAAc,CAAC,cAAA,KAAmB,UAAU,EAAE,iBAAiB,CAAC,cAAc,EAAE,gBAAgB,CAAC;AAC9G;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,cAAc,EAA2B;AAC5E,EAAE,gBAAgB,CAAC,cAAc,CAAC;AAClC,EAAE,oBAAoB,CAAC,cAAc,CAAC;AACtC,EAAE,kBAAkB,CAAC,cAAc,CAAC;AACpC;;;;"}
1
+ {"version":3,"file":"handlers.js","sources":["../../../../src/integrations/mcp-server/handlers.ts"],"sourcesContent":["/**\n * Handler method wrapping for MCP server instrumentation\n *\n * Provides automatic error capture and span correlation for tool, resource,\n * and prompt handlers.\n */\n\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { debug } from '../../utils/debug-logger';\nimport { fill } from '../../utils/object';\nimport { captureError } from './errorCapture';\nimport type { MCPHandler, MCPServerInstance } from './types';\n\n/**\n * Generic function to wrap MCP server method handlers\n * @internal\n * @param serverInstance - MCP server instance\n * @param methodName - Method name to wrap (tool, resource, prompt)\n */\nfunction wrapMethodHandler(serverInstance: MCPServerInstance, methodName: keyof MCPServerInstance): void {\n fill(serverInstance, methodName, originalMethod => {\n return function (this: MCPServerInstance, name: string, ...args: unknown[]) {\n const handler = args[args.length - 1];\n\n if (typeof handler !== 'function') {\n return (originalMethod as (...args: unknown[]) => unknown).call(this, name, ...args);\n }\n\n const wrappedHandler = createWrappedHandler(handler as MCPHandler, methodName, name);\n return (originalMethod as (...args: unknown[]) => unknown).call(this, name, ...args.slice(0, -1), wrappedHandler);\n };\n });\n}\n\n/**\n * Creates a wrapped handler with span correlation and error capture\n * @internal\n * @param originalHandler - Original handler function\n * @param methodName - MCP method name\n * @param handlerName - Handler identifier\n * @returns Wrapped handler function\n */\nfunction createWrappedHandler(originalHandler: MCPHandler, methodName: keyof MCPServerInstance, handlerName: string) {\n return function (this: unknown, ...handlerArgs: unknown[]): unknown {\n try {\n return createErrorCapturingHandler.call(this, originalHandler, methodName, handlerName, handlerArgs);\n } catch (error) {\n DEBUG_BUILD && debug.warn('MCP handler wrapping failed:', error);\n return originalHandler.apply(this, handlerArgs);\n }\n };\n}\n\n/**\n * Creates an error-capturing wrapper for handler execution\n * @internal\n * @param originalHandler - Original handler function\n * @param methodName - MCP method name\n * @param handlerName - Handler identifier\n * @param handlerArgs - Handler arguments\n * @param extraHandlerData - Additional handler context\n * @returns Handler execution result\n */\nfunction createErrorCapturingHandler(\n this: MCPServerInstance,\n originalHandler: MCPHandler,\n methodName: keyof MCPServerInstance,\n handlerName: string,\n handlerArgs: unknown[],\n): unknown {\n try {\n const result = originalHandler.apply(this, handlerArgs);\n\n if (result && typeof result === 'object' && typeof (result as { then?: unknown }).then === 'function') {\n return Promise.resolve(result).catch(error => {\n captureHandlerError(error, methodName, handlerName);\n throw error;\n });\n }\n\n return result;\n } catch (error) {\n captureHandlerError(error as Error, methodName, handlerName);\n throw error;\n }\n}\n\n/**\n * Captures handler execution errors based on handler type\n * @internal\n * @param error - Error to capture\n * @param methodName - MCP method name\n * @param handlerName - Handler identifier\n */\nfunction captureHandlerError(error: Error, methodName: keyof MCPServerInstance, handlerName: string): void {\n try {\n const extraData: Record<string, unknown> = {};\n\n if (methodName === 'tool' || methodName === 'registerTool') {\n extraData.tool_name = handlerName;\n\n if (\n error.name === 'ProtocolValidationError' ||\n error.message.includes('validation') ||\n error.message.includes('protocol')\n ) {\n captureError(error, 'validation', extraData);\n } else if (\n error.name === 'ServerTimeoutError' ||\n error.message.includes('timed out') ||\n error.message.includes('timeout')\n ) {\n captureError(error, 'timeout', extraData);\n } else {\n captureError(error, 'tool_execution', extraData);\n }\n } else if (methodName === 'resource' || methodName === 'registerResource') {\n extraData.resource_uri = handlerName;\n captureError(error, 'resource_execution', extraData);\n } else if (methodName === 'prompt' || methodName === 'registerPrompt') {\n extraData.prompt_name = handlerName;\n captureError(error, 'prompt_execution', extraData);\n }\n } catch (_captureErr) {\n // noop\n }\n}\n\n/**\n * Wraps tool handlers to associate them with request spans.\n * Instruments both `tool` (legacy API) and `registerTool` (new API) if present.\n * @param serverInstance - MCP server instance\n */\nexport function wrapToolHandlers(serverInstance: MCPServerInstance): void {\n if (typeof serverInstance.tool === 'function') wrapMethodHandler(serverInstance, 'tool');\n if (typeof serverInstance.registerTool === 'function') wrapMethodHandler(serverInstance, 'registerTool');\n}\n\n/**\n * Wraps resource handlers to associate them with request spans.\n * Instruments both `resource` (legacy API) and `registerResource` (new API) if present.\n * @param serverInstance - MCP server instance\n */\nexport function wrapResourceHandlers(serverInstance: MCPServerInstance): void {\n if (typeof serverInstance.resource === 'function') wrapMethodHandler(serverInstance, 'resource');\n if (typeof serverInstance.registerResource === 'function') wrapMethodHandler(serverInstance, 'registerResource');\n}\n\n/**\n * Wraps prompt handlers to associate them with request spans.\n * Instruments both `prompt` (legacy API) and `registerPrompt` (new API) if present.\n * @param serverInstance - MCP server instance\n */\nexport function wrapPromptHandlers(serverInstance: MCPServerInstance): void {\n if (typeof serverInstance.prompt === 'function') wrapMethodHandler(serverInstance, 'prompt');\n if (typeof serverInstance.registerPrompt === 'function') wrapMethodHandler(serverInstance, 'registerPrompt');\n}\n\n/**\n * Wraps all MCP handler types for span correlation.\n * Supports both the legacy API (`tool`, `resource`, `prompt`) and the newer API\n * (`registerTool`, `registerResource`, `registerPrompt`), instrumenting whichever methods are present.\n * @param serverInstance - MCP server instance\n */\nexport function wrapAllMCPHandlers(serverInstance: MCPServerInstance): void {\n wrapToolHandlers(serverInstance);\n wrapResourceHandlers(serverInstance);\n wrapPromptHandlers(serverInstance);\n}\n\n/**\n * Retroactively wraps handlers on tools, resources, and prompts that were registered\n * before `wrapMcpServerWithSentry` was called.\n *\n * The MCP SDK stores registered entries in private maps and invokes them via the entry's\n * own property at call time — `executor` for tools, `readCallback` for resources, and\n * `handler` for prompts. Replacing those properties\n * in-place is therefore equivalent to having wrapped the original registration call.\n *\n * NOTE: This intentionally accesses private MCP SDK internals (`_registeredTools` etc.).\n * The properties and their shapes are verified against @modelcontextprotocol/sdk source:\n * https://github.com/modelcontextprotocol/typescript-sdk/blob/2c0c481cb9dbfd15c8613f765c940a5f5bace94d/packages/server/src/server/mcp.ts#L304\n * When upgrading the MCP SDK, re-verify that these internal maps and their callable\n * properties still exist and are invoked directly (not captured by closure at registration).\n * All access is defensive — if a property is absent or not a function we skip silently.\n * @internal\n */\nexport function wrapExistingHandlers(serverInstance: MCPServerInstance): void {\n const server = serverInstance as unknown as Record<string, unknown>;\n\n // Tools: MCP SDK calls registeredTool.executor (generated from handler at registration time)\n const registeredTools = server['_registeredTools'];\n if (registeredTools && typeof registeredTools === 'object') {\n for (const [name, tool] of Object.entries(registeredTools as Record<string, Record<string, unknown>>)) {\n if (typeof tool['executor'] === 'function') {\n tool['executor'] = createWrappedHandler(tool['executor'] as MCPHandler, 'registerTool', name);\n }\n }\n }\n\n // Resources: MCP SDK calls registeredResource.readCallback\n const registeredResources = server['_registeredResources'];\n if (registeredResources && typeof registeredResources === 'object') {\n for (const [name, resource] of Object.entries(registeredResources as Record<string, Record<string, unknown>>)) {\n if (typeof resource['readCallback'] === 'function') {\n resource['readCallback'] = createWrappedHandler(\n resource['readCallback'] as MCPHandler,\n 'registerResource',\n name,\n );\n }\n }\n }\n\n // Resource templates: MCP SDK calls registeredResourceTemplate.readCallback\n const registeredResourceTemplates = server['_registeredResourceTemplates'];\n if (registeredResourceTemplates && typeof registeredResourceTemplates === 'object') {\n for (const [name, template] of Object.entries(\n registeredResourceTemplates as Record<string, Record<string, unknown>>,\n )) {\n if (typeof template['readCallback'] === 'function') {\n template['readCallback'] = createWrappedHandler(\n template['readCallback'] as MCPHandler,\n 'registerResource',\n name,\n );\n }\n }\n }\n\n // Prompts: MCP SDK calls registeredPrompt.handler\n const registeredPrompts = server['_registeredPrompts'];\n if (registeredPrompts && typeof registeredPrompts === 'object') {\n for (const [name, prompt] of Object.entries(registeredPrompts as Record<string, Record<string, unknown>>)) {\n if (typeof prompt['handler'] === 'function') {\n prompt['handler'] = createWrappedHandler(prompt['handler'] as MCPHandler, 'registerPrompt', name);\n }\n }\n }\n}\n"],"names":[],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,iBAAiB,CAAC,cAAc,EAAqB,UAAU,EAAiC;AACzG,EAAE,IAAI,CAAC,cAAc,EAAE,UAAU,EAAE,kBAAkB;AACrD,IAAI,OAAO,WAAmC,IAAI,EAAU,GAAG,IAAI,EAAa;AAChF,MAAM,MAAM,OAAA,GAAU,IAAI,CAAC,IAAI,CAAC,MAAA,GAAS,CAAC,CAAC;;AAE3C,MAAM,IAAI,OAAO,OAAA,KAAY,UAAU,EAAE;AACzC,QAAQ,OAAO,CAAC,cAAA,GAAmD,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;AAC5F,MAAM;;AAEN,MAAM,MAAM,cAAA,GAAiB,oBAAoB,CAAC,UAAuB,UAAU,EAAE,IAAI,CAAC;AAC1F,MAAM,OAAO,CAAC,cAAA,GAAmD,IAAI,CAAC,IAAI,EA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AK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAA,IAAK,MAAM,CAAC,OAAO;AACjD,MAAM,2BAAA;AACN,KAAK,EAAE;AACP,MAAM,IAAI,OAAO,QAAQ,CAAC,cAAc,CAAA,KAAM,UAAU,EAAE;AAC1D,QAAQ,QAAQ,CAAC,cAAc,CAAA,GAAI,oBAAoB;AACvD,UAAU,QAAQ,CAAC,cAAc,CAAA;AACjC,UAAU,kBAAkB;AAC5B,UAAU,IAAI;AACd,SAAS;AACT,MAAM;AACN,IAAI;AACJ,EAAE;;AAEF;AACA,EAAE,MAAM,iBAAA,GAAoB,MAAM,CAAC,oBAAoB,CAAC;AACxD,EAAE,IAAI,iBAAA,IAAqB,OAAO,iBAAA,KAAsB,QAAQ,EAAE;AAClE,IAAI,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAA,IAAK,MAAM,CAAC,OAAO,CAAC,iBAAA,EAA6D,EAAE;AAC/G,MAAM,IAAI,OAAO,MAAM,CAAC,SAAS,CAAA,KAAM,UAAU,EAAE;AACnD,QAAQ,MAAM,CAAC,SAAS,CAAA,GAAI,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAA,GAAiB,gBAAgB,EAAE,IAAI,CAAC;AACzG,MAAM;AACN,IAAI;AACJ,EAAE;AACF;;;;"}
@@ -1,6 +1,6 @@
1
1
  import { getClient } from '../../currentScopes.js';
2
2
  import { fill } from '../../utils/object.js';
3
- import { wrapAllMCPHandlers } from './handlers.js';
3
+ import { wrapAllMCPHandlers, wrapExistingHandlers } from './handlers.js';
4
4
  import { wrapTransportOnMessage, wrapTransportSend, wrapTransportOnClose, wrapTransportError } from './transport.js';
5
5
  import { validateMcpServerInstance } from './validation.js';
6
6
 
@@ -17,17 +17,24 @@ const wrappedMcpServerInstances = new WeakSet();
17
17
  * and versions that expose the newer `registerTool`/`registerResource`/`registerPrompt` API (introduced in 1.x, sole API in 2.x).
18
18
  * Automatically instruments transport methods and handler functions for comprehensive monitoring.
19
19
  *
20
+ * Both call orderings are supported: wrapping before or after registering tools, resources,
21
+ * and prompts. Sentry patches the registration methods for future handlers and retroactively
22
+ * wraps any already-registered ones. Wrapping at construction time is recommended by
23
+ * convention (consistent with other SDK integrations), but is not required.
24
+ *
20
25
  * @example
21
26
  * ```typescript
22
27
  * import * as Sentry from '@sentry/core';
23
28
  * import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
24
29
  * import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
25
30
  *
26
- * // Default: inputs/outputs captured based on sendDefaultPii option
31
+ * // Wrap first, then register tools this is the correct order
27
32
  * const server = Sentry.wrapMcpServerWithSentry(
28
33
  * new McpServer({ name: "my-server", version: "1.0.0" })
29
34
  * );
30
35
  *
36
+ * server.registerTool('my-tool', schema, handler);
37
+ *
31
38
  * // Explicitly control input/output capture
32
39
  * const server = Sentry.wrapMcpServerWithSentry(
33
40
  * new McpServer({ name: "my-server", version: "1.0.0" }),
@@ -79,6 +86,8 @@ function wrapMcpServerWithSentry(mcpServerInstance, options) {
79
86
 
80
87
  wrapAllMCPHandlers(serverInstance);
81
88
 
89
+ wrapExistingHandlers(serverInstance);
90
+
82
91
  wrappedMcpServerInstances.add(mcpServerInstance);
83
92
  return mcpServerInstance;
84
93
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/integrations/mcp-server/index.ts"],"sourcesContent":["import { getClient } from '../../currentScopes';\nimport { fill } from '../../utils/object';\nimport { wrapAllMCPHandlers } from './handlers';\nimport { wrapTransportError, wrapTransportOnClose, wrapTransportOnMessage, wrapTransportSend } from './transport';\nimport type { MCPServerInstance, McpServerWrapperOptions, MCPTransport, ResolvedMcpOptions } from './types';\nimport { validateMcpServerInstance } from './validation';\n\n/**\n * Tracks wrapped MCP server instances to prevent double-wrapping\n * @internal\n */\nconst wrappedMcpServerInstances = new WeakSet();\n\n/**\n * Wraps a MCP Server instance from the `@modelcontextprotocol/sdk` package with Sentry instrumentation.\n *\n * Compatible with versions `^1.9.0` of the `@modelcontextprotocol/sdk` package (legacy `tool`/`resource`/`prompt` API)\n * and versions that expose the newer `registerTool`/`registerResource`/`registerPrompt` API (introduced in 1.x, sole API in 2.x).\n * Automatically instruments transport methods and handler functions for comprehensive monitoring.\n *\n * @example\n * ```typescript\n * import * as Sentry from '@sentry/core';\n * import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\n * import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';\n *\n * // Default: inputs/outputs captured based on sendDefaultPii option\n * const server = Sentry.wrapMcpServerWithSentry(\n * new McpServer({ name: \"my-server\", version: \"1.0.0\" })\n * );\n *\n * // Explicitly control input/output capture\n * const server = Sentry.wrapMcpServerWithSentry(\n * new McpServer({ name: \"my-server\", version: \"1.0.0\" }),\n * { recordInputs: true, recordOutputs: false }\n * );\n *\n * const transport = new StreamableHTTPServerTransport();\n * await server.connect(transport);\n * ```\n *\n * @param mcpServerInstance - MCP server instance to instrument\n * @param options - Optional configuration for recording inputs and outputs\n * @returns Instrumented server instance (same reference)\n */\nexport function wrapMcpServerWithSentry<S extends object>(mcpServerInstance: S, options?: McpServerWrapperOptions): S {\n if (wrappedMcpServerInstances.has(mcpServerInstance)) {\n return mcpServerInstance;\n }\n\n if (!validateMcpServerInstance(mcpServerInstance)) {\n return mcpServerInstance;\n }\n\n const serverInstance = mcpServerInstance as MCPServerInstance;\n const client = getClient();\n const sendDefaultPii = Boolean(client?.getOptions().sendDefaultPii);\n\n const resolvedOptions: ResolvedMcpOptions = {\n recordInputs: options?.recordInputs ?? sendDefaultPii,\n recordOutputs: options?.recordOutputs ?? sendDefaultPii,\n };\n\n fill(serverInstance, 'connect', originalConnect => {\n return async function (this: MCPServerInstance, transport: MCPTransport, ...restArgs: unknown[]) {\n const result = await (originalConnect as (...args: unknown[]) => Promise<unknown>).call(\n this,\n transport,\n ...restArgs,\n );\n\n wrapTransportOnMessage(transport, resolvedOptions);\n wrapTransportSend(transport, resolvedOptions);\n wrapTransportOnClose(transport);\n wrapTransportError(transport);\n\n return result;\n };\n });\n\n wrapAllMCPHandlers(serverInstance);\n\n wrappedMcpServerInstances.add(mcpServerInstance);\n return mcpServerInstance;\n}\n"],"names":[],"mappings":";;;;;;AAOA;AACA;AACA;AACA;AACA,MAAM,yBAAA,GAA4B,IAAI,OAAO,EAAE;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,uBAAuB,CAAmB,iBAAiB,EAAK,OAAO,EAA+B;AACtH,EAAE,IAAI,yBAAyB,CAAC,GAAG,CAAC,iBAAiB,CAAC,EAAE;AACxD,IAAI,OAAO,iBAAiB;AAC5B,EAAE;;AAEF,EAAE,IAAI,CAAC,yBAAyB,CAAC,iBAAiB,CAAC,EAAE;AACrD,IAAI,OAAO,iBAAiB;AAC5B,EAAE;;AAEF,EAAE,MAAM,cAAA,GAAiB,iBAAA;AACzB,EAAE,MAAM,MAAA,GAAS,SAAS,EAAE;AAC5B,EAAE,MAAM,cAAA,GAAiB,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,cAAc,CAAC;;AAErE,EAAE,MAAM,eAAe,GAAuB;AAC9C,IAAI,YAAY,EAAE,OAAO,EAAE,YAAA,IAAgB,cAAc;AACzD,IAAI,aAAa,EAAE,OAAO,EAAE,aAAA,IAAiB,cAAc;AAC3D,GAAG;;AAEH,EAAE,IAAI,CAAC,cAAc,EAAE,SAAS,EAAE,mBAAmB;AACrD,IAAI,OAAO,iBAAyC,SAAS,EAAgB,GAAG,QAAQ,EAAa;AACrG,MAAM,MAAM,SAAS,MAAM,CAAC,eAAA,GAA6D,IAAI;AAC7F,QAAQ,IAAI;AACZ,QAAQ,SAAS;AACjB,QAAQ,GAAG,QAAQ;AACnB,OAAO;;AAEP,MAAM,sBAAsB,CAAC,SAAS,EAAE,eAAe,CAAC;AACxD,MAAM,iBAAiB,CAAC,SAAS,EAAE,eAAe,CAAC;AACnD,MAAM,oBAAoB,CAAC,SAAS,CAAC;AACrC,MAAM,kBAAkB,CAAC,SAAS,CAAC;;AAEnC,MAAM,OAAO,MAAM;AACnB,IAAI,CAAC;AACL,EAAE,CAAC,CAAC;;AAEJ,EAAE,kBAAkB,CAAC,cAAc,CAAC;;AAEpC,EAAE,yBAAyB,CAAC,GAAG,CAAC,iBAAiB,CAAC;AAClD,EAAE,OAAO,iBAAiB;AAC1B;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/integrations/mcp-server/index.ts"],"sourcesContent":["import { getClient } from '../../currentScopes';\nimport { fill } from '../../utils/object';\nimport { wrapAllMCPHandlers, wrapExistingHandlers } from './handlers';\nimport { wrapTransportError, wrapTransportOnClose, wrapTransportOnMessage, wrapTransportSend } from './transport';\nimport type { MCPServerInstance, McpServerWrapperOptions, MCPTransport, ResolvedMcpOptions } from './types';\nimport { validateMcpServerInstance } from './validation';\n\n/**\n * Tracks wrapped MCP server instances to prevent double-wrapping\n * @internal\n */\nconst wrappedMcpServerInstances = new WeakSet();\n\n/**\n * Wraps a MCP Server instance from the `@modelcontextprotocol/sdk` package with Sentry instrumentation.\n *\n * Compatible with versions `^1.9.0` of the `@modelcontextprotocol/sdk` package (legacy `tool`/`resource`/`prompt` API)\n * and versions that expose the newer `registerTool`/`registerResource`/`registerPrompt` API (introduced in 1.x, sole API in 2.x).\n * Automatically instruments transport methods and handler functions for comprehensive monitoring.\n *\n * Both call orderings are supported: wrapping before or after registering tools, resources,\n * and prompts. Sentry patches the registration methods for future handlers and retroactively\n * wraps any already-registered ones. Wrapping at construction time is recommended by\n * convention (consistent with other SDK integrations), but is not required.\n *\n * @example\n * ```typescript\n * import * as Sentry from '@sentry/core';\n * import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\n * import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';\n *\n * // Wrap first, then register tools this is the correct order\n * const server = Sentry.wrapMcpServerWithSentry(\n * new McpServer({ name: \"my-server\", version: \"1.0.0\" })\n * );\n *\n * server.registerTool('my-tool', schema, handler);\n *\n * // Explicitly control input/output capture\n * const server = Sentry.wrapMcpServerWithSentry(\n * new McpServer({ name: \"my-server\", version: \"1.0.0\" }),\n * { recordInputs: true, recordOutputs: false }\n * );\n *\n * const transport = new StreamableHTTPServerTransport();\n * await server.connect(transport);\n * ```\n *\n * @param mcpServerInstance - MCP server instance to instrument\n * @param options - Optional configuration for recording inputs and outputs\n * @returns Instrumented server instance (same reference)\n */\nexport function wrapMcpServerWithSentry<S extends object>(mcpServerInstance: S, options?: McpServerWrapperOptions): S {\n if (wrappedMcpServerInstances.has(mcpServerInstance)) {\n return mcpServerInstance;\n }\n\n if (!validateMcpServerInstance(mcpServerInstance)) {\n return mcpServerInstance;\n }\n\n const serverInstance = mcpServerInstance as MCPServerInstance;\n const client = getClient();\n const sendDefaultPii = Boolean(client?.getOptions().sendDefaultPii);\n\n const resolvedOptions: ResolvedMcpOptions = {\n recordInputs: options?.recordInputs ?? sendDefaultPii,\n recordOutputs: options?.recordOutputs ?? sendDefaultPii,\n };\n\n fill(serverInstance, 'connect', originalConnect => {\n return async function (this: MCPServerInstance, transport: MCPTransport, ...restArgs: unknown[]) {\n const result = await (originalConnect as (...args: unknown[]) => Promise<unknown>).call(\n this,\n transport,\n ...restArgs,\n );\n\n wrapTransportOnMessage(transport, resolvedOptions);\n wrapTransportSend(transport, resolvedOptions);\n wrapTransportOnClose(transport);\n wrapTransportError(transport);\n\n return result;\n };\n });\n\n wrapAllMCPHandlers(serverInstance);\n\n wrapExistingHandlers(serverInstance);\n\n wrappedMcpServerInstances.add(mcpServerInstance);\n return mcpServerInstance;\n}\n"],"names":[],"mappings":";;;;;;AAOA;AACA;AACA;AACA;AACA,MAAM,yBAAA,GAA4B,IAAI,OAAO,EAAE;;AAE/C;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AI,CAAC;AACL,EAAE,CAAC,CAAC;;AAEJ,EAAE,kBAAkB,CAAC,cAAc,CAAC;;AAEpC,EAAE,oBAAoB,CAAC,cAAc,CAAC;;AAEtC,EAAE,yBAAyB,CAAC,GAAG,CAAC,iBAAiB,CAAC;AAClD,EAAE,OAAO,iBAAiB;AAC1B;;;;"}
@@ -1,6 +1,10 @@
1
+ import { getIsolationScope } from '../currentScopes.js';
1
2
  import { defineIntegration } from '../integration.js';
3
+ import { SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS } from '../semanticAttributes.js';
2
4
  import { parseCookie } from '../utils/cookie.js';
5
+ import { httpHeadersToSpanAttributes } from '../utils/request.js';
3
6
  import { getClientIPAddress, ipHeaderNames } from '../vendor/getIpAddress.js';
7
+ import { safeSetSpanJSONAttributes } from '../tracing/spans/captureSpan.js';
4
8
 
5
9
  // TODO(v11): Change defaults based on `sendDefaultPii`
6
10
  const DEFAULT_INCLUDE = {
@@ -36,6 +40,22 @@ const _requestDataIntegration = ((options = {}) => {
36
40
 
37
41
  return event;
38
42
  },
43
+ processSegmentSpan(span, client) {
44
+ const { sdkProcessingMetadata = {} } = getIsolationScope().getScopeData();
45
+ const { normalizedRequest, ipAddress } = sdkProcessingMetadata;
46
+
47
+ if (!normalizedRequest) {
48
+ return;
49
+ }
50
+
51
+ const { sendDefaultPii } = client.getOptions();
52
+ const includeWithDefaultPiiApplied = {
53
+ ...include,
54
+ ip: include.ip ?? sendDefaultPii,
55
+ };
56
+
57
+ addNormalizedRequestDataToSpan(span, normalizedRequest, ipAddress, includeWithDefaultPiiApplied, sendDefaultPii);
58
+ },
39
59
  };
40
60
  }) ;
41
61
 
@@ -72,6 +92,60 @@ function addNormalizedRequestDataToEvent(
72
92
  }
73
93
  }
74
94
 
95
+ function addNormalizedRequestDataToSpan(
96
+ span,
97
+ normalizedRequest,
98
+ ipAddress,
99
+ include,
100
+ sendDefaultPii,
101
+ ) {
102
+ const requestData = extractNormalizedRequestData(normalizedRequest, include);
103
+ const attributes = {};
104
+
105
+ if (requestData.url) {
106
+ attributes['url.full'] = requestData.url;
107
+ }
108
+
109
+ if (requestData.method) {
110
+ attributes['http.request.method'] = requestData.method;
111
+ }
112
+
113
+ if (requestData.query_string) {
114
+ attributes['url.query'] = normalizeQueryString(requestData.query_string);
115
+ }
116
+
117
+ safeSetSpanJSONAttributes(span, attributes);
118
+
119
+ // Process cookies before headers so normalizedRequest.cookies takes precedence
120
+ // over the raw cookie header (matching the processEvent path).
121
+ if (requestData.cookies && Object.keys(requestData.cookies).length > 0) {
122
+ const cookieString = Object.entries(requestData.cookies)
123
+ .map(([name, value]) => `${name}=${value}`)
124
+ .join('; ');
125
+ const cookieAttributes = httpHeadersToSpanAttributes({ cookie: cookieString }, sendDefaultPii ?? false, 'request');
126
+ safeSetSpanJSONAttributes(span, cookieAttributes);
127
+ }
128
+
129
+ if (requestData.headers) {
130
+ const headerAttributes = httpHeadersToSpanAttributes(requestData.headers, sendDefaultPii ?? false, 'request');
131
+ safeSetSpanJSONAttributes(span, headerAttributes);
132
+ }
133
+
134
+ if (requestData.data != null) {
135
+ const serialized = typeof requestData.data === 'string' ? requestData.data : JSON.stringify(requestData.data);
136
+ if (serialized) {
137
+ safeSetSpanJSONAttributes(span, { 'http.request.body.data': serialized });
138
+ }
139
+ }
140
+
141
+ if (include.ip) {
142
+ const ip = (normalizedRequest.headers && getClientIPAddress(normalizedRequest.headers)) || ipAddress || undefined;
143
+ if (ip) {
144
+ safeSetSpanJSONAttributes(span, { [SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS]: ip });
145
+ }
146
+ }
147
+ }
148
+
75
149
  function extractNormalizedRequestData(
76
150
  normalizedRequest,
77
151
  include,
@@ -82,13 +156,10 @@ function extractNormalizedRequestData(
82
156
  if (include.headers) {
83
157
  requestData.headers = headers;
84
158
 
85
- // Remove the Cookie header in case cookie data should not be included in the event
86
159
  if (!include.cookies) {
87
160
  delete (headers ).cookie;
88
161
  }
89
162
 
90
- // Remove IP headers in case IP data should not be included in the event.
91
- // Match case-insensitively — same as getClientIPAddress — so lowercase keys are stripped too.
92
163
  if (!include.ip) {
93
164
  const ipHeaderNamesLower = new Set(ipHeaderNames.map(name => name.toLowerCase()));
94
165
  for (const key of Object.keys(headers)) {
@@ -122,5 +193,16 @@ function extractNormalizedRequestData(
122
193
  return requestData;
123
194
  }
124
195
 
196
+ function normalizeQueryString(queryString) {
197
+ if (typeof queryString === 'string') {
198
+ return queryString || undefined;
199
+ }
200
+
201
+ const pairs = Array.isArray(queryString) ? queryString : Object.entries(queryString);
202
+ const result = pairs.map(([key, value]) => `${key}=${value}`).join('&');
203
+
204
+ return result || undefined;
205
+ }
206
+
125
207
  export { requestDataIntegration };
126
208
  //# sourceMappingURL=requestdata.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"requestdata.js","sources":["../../../src/integrations/requestdata.ts"],"sourcesContent":["import { defineIntegration } from '../integration';\nimport type { Event } from '../types-hoist/event';\nimport type { IntegrationFn } from '../types-hoist/integration';\nimport type { RequestEventData } from '../types-hoist/request';\nimport { parseCookie } from '../utils/cookie';\nimport { getClientIPAddress, ipHeaderNames } from '../vendor/getIpAddress';\n\ninterface RequestDataIncludeOptions {\n cookies?: boolean;\n data?: boolean;\n headers?: boolean;\n ip?: boolean;\n query_string?: boolean;\n url?: boolean;\n}\n\ntype RequestDataIntegrationOptions = {\n /**\n * Controls what data is pulled from the request and added to the event.\n */\n include?: RequestDataIncludeOptions;\n};\n\n// TODO(v11): Change defaults based on `sendDefaultPii`\nconst DEFAULT_INCLUDE: RequestDataIncludeOptions = {\n cookies: true,\n data: true,\n headers: true,\n query_string: true,\n url: true,\n};\n\nconst INTEGRATION_NAME = 'RequestData';\n\nconst _requestDataIntegration = ((options: RequestDataIntegrationOptions = {}) => {\n const include = {\n ...DEFAULT_INCLUDE,\n ...options.include,\n };\n\n return {\n name: INTEGRATION_NAME,\n processEvent(event, _hint, client) {\n const { sdkProcessingMetadata = {} } = event;\n const { normalizedRequest, ipAddress } = sdkProcessingMetadata;\n\n const includeWithDefaultPiiApplied: RequestDataIncludeOptions = {\n ...include,\n ip: include.ip ?? client.getOptions().sendDefaultPii,\n };\n\n if (normalizedRequest) {\n addNormalizedRequestDataToEvent(event, normalizedRequest, { ipAddress }, includeWithDefaultPiiApplied);\n }\n\n return event;\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Add data about a request to an event. Primarily for use in Node-based SDKs, but included in `@sentry/core`\n * so it can be used in cross-platform SDKs like `@sentry/nextjs`.\n */\nexport const requestDataIntegration = defineIntegration(_requestDataIntegration);\n\n/**\n * Add already normalized request data to an event.\n * This mutates the passed in event.\n */\nfunction addNormalizedRequestDataToEvent(\n event: Event,\n req: RequestEventData,\n // Data that should not go into `event.request` but is somehow related to requests\n additionalData: { ipAddress?: string },\n include: RequestDataIncludeOptions,\n): void {\n event.request = {\n ...event.request,\n ...extractNormalizedRequestData(req, include),\n };\n\n if (include.ip) {\n const ip = (req.headers && getClientIPAddress(req.headers)) || additionalData.ipAddress;\n if (ip) {\n event.user = {\n ...event.user,\n ip_address: ip,\n };\n }\n }\n}\n\nfunction extractNormalizedRequestData(\n normalizedRequest: RequestEventData,\n include: RequestDataIncludeOptions,\n): RequestEventData {\n const requestData: RequestEventData = {};\n const headers = { ...normalizedRequest.headers };\n\n if (include.headers) {\n requestData.headers = headers;\n\n // Remove the Cookie header in case cookie data should not be included in the event\n if (!include.cookies) {\n delete (headers as { cookie?: string }).cookie;\n }\n\n // Remove IP headers in case IP data should not be included in the event.\n // Match case-insensitively — same as getClientIPAddress — so lowercase keys are stripped too.\n if (!include.ip) {\n const ipHeaderNamesLower = new Set(ipHeaderNames.map(name => name.toLowerCase()));\n for (const key of Object.keys(headers)) {\n if (ipHeaderNamesLower.has(key.toLowerCase())) {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete (headers as Record<string, unknown>)[key];\n }\n }\n }\n }\n\n requestData.method = normalizedRequest.method;\n\n if (include.url) {\n requestData.url = normalizedRequest.url;\n }\n\n if (include.cookies) {\n const cookies = normalizedRequest.cookies || (headers?.cookie ? parseCookie(headers.cookie) : undefined);\n requestData.cookies = cookies || {};\n }\n\n if (include.query_string) {\n requestData.query_string = normalizedRequest.query_string;\n }\n\n if (include.data) {\n requestData.data = normalizedRequest.data;\n }\n\n return requestData;\n}\n"],"names":[],"mappings":";;;;AAuBA;AACA,MAAM,eAAe,GAA8B;AACnD,EAAE,OAAO,EAAE,IAAI;AACf,EAAE,IAAI,EAAE,IAAI;AACZ,EAAE,OAAO,EAAE,IAAI;AACf,EAAE,YAAY,EAAE,IAAI;AACpB,EAAE,GAAG,EAAE,IAAI;AACX,CAAC;;AAED,MAAM,gBAAA,GAAmB,aAAa;;AAEtC,MAAM,uBAAA,IAA2B,CAAC,OAAO,GAAkC,EAAE,KAAK;AAClF,EAAE,MAAM,UAAU;AAClB,IAAI,GAAG,eAAe;AACtB,IAAI,GAAG,OAAO,CAAC,OAAO;AACtB,GAAG;;AAEH,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B,IAAI,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE;AACvC,MAAM,MAAM,EAAE,qBAAA,GAAwB,EAAC,EAAE,GAAI,KAAK;AAClD,MAAM,MAAM,EAAE,iBAAiB,EAAE,SAAA,EAAU,GAAI,qBAAqB;;AAEpE,MAAM,MAAM,4BAA4B,GAA8B;AACtE,QAAQ,GAAG,OAAO;AAClB,QAAQ,EAAE,EAAE,OAAO,CAAC,EAAA,IAAM,MAAM,CAAC,UAAU,EAAE,CAAC,cAAc;AAC5D,OAAO;;AAEP,MAAM,IAAI,iBAAiB,EAAE;AAC7B,QAAQ,+BAA+B,CAAC,KAAK,EAAE,iBAAiB,EAAE,EAAE,SAAA,EAAW,EAAE,4BAA4B,CAAC;AAC9G,MAAM;;AAEN,MAAM,OAAO,KAAK;AAClB,IAAI,CAAC;AACL,GAAG;AACH,CAAC,CAAA;;AAED;AACA;AACA;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AO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;AAC9C,QAAQ,IAAI,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,EAAE;AACvD;AACA,UAAU,OAAO,CAAC,OAAA,GAAoC,GAAG,CAAC;AAC1D,QAAQ;AACR,MAAM;AACN,IAAI;AACJ,EAAE;;AAEF,EAAE,WAAW,CAAC,MAAA,GAAS,iBAAiB,CAAC,MAAM;;AAE/C,EAAE,IAAI,OAAO,CAAC,GAAG,EAAE;AACnB,IAAI,WAAW,CAAC,GAAA,GAAM,iBAAiB,CAAC,GAAG;AAC3C,EAAE;;AAEF,EAAE,IAAI,OAAO,CAAC,OAAO,EAAE;AACvB,IAAI,MAAM,UAAU,iBAAiB,CAAC,OAAA,KAAY,OAAO,EAAE,SAAS,WAAW,CAAC,OAAO,CAAC,MAAM,CAAA,GAAI,SAAS,CAAC;AAC5G,IAAI,WAAW,CAAC,OAAA,GAAU,OAAA,IAAW,EAAE;AACvC,EAAE;;AAEF,EAAE,IAAI,OAAO,CAAC,YAAY,EAAE;AAC5B,IAAI,WAAW,CAAC,YAAA,GAAe,iBAAiB,CAAC,YAAY;AAC7D,EAAE;;AAEF,EAAE,IAAI,OAAO,CAAC,IAAI,EAAE;AACpB,IAAI,WAAW,CAAC,IAAA,GAAO,iBAAiB,CAAC,IAAI;AAC7C,EAAE;;AAEF,EAAE,OAAO,WAAW;AACpB;;;;"}
1
+ {"version":3,"file":"requestdata.js","sources":["../../../src/integrations/requestdata.ts"],"sourcesContent":["import { getIsolationScope } from '../currentScopes';\nimport { defineIntegration } from '../integration';\nimport { SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS } from '../semanticAttributes';\nimport type { Event } from '../types-hoist/event';\nimport type { IntegrationFn } from '../types-hoist/integration';\nimport type { QueryParams, RequestEventData } from '../types-hoist/request';\nimport type { StreamedSpanJSON } from '../types-hoist/span';\nimport { parseCookie } from '../utils/cookie';\nimport { httpHeadersToSpanAttributes } from '../utils/request';\nimport { getClientIPAddress, ipHeaderNames } from '../vendor/getIpAddress';\nimport { safeSetSpanJSONAttributes } from '../tracing/spans/captureSpan';\n\ninterface RequestDataIncludeOptions {\n cookies?: boolean;\n data?: boolean;\n headers?: boolean;\n ip?: boolean;\n query_string?: boolean;\n url?: boolean;\n}\n\ntype RequestDataIntegrationOptions = {\n /**\n * Controls what data is pulled from the request and added to the event.\n */\n include?: RequestDataIncludeOptions;\n};\n\n// TODO(v11): Change defaults based on `sendDefaultPii`\nconst DEFAULT_INCLUDE: RequestDataIncludeOptions = {\n cookies: true,\n data: true,\n headers: true,\n query_string: true,\n url: true,\n};\n\nconst INTEGRATION_NAME = 'RequestData';\n\nconst _requestDataIntegration = ((options: RequestDataIntegrationOptions = {}) => {\n const include = {\n ...DEFAULT_INCLUDE,\n ...options.include,\n };\n\n return {\n name: INTEGRATION_NAME,\n processEvent(event, _hint, client) {\n const { sdkProcessingMetadata = {} } = event;\n const { normalizedRequest, ipAddress } = sdkProcessingMetadata;\n\n const includeWithDefaultPiiApplied: RequestDataIncludeOptions = {\n ...include,\n ip: include.ip ?? client.getOptions().sendDefaultPii,\n };\n\n if (normalizedRequest) {\n addNormalizedRequestDataToEvent(event, normalizedRequest, { ipAddress }, includeWithDefaultPiiApplied);\n }\n\n return event;\n },\n processSegmentSpan(span, client) {\n const { sdkProcessingMetadata = {} } = getIsolationScope().getScopeData();\n const { normalizedRequest, ipAddress } = sdkProcessingMetadata;\n\n if (!normalizedRequest) {\n return;\n }\n\n const { sendDefaultPii } = client.getOptions();\n const includeWithDefaultPiiApplied: RequestDataIncludeOptions = {\n ...include,\n ip: include.ip ?? sendDefaultPii,\n };\n\n addNormalizedRequestDataToSpan(span, normalizedRequest, ipAddress, includeWithDefaultPiiApplied, sendDefaultPii);\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Add data about a request to an event. Primarily for use in Node-based SDKs, but included in `@sentry/core`\n * so it can be used in cross-platform SDKs like `@sentry/nextjs`.\n */\nexport const requestDataIntegration = defineIntegration(_requestDataIntegration);\n\n/**\n * Add already normalized request data to an event.\n * This mutates the passed in event.\n */\nfunction addNormalizedRequestDataToEvent(\n event: Event,\n req: RequestEventData,\n // Data that should not go into `event.request` but is somehow related to requests\n additionalData: { ipAddress?: string },\n include: RequestDataIncludeOptions,\n): void {\n event.request = {\n ...event.request,\n ...extractNormalizedRequestData(req, include),\n };\n\n if (include.ip) {\n const ip = (req.headers && getClientIPAddress(req.headers)) || additionalData.ipAddress;\n if (ip) {\n event.user = {\n ...event.user,\n ip_address: ip,\n };\n }\n }\n}\n\nfunction addNormalizedRequestDataToSpan(\n span: StreamedSpanJSON,\n normalizedRequest: RequestEventData,\n ipAddress: string | undefined,\n include: RequestDataIncludeOptions,\n sendDefaultPii: boolean | undefined,\n): void {\n const requestData = extractNormalizedRequestData(normalizedRequest, include);\n const attributes: Record<string, unknown> = {};\n\n if (requestData.url) {\n attributes['url.full'] = requestData.url;\n }\n\n if (requestData.method) {\n attributes['http.request.method'] = requestData.method;\n }\n\n if (requestData.query_string) {\n attributes['url.query'] = normalizeQueryString(requestData.query_string);\n }\n\n safeSetSpanJSONAttributes(span, attributes);\n\n // Process cookies before headers so normalizedRequest.cookies takes precedence\n // over the raw cookie header (matching the processEvent path).\n if (requestData.cookies && Object.keys(requestData.cookies).length > 0) {\n const cookieString = Object.entries(requestData.cookies)\n .map(([name, value]) => `${name}=${value}`)\n .join('; ');\n const cookieAttributes = httpHeadersToSpanAttributes({ cookie: cookieString }, sendDefaultPii ?? false, 'request');\n safeSetSpanJSONAttributes(span, cookieAttributes);\n }\n\n if (requestData.headers) {\n const headerAttributes = httpHeadersToSpanAttributes(requestData.headers, sendDefaultPii ?? false, 'request');\n safeSetSpanJSONAttributes(span, headerAttributes);\n }\n\n if (requestData.data != null) {\n const serialized = typeof requestData.data === 'string' ? requestData.data : JSON.stringify(requestData.data);\n if (serialized) {\n safeSetSpanJSONAttributes(span, { 'http.request.body.data': serialized });\n }\n }\n\n if (include.ip) {\n const ip = (normalizedRequest.headers && getClientIPAddress(normalizedRequest.headers)) || ipAddress || undefined;\n if (ip) {\n safeSetSpanJSONAttributes(span, { [SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS]: ip });\n }\n }\n}\n\nfunction extractNormalizedRequestData(\n normalizedRequest: RequestEventData,\n include: RequestDataIncludeOptions,\n): RequestEventData {\n const requestData: RequestEventData = {};\n const headers = { ...normalizedRequest.headers };\n\n if (include.headers) {\n requestData.headers = headers;\n\n if (!include.cookies) {\n delete (headers as { cookie?: string }).cookie;\n }\n\n if (!include.ip) {\n const ipHeaderNamesLower = new Set(ipHeaderNames.map(name => name.toLowerCase()));\n for (const key of Object.keys(headers)) {\n if (ipHeaderNamesLower.has(key.toLowerCase())) {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete (headers as Record<string, unknown>)[key];\n }\n }\n }\n }\n\n requestData.method = normalizedRequest.method;\n\n if (include.url) {\n requestData.url = normalizedRequest.url;\n }\n\n if (include.cookies) {\n const cookies = normalizedRequest.cookies || (headers?.cookie ? parseCookie(headers.cookie) : undefined);\n requestData.cookies = cookies || {};\n }\n\n if (include.query_string) {\n requestData.query_string = normalizedRequest.query_string;\n }\n\n if (include.data) {\n requestData.data = normalizedRequest.data;\n }\n\n return requestData;\n}\n\nfunction normalizeQueryString(queryString: QueryParams): string | undefined {\n if (typeof queryString === 'string') {\n return queryString || undefined;\n }\n\n const pairs = Array.isArray(queryString) ? queryString : Object.entries(queryString);\n const result = pairs.map(([key, value]) => `${key}=${value}`).join('&');\n\n return result || undefined;\n}\n"],"names":[],"mappings":";;;;;;;;AA4BA;AACA,MAAM,eAAe,GAA8B;AACnD,EAAE,OAAO,EAAE,IAAI;AACf,EAAE,IAAI,EAAE,IAAI;AACZ,EAAE,OAAO,EAAE,IAAI;AACf,EAAE,YAAY,EAAE,IAAI;AACpB,EAAE,GAAG,EAAE,IAAI;AACX,CAAC;;AAED,MAAM,gBAAA,GAAmB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BAAA,CAAA,GAAA;AACA,EAAA;;AAEA,EAAA,IAAA,OAAA,CAAA,OAAA,EAAA;AACA,IAAA,MAAA,OAAA,GAAA,iBAAA,CAAA,OAAA,KAAA,OAAA,EAAA,MAAA,GAAA,WAAA,CAAA,OAAA,CAAA,MAAA,CAAA,GAAA,SAAA,CAAA;AACA,IAAA,WAAA,CAAA,OAAA,GAAA,OAAA,IAAA,EAAA;AACA,EAAA;;AAEA,EAAA,IAAA,OAAA,CAAA,YAAA,EAAA;AACA,IAAA,WAAA,CAAA,YAAA,GAAA,iBAAA,CAAA,YAAA;AACA,EAAA;;AAEA,EAAA,IAAA,OAAA,CAAA,IAAA,EAAA;AACA,IAAA,WAAA,CAAA,IAAA,GAAA,iBAAA,CAAA,IAAA;AACA,EAAA;;AAEA,EAAA,OAAA,WAAA;AACA;;AAEA,SAAA,oBAAA,CAAA,WAAA,EAAA;AACA,EAAA,IAAA,OAAA,WAAA,KAAA,QAAA,EAAA;AACA,IAAA,OAAA,WAAA,IAAA,SAAA;AACA,EAAA;;AAEA,EAAA,MAAA,KAAA,GAAA,KAAA,CAAA,OAAA,CAAA,WAAA,CAAA,GAAA,WAAA,GAAA,MAAA,CAAA,OAAA,CAAA,WAAA,CAAA;AACA,EAAA,MAAA,MAAA,GAAA,KAAA,CAAA,GAAA,CAAA,CAAA,CAAA,GAAA,EAAA,KAAA,CAAA,KAAA,CAAA,EAAA,GAAA,CAAA,CAAA,EAAA,KAAA,CAAA,CAAA,CAAA,CAAA,IAAA,CAAA,GAAA,CAAA;;AAEA,EAAA,OAAA,MAAA,IAAA,SAAA;AACA;;;;"}
@@ -1,13 +1,17 @@
1
1
  import { dsnToString } from '../utils/dsn.js';
2
2
  import { createEnvelope } from '../utils/envelope.js';
3
+ import { isBrowser } from '../utils/isBrowser.js';
3
4
 
4
5
  /**
5
6
  * Creates a log container envelope item for a list of logs.
6
7
  *
7
8
  * @param items - The logs to include in the envelope.
9
+ * @param inferUserData - If true, tells Relay to infer the end-user IP and User-Agent from the incoming request.
10
+ * Only emitted as `ingest_settings` in browser environments.
8
11
  * @returns The created log container envelope item.
9
12
  */
10
- function createLogContainerEnvelopeItem(items) {
13
+ function createLogContainerEnvelopeItem(items, inferUserData) {
14
+ const inferSetting = inferUserData ? 'auto' : 'never';
11
15
  return [
12
16
  {
13
17
  type: 'log',
@@ -15,6 +19,10 @@ function createLogContainerEnvelopeItem(items) {
15
19
  content_type: 'application/vnd.sentry.items.log+json',
16
20
  },
17
21
  {
22
+ version: 2,
23
+ ...(isBrowser() && {
24
+ ingest_settings: { infer_ip: inferSetting, infer_user_agent: inferSetting },
25
+ }),
18
26
  items,
19
27
  },
20
28
  ];
@@ -29,6 +37,7 @@ function createLogContainerEnvelopeItem(items) {
29
37
  * @param metadata - The metadata to include in the envelope.
30
38
  * @param tunnel - The tunnel to include in the envelope.
31
39
  * @param dsn - The DSN to include in the envelope.
40
+ * @param inferUserData - If true, tells Relay to infer the end-user IP and User-Agent from the incoming request.
32
41
  * @returns The created envelope.
33
42
  */
34
43
  function createLogEnvelope(
@@ -36,6 +45,7 @@ function createLogEnvelope(
36
45
  metadata,
37
46
  tunnel,
38
47
  dsn,
48
+ inferUserData,
39
49
  ) {
40
50
  const headers = {};
41
51
 
@@ -50,7 +60,7 @@ function createLogEnvelope(
50
60
  headers.dsn = dsnToString(dsn);
51
61
  }
52
62
 
53
- return createEnvelope(headers, [createLogContainerEnvelopeItem(logs)]);
63
+ return createEnvelope(headers, [createLogContainerEnvelopeItem(logs, inferUserData)]);
54
64
  }
55
65
 
56
66
  export { createLogContainerEnvelopeItem, createLogEnvelope };
@@ -1 +1 @@
1
- {"version":3,"file":"envelope.js","sources":["../../../src/logs/envelope.ts"],"sourcesContent":["import type { DsnComponents } from '../types-hoist/dsn';\nimport type { LogContainerItem, LogEnvelope } from '../types-hoist/envelope';\nimport type { SerializedLog } from '../types-hoist/log';\nimport type { SdkMetadata } from '../types-hoist/sdkmetadata';\nimport { dsnToString } from '../utils/dsn';\nimport { createEnvelope } from '../utils/envelope';\n\n/**\n * Creates a log container envelope item for a list of logs.\n *\n * @param items - The logs to include in the envelope.\n * @returns The created log container envelope item.\n */\nexport function createLogContainerEnvelopeItem(items: Array<SerializedLog>): LogContainerItem {\n return [\n {\n type: 'log',\n item_count: items.length,\n content_type: 'application/vnd.sentry.items.log+json',\n },\n {\n items,\n },\n ];\n}\n\n/**\n * Creates an envelope for a list of logs.\n *\n * Logs from multiple traces can be included in the same envelope.\n *\n * @param logs - The logs to include in the envelope.\n * @param metadata - The metadata to include in the envelope.\n * @param tunnel - The tunnel to include in the envelope.\n * @param dsn - The DSN to include in the envelope.\n * @returns The created envelope.\n */\nexport function createLogEnvelope(\n logs: Array<SerializedLog>,\n metadata?: SdkMetadata,\n tunnel?: string,\n dsn?: DsnComponents,\n): LogEnvelope {\n const headers: LogEnvelope[0] = {};\n\n if (metadata?.sdk) {\n headers.sdk = {\n name: metadata.sdk.name,\n version: metadata.sdk.version,\n };\n }\n\n if (!!tunnel && !!dsn) {\n headers.dsn = dsnToString(dsn);\n }\n\n return createEnvelope<LogEnvelope>(headers, [createLogContainerEnvelopeItem(logs)]);\n}\n"],"names":[],"mappings":";;;AAOA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,8BAA8B,CAAC,KAAK,EAA0C;AAC9F,EAAE,OAAO;AACT,IAAI;AACJ,MAAM,IAAI,EAAE,KAAK;AACjB,MAAM,UAAU,EAAE,KAAK,CAAC,MAAM;AAC9B,MAAM,YAAY,EAAE,uCAAuC;AAC3D,KAAK;AACL,IAAI;AACJ,MAAM,KAAK;AACX,KAAK;AACL,GAAG;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,iBAAiB;AACjC,EAAE,IAAI;AACN,EAAE,QAAQ;AACV,EAAE,MAAM;AACR,EAAE,GAAG;AACL,EAAe;AACf,EAAE,MAAM,OAAO,GAAmB,EAAE;;AAEpC,EAAE,IAAI,QAAQ,EAAE,GAAG,EAAE;AACrB,IAAI,OAAO,CAAC,GAAA,GAAM;AAClB,MAAM,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI;AAC7B,MAAM,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO;AACnC,KAAK;AACL,EAAE;;AAEF,EAAE,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,GAAG,EAAE;AACzB,IAAI,OAAO,CAAC,GAAA,GAAM,WAAW,CAAC,GAAG,CAAC;AAClC,EAAE;;AAEF,EAAE,OAAO,cAAc,CAAc,OAAO,EAAE,CAAC,8BAA8B,CAAC,IAAI,CAAC,CAAC,CAAC;AACrF;;;;"}
1
+ {"version":3,"file":"envelope.js","sources":["../../../src/logs/envelope.ts"],"sourcesContent":["import type { DsnComponents } from '../types-hoist/dsn';\nimport type { LogContainerItem, LogEnvelope } from '../types-hoist/envelope';\nimport type { SerializedLog } from '../types-hoist/log';\nimport type { SdkMetadata } from '../types-hoist/sdkmetadata';\nimport { dsnToString } from '../utils/dsn';\nimport { createEnvelope } from '../utils/envelope';\nimport { isBrowser } from '../utils/isBrowser';\n\n/**\n * Creates a log container envelope item for a list of logs.\n *\n * @param items - The logs to include in the envelope.\n * @param inferUserData - If true, tells Relay to infer the end-user IP and User-Agent from the incoming request.\n * Only emitted as `ingest_settings` in browser environments.\n * @returns The created log container envelope item.\n */\nexport function createLogContainerEnvelopeItem(items: Array<SerializedLog>, inferUserData?: boolean): LogContainerItem {\n const inferSetting = inferUserData ? 'auto' : 'never';\n return [\n {\n type: 'log',\n item_count: items.length,\n content_type: 'application/vnd.sentry.items.log+json',\n },\n {\n version: 2,\n ...(isBrowser() && {\n ingest_settings: { infer_ip: inferSetting, infer_user_agent: inferSetting },\n }),\n items,\n },\n ];\n}\n\n/**\n * Creates an envelope for a list of logs.\n *\n * Logs from multiple traces can be included in the same envelope.\n *\n * @param logs - The logs to include in the envelope.\n * @param metadata - The metadata to include in the envelope.\n * @param tunnel - The tunnel to include in the envelope.\n * @param dsn - The DSN to include in the envelope.\n * @param inferUserData - If true, tells Relay to infer the end-user IP and User-Agent from the incoming request.\n * @returns The created envelope.\n */\nexport function createLogEnvelope(\n logs: Array<SerializedLog>,\n metadata?: SdkMetadata,\n tunnel?: string,\n dsn?: DsnComponents,\n inferUserData?: boolean,\n): LogEnvelope {\n const headers: LogEnvelope[0] = {};\n\n if (metadata?.sdk) {\n headers.sdk = {\n name: metadata.sdk.name,\n version: metadata.sdk.version,\n };\n }\n\n if (!!tunnel && !!dsn) {\n headers.dsn = dsnToString(dsn);\n }\n\n return createEnvelope<LogEnvelope>(headers, [createLogContainerEnvelopeItem(logs, inferUserData)]);\n}\n"],"names":[],"mappings":";;;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,8BAA8B,CAAC,KAAK,EAAwB,aAAa,EAA8B;AACvH,EAAE,MAAM,YAAA,GAAe,gBAAgB,MAAA,GAAS,OAAO;AACvD,EAAE,OAAO;AACT,IAAI;AACJ,MAAM,IAAI,EAAE,KAAK;AACjB,MAAM,UAAU,EAAE,KAAK,CAAC,MAAM;AAC9B,MAAM,YAAY,EAAE,uCAAuC;AAC3D,KAAK;AACL,IAAI;AACJ,MAAM,OAAO,EAAE,CAAC;AAChB,MAAM,IAAI,SAAS,MAAM;AACzB,QAAQ,eAAe,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,gBAAgB,EAAE,YAAA,EAAc;AACnF,OAAO,CAAC;AACR,MAAM,KAAK;AACX,KAAK;AACL,GAAG;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,iBAAiB;AACjC,EAAE,IAAI;AACN,EAAE,QAAQ;AACV,EAAE,MAAM;AACR,EAAE,GAAG;AACL,EAAE,aAAa;AACf,EAAe;AACf,EAAE,MAAM,OAAO,GAAmB,EAAE;;AAEpC,EAAE,IAAI,QAAQ,EAAE,GAAG,EAAE;AACrB,IAAI,OAAO,CAAC,GAAA,GAAM;AAClB,MAAM,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI;AAC7B,MAAM,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO;AACnC,KAAK;AACL,EAAE;;AAEF,EAAE,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,GAAG,EAAE;AACzB,IAAI,OAAO,CAAC,GAAA,GAAM,WAAW,CAAC,GAAG,CAAC;AAClC,EAAE;;AAEF,EAAE,OAAO,cAAc,CAAc,OAAO,EAAE,CAAC,8BAA8B,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC;AACpG;;;;"}
@@ -186,7 +186,13 @@ function _INTERNAL_flushLogsBuffer(client, maybeLogBuffer) {
186
186
  }
187
187
 
188
188
  const clientOptions = client.getOptions();
189
- const envelope = createLogEnvelope(logBuffer, clientOptions._metadata, clientOptions.tunnel, client.getDsn());
189
+ const envelope = createLogEnvelope(
190
+ logBuffer,
191
+ clientOptions._metadata,
192
+ clientOptions.tunnel,
193
+ client.getDsn(),
194
+ clientOptions.sendDefaultPii,
195
+ );
190
196
 
191
197
  // Clear the log buffer after envelopes have been constructed.
192
198
  _getBufferMap().set(client, []);
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sources":["../../../src/logs/internal.ts"],"sourcesContent":["import { serializeAttributes } from '../attributes';\nimport { getGlobalSingleton } from '../carrier';\nimport type { Client } from '../client';\nimport { getClient, getCurrentScope, getIsolationScope } from '../currentScopes';\nimport { DEBUG_BUILD } from '../debug-build';\nimport type { Integration } from '../types-hoist/integration';\nimport type { Log, SerializedLog } from '../types-hoist/log';\nimport { consoleSandbox, debug } from '../utils/debug-logger';\nimport { isParameterizedString } from '../utils/is';\nimport { getCombinedScopeData } from '../utils/scopeData';\nimport { _getSpanForScope } from '../utils/spanOnScope';\nimport { timestampInSeconds } from '../utils/time';\nimport { getSequenceAttribute } from '../utils/timestampSequence';\nimport { _getTraceInfoFromScope } from '../utils/trace-info';\nimport { SEVERITY_TEXT_TO_SEVERITY_NUMBER } from './constants';\nimport { createLogEnvelope } from './envelope';\n\nconst MAX_LOG_BUFFER_SIZE = 100;\n\n/**\n * Sets a log attribute if the value exists and the attribute key is not already present.\n *\n * @param logAttributes - The log attributes object to modify.\n * @param key - The attribute key to set.\n * @param value - The value to set (only sets if truthy and key not present).\n * @param setEvenIfPresent - Whether to set the attribute if it is present. Defaults to true.\n */\nfunction setLogAttribute(\n logAttributes: Record<string, unknown>,\n key: string,\n value: unknown,\n setEvenIfPresent = true,\n): void {\n if (value && (!logAttributes[key] || setEvenIfPresent)) {\n logAttributes[key] = value;\n }\n}\n\n/**\n * Captures a serialized log event and adds it to the log buffer for the given client.\n *\n * @param client - A client. Uses the current client if not provided.\n * @param serializedLog - The serialized log event to capture.\n *\n * @experimental This method will experience breaking changes. This is not yet part of\n * the stable Sentry SDK API and can be changed or removed without warning.\n */\nexport function _INTERNAL_captureSerializedLog(client: Client, serializedLog: SerializedLog): void {\n const bufferMap = _getBufferMap();\n const logBuffer = _INTERNAL_getLogBuffer(client);\n\n if (logBuffer === undefined) {\n bufferMap.set(client, [serializedLog]);\n } else {\n if (logBuffer.length >= MAX_LOG_BUFFER_SIZE) {\n _INTERNAL_flushLogsBuffer(client, logBuffer);\n bufferMap.set(client, [serializedLog]);\n } else {\n bufferMap.set(client, [...logBuffer, serializedLog]);\n }\n }\n}\n\n/**\n * Captures a log event and sends it to Sentry.\n *\n * @param log - The log event to capture.\n * @param scope - A scope. Uses the current scope if not provided.\n * @param client - A client. Uses the current client if not provided.\n * @param captureSerializedLog - A function to capture the serialized log.\n *\n * @experimental This method will experience breaking changes. This is not yet part of\n * the stable Sentry SDK API and can be changed or removed without warning.\n */\nexport function _INTERNAL_captureLog(\n beforeLog: Log,\n currentScope = getCurrentScope(),\n captureSerializedLog: (client: Client, log: SerializedLog) => void = _INTERNAL_captureSerializedLog,\n): void {\n const client = currentScope?.getClient() ?? getClient();\n if (!client) {\n DEBUG_BUILD && debug.warn('No client available to capture log.');\n return;\n }\n\n const { release, environment, enableLogs = false, beforeSendLog } = client.getOptions();\n if (!enableLogs) {\n DEBUG_BUILD && debug.warn('logging option not enabled, log will not be captured.');\n return;\n }\n\n const [, traceContext] = _getTraceInfoFromScope(client, currentScope);\n\n const processedLogAttributes = {\n ...beforeLog.attributes,\n };\n\n const {\n user: { id, email, username },\n attributes: scopeAttributes = {},\n } = getCombinedScopeData(getIsolationScope(), currentScope);\n\n setLogAttribute(processedLogAttributes, 'user.id', id, false);\n setLogAttribute(processedLogAttributes, 'user.email', email, false);\n setLogAttribute(processedLogAttributes, 'user.name', username, false);\n\n setLogAttribute(processedLogAttributes, 'sentry.release', release);\n setLogAttribute(processedLogAttributes, 'sentry.environment', environment);\n\n const { name, version } = client.getSdkMetadata()?.sdk ?? {};\n setLogAttribute(processedLogAttributes, 'sentry.sdk.name', name);\n setLogAttribute(processedLogAttributes, 'sentry.sdk.version', version);\n\n const replay = client.getIntegrationByName<\n Integration & {\n getReplayId: (onlyIfSampled?: boolean) => string;\n getRecordingMode: () => 'session' | 'buffer' | undefined;\n }\n >('Replay');\n\n const replayId = replay?.getReplayId(true);\n setLogAttribute(processedLogAttributes, 'sentry.replay_id', replayId);\n\n if (replayId && replay?.getRecordingMode() === 'buffer') {\n // We send this so we can identify cases where the replayId is attached but the replay itself might not have been sent to Sentry\n setLogAttribute(processedLogAttributes, 'sentry._internal.replay_is_buffering', true);\n }\n\n const beforeLogMessage = beforeLog.message;\n if (isParameterizedString(beforeLogMessage)) {\n const { __sentry_template_string__, __sentry_template_values__ = [] } = beforeLogMessage;\n if (__sentry_template_values__?.length) {\n processedLogAttributes['sentry.message.template'] = __sentry_template_string__;\n }\n __sentry_template_values__.forEach((param, index) => {\n processedLogAttributes[`sentry.message.parameter.${index}`] = param;\n });\n }\n\n const span = _getSpanForScope(currentScope);\n // Add the parent span ID to the log attributes for trace context\n setLogAttribute(processedLogAttributes, 'sentry.trace.parent_span_id', span?.spanContext().spanId);\n\n const processedLog = { ...beforeLog, attributes: processedLogAttributes };\n\n client.emit('beforeCaptureLog', processedLog);\n\n // We need to wrap this in `consoleSandbox` to avoid recursive calls to `beforeSendLog`\n const log = beforeSendLog ? consoleSandbox(() => beforeSendLog(processedLog)) : processedLog;\n if (!log) {\n client.recordDroppedEvent('before_send', 'log_item', 1);\n DEBUG_BUILD && debug.warn('beforeSendLog returned null, log will not be captured.');\n return;\n }\n\n const { level, message, attributes: logAttributes = {}, severityNumber } = log;\n\n const timestamp = timestampInSeconds();\n const sequenceAttr = getSequenceAttribute(timestamp);\n\n const serializedLog: SerializedLog = {\n timestamp,\n level,\n body: message,\n trace_id: traceContext?.trace_id,\n severity_number: severityNumber ?? SEVERITY_TEXT_TO_SEVERITY_NUMBER[level],\n attributes: {\n ...serializeAttributes(scopeAttributes),\n ...serializeAttributes(logAttributes, true),\n [sequenceAttr.key]: sequenceAttr.value,\n },\n };\n\n captureSerializedLog(client, serializedLog);\n\n client.emit('afterCaptureLog', log);\n}\n\n/**\n * Flushes the logs buffer to Sentry.\n *\n * @param client - A client.\n * @param maybeLogBuffer - A log buffer. Uses the log buffer for the given client if not provided.\n *\n * @experimental This method will experience breaking changes. This is not yet part of\n * the stable Sentry SDK API and can be changed or removed without warning.\n */\nexport function _INTERNAL_flushLogsBuffer(client: Client, maybeLogBuffer?: Array<SerializedLog>): void {\n const logBuffer = maybeLogBuffer ?? _INTERNAL_getLogBuffer(client) ?? [];\n if (logBuffer.length === 0) {\n return;\n }\n\n const clientOptions = client.getOptions();\n const envelope = createLogEnvelope(logBuffer, clientOptions._metadata, clientOptions.tunnel, client.getDsn());\n\n // Clear the log buffer after envelopes have been constructed.\n _getBufferMap().set(client, []);\n\n client.emit('flushLogs');\n\n // sendEnvelope should not throw\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n client.sendEnvelope(envelope);\n}\n\n/**\n * Returns the log buffer for a given client.\n *\n * Exported for testing purposes.\n *\n * @param client - The client to get the log buffer for.\n * @returns The log buffer for the given client.\n */\nexport function _INTERNAL_getLogBuffer(client: Client): Array<SerializedLog> | undefined {\n return _getBufferMap().get(client);\n}\n\nfunction _getBufferMap(): WeakMap<Client, Array<SerializedLog>> {\n // The reference to the Client <> LogBuffer map is stored on the carrier to ensure it's always the same\n return getGlobalSingleton('clientToLogBufferMap', () => new WeakMap<Client, Array<SerializedLog>>());\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAiBA,MAAM,mBAAA,GAAsB,GAAG;;AAE/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,eAAe;AACxB,EAAE,aAAa;AACf,EAAE,GAAG;AACL,EAAE,KAAK;AACP,EAAE,gBAAA,GAAmB,IAAI;AACzB,EAAQ;AACR,EAAE,IAAI,KAAA,KAAU,CAAC,aAAa,CAAC,GAAG,CAAA,IAAK,gBAAgB,CAAC,EAAE;AAC1D,IAAI,aAAa,CAAC,GAAG,CAAA,GAAI,KAAK;AAC9B,EAAE;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,8BAA8B,CAAC,MAAM,EAAU,aAAa,EAAuB;AACnG,EAAE,MAAM,SAAA,GAAY,aAAa,EAAE;AACnC,EAAE,MAAM,SAAA,GAAY,sBAAsB,CAAC,MAAM,CAAC;;AAElD,EAAE,IAAI,SAAA,KAAc,SAAS,EAAE;AAC/B,IAAI,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,aAAa,CAAC,CAAC;AAC1C,EAAE,OAAO;AACT,IAAI,IAAI,SAAS,CAAC,MAAA,IAAU,mBAAmB,EAAE;AACjD,MAAM,yBAAyB,CAAC,MAAM,EAAE,SAAS,CAAC;AAClD,MAAM,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,aAAa,CAAC,CAAC;AAC5C,IAAI,OAAO;AACX,MAAM,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,SAAS,EAAE,aAAa,CAAC,CAAC;AAC1D,IAAI;AAC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;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,yBAAA,CAAA,MAAA,EAAA,cAAA,EAAA;AACA,EAAA,MAAA,SAAA,GAAA,cAAA,IAAA,sBAAA,CAAA,MAAA,CAAA,IAAA,EAAA;AACA,EAAA,IAAA,SAAA,CAAA,MAAA,KAAA,CAAA,EAAA;AACA,IAAA;AACA,EAAA;;AAEA,EAAA,MAAA,aAAA,GAAA,MAAA,CAAA,UAAA,EAAA;AACA,EAAA,MAAA,QAAA,GAAA,iBAAA,CAAA,SAAA,EAAA,aAAA,CAAA,SAAA,EAAA,aAAA,CAAA,MAAA,EAAA,MAAA,CAAA,MAAA,EAAA,CAAA;;AAEA;AACA,EAAA,aAAA,EAAA,CAAA,GAAA,CAAA,MAAA,EAAA,EAAA,CAAA;;AAEA,EAAA,MAAA,CAAA,IAAA,CAAA,WAAA,CAAA;;AAEA;AACA;AACA,EAAA,MAAA,CAAA,YAAA,CAAA,QAAA,CAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,sBAAA,CAAA,MAAA,EAAA;AACA,EAAA,OAAA,aAAA,EAAA,CAAA,GAAA,CAAA,MAAA,CAAA;AACA;;AAEA,SAAA,aAAA,GAAA;AACA;AACA,EAAA,OAAA,kBAAA,CAAA,sBAAA,EAAA,MAAA,IAAA,OAAA,EAAA,CAAA;AACA;;;;"}
1
+ {"version":3,"file":"internal.js","sources":["../../../src/logs/internal.ts"],"sourcesContent":["import { serializeAttributes } from '../attributes';\nimport { getGlobalSingleton } from '../carrier';\nimport type { Client } from '../client';\nimport { getClient, getCurrentScope, getIsolationScope } from '../currentScopes';\nimport { DEBUG_BUILD } from '../debug-build';\nimport type { Integration } from '../types-hoist/integration';\nimport type { Log, SerializedLog } from '../types-hoist/log';\nimport { consoleSandbox, debug } from '../utils/debug-logger';\nimport { isParameterizedString } from '../utils/is';\nimport { getCombinedScopeData } from '../utils/scopeData';\nimport { _getSpanForScope } from '../utils/spanOnScope';\nimport { timestampInSeconds } from '../utils/time';\nimport { getSequenceAttribute } from '../utils/timestampSequence';\nimport { _getTraceInfoFromScope } from '../utils/trace-info';\nimport { SEVERITY_TEXT_TO_SEVERITY_NUMBER } from './constants';\nimport { createLogEnvelope } from './envelope';\n\nconst MAX_LOG_BUFFER_SIZE = 100;\n\n/**\n * Sets a log attribute if the value exists and the attribute key is not already present.\n *\n * @param logAttributes - The log attributes object to modify.\n * @param key - The attribute key to set.\n * @param value - The value to set (only sets if truthy and key not present).\n * @param setEvenIfPresent - Whether to set the attribute if it is present. Defaults to true.\n */\nfunction setLogAttribute(\n logAttributes: Record<string, unknown>,\n key: string,\n value: unknown,\n setEvenIfPresent = true,\n): void {\n if (value && (!logAttributes[key] || setEvenIfPresent)) {\n logAttributes[key] = value;\n }\n}\n\n/**\n * Captures a serialized log event and adds it to the log buffer for the given client.\n *\n * @param client - A client. Uses the current client if not provided.\n * @param serializedLog - The serialized log event to capture.\n *\n * @experimental This method will experience breaking changes. This is not yet part of\n * the stable Sentry SDK API and can be changed or removed without warning.\n */\nexport function _INTERNAL_captureSerializedLog(client: Client, serializedLog: SerializedLog): void {\n const bufferMap = _getBufferMap();\n const logBuffer = _INTERNAL_getLogBuffer(client);\n\n if (logBuffer === undefined) {\n bufferMap.set(client, [serializedLog]);\n } else {\n if (logBuffer.length >= MAX_LOG_BUFFER_SIZE) {\n _INTERNAL_flushLogsBuffer(client, logBuffer);\n bufferMap.set(client, [serializedLog]);\n } else {\n bufferMap.set(client, [...logBuffer, serializedLog]);\n }\n }\n}\n\n/**\n * Captures a log event and sends it to Sentry.\n *\n * @param log - The log event to capture.\n * @param scope - A scope. Uses the current scope if not provided.\n * @param client - A client. Uses the current client if not provided.\n * @param captureSerializedLog - A function to capture the serialized log.\n *\n * @experimental This method will experience breaking changes. This is not yet part of\n * the stable Sentry SDK API and can be changed or removed without warning.\n */\nexport function _INTERNAL_captureLog(\n beforeLog: Log,\n currentScope = getCurrentScope(),\n captureSerializedLog: (client: Client, log: SerializedLog) => void = _INTERNAL_captureSerializedLog,\n): void {\n const client = currentScope?.getClient() ?? getClient();\n if (!client) {\n DEBUG_BUILD && debug.warn('No client available to capture log.');\n return;\n }\n\n const { release, environment, enableLogs = false, beforeSendLog } = client.getOptions();\n if (!enableLogs) {\n DEBUG_BUILD && debug.warn('logging option not enabled, log will not be captured.');\n return;\n }\n\n const [, traceContext] = _getTraceInfoFromScope(client, currentScope);\n\n const processedLogAttributes = {\n ...beforeLog.attributes,\n };\n\n const {\n user: { id, email, username },\n attributes: scopeAttributes = {},\n } = getCombinedScopeData(getIsolationScope(), currentScope);\n\n setLogAttribute(processedLogAttributes, 'user.id', id, false);\n setLogAttribute(processedLogAttributes, 'user.email', email, false);\n setLogAttribute(processedLogAttributes, 'user.name', username, false);\n\n setLogAttribute(processedLogAttributes, 'sentry.release', release);\n setLogAttribute(processedLogAttributes, 'sentry.environment', environment);\n\n const { name, version } = client.getSdkMetadata()?.sdk ?? {};\n setLogAttribute(processedLogAttributes, 'sentry.sdk.name', name);\n setLogAttribute(processedLogAttributes, 'sentry.sdk.version', version);\n\n const replay = client.getIntegrationByName<\n Integration & {\n getReplayId: (onlyIfSampled?: boolean) => string;\n getRecordingMode: () => 'session' | 'buffer' | undefined;\n }\n >('Replay');\n\n const replayId = replay?.getReplayId(true);\n setLogAttribute(processedLogAttributes, 'sentry.replay_id', replayId);\n\n if (replayId && replay?.getRecordingMode() === 'buffer') {\n // We send this so we can identify cases where the replayId is attached but the replay itself might not have been sent to Sentry\n setLogAttribute(processedLogAttributes, 'sentry._internal.replay_is_buffering', true);\n }\n\n const beforeLogMessage = beforeLog.message;\n if (isParameterizedString(beforeLogMessage)) {\n const { __sentry_template_string__, __sentry_template_values__ = [] } = beforeLogMessage;\n if (__sentry_template_values__?.length) {\n processedLogAttributes['sentry.message.template'] = __sentry_template_string__;\n }\n __sentry_template_values__.forEach((param, index) => {\n processedLogAttributes[`sentry.message.parameter.${index}`] = param;\n });\n }\n\n const span = _getSpanForScope(currentScope);\n // Add the parent span ID to the log attributes for trace context\n setLogAttribute(processedLogAttributes, 'sentry.trace.parent_span_id', span?.spanContext().spanId);\n\n const processedLog = { ...beforeLog, attributes: processedLogAttributes };\n\n client.emit('beforeCaptureLog', processedLog);\n\n // We need to wrap this in `consoleSandbox` to avoid recursive calls to `beforeSendLog`\n const log = beforeSendLog ? consoleSandbox(() => beforeSendLog(processedLog)) : processedLog;\n if (!log) {\n client.recordDroppedEvent('before_send', 'log_item', 1);\n DEBUG_BUILD && debug.warn('beforeSendLog returned null, log will not be captured.');\n return;\n }\n\n const { level, message, attributes: logAttributes = {}, severityNumber } = log;\n\n const timestamp = timestampInSeconds();\n const sequenceAttr = getSequenceAttribute(timestamp);\n\n const serializedLog: SerializedLog = {\n timestamp,\n level,\n body: message,\n trace_id: traceContext?.trace_id,\n severity_number: severityNumber ?? SEVERITY_TEXT_TO_SEVERITY_NUMBER[level],\n attributes: {\n ...serializeAttributes(scopeAttributes),\n ...serializeAttributes(logAttributes, true),\n [sequenceAttr.key]: sequenceAttr.value,\n },\n };\n\n captureSerializedLog(client, serializedLog);\n\n client.emit('afterCaptureLog', log);\n}\n\n/**\n * Flushes the logs buffer to Sentry.\n *\n * @param client - A client.\n * @param maybeLogBuffer - A log buffer. Uses the log buffer for the given client if not provided.\n *\n * @experimental This method will experience breaking changes. This is not yet part of\n * the stable Sentry SDK API and can be changed or removed without warning.\n */\nexport function _INTERNAL_flushLogsBuffer(client: Client, maybeLogBuffer?: Array<SerializedLog>): void {\n const logBuffer = maybeLogBuffer ?? _INTERNAL_getLogBuffer(client) ?? [];\n if (logBuffer.length === 0) {\n return;\n }\n\n const clientOptions = client.getOptions();\n const envelope = createLogEnvelope(\n logBuffer,\n clientOptions._metadata,\n clientOptions.tunnel,\n client.getDsn(),\n clientOptions.sendDefaultPii,\n );\n\n // Clear the log buffer after envelopes have been constructed.\n _getBufferMap().set(client, []);\n\n client.emit('flushLogs');\n\n // sendEnvelope should not throw\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n client.sendEnvelope(envelope);\n}\n\n/**\n * Returns the log buffer for a given client.\n *\n * Exported for testing purposes.\n *\n * @param client - The client to get the log buffer for.\n * @returns The log buffer for the given client.\n */\nexport function _INTERNAL_getLogBuffer(client: Client): Array<SerializedLog> | undefined {\n return _getBufferMap().get(client);\n}\n\nfunction _getBufferMap(): WeakMap<Client, Array<SerializedLog>> {\n // The reference to the Client <> LogBuffer map is stored on the carrier to ensure it's always the same\n return getGlobalSingleton('clientToLogBufferMap', () => new WeakMap<Client, Array<SerializedLog>>());\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAiBA,MAAM,mBAAA,GAAsB,GAAG;;AAE/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,eAAe;AACxB,EAAE,aAAa;AACf,EAAE,GAAG;AACL,EAAE,KAAK;AACP,EAAE,gBAAA,GAAmB,IAAI;AACzB,EAAQ;AACR,EAAE,IAAI,KAAA,KAAU,CAAC,aAAa,CAAC,GAAG,CAAA,IAAK,gBAAgB,CAAC,EAAE;AAC1D,IAAI,aAAa,CAAC,GAAG,CAAA,GAAI,KAAK;AAC9B,EAAE;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,8BAA8B,CAAC,MAAM,EAAU,aAAa,EAAuB;AACnG,EAAE,MAAM,SAAA,GAAY,aAAa,EAAE;AACnC,EAAE,MAAM,SAAA,GAAY,sBAAsB,CAAC,MAAM,CAAC;;AAElD,EAAE,IAAI,SAAA,KAAc,SAAS,EAAE;AAC/B,IAAI,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,aAAa,CAAC,CAAC;AAC1C,EAAE,OAAO;AACT,IAAI,IAAI,SAAS,CAAC,MAAA,IAAU,mBAAmB,EAAE;AACjD,MAAM,yBAAyB,CAAC,MAAM,EAAE,SAAS,CAAC;AAClD,MAAM,SAAS,CAAC,GAAG,CA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GAAA,GAAA,YAAA,CAAA,KAAA;AACA,KAAA;AACA,GAAA;;AAEA,EAAA,oBAAA,CAAA,MAAA,EAAA,aAAA,CAAA;;AAEA,EAAA,MAAA,CAAA,IAAA,CAAA,iBAAA,EAAA,GAAA,CAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,yBAAA,CAAA,MAAA,EAAA,cAAA,EAAA;AACA,EAAA,MAAA,SAAA,GAAA,cAAA,IAAA,sBAAA,CAAA,MAAA,CAAA,IAAA,EAAA;AACA,EAAA,IAAA,SAAA,CAAA,MAAA,KAAA,CAAA,EAAA;AACA,IAAA;AACA,EAAA;;AAEA,EAAA,MAAA,aAAA,GAAA,MAAA,CAAA,UAAA,EAAA;AACA,EAAA,MAAA,QAAA,GAAA,iBAAA;AACA,IAAA,SAAA;AACA,IAAA,aAAA,CAAA,SAAA;AACA,IAAA,aAAA,CAAA,MAAA;AACA,IAAA,MAAA,CAAA,MAAA,EAAA;AACA,IAAA,aAAA,CAAA,cAAA;AACA,GAAA;;AAEA;AACA,EAAA,aAAA,EAAA,CAAA,GAAA,CAAA,MAAA,EAAA,EAAA,CAAA;;AAEA,EAAA,MAAA,CAAA,IAAA,CAAA,WAAA,CAAA;;AAEA;AACA;AACA,EAAA,MAAA,CAAA,YAAA,CAAA,QAAA,CAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,sBAAA,CAAA,MAAA,EAAA;AACA,EAAA,OAAA,aAAA,EAAA,CAAA,GAAA,CAAA,MAAA,CAAA;AACA;;AAEA,SAAA,aAAA,GAAA;AACA;AACA,EAAA,OAAA,kBAAA,CAAA,sBAAA,EAAA,MAAA,IAAA,OAAA,EAAA,CAAA;AACA;;;;"}
@@ -1,13 +1,20 @@
1
1
  import { dsnToString } from '../utils/dsn.js';
2
2
  import { createEnvelope } from '../utils/envelope.js';
3
+ import { isBrowser } from '../utils/isBrowser.js';
3
4
 
4
5
  /**
5
6
  * Creates a metric container envelope item for a list of metrics.
6
7
  *
7
8
  * @param items - The metrics to include in the envelope.
9
+ * @param inferUserData - If true, tells Relay to infer the end-user IP and User-Agent from the incoming request.
10
+ * Only emitted as `ingest_settings` in browser environments.
8
11
  * @returns The created metric container envelope item.
9
12
  */
10
- function createMetricContainerEnvelopeItem(items) {
13
+ function createMetricContainerEnvelopeItem(
14
+ items,
15
+ inferUserData,
16
+ ) {
17
+ const inferSetting = inferUserData ? 'auto' : 'never';
11
18
  return [
12
19
  {
13
20
  type: 'trace_metric',
@@ -15,6 +22,10 @@ function createMetricContainerEnvelopeItem(items) {
15
22
  content_type: 'application/vnd.sentry.items.trace-metric+json',
16
23
  } ,
17
24
  {
25
+ version: 2,
26
+ ...(isBrowser() && {
27
+ ingest_settings: { infer_ip: inferSetting, infer_user_agent: inferSetting },
28
+ }),
18
29
  items,
19
30
  },
20
31
  ];
@@ -29,6 +40,7 @@ function createMetricContainerEnvelopeItem(items) {
29
40
  * @param metadata - The metadata to include in the envelope.
30
41
  * @param tunnel - The tunnel to include in the envelope.
31
42
  * @param dsn - The DSN to include in the envelope.
43
+ * @param inferUserData - If true, tells Relay to infer the end-user IP and User-Agent from the incoming request.
32
44
  * @returns The created envelope.
33
45
  */
34
46
  function createMetricEnvelope(
@@ -36,6 +48,7 @@ function createMetricEnvelope(
36
48
  metadata,
37
49
  tunnel,
38
50
  dsn,
51
+ inferUserData,
39
52
  ) {
40
53
  const headers = {};
41
54
 
@@ -50,7 +63,7 @@ function createMetricEnvelope(
50
63
  headers.dsn = dsnToString(dsn);
51
64
  }
52
65
 
53
- return createEnvelope(headers, [createMetricContainerEnvelopeItem(metrics)]);
66
+ return createEnvelope(headers, [createMetricContainerEnvelopeItem(metrics, inferUserData)]);
54
67
  }
55
68
 
56
69
  export { createMetricContainerEnvelopeItem, createMetricEnvelope };
@@ -1 +1 @@
1
- {"version":3,"file":"envelope.js","sources":["../../../src/metrics/envelope.ts"],"sourcesContent":["import type { DsnComponents } from '../types-hoist/dsn';\nimport type { MetricContainerItem, MetricEnvelope } from '../types-hoist/envelope';\nimport type { SerializedMetric } from '../types-hoist/metric';\nimport type { SdkMetadata } from '../types-hoist/sdkmetadata';\nimport { dsnToString } from '../utils/dsn';\nimport { createEnvelope } from '../utils/envelope';\n\n/**\n * Creates a metric container envelope item for a list of metrics.\n *\n * @param items - The metrics to include in the envelope.\n * @returns The created metric container envelope item.\n */\nexport function createMetricContainerEnvelopeItem(items: Array<SerializedMetric>): MetricContainerItem {\n return [\n {\n type: 'trace_metric',\n item_count: items.length,\n content_type: 'application/vnd.sentry.items.trace-metric+json',\n } as MetricContainerItem[0],\n {\n items,\n },\n ];\n}\n\n/**\n * Creates an envelope for a list of metrics.\n *\n * Metrics from multiple traces can be included in the same envelope.\n *\n * @param metrics - The metrics to include in the envelope.\n * @param metadata - The metadata to include in the envelope.\n * @param tunnel - The tunnel to include in the envelope.\n * @param dsn - The DSN to include in the envelope.\n * @returns The created envelope.\n */\nexport function createMetricEnvelope(\n metrics: Array<SerializedMetric>,\n metadata?: SdkMetadata,\n tunnel?: string,\n dsn?: DsnComponents,\n): MetricEnvelope {\n const headers: MetricEnvelope[0] = {};\n\n if (metadata?.sdk) {\n headers.sdk = {\n name: metadata.sdk.name,\n version: metadata.sdk.version,\n };\n }\n\n if (!!tunnel && !!dsn) {\n headers.dsn = dsnToString(dsn);\n }\n\n return createEnvelope<MetricEnvelope>(headers, [createMetricContainerEnvelopeItem(metrics)]);\n}\n"],"names":[],"mappings":";;;AAOA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,iCAAiC,CAAC,KAAK,EAAgD;AACvG,EAAE,OAAO;AACT,IAAI;AACJ,MAAM,IAAI,EAAE,cAAc;AAC1B,MAAM,UAAU,EAAE,KAAK,CAAC,MAAM;AAC9B,MAAM,YAAY,EAAE,gDAAgD;AACpE,KAAI;AACJ,IAAI;AACJ,MAAM,KAAK;AACX,KAAK;AACL,GAAG;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,oBAAoB;AACpC,EAAE,OAAO;AACT,EAAE,QAAQ;AACV,EAAE,MAAM;AACR,EAAE,GAAG;AACL,EAAkB;AAClB,EAAE,MAAM,OAAO,GAAsB,EAAE;;AAEvC,EAAE,IAAI,QAAQ,EAAE,GAAG,EAAE;AACrB,IAAI,OAAO,CAAC,GAAA,GAAM;AAClB,MAAM,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI;AAC7B,MAAM,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO;AACnC,KAAK;AACL,EAAE;;AAEF,EAAE,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,GAAG,EAAE;AACzB,IAAI,OAAO,CAAC,GAAA,GAAM,WAAW,CAAC,GAAG,CAAC;AAClC,EAAE;;AAEF,EAAE,OAAO,cAAc,CAAiB,OAAO,EAAE,CAAC,iCAAiC,CAAC,OAAO,CAAC,CAAC,CAAC;AAC9F;;;;"}
1
+ {"version":3,"file":"envelope.js","sources":["../../../src/metrics/envelope.ts"],"sourcesContent":["import type { DsnComponents } from '../types-hoist/dsn';\nimport type { MetricContainerItem, MetricEnvelope } from '../types-hoist/envelope';\nimport type { SerializedMetric } from '../types-hoist/metric';\nimport type { SdkMetadata } from '../types-hoist/sdkmetadata';\nimport { dsnToString } from '../utils/dsn';\nimport { createEnvelope } from '../utils/envelope';\nimport { isBrowser } from '../utils/isBrowser';\n\n/**\n * Creates a metric container envelope item for a list of metrics.\n *\n * @param items - The metrics to include in the envelope.\n * @param inferUserData - If true, tells Relay to infer the end-user IP and User-Agent from the incoming request.\n * Only emitted as `ingest_settings` in browser environments.\n * @returns The created metric container envelope item.\n */\nexport function createMetricContainerEnvelopeItem(\n items: Array<SerializedMetric>,\n inferUserData?: boolean,\n): MetricContainerItem {\n const inferSetting = inferUserData ? 'auto' : 'never';\n return [\n {\n type: 'trace_metric',\n item_count: items.length,\n content_type: 'application/vnd.sentry.items.trace-metric+json',\n } as MetricContainerItem[0],\n {\n version: 2,\n ...(isBrowser() && {\n ingest_settings: { infer_ip: inferSetting, infer_user_agent: inferSetting },\n }),\n items,\n },\n ];\n}\n\n/**\n * Creates an envelope for a list of metrics.\n *\n * Metrics from multiple traces can be included in the same envelope.\n *\n * @param metrics - The metrics to include in the envelope.\n * @param metadata - The metadata to include in the envelope.\n * @param tunnel - The tunnel to include in the envelope.\n * @param dsn - The DSN to include in the envelope.\n * @param inferUserData - If true, tells Relay to infer the end-user IP and User-Agent from the incoming request.\n * @returns The created envelope.\n */\nexport function createMetricEnvelope(\n metrics: Array<SerializedMetric>,\n metadata?: SdkMetadata,\n tunnel?: string,\n dsn?: DsnComponents,\n inferUserData?: boolean,\n): MetricEnvelope {\n const headers: MetricEnvelope[0] = {};\n\n if (metadata?.sdk) {\n headers.sdk = {\n name: metadata.sdk.name,\n version: metadata.sdk.version,\n };\n }\n\n if (!!tunnel && !!dsn) {\n headers.dsn = dsnToString(dsn);\n }\n\n return createEnvelope<MetricEnvelope>(headers, [createMetricContainerEnvelopeItem(metrics, inferUserData)]);\n}\n"],"names":[],"mappings":";;;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,iCAAiC;AACjD,EAAE,KAAK;AACP,EAAE,aAAa;AACf,EAAuB;AACvB,EAAE,MAAM,YAAA,GAAe,gBAAgB,MAAA,GAAS,OAAO;AACvD,EAAE,OAAO;AACT,IAAI;AACJ,MAAM,IAAI,EAAE,cAAc;AAC1B,MAAM,UAAU,EAAE,KAAK,CAAC,MAAM;AAC9B,MAAM,YAAY,EAAE,gDAAgD;AACpE,KAAI;AACJ,IAAI;AACJ,MAAM,OAAO,EAAE,CAAC;AAChB,MAAM,IAAI,SAAS,MAAM;AACzB,QAAQ,eAAe,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,gBAAgB,EAAE,YAAA,EAAc;AACnF,OAAO,CAAC;AACR,MAAM,KAAK;AACX,KAAK;AACL,GAAG;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,oBAAoB;AACpC,EAAE,OAAO;AACT,EAAE,QAAQ;AACV,EAAE,MAAM;AACR,EAAE,GAAG;AACL,EAAE,aAAa;AACf,EAAkB;AAClB,EAAE,MAAM,OAAO,GAAsB,EAAE;;AAEvC,EAAE,IAAI,QAAQ,EAAE,GAAG,EAAE;AACrB,IAAI,OAAO,CAAC,GAAA,GAAM;AAClB,MAAM,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI;AAC7B,MAAM,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO;AACnC,KAAK;AACL,EAAE;;AAEF,EAAE,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,GAAG,EAAE;AACzB,IAAI,OAAO,CAAC,GAAA,GAAM,WAAW,CAAC,GAAG,CAAC;AAClC,EAAE;;AAEF,EAAE,OAAO,cAAc,CAAiB,OAAO,EAAE,CAAC,iCAAiC,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC;AAC7G;;;;"}
@@ -206,7 +206,13 @@ function _INTERNAL_flushMetricsBuffer(client, maybeMetricBuffer) {
206
206
  }
207
207
 
208
208
  const clientOptions = client.getOptions();
209
- const envelope = createMetricEnvelope(metricBuffer, clientOptions._metadata, clientOptions.tunnel, client.getDsn());
209
+ const envelope = createMetricEnvelope(
210
+ metricBuffer,
211
+ clientOptions._metadata,
212
+ clientOptions.tunnel,
213
+ client.getDsn(),
214
+ clientOptions.sendDefaultPii,
215
+ );
210
216
 
211
217
  // Clear the metric buffer after envelopes have been constructed.
212
218
  _getBufferMap().set(client, []);