@sentry/core 10.47.0 → 10.49.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 (413) hide show
  1. package/build/cjs/attributes.js +43 -0
  2. package/build/cjs/attributes.js.map +1 -1
  3. package/build/cjs/client.js +13 -6
  4. package/build/cjs/client.js.map +1 -1
  5. package/build/cjs/envelope.js +4 -3
  6. package/build/cjs/envelope.js.map +1 -1
  7. package/build/cjs/fetch.js +36 -17
  8. package/build/cjs/fetch.js.map +1 -1
  9. package/build/cjs/index.js +53 -18
  10. package/build/cjs/index.js.map +1 -1
  11. package/build/cjs/integration.js +6 -0
  12. package/build/cjs/integration.js.map +1 -1
  13. package/build/cjs/integrations/conversationId.js +11 -0
  14. package/build/cjs/integrations/conversationId.js.map +1 -1
  15. package/build/cjs/integrations/express/index.js +243 -0
  16. package/build/cjs/integrations/express/index.js.map +1 -0
  17. package/build/cjs/integrations/express/patch-layer.js +257 -0
  18. package/build/cjs/integrations/express/patch-layer.js.map +1 -0
  19. package/build/cjs/integrations/express/request-layer-store.js +25 -0
  20. package/build/cjs/integrations/express/request-layer-store.js.map +1 -0
  21. package/build/cjs/integrations/express/set-sdk-processing-metadata.js +17 -0
  22. package/build/cjs/integrations/express/set-sdk-processing-metadata.js.map +1 -0
  23. package/build/cjs/integrations/express/types.js +17 -0
  24. package/build/cjs/integrations/express/types.js.map +1 -0
  25. package/build/cjs/integrations/express/utils.js +238 -0
  26. package/build/cjs/integrations/express/utils.js.map +1 -0
  27. package/build/cjs/integrations/mcp-server/correlation.js +5 -1
  28. package/build/cjs/integrations/mcp-server/correlation.js.map +1 -1
  29. package/build/cjs/integrations/mcp-server/handlers.js +18 -10
  30. package/build/cjs/integrations/mcp-server/handlers.js.map +1 -1
  31. package/build/cjs/integrations/mcp-server/index.js +2 -1
  32. package/build/cjs/integrations/mcp-server/index.js.map +1 -1
  33. package/build/cjs/integrations/mcp-server/transport.js +1 -1
  34. package/build/cjs/integrations/mcp-server/transport.js.map +1 -1
  35. package/build/cjs/integrations/mcp-server/validation.js +7 -5
  36. package/build/cjs/integrations/mcp-server/validation.js.map +1 -1
  37. package/build/cjs/integrations/requestdata.js.map +1 -1
  38. package/build/cjs/integrations/spanStreaming.js +48 -0
  39. package/build/cjs/integrations/spanStreaming.js.map +1 -0
  40. package/build/cjs/semanticAttributes.js +35 -3
  41. package/build/cjs/semanticAttributes.js.map +1 -1
  42. package/build/cjs/tracing/ai/gen-ai-attributes.js +3 -89
  43. package/build/cjs/tracing/ai/gen-ai-attributes.js.map +1 -1
  44. package/build/cjs/tracing/ai/utils.js +74 -0
  45. package/build/cjs/tracing/ai/utils.js.map +1 -1
  46. package/build/cjs/tracing/anthropic-ai/index.js +6 -17
  47. package/build/cjs/tracing/anthropic-ai/index.js.map +1 -1
  48. package/build/cjs/tracing/anthropic-ai/streaming.js +2 -100
  49. package/build/cjs/tracing/anthropic-ai/streaming.js.map +1 -1
  50. package/build/cjs/tracing/anthropic-ai/utils.js +4 -2
  51. package/build/cjs/tracing/anthropic-ai/utils.js.map +1 -1
  52. package/build/cjs/tracing/dynamicSamplingContext.js +2 -1
  53. package/build/cjs/tracing/dynamicSamplingContext.js.map +1 -1
  54. package/build/cjs/tracing/google-genai/constants.js +1 -6
  55. package/build/cjs/tracing/google-genai/constants.js.map +1 -1
  56. package/build/cjs/tracing/google-genai/index.js +40 -35
  57. package/build/cjs/tracing/google-genai/index.js.map +1 -1
  58. package/build/cjs/tracing/google-genai/streaming.js +2 -23
  59. package/build/cjs/tracing/google-genai/streaming.js.map +1 -1
  60. package/build/cjs/tracing/langchain/embeddings.js +132 -0
  61. package/build/cjs/tracing/langchain/embeddings.js.map +1 -0
  62. package/build/cjs/tracing/langchain/index.js +3 -0
  63. package/build/cjs/tracing/langchain/index.js.map +1 -1
  64. package/build/cjs/tracing/langchain/utils.js +12 -4
  65. package/build/cjs/tracing/langchain/utils.js.map +1 -1
  66. package/build/cjs/tracing/langgraph/index.js +4 -3
  67. package/build/cjs/tracing/langgraph/index.js.map +1 -1
  68. package/build/cjs/tracing/openai/index.js +14 -34
  69. package/build/cjs/tracing/openai/index.js.map +1 -1
  70. package/build/cjs/tracing/openai/streaming.js +3 -34
  71. package/build/cjs/tracing/openai/streaming.js.map +1 -1
  72. package/build/cjs/tracing/openai/utils.js +78 -204
  73. package/build/cjs/tracing/openai/utils.js.map +1 -1
  74. package/build/cjs/tracing/sentryNonRecordingSpan.js +7 -0
  75. package/build/cjs/tracing/sentryNonRecordingSpan.js.map +1 -1
  76. package/build/cjs/tracing/sentrySpan.js +39 -0
  77. package/build/cjs/tracing/sentrySpan.js.map +1 -1
  78. package/build/cjs/tracing/spans/beforeSendSpan.js +43 -0
  79. package/build/cjs/tracing/spans/beforeSendSpan.js.map +1 -0
  80. package/build/cjs/tracing/spans/captureSpan.js +126 -0
  81. package/build/cjs/tracing/spans/captureSpan.js.map +1 -0
  82. package/build/cjs/tracing/spans/envelope.js +38 -0
  83. package/build/cjs/tracing/spans/envelope.js.map +1 -0
  84. package/build/cjs/tracing/spans/estimateSize.js +41 -0
  85. package/build/cjs/tracing/spans/estimateSize.js.map +1 -0
  86. package/build/cjs/tracing/spans/hasSpanStreamingEnabled.js +11 -0
  87. package/build/cjs/tracing/spans/hasSpanStreamingEnabled.js.map +1 -0
  88. package/build/cjs/tracing/spans/spanBuffer.js +158 -0
  89. package/build/cjs/tracing/spans/spanBuffer.js.map +1 -0
  90. package/build/cjs/tracing/trace.js +83 -13
  91. package/build/cjs/tracing/trace.js.map +1 -1
  92. package/build/cjs/tracing/utils.js +3 -37
  93. package/build/cjs/tracing/utils.js.map +1 -1
  94. package/build/cjs/tracing/vercel-ai/constants.js +15 -23
  95. package/build/cjs/tracing/vercel-ai/constants.js.map +1 -1
  96. package/build/cjs/tracing/vercel-ai/index.js +32 -45
  97. package/build/cjs/tracing/vercel-ai/index.js.map +1 -1
  98. package/build/cjs/tracing/vercel-ai/utils.js +11 -42
  99. package/build/cjs/tracing/vercel-ai/utils.js.map +1 -1
  100. package/build/cjs/tracing/vercel-ai/vercel-ai-attributes.js +4 -1
  101. package/build/cjs/tracing/vercel-ai/vercel-ai-attributes.js.map +1 -1
  102. package/build/cjs/utils/browser.js +2 -3
  103. package/build/cjs/utils/browser.js.map +1 -1
  104. package/build/cjs/utils/featureFlags.js +6 -0
  105. package/build/cjs/utils/featureFlags.js.map +1 -1
  106. package/build/cjs/utils/object.js +33 -0
  107. package/build/cjs/utils/object.js.map +1 -1
  108. package/build/cjs/utils/spanUtils.js +116 -13
  109. package/build/cjs/utils/spanUtils.js.map +1 -1
  110. package/build/cjs/utils/stacktrace.js +3 -1
  111. package/build/cjs/utils/stacktrace.js.map +1 -1
  112. package/build/cjs/utils/string.js +3 -0
  113. package/build/cjs/utils/string.js.map +1 -1
  114. package/build/cjs/utils/version.js +1 -1
  115. package/build/cjs/utils/weakRef.js +62 -0
  116. package/build/cjs/utils/weakRef.js.map +1 -0
  117. package/build/esm/attributes.js +43 -1
  118. package/build/esm/attributes.js.map +1 -1
  119. package/build/esm/client.js +8 -1
  120. package/build/esm/client.js.map +1 -1
  121. package/build/esm/envelope.js +2 -1
  122. package/build/esm/envelope.js.map +1 -1
  123. package/build/esm/fetch.js +36 -17
  124. package/build/esm/fetch.js.map +1 -1
  125. package/build/esm/index.js +12 -3
  126. package/build/esm/index.js.map +1 -1
  127. package/build/esm/integration.js +6 -0
  128. package/build/esm/integration.js.map +1 -1
  129. package/build/esm/integrations/conversationId.js +11 -0
  130. package/build/esm/integrations/conversationId.js.map +1 -1
  131. package/build/esm/integrations/express/index.js +239 -0
  132. package/build/esm/integrations/express/index.js.map +1 -0
  133. package/build/esm/integrations/express/patch-layer.js +255 -0
  134. package/build/esm/integrations/express/patch-layer.js.map +1 -0
  135. package/build/esm/integrations/express/request-layer-store.js +22 -0
  136. package/build/esm/integrations/express/request-layer-store.js.map +1 -0
  137. package/build/esm/integrations/express/set-sdk-processing-metadata.js +15 -0
  138. package/build/esm/integrations/express/set-sdk-processing-metadata.js.map +1 -0
  139. package/build/esm/integrations/express/types.js +10 -0
  140. package/build/esm/integrations/express/types.js.map +1 -0
  141. package/build/esm/integrations/express/utils.js +225 -0
  142. package/build/esm/integrations/express/utils.js.map +1 -0
  143. package/build/esm/integrations/mcp-server/correlation.js +5 -1
  144. package/build/esm/integrations/mcp-server/correlation.js.map +1 -1
  145. package/build/esm/integrations/mcp-server/handlers.js +18 -10
  146. package/build/esm/integrations/mcp-server/handlers.js.map +1 -1
  147. package/build/esm/integrations/mcp-server/index.js +2 -1
  148. package/build/esm/integrations/mcp-server/index.js.map +1 -1
  149. package/build/esm/integrations/mcp-server/transport.js +1 -1
  150. package/build/esm/integrations/mcp-server/transport.js.map +1 -1
  151. package/build/esm/integrations/mcp-server/validation.js +7 -5
  152. package/build/esm/integrations/mcp-server/validation.js.map +1 -1
  153. package/build/esm/integrations/requestdata.js.map +1 -1
  154. package/build/esm/integrations/spanStreaming.js +46 -0
  155. package/build/esm/integrations/spanStreaming.js.map +1 -0
  156. package/build/esm/package.json +1 -1
  157. package/build/esm/semanticAttributes.js +26 -4
  158. package/build/esm/semanticAttributes.js.map +1 -1
  159. package/build/esm/tracing/ai/gen-ai-attributes.js +3 -76
  160. package/build/esm/tracing/ai/gen-ai-attributes.js.map +1 -1
  161. package/build/esm/tracing/ai/utils.js +73 -2
  162. package/build/esm/tracing/ai/utils.js.map +1 -1
  163. package/build/esm/tracing/anthropic-ai/index.js +8 -19
  164. package/build/esm/tracing/anthropic-ai/index.js.map +1 -1
  165. package/build/esm/tracing/anthropic-ai/streaming.js +3 -101
  166. package/build/esm/tracing/anthropic-ai/streaming.js.map +1 -1
  167. package/build/esm/tracing/anthropic-ai/utils.js +5 -3
  168. package/build/esm/tracing/anthropic-ai/utils.js.map +1 -1
  169. package/build/esm/tracing/dynamicSamplingContext.js +2 -1
  170. package/build/esm/tracing/dynamicSamplingContext.js.map +1 -1
  171. package/build/esm/tracing/google-genai/constants.js +2 -5
  172. package/build/esm/tracing/google-genai/constants.js.map +1 -1
  173. package/build/esm/tracing/google-genai/index.js +42 -37
  174. package/build/esm/tracing/google-genai/index.js.map +1 -1
  175. package/build/esm/tracing/google-genai/streaming.js +2 -23
  176. package/build/esm/tracing/google-genai/streaming.js.map +1 -1
  177. package/build/esm/tracing/langchain/embeddings.js +129 -0
  178. package/build/esm/tracing/langchain/embeddings.js.map +1 -0
  179. package/build/esm/tracing/langchain/index.js +4 -1
  180. package/build/esm/tracing/langchain/index.js.map +1 -1
  181. package/build/esm/tracing/langchain/utils.js +13 -5
  182. package/build/esm/tracing/langchain/utils.js.map +1 -1
  183. package/build/esm/tracing/langgraph/index.js +5 -4
  184. package/build/esm/tracing/langgraph/index.js.map +1 -1
  185. package/build/esm/tracing/openai/index.js +16 -36
  186. package/build/esm/tracing/openai/index.js.map +1 -1
  187. package/build/esm/tracing/openai/streaming.js +4 -35
  188. package/build/esm/tracing/openai/streaming.js.map +1 -1
  189. package/build/esm/tracing/openai/utils.js +79 -196
  190. package/build/esm/tracing/openai/utils.js.map +1 -1
  191. package/build/esm/tracing/sentryNonRecordingSpan.js +7 -0
  192. package/build/esm/tracing/sentryNonRecordingSpan.js.map +1 -1
  193. package/build/esm/tracing/sentrySpan.js +40 -1
  194. package/build/esm/tracing/sentrySpan.js.map +1 -1
  195. package/build/esm/tracing/spans/beforeSendSpan.js +40 -0
  196. package/build/esm/tracing/spans/beforeSendSpan.js.map +1 -0
  197. package/build/esm/tracing/spans/captureSpan.js +122 -0
  198. package/build/esm/tracing/spans/captureSpan.js.map +1 -0
  199. package/build/esm/tracing/spans/envelope.js +36 -0
  200. package/build/esm/tracing/spans/envelope.js.map +1 -0
  201. package/build/esm/tracing/spans/estimateSize.js +39 -0
  202. package/build/esm/tracing/spans/estimateSize.js.map +1 -0
  203. package/build/esm/tracing/spans/hasSpanStreamingEnabled.js +9 -0
  204. package/build/esm/tracing/spans/hasSpanStreamingEnabled.js.map +1 -0
  205. package/build/esm/tracing/spans/spanBuffer.js +156 -0
  206. package/build/esm/tracing/spans/spanBuffer.js.map +1 -0
  207. package/build/esm/tracing/trace.js +84 -14
  208. package/build/esm/tracing/trace.js.map +1 -1
  209. package/build/esm/tracing/utils.js +3 -37
  210. package/build/esm/tracing/utils.js.map +1 -1
  211. package/build/esm/tracing/vercel-ai/constants.js +15 -19
  212. package/build/esm/tracing/vercel-ai/constants.js.map +1 -1
  213. package/build/esm/tracing/vercel-ai/index.js +29 -42
  214. package/build/esm/tracing/vercel-ai/index.js.map +1 -1
  215. package/build/esm/tracing/vercel-ai/utils.js +14 -44
  216. package/build/esm/tracing/vercel-ai/utils.js.map +1 -1
  217. package/build/esm/tracing/vercel-ai/vercel-ai-attributes.js +4 -1
  218. package/build/esm/tracing/vercel-ai/vercel-ai-attributes.js.map +1 -1
  219. package/build/esm/utils/browser.js +2 -3
  220. package/build/esm/utils/browser.js.map +1 -1
  221. package/build/esm/utils/featureFlags.js +6 -0
  222. package/build/esm/utils/featureFlags.js.map +1 -1
  223. package/build/esm/utils/object.js +33 -1
  224. package/build/esm/utils/object.js.map +1 -1
  225. package/build/esm/utils/spanUtils.js +112 -14
  226. package/build/esm/utils/spanUtils.js.map +1 -1
  227. package/build/esm/utils/stacktrace.js +3 -1
  228. package/build/esm/utils/stacktrace.js.map +1 -1
  229. package/build/esm/utils/string.js +3 -0
  230. package/build/esm/utils/string.js.map +1 -1
  231. package/build/esm/utils/version.js +1 -1
  232. package/build/esm/utils/weakRef.js +59 -0
  233. package/build/esm/utils/weakRef.js.map +1 -0
  234. package/build/types/attributes.d.ts +5 -0
  235. package/build/types/attributes.d.ts.map +1 -1
  236. package/build/types/build-time-plugins/buildTimeOptionsBase.d.ts +13 -0
  237. package/build/types/build-time-plugins/buildTimeOptionsBase.d.ts.map +1 -1
  238. package/build/types/client.d.ts +35 -1
  239. package/build/types/client.d.ts.map +1 -1
  240. package/build/types/envelope.d.ts.map +1 -1
  241. package/build/types/fetch.d.ts +12 -8
  242. package/build/types/fetch.d.ts.map +1 -1
  243. package/build/types/index.d.ts +16 -5
  244. package/build/types/index.d.ts.map +1 -1
  245. package/build/types/integration.d.ts.map +1 -1
  246. package/build/types/integrations/conversationId.d.ts.map +1 -1
  247. package/build/types/integrations/express/index.d.ts +82 -0
  248. package/build/types/integrations/express/index.d.ts.map +1 -0
  249. package/build/types/integrations/express/patch-layer.d.ts +32 -0
  250. package/build/types/integrations/express/patch-layer.d.ts.map +1 -0
  251. package/build/types/integrations/express/request-layer-store.d.ts +32 -0
  252. package/build/types/integrations/express/request-layer-store.d.ts.map +1 -0
  253. package/build/types/integrations/express/set-sdk-processing-metadata.d.ts +35 -0
  254. package/build/types/integrations/express/set-sdk-processing-metadata.d.ts.map +1 -0
  255. package/build/types/integrations/express/types.d.ts +158 -0
  256. package/build/types/integrations/express/types.d.ts.map +1 -0
  257. package/build/types/integrations/express/utils.d.ts +93 -0
  258. package/build/types/integrations/express/utils.d.ts.map +1 -0
  259. package/build/types/integrations/mcp-server/correlation.d.ts +2 -1
  260. package/build/types/integrations/mcp-server/correlation.d.ts.map +1 -1
  261. package/build/types/integrations/mcp-server/handlers.d.ts +9 -4
  262. package/build/types/integrations/mcp-server/handlers.d.ts.map +1 -1
  263. package/build/types/integrations/mcp-server/index.d.ts +2 -1
  264. package/build/types/integrations/mcp-server/index.d.ts.map +1 -1
  265. package/build/types/integrations/mcp-server/types.d.ts +40 -7
  266. package/build/types/integrations/mcp-server/types.d.ts.map +1 -1
  267. package/build/types/integrations/mcp-server/validation.d.ts +4 -1
  268. package/build/types/integrations/mcp-server/validation.d.ts.map +1 -1
  269. package/build/types/integrations/requestdata.d.ts.map +1 -1
  270. package/build/types/integrations/spanStreaming.d.ts +2 -0
  271. package/build/types/integrations/spanStreaming.d.ts.map +1 -0
  272. package/build/types/semanticAttributes.d.ts +23 -3
  273. package/build/types/semanticAttributes.d.ts.map +1 -1
  274. package/build/types/tracing/ai/gen-ai-attributes.d.ts +4 -44
  275. package/build/types/tracing/ai/gen-ai-attributes.d.ts.map +1 -1
  276. package/build/types/tracing/ai/utils.d.ts +32 -2
  277. package/build/types/tracing/ai/utils.d.ts.map +1 -1
  278. package/build/types/tracing/anthropic-ai/index.d.ts.map +1 -1
  279. package/build/types/tracing/anthropic-ai/streaming.d.ts.map +1 -1
  280. package/build/types/tracing/anthropic-ai/types.d.ts +5 -0
  281. package/build/types/tracing/anthropic-ai/types.d.ts.map +1 -1
  282. package/build/types/tracing/anthropic-ai/utils.d.ts +1 -1
  283. package/build/types/tracing/anthropic-ai/utils.d.ts.map +1 -1
  284. package/build/types/tracing/dynamicSamplingContext.d.ts.map +1 -1
  285. package/build/types/tracing/google-genai/constants.d.ts +1 -3
  286. package/build/types/tracing/google-genai/constants.d.ts.map +1 -1
  287. package/build/types/tracing/google-genai/index.d.ts.map +1 -1
  288. package/build/types/tracing/google-genai/streaming.d.ts.map +1 -1
  289. package/build/types/tracing/google-genai/types.d.ts +5 -0
  290. package/build/types/tracing/google-genai/types.d.ts.map +1 -1
  291. package/build/types/tracing/index.d.ts +1 -0
  292. package/build/types/tracing/index.d.ts.map +1 -1
  293. package/build/types/tracing/langchain/embeddings.d.ts +27 -0
  294. package/build/types/tracing/langchain/embeddings.d.ts.map +1 -0
  295. package/build/types/tracing/langchain/index.d.ts +1 -0
  296. package/build/types/tracing/langchain/index.d.ts.map +1 -1
  297. package/build/types/tracing/langchain/types.d.ts +5 -0
  298. package/build/types/tracing/langchain/types.d.ts.map +1 -1
  299. package/build/types/tracing/langchain/utils.d.ts +2 -2
  300. package/build/types/tracing/langchain/utils.d.ts.map +1 -1
  301. package/build/types/tracing/langgraph/index.d.ts.map +1 -1
  302. package/build/types/tracing/langgraph/types.d.ts +5 -0
  303. package/build/types/tracing/langgraph/types.d.ts.map +1 -1
  304. package/build/types/tracing/openai/index.d.ts.map +1 -1
  305. package/build/types/tracing/openai/streaming.d.ts.map +1 -1
  306. package/build/types/tracing/openai/types.d.ts +5 -0
  307. package/build/types/tracing/openai/types.d.ts.map +1 -1
  308. package/build/types/tracing/openai/utils.d.ts +4 -49
  309. package/build/types/tracing/openai/utils.d.ts.map +1 -1
  310. package/build/types/tracing/sentryNonRecordingSpan.d.ts +12 -1
  311. package/build/types/tracing/sentryNonRecordingSpan.d.ts.map +1 -1
  312. package/build/types/tracing/sentrySpan.d.ts +10 -1
  313. package/build/types/tracing/sentrySpan.d.ts.map +1 -1
  314. package/build/types/tracing/spans/beforeSendSpan.d.ts +35 -0
  315. package/build/types/tracing/spans/beforeSendSpan.d.ts.map +1 -0
  316. package/build/types/tracing/spans/captureSpan.d.ts +26 -0
  317. package/build/types/tracing/spans/captureSpan.d.ts.map +1 -0
  318. package/build/types/tracing/spans/envelope.d.ts +8 -0
  319. package/build/types/tracing/spans/envelope.d.ts.map +1 -0
  320. package/build/types/tracing/spans/estimateSize.d.ts +12 -0
  321. package/build/types/tracing/spans/estimateSize.d.ts.map +1 -0
  322. package/build/types/tracing/spans/hasSpanStreamingEnabled.d.ts +6 -0
  323. package/build/types/tracing/spans/hasSpanStreamingEnabled.d.ts.map +1 -0
  324. package/build/types/tracing/spans/spanBuffer.d.ts +60 -0
  325. package/build/types/tracing/spans/spanBuffer.d.ts.map +1 -0
  326. package/build/types/tracing/trace.d.ts.map +1 -1
  327. package/build/types/tracing/utils.d.ts.map +1 -1
  328. package/build/types/tracing/vercel-ai/constants.d.ts +2 -5
  329. package/build/types/tracing/vercel-ai/constants.d.ts.map +1 -1
  330. package/build/types/tracing/vercel-ai/index.d.ts.map +1 -1
  331. package/build/types/tracing/vercel-ai/utils.d.ts +1 -5
  332. package/build/types/tracing/vercel-ai/utils.d.ts.map +1 -1
  333. package/build/types/tracing/vercel-ai/vercel-ai-attributes.d.ts +0 -480
  334. package/build/types/tracing/vercel-ai/vercel-ai-attributes.d.ts.map +1 -1
  335. package/build/types/types-hoist/envelope.d.ts +22 -2
  336. package/build/types/types-hoist/envelope.d.ts.map +1 -1
  337. package/build/types/types-hoist/integration.d.ts +8 -0
  338. package/build/types/types-hoist/integration.d.ts.map +1 -1
  339. package/build/types/types-hoist/link.d.ts +2 -2
  340. package/build/types/types-hoist/link.d.ts.map +1 -1
  341. package/build/types/types-hoist/options.d.ts +26 -2
  342. package/build/types/types-hoist/options.d.ts.map +1 -1
  343. package/build/types/types-hoist/span.d.ts +35 -0
  344. package/build/types/types-hoist/span.d.ts.map +1 -1
  345. package/build/types/types-hoist/view-hierarchy.d.ts +1 -0
  346. package/build/types/types-hoist/view-hierarchy.d.ts.map +1 -1
  347. package/build/types/utils/browser.d.ts +1 -1
  348. package/build/types/utils/browser.d.ts.map +1 -1
  349. package/build/types/utils/featureFlags.d.ts.map +1 -1
  350. package/build/types/utils/object.d.ts +10 -0
  351. package/build/types/utils/object.d.ts.map +1 -1
  352. package/build/types/utils/spanUtils.d.ts +27 -2
  353. package/build/types/utils/spanUtils.d.ts.map +1 -1
  354. package/build/types/utils/stacktrace.d.ts.map +1 -1
  355. package/build/types/utils/string.d.ts +2 -2
  356. package/build/types/utils/string.d.ts.map +1 -1
  357. package/build/types/utils/weakRef.d.ts +34 -0
  358. package/build/types/utils/weakRef.d.ts.map +1 -0
  359. package/build/types-ts3.8/attributes.d.ts +5 -0
  360. package/build/types-ts3.8/build-time-plugins/buildTimeOptionsBase.d.ts +13 -0
  361. package/build/types-ts3.8/client.d.ts +35 -1
  362. package/build/types-ts3.8/fetch.d.ts +14 -10
  363. package/build/types-ts3.8/index.d.ts +16 -5
  364. package/build/types-ts3.8/integrations/express/index.d.ts +82 -0
  365. package/build/types-ts3.8/integrations/express/patch-layer.d.ts +32 -0
  366. package/build/types-ts3.8/integrations/express/request-layer-store.d.ts +32 -0
  367. package/build/types-ts3.8/integrations/express/set-sdk-processing-metadata.d.ts +35 -0
  368. package/build/types-ts3.8/integrations/express/types.d.ts +158 -0
  369. package/build/types-ts3.8/integrations/express/utils.d.ts +96 -0
  370. package/build/types-ts3.8/integrations/mcp-server/correlation.d.ts +2 -1
  371. package/build/types-ts3.8/integrations/mcp-server/handlers.d.ts +9 -4
  372. package/build/types-ts3.8/integrations/mcp-server/index.d.ts +2 -1
  373. package/build/types-ts3.8/integrations/mcp-server/types.d.ts +40 -7
  374. package/build/types-ts3.8/integrations/mcp-server/validation.d.ts +4 -1
  375. package/build/types-ts3.8/integrations/spanStreaming.d.ts +2 -0
  376. package/build/types-ts3.8/semanticAttributes.d.ts +23 -3
  377. package/build/types-ts3.8/tracing/ai/gen-ai-attributes.d.ts +4 -44
  378. package/build/types-ts3.8/tracing/ai/utils.d.ts +32 -2
  379. package/build/types-ts3.8/tracing/anthropic-ai/types.d.ts +5 -0
  380. package/build/types-ts3.8/tracing/anthropic-ai/utils.d.ts +1 -1
  381. package/build/types-ts3.8/tracing/google-genai/constants.d.ts +1 -3
  382. package/build/types-ts3.8/tracing/google-genai/types.d.ts +5 -0
  383. package/build/types-ts3.8/tracing/index.d.ts +1 -0
  384. package/build/types-ts3.8/tracing/langchain/embeddings.d.ts +27 -0
  385. package/build/types-ts3.8/tracing/langchain/index.d.ts +1 -0
  386. package/build/types-ts3.8/tracing/langchain/types.d.ts +5 -0
  387. package/build/types-ts3.8/tracing/langchain/utils.d.ts +2 -2
  388. package/build/types-ts3.8/tracing/langgraph/types.d.ts +5 -0
  389. package/build/types-ts3.8/tracing/openai/types.d.ts +5 -0
  390. package/build/types-ts3.8/tracing/openai/utils.d.ts +4 -49
  391. package/build/types-ts3.8/tracing/sentryNonRecordingSpan.d.ts +12 -1
  392. package/build/types-ts3.8/tracing/sentrySpan.d.ts +10 -1
  393. package/build/types-ts3.8/tracing/spans/beforeSendSpan.d.ts +35 -0
  394. package/build/types-ts3.8/tracing/spans/captureSpan.d.ts +26 -0
  395. package/build/types-ts3.8/tracing/spans/envelope.d.ts +8 -0
  396. package/build/types-ts3.8/tracing/spans/estimateSize.d.ts +12 -0
  397. package/build/types-ts3.8/tracing/spans/hasSpanStreamingEnabled.d.ts +6 -0
  398. package/build/types-ts3.8/tracing/spans/spanBuffer.d.ts +60 -0
  399. package/build/types-ts3.8/tracing/vercel-ai/constants.d.ts +2 -5
  400. package/build/types-ts3.8/tracing/vercel-ai/utils.d.ts +1 -5
  401. package/build/types-ts3.8/tracing/vercel-ai/vercel-ai-attributes.d.ts +0 -480
  402. package/build/types-ts3.8/types-hoist/envelope.d.ts +22 -2
  403. package/build/types-ts3.8/types-hoist/integration.d.ts +8 -0
  404. package/build/types-ts3.8/types-hoist/link.d.ts +2 -2
  405. package/build/types-ts3.8/types-hoist/options.d.ts +26 -2
  406. package/build/types-ts3.8/types-hoist/span.d.ts +35 -0
  407. package/build/types-ts3.8/types-hoist/view-hierarchy.d.ts +1 -0
  408. package/build/types-ts3.8/utils/browser.d.ts +1 -1
  409. package/build/types-ts3.8/utils/object.d.ts +10 -0
  410. package/build/types-ts3.8/utils/spanUtils.d.ts +27 -2
  411. package/build/types-ts3.8/utils/string.d.ts +2 -2
  412. package/build/types-ts3.8/utils/weakRef.d.ts +34 -0
  413. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
- import { GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE, GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE, GEN_AI_TOOL_NAME_ATTRIBUTE, GEN_AI_TOOL_DESCRIPTION_ATTRIBUTE, GEN_AI_INPUT_MESSAGES_ATTRIBUTE, GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE, GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE, GEN_AI_EXECUTE_TOOL_OPERATION_ATTRIBUTE, GEN_AI_RERANK_DO_RERANK_OPERATION_ATTRIBUTE, GEN_AI_EMBED_MANY_DO_EMBED_OPERATION_ATTRIBUTE, GEN_AI_EMBED_DO_EMBED_OPERATION_ATTRIBUTE, GEN_AI_STREAM_OBJECT_DO_STREAM_OPERATION_ATTRIBUTE, GEN_AI_GENERATE_OBJECT_DO_GENERATE_OPERATION_ATTRIBUTE, GEN_AI_STREAM_TEXT_DO_STREAM_OPERATION_ATTRIBUTE, GEN_AI_GENERATE_TEXT_DO_GENERATE_OPERATION_ATTRIBUTE, GEN_AI_INVOKE_AGENT_OPERATION_ATTRIBUTE, GEN_AI_REQUEST_AVAILABLE_TOOLS_ATTRIBUTE } from '../ai/gen-ai-attributes.js';
2
- import { extractSystemInstructions, getTruncatedJsonString } from '../ai/utils.js';
1
+ import { GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE, GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE, GEN_AI_TOOL_NAME_ATTRIBUTE, GEN_AI_TOOL_DESCRIPTION_ATTRIBUTE, GEN_AI_INPUT_MESSAGES_ATTRIBUTE, GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE, GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE, GEN_AI_REQUEST_AVAILABLE_TOOLS_ATTRIBUTE } from '../ai/gen-ai-attributes.js';
2
+ import { extractSystemInstructions, getTruncatedJsonString, getJsonString } from '../ai/utils.js';
3
3
  import { toolCallSpanContextMap } from './constants.js';
4
4
  import { AI_PROMPT_ATTRIBUTE, AI_PROMPT_MESSAGES_ATTRIBUTE } from './vercel-ai-attributes.js';
5
5
 
@@ -209,7 +209,7 @@ function convertUserInputToMessagesFormat(userInput) {
209
209
  * Generate a request.messages JSON array from the prompt field in the
210
210
  * invoke_agent op
211
211
  */
212
- function requestMessagesFromPrompt(span, attributes) {
212
+ function requestMessagesFromPrompt(span, attributes, enableTruncation) {
213
213
  if (
214
214
  typeof attributes[AI_PROMPT_ATTRIBUTE] === 'string' &&
215
215
  !attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE] &&
@@ -229,11 +229,13 @@ function requestMessagesFromPrompt(span, attributes) {
229
229
  }
230
230
 
231
231
  const filteredLength = Array.isArray(filteredMessages) ? filteredMessages.length : 0;
232
- const truncatedMessages = getTruncatedJsonString(filteredMessages);
232
+ const messagesJson = enableTruncation
233
+ ? getTruncatedJsonString(filteredMessages)
234
+ : getJsonString(filteredMessages);
233
235
 
234
236
  span.setAttributes({
235
- [AI_PROMPT_ATTRIBUTE]: truncatedMessages,
236
- [GEN_AI_INPUT_MESSAGES_ATTRIBUTE]: truncatedMessages,
237
+ [AI_PROMPT_ATTRIBUTE]: messagesJson,
238
+ [GEN_AI_INPUT_MESSAGES_ATTRIBUTE]: messagesJson,
237
239
  [GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE]: filteredLength,
238
240
  });
239
241
  }
@@ -250,11 +252,13 @@ function requestMessagesFromPrompt(span, attributes) {
250
252
  }
251
253
 
252
254
  const filteredLength = Array.isArray(filteredMessages) ? filteredMessages.length : 0;
253
- const truncatedMessages = getTruncatedJsonString(filteredMessages);
255
+ const messagesJson = enableTruncation
256
+ ? getTruncatedJsonString(filteredMessages)
257
+ : getJsonString(filteredMessages);
254
258
 
255
259
  span.setAttributes({
256
- [AI_PROMPT_MESSAGES_ATTRIBUTE]: truncatedMessages,
257
- [GEN_AI_INPUT_MESSAGES_ATTRIBUTE]: truncatedMessages,
260
+ [AI_PROMPT_MESSAGES_ATTRIBUTE]: messagesJson,
261
+ [GEN_AI_INPUT_MESSAGES_ATTRIBUTE]: messagesJson,
258
262
  [GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE]: filteredLength,
259
263
  });
260
264
  }
@@ -263,39 +267,5 @@ function requestMessagesFromPrompt(span, attributes) {
263
267
  }
264
268
  }
265
269
 
266
- /**
267
- * Maps a Vercel AI span name to the corresponding Sentry op.
268
- */
269
- function getSpanOpFromName(name) {
270
- switch (name) {
271
- case 'ai.generateText':
272
- case 'ai.streamText':
273
- case 'ai.generateObject':
274
- case 'ai.streamObject':
275
- return GEN_AI_INVOKE_AGENT_OPERATION_ATTRIBUTE;
276
- case 'ai.generateText.doGenerate':
277
- return GEN_AI_GENERATE_TEXT_DO_GENERATE_OPERATION_ATTRIBUTE;
278
- case 'ai.streamText.doStream':
279
- return GEN_AI_STREAM_TEXT_DO_STREAM_OPERATION_ATTRIBUTE;
280
- case 'ai.generateObject.doGenerate':
281
- return GEN_AI_GENERATE_OBJECT_DO_GENERATE_OPERATION_ATTRIBUTE;
282
- case 'ai.streamObject.doStream':
283
- return GEN_AI_STREAM_OBJECT_DO_STREAM_OPERATION_ATTRIBUTE;
284
- case 'ai.embed.doEmbed':
285
- return GEN_AI_EMBED_DO_EMBED_OPERATION_ATTRIBUTE;
286
- case 'ai.embedMany.doEmbed':
287
- return GEN_AI_EMBED_MANY_DO_EMBED_OPERATION_ATTRIBUTE;
288
- case 'ai.rerank.doRerank':
289
- return GEN_AI_RERANK_DO_RERANK_OPERATION_ATTRIBUTE;
290
- case 'ai.toolCall':
291
- return GEN_AI_EXECUTE_TOOL_OPERATION_ATTRIBUTE;
292
- default:
293
- if (name.startsWith('ai.stream')) {
294
- return 'ai.run';
295
- }
296
- return undefined;
297
- }
298
- }
299
-
300
- export { _INTERNAL_cleanupToolCallSpanContext, _INTERNAL_getSpanContextForToolCallId, accumulateTokensForParent, applyAccumulatedTokens, applyToolDescriptionsAndTokens, convertAvailableToolsToJsonString, convertUserInputToMessagesFormat, getSpanOpFromName, requestMessagesFromPrompt };
270
+ export { _INTERNAL_cleanupToolCallSpanContext, _INTERNAL_getSpanContextForToolCallId, accumulateTokensForParent, applyAccumulatedTokens, applyToolDescriptionsAndTokens, convertAvailableToolsToJsonString, convertUserInputToMessagesFormat, requestMessagesFromPrompt };
301
271
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../../../src/tracing/vercel-ai/utils.ts"],"sourcesContent":["import type { TraceContext } from '../../types-hoist/context';\nimport type { Span, SpanAttributes, SpanJSON } from '../../types-hoist/span';\nimport {\n GEN_AI_EMBED_DO_EMBED_OPERATION_ATTRIBUTE,\n GEN_AI_EMBED_MANY_DO_EMBED_OPERATION_ATTRIBUTE,\n GEN_AI_EXECUTE_TOOL_OPERATION_ATTRIBUTE,\n GEN_AI_GENERATE_OBJECT_DO_GENERATE_OPERATION_ATTRIBUTE,\n GEN_AI_GENERATE_TEXT_DO_GENERATE_OPERATION_ATTRIBUTE,\n GEN_AI_INPUT_MESSAGES_ATTRIBUTE,\n GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE,\n GEN_AI_INVOKE_AGENT_OPERATION_ATTRIBUTE,\n GEN_AI_RERANK_DO_RERANK_OPERATION_ATTRIBUTE,\n GEN_AI_REQUEST_AVAILABLE_TOOLS_ATTRIBUTE,\n GEN_AI_STREAM_OBJECT_DO_STREAM_OPERATION_ATTRIBUTE,\n GEN_AI_STREAM_TEXT_DO_STREAM_OPERATION_ATTRIBUTE,\n GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE,\n GEN_AI_TOOL_DESCRIPTION_ATTRIBUTE,\n GEN_AI_TOOL_NAME_ATTRIBUTE,\n GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE,\n GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE,\n} from '../ai/gen-ai-attributes';\nimport { extractSystemInstructions, getTruncatedJsonString } from '../ai/utils';\nimport { toolCallSpanContextMap } from './constants';\nimport type { TokenSummary, ToolCallSpanContext } from './types';\nimport { AI_PROMPT_ATTRIBUTE, AI_PROMPT_MESSAGES_ATTRIBUTE } from './vercel-ai-attributes';\n\n/**\n * Accumulates token data from a span to its parent in the token accumulator map.\n * This function extracts token usage from the current span and adds it to the\n * accumulated totals for its parent span.\n */\nexport function accumulateTokensForParent(span: SpanJSON, tokenAccumulator: Map<string, TokenSummary>): void {\n const parentSpanId = span.parent_span_id;\n if (!parentSpanId) {\n return;\n }\n\n const inputTokens = span.data[GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE];\n const outputTokens = span.data[GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE];\n\n if (typeof inputTokens === 'number' || typeof outputTokens === 'number') {\n const existing = tokenAccumulator.get(parentSpanId) || { inputTokens: 0, outputTokens: 0 };\n\n if (typeof inputTokens === 'number') {\n existing.inputTokens += inputTokens;\n }\n if (typeof outputTokens === 'number') {\n existing.outputTokens += outputTokens;\n }\n\n tokenAccumulator.set(parentSpanId, existing);\n }\n}\n\n/**\n * Applies accumulated token data to the `gen_ai.invoke_agent` span.\n * Only immediate children of the `gen_ai.invoke_agent` span are considered,\n * since aggregation will automatically occur for each parent span.\n */\nexport function applyAccumulatedTokens(\n spanOrTrace: SpanJSON | TraceContext,\n tokenAccumulator: Map<string, TokenSummary>,\n): void {\n const accumulated = tokenAccumulator.get(spanOrTrace.span_id);\n if (!accumulated || !spanOrTrace.data) {\n return;\n }\n\n if (accumulated.inputTokens > 0) {\n spanOrTrace.data[GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE] = accumulated.inputTokens;\n }\n if (accumulated.outputTokens > 0) {\n spanOrTrace.data[GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE] = accumulated.outputTokens;\n }\n if (accumulated.inputTokens > 0 || accumulated.outputTokens > 0) {\n spanOrTrace.data['gen_ai.usage.total_tokens'] = accumulated.inputTokens + accumulated.outputTokens;\n }\n}\n\n/**\n * Builds a map of tool name -> description from all spans with available_tools.\n * This avoids O(n²) iteration and repeated JSON parsing.\n */\nfunction buildToolDescriptionMap(spans: SpanJSON[]): Map<string, string> {\n const toolDescriptions = new Map<string, string>();\n\n for (const span of spans) {\n const availableTools = span.data[GEN_AI_REQUEST_AVAILABLE_TOOLS_ATTRIBUTE];\n if (typeof availableTools !== 'string') {\n continue;\n }\n try {\n const tools = JSON.parse(availableTools) as Array<{ name?: string; description?: string }>;\n for (const tool of tools) {\n if (tool.name && tool.description && !toolDescriptions.has(tool.name)) {\n toolDescriptions.set(tool.name, tool.description);\n }\n }\n } catch {\n // ignore parse errors\n }\n }\n\n return toolDescriptions;\n}\n\n/**\n * Applies tool descriptions and accumulated tokens to spans in a single pass.\n *\n * - For `gen_ai.execute_tool` spans: looks up tool description from\n * `gen_ai.request.available_tools` on sibling spans\n * - For `gen_ai.invoke_agent` spans: applies accumulated token data from children\n */\nexport function applyToolDescriptionsAndTokens(spans: SpanJSON[], tokenAccumulator: Map<string, TokenSummary>): void {\n // Build lookup map once to avoid O(n²) iteration and repeated JSON parsing\n const toolDescriptions = buildToolDescriptionMap(spans);\n\n for (const span of spans) {\n if (span.op === 'gen_ai.execute_tool') {\n const toolName = span.data[GEN_AI_TOOL_NAME_ATTRIBUTE];\n if (typeof toolName === 'string') {\n const description = toolDescriptions.get(toolName);\n if (description) {\n span.data[GEN_AI_TOOL_DESCRIPTION_ATTRIBUTE] = description;\n }\n }\n }\n\n if (span.op === 'gen_ai.invoke_agent') {\n applyAccumulatedTokens(span, tokenAccumulator);\n }\n }\n}\n\n/**\n * Get the span context associated with a tool call ID.\n */\nexport function _INTERNAL_getSpanContextForToolCallId(toolCallId: string): ToolCallSpanContext | undefined {\n return toolCallSpanContextMap.get(toolCallId);\n}\n\n/**\n * Clean up the span mapping for a tool call ID\n */\nexport function _INTERNAL_cleanupToolCallSpanContext(toolCallId: string): void {\n toolCallSpanContextMap.delete(toolCallId);\n}\n\n/**\n * Convert an array of tool strings to a JSON string\n */\nexport function convertAvailableToolsToJsonString(tools: unknown[]): string {\n const toolObjects = tools.map(tool => {\n if (typeof tool === 'string') {\n try {\n return JSON.parse(tool);\n } catch {\n return tool;\n }\n }\n return tool;\n });\n return JSON.stringify(toolObjects);\n}\n\n/**\n * Filter out invalid entries in messages array\n * @param input - The input array to filter\n * @returns The filtered array\n */\nfunction filterMessagesArray(input: unknown[]): { role: string; content: string }[] {\n return input.filter(\n (m: unknown): m is { role: string; content: string } =>\n !!m && typeof m === 'object' && 'role' in m && 'content' in m,\n );\n}\n\n/**\n * Normalize the user input (stringified object with prompt, system, messages) to messages array\n */\nexport function convertUserInputToMessagesFormat(userInput: string): { role: string; content: string }[] {\n try {\n const p = JSON.parse(userInput);\n if (!!p && typeof p === 'object') {\n let { messages } = p;\n const { prompt, system } = p;\n const result: { role: string; content: string }[] = [];\n\n // prepend top-level system instruction if present\n if (typeof system === 'string') {\n result.push({ role: 'system', content: system });\n }\n\n // stringified messages array\n if (typeof messages === 'string') {\n try {\n messages = JSON.parse(messages);\n } catch {\n // ignore parse errors\n }\n }\n\n // messages array format: { messages: [...] }\n if (Array.isArray(messages)) {\n result.push(...filterMessagesArray(messages));\n return result;\n }\n\n // prompt array format: { prompt: [...] }\n if (Array.isArray(prompt)) {\n result.push(...filterMessagesArray(prompt));\n return result;\n }\n\n // prompt string format: { prompt: \"...\" }\n if (typeof prompt === 'string') {\n result.push({ role: 'user', content: prompt });\n }\n\n if (result.length > 0) {\n return result;\n }\n }\n // eslint-disable-next-line no-empty\n } catch {}\n return [];\n}\n\n/**\n * Generate a request.messages JSON array from the prompt field in the\n * invoke_agent op\n */\nexport function requestMessagesFromPrompt(span: Span, attributes: SpanAttributes): void {\n if (\n typeof attributes[AI_PROMPT_ATTRIBUTE] === 'string' &&\n !attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE] &&\n !attributes[AI_PROMPT_MESSAGES_ATTRIBUTE]\n ) {\n // No messages array is present, so we need to convert the prompt to the proper messages format\n // This is the case for ai.generateText spans\n // The ai.prompt attribute is a stringified object with prompt, system, messages attributes\n // The format of these is described in the vercel docs, for instance: https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-object#parameters\n const userInput = attributes[AI_PROMPT_ATTRIBUTE];\n const messages = convertUserInputToMessagesFormat(userInput);\n if (messages.length) {\n const { systemInstructions, filteredMessages } = extractSystemInstructions(messages);\n\n if (systemInstructions) {\n span.setAttribute(GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE, systemInstructions);\n }\n\n const filteredLength = Array.isArray(filteredMessages) ? filteredMessages.length : 0;\n const truncatedMessages = getTruncatedJsonString(filteredMessages);\n\n span.setAttributes({\n [AI_PROMPT_ATTRIBUTE]: truncatedMessages,\n [GEN_AI_INPUT_MESSAGES_ATTRIBUTE]: truncatedMessages,\n [GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE]: filteredLength,\n });\n }\n } else if (typeof attributes[AI_PROMPT_MESSAGES_ATTRIBUTE] === 'string') {\n // In this case we already get a properly formatted messages array, this is the preferred way to get the messages\n // This is the case for ai.generateText.doGenerate spans\n try {\n const messages = JSON.parse(attributes[AI_PROMPT_MESSAGES_ATTRIBUTE]);\n if (Array.isArray(messages)) {\n const { systemInstructions, filteredMessages } = extractSystemInstructions(messages);\n\n if (systemInstructions) {\n span.setAttribute(GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE, systemInstructions);\n }\n\n const filteredLength = Array.isArray(filteredMessages) ? filteredMessages.length : 0;\n const truncatedMessages = getTruncatedJsonString(filteredMessages);\n\n span.setAttributes({\n [AI_PROMPT_MESSAGES_ATTRIBUTE]: truncatedMessages,\n [GEN_AI_INPUT_MESSAGES_ATTRIBUTE]: truncatedMessages,\n [GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE]: filteredLength,\n });\n }\n // eslint-disable-next-line no-empty\n } catch {}\n }\n}\n\n/**\n * Maps a Vercel AI span name to the corresponding Sentry op.\n */\nexport function getSpanOpFromName(name: string): string | undefined {\n switch (name) {\n case 'ai.generateText':\n case 'ai.streamText':\n case 'ai.generateObject':\n case 'ai.streamObject':\n return GEN_AI_INVOKE_AGENT_OPERATION_ATTRIBUTE;\n case 'ai.generateText.doGenerate':\n return GEN_AI_GENERATE_TEXT_DO_GENERATE_OPERATION_ATTRIBUTE;\n case 'ai.streamText.doStream':\n return GEN_AI_STREAM_TEXT_DO_STREAM_OPERATION_ATTRIBUTE;\n case 'ai.generateObject.doGenerate':\n return GEN_AI_GENERATE_OBJECT_DO_GENERATE_OPERATION_ATTRIBUTE;\n case 'ai.streamObject.doStream':\n return GEN_AI_STREAM_OBJECT_DO_STREAM_OPERATION_ATTRIBUTE;\n case 'ai.embed.doEmbed':\n return GEN_AI_EMBED_DO_EMBED_OPERATION_ATTRIBUTE;\n case 'ai.embedMany.doEmbed':\n return GEN_AI_EMBED_MANY_DO_EMBED_OPERATION_ATTRIBUTE;\n case 'ai.rerank.doRerank':\n return GEN_AI_RERANK_DO_RERANK_OPERATION_ATTRIBUTE;\n case 'ai.toolCall':\n return GEN_AI_EXECUTE_TOOL_OPERATION_ATTRIBUTE;\n default:\n if (name.startsWith('ai.stream')) {\n return 'ai.run';\n }\n return undefined;\n }\n}\n"],"names":[],"mappings":";;;;;AA0BA;AACA;AACA;AACA;AACA;AACO,SAAS,yBAAyB,CAAC,IAAI,EAAY,gBAAgB,EAAmC;AAC7G,EAAE,MAAM,YAAA,GAAe,IAAI,CAAC,cAAc;AAC1C,EAAE,IAAI,CAAC,YAAY,EAAE;AACrB,IAAI;AACJ,EAAE;;AAEF,EAAE,MAAM,cAAc,IAAI,CAAC,IAAI,CAAC,mCAAmC,CAAC;AACpE,EAAE,MAAM,eAAe,IAAI,CAAC,IAAI,CAAC,oCAAoC,CAAC;;AAEtE,EAAE,IAAI,OAAO,WAAA,KAAgB,QAAA,IAAY,OAAO,YAAA,KAAiB,QAAQ,EAAE;AAC3E,IAAI,MAAM,QAAA,GAAW,gBAAgB,CAAC,GAAG,CAAC,YAAY,CAAA,IAAK,EAAE,WAAW,EAAE,CAAC,EAAE,YAAY,EAAE,GAAG;;AAE9F,IAAI,IAAI,OAAO,WAAA,KAAgB,QAAQ,EAAE;AACzC,MAAM,QAAQ,CAAC,WAAA,IAAe,WAAW;AACzC,IAAI;AACJ,IAAI,IAAI,OAAO,YAAA,KAAiB,QAAQ,EAAE;AAC1C,MAAM,QAAQ,CAAC,YAAA,IAAgB,YAAY;AAC3C,IAAI;;AAEJ,IAAI,gBAAgB,CAAC,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC;AAChD,EAAE;AACF;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,sBAAsB;AACtC,EAAE,WAAW;AACb,EAAE,gBAAgB;AAClB,EAAQ;AACR,EAAE,MAAM,WAAA,GAAc,gBAAgB,CAA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,SAAS,CAAC;AACV,MAAM;AACN;AACA,IAAI,CAAA,CAAE,MAAM,CAAC;AACb,EAAE;AACF;;AAEA;AACA;AACA;AACO,SAAS,iBAAiB,CAAC,IAAI,EAA8B;AACpE,EAAE,QAAQ,IAAI;AACd,IAAI,KAAK,iBAAiB;AAC1B,IAAI,KAAK,eAAe;AACxB,IAAI,KAAK,mBAAmB;AAC5B,IAAI,KAAK,iBAAiB;AAC1B,MAAM,OAAO,uCAAuC;AACpD,IAAI,KAAK,4BAA4B;AACrC,MAAM,OAAO,oDAAoD;AACjE,IAAI,KAAK,wBAAwB;AACjC,MAAM,OAAO,gDAAgD;AAC7D,IAAI,KAAK,8BAA8B;AACvC,MAAM,OAAO,sDAAsD;AACnE,IAAI,KAAK,0BAA0B;AACnC,MAAM,OAAO,kDAAkD;AAC/D,IAAI,KAAK,kBAAkB;AAC3B,MAAM,OAAO,yCAAyC;AACtD,IAAI,KAAK,sBAAsB;AAC/B,MAAM,OAAO,8CAA8C;AAC3D,IAAI,KAAK,oBAAoB;AAC7B,MAAM,OAAO,2CAA2C;AACxD,IAAI,KAAK,aAAa;AACtB,MAAM,OAAO,uCAAuC;AACpD,IAAI;AACJ,MAAM,IAAI,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE;AACxC,QAAQ,OAAO,QAAQ;AACvB,MAAM;AACN,MAAM,OAAO,SAAS;AACtB;AACA;;;;"}
1
+ {"version":3,"file":"utils.js","sources":["../../../../src/tracing/vercel-ai/utils.ts"],"sourcesContent":["import type { TraceContext } from '../../types-hoist/context';\nimport type { Span, SpanAttributes, SpanJSON } from '../../types-hoist/span';\nimport {\n GEN_AI_INPUT_MESSAGES_ATTRIBUTE,\n GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE,\n GEN_AI_REQUEST_AVAILABLE_TOOLS_ATTRIBUTE,\n GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE,\n GEN_AI_TOOL_DESCRIPTION_ATTRIBUTE,\n GEN_AI_TOOL_NAME_ATTRIBUTE,\n GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE,\n GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE,\n} from '../ai/gen-ai-attributes';\nimport { extractSystemInstructions, getJsonString, getTruncatedJsonString } from '../ai/utils';\nimport { toolCallSpanContextMap } from './constants';\nimport type { TokenSummary, ToolCallSpanContext } from './types';\nimport { AI_PROMPT_ATTRIBUTE, AI_PROMPT_MESSAGES_ATTRIBUTE } from './vercel-ai-attributes';\n\n/**\n * Accumulates token data from a span to its parent in the token accumulator map.\n * This function extracts token usage from the current span and adds it to the\n * accumulated totals for its parent span.\n */\nexport function accumulateTokensForParent(span: SpanJSON, tokenAccumulator: Map<string, TokenSummary>): void {\n const parentSpanId = span.parent_span_id;\n if (!parentSpanId) {\n return;\n }\n\n const inputTokens = span.data[GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE];\n const outputTokens = span.data[GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE];\n\n if (typeof inputTokens === 'number' || typeof outputTokens === 'number') {\n const existing = tokenAccumulator.get(parentSpanId) || { inputTokens: 0, outputTokens: 0 };\n\n if (typeof inputTokens === 'number') {\n existing.inputTokens += inputTokens;\n }\n if (typeof outputTokens === 'number') {\n existing.outputTokens += outputTokens;\n }\n\n tokenAccumulator.set(parentSpanId, existing);\n }\n}\n\n/**\n * Applies accumulated token data to the `gen_ai.invoke_agent` span.\n * Only immediate children of the `gen_ai.invoke_agent` span are considered,\n * since aggregation will automatically occur for each parent span.\n */\nexport function applyAccumulatedTokens(\n spanOrTrace: SpanJSON | TraceContext,\n tokenAccumulator: Map<string, TokenSummary>,\n): void {\n const accumulated = tokenAccumulator.get(spanOrTrace.span_id);\n if (!accumulated || !spanOrTrace.data) {\n return;\n }\n\n if (accumulated.inputTokens > 0) {\n spanOrTrace.data[GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE] = accumulated.inputTokens;\n }\n if (accumulated.outputTokens > 0) {\n spanOrTrace.data[GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE] = accumulated.outputTokens;\n }\n if (accumulated.inputTokens > 0 || accumulated.outputTokens > 0) {\n spanOrTrace.data['gen_ai.usage.total_tokens'] = accumulated.inputTokens + accumulated.outputTokens;\n }\n}\n\n/**\n * Builds a map of tool name -> description from all spans with available_tools.\n * This avoids O(n²) iteration and repeated JSON parsing.\n */\nfunction buildToolDescriptionMap(spans: SpanJSON[]): Map<string, string> {\n const toolDescriptions = new Map<string, string>();\n\n for (const span of spans) {\n const availableTools = span.data[GEN_AI_REQUEST_AVAILABLE_TOOLS_ATTRIBUTE];\n if (typeof availableTools !== 'string') {\n continue;\n }\n try {\n const tools = JSON.parse(availableTools) as Array<{ name?: string; description?: string }>;\n for (const tool of tools) {\n if (tool.name && tool.description && !toolDescriptions.has(tool.name)) {\n toolDescriptions.set(tool.name, tool.description);\n }\n }\n } catch {\n // ignore parse errors\n }\n }\n\n return toolDescriptions;\n}\n\n/**\n * Applies tool descriptions and accumulated tokens to spans in a single pass.\n *\n * - For `gen_ai.execute_tool` spans: looks up tool description from\n * `gen_ai.request.available_tools` on sibling spans\n * - For `gen_ai.invoke_agent` spans: applies accumulated token data from children\n */\nexport function applyToolDescriptionsAndTokens(spans: SpanJSON[], tokenAccumulator: Map<string, TokenSummary>): void {\n // Build lookup map once to avoid O(n²) iteration and repeated JSON parsing\n const toolDescriptions = buildToolDescriptionMap(spans);\n\n for (const span of spans) {\n if (span.op === 'gen_ai.execute_tool') {\n const toolName = span.data[GEN_AI_TOOL_NAME_ATTRIBUTE];\n if (typeof toolName === 'string') {\n const description = toolDescriptions.get(toolName);\n if (description) {\n span.data[GEN_AI_TOOL_DESCRIPTION_ATTRIBUTE] = description;\n }\n }\n }\n\n if (span.op === 'gen_ai.invoke_agent') {\n applyAccumulatedTokens(span, tokenAccumulator);\n }\n }\n}\n\n/**\n * Get the span context associated with a tool call ID.\n */\nexport function _INTERNAL_getSpanContextForToolCallId(toolCallId: string): ToolCallSpanContext | undefined {\n return toolCallSpanContextMap.get(toolCallId);\n}\n\n/**\n * Clean up the span mapping for a tool call ID\n */\nexport function _INTERNAL_cleanupToolCallSpanContext(toolCallId: string): void {\n toolCallSpanContextMap.delete(toolCallId);\n}\n\n/**\n * Convert an array of tool strings to a JSON string\n */\nexport function convertAvailableToolsToJsonString(tools: unknown[]): string {\n const toolObjects = tools.map(tool => {\n if (typeof tool === 'string') {\n try {\n return JSON.parse(tool);\n } catch {\n return tool;\n }\n }\n return tool;\n });\n return JSON.stringify(toolObjects);\n}\n\n/**\n * Filter out invalid entries in messages array\n * @param input - The input array to filter\n * @returns The filtered array\n */\nfunction filterMessagesArray(input: unknown[]): { role: string; content: string }[] {\n return input.filter(\n (m: unknown): m is { role: string; content: string } =>\n !!m && typeof m === 'object' && 'role' in m && 'content' in m,\n );\n}\n\n/**\n * Normalize the user input (stringified object with prompt, system, messages) to messages array\n */\nexport function convertUserInputToMessagesFormat(userInput: string): { role: string; content: string }[] {\n try {\n const p = JSON.parse(userInput);\n if (!!p && typeof p === 'object') {\n let { messages } = p;\n const { prompt, system } = p;\n const result: { role: string; content: string }[] = [];\n\n // prepend top-level system instruction if present\n if (typeof system === 'string') {\n result.push({ role: 'system', content: system });\n }\n\n // stringified messages array\n if (typeof messages === 'string') {\n try {\n messages = JSON.parse(messages);\n } catch {\n // ignore parse errors\n }\n }\n\n // messages array format: { messages: [...] }\n if (Array.isArray(messages)) {\n result.push(...filterMessagesArray(messages));\n return result;\n }\n\n // prompt array format: { prompt: [...] }\n if (Array.isArray(prompt)) {\n result.push(...filterMessagesArray(prompt));\n return result;\n }\n\n // prompt string format: { prompt: \"...\" }\n if (typeof prompt === 'string') {\n result.push({ role: 'user', content: prompt });\n }\n\n if (result.length > 0) {\n return result;\n }\n }\n // eslint-disable-next-line no-empty\n } catch {}\n return [];\n}\n\n/**\n * Generate a request.messages JSON array from the prompt field in the\n * invoke_agent op\n */\nexport function requestMessagesFromPrompt(span: Span, attributes: SpanAttributes, enableTruncation: boolean): void {\n if (\n typeof attributes[AI_PROMPT_ATTRIBUTE] === 'string' &&\n !attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE] &&\n !attributes[AI_PROMPT_MESSAGES_ATTRIBUTE]\n ) {\n // No messages array is present, so we need to convert the prompt to the proper messages format\n // This is the case for ai.generateText spans\n // The ai.prompt attribute is a stringified object with prompt, system, messages attributes\n // The format of these is described in the vercel docs, for instance: https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-object#parameters\n const userInput = attributes[AI_PROMPT_ATTRIBUTE];\n const messages = convertUserInputToMessagesFormat(userInput);\n if (messages.length) {\n const { systemInstructions, filteredMessages } = extractSystemInstructions(messages);\n\n if (systemInstructions) {\n span.setAttribute(GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE, systemInstructions);\n }\n\n const filteredLength = Array.isArray(filteredMessages) ? filteredMessages.length : 0;\n const messagesJson = enableTruncation\n ? getTruncatedJsonString(filteredMessages)\n : getJsonString(filteredMessages);\n\n span.setAttributes({\n [AI_PROMPT_ATTRIBUTE]: messagesJson,\n [GEN_AI_INPUT_MESSAGES_ATTRIBUTE]: messagesJson,\n [GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE]: filteredLength,\n });\n }\n } else if (typeof attributes[AI_PROMPT_MESSAGES_ATTRIBUTE] === 'string') {\n // In this case we already get a properly formatted messages array, this is the preferred way to get the messages\n // This is the case for ai.generateText.doGenerate spans\n try {\n const messages = JSON.parse(attributes[AI_PROMPT_MESSAGES_ATTRIBUTE]);\n if (Array.isArray(messages)) {\n const { systemInstructions, filteredMessages } = extractSystemInstructions(messages);\n\n if (systemInstructions) {\n span.setAttribute(GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE, systemInstructions);\n }\n\n const filteredLength = Array.isArray(filteredMessages) ? filteredMessages.length : 0;\n const messagesJson = enableTruncation\n ? getTruncatedJsonString(filteredMessages)\n : getJsonString(filteredMessages);\n\n span.setAttributes({\n [AI_PROMPT_MESSAGES_ATTRIBUTE]: messagesJson,\n [GEN_AI_INPUT_MESSAGES_ATTRIBUTE]: messagesJson,\n [GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE]: filteredLength,\n });\n }\n // eslint-disable-next-line no-empty\n } catch {}\n }\n}\n"],"names":[],"mappings":";;;;;AAiBA;AACA;AACA;AACA;AACA;AACO,SAAS,yBAAyB,CAAC,IAAI,EAAY,gBAAgB,EAAmC;AAC7G,EAAE,MAAM,YAAA,GAAe,IAAI,CAAC,cAAc;AAC1C,EAAE,IAAI,CAAC,YAAY,EAAE;AACrB,IAAI;AACJ,EAAE;;AAEF,EAAE,MAAM,cAAc,IAAI,CAAC,IAAI,CAAC,mCAAmC,CAAC;AACpE,EAAE,MAAM,eAAe,IAAI,CAAC,IAAI,CAAC,oCAAoC,CAAC;;AAEtE,EAAE,IAAI,OAAO,WAAA,KAAgB,QAAA,IAAY,OAAO,YAAA,KAAiB,QAAQ,EAAE;AAC3E,IAAI,MAAM,QAAA,GAAW,gBAAgB,CAAC,GAAG,CAAC,YAAY,CAAA,IAAK,EAAE,WAAW,EAAE,CAAC,EAAE,YAAY,EAAE,GAAG;;AAE9F,IAAI,IAAI,OAAO,WAAA,KAAgB,QAAQ,EAAE;AACzC,MAAM,QAAQ,CAAC,WAAA,IAAe,WAAW;AACzC,IAAI;AACJ,IAAI,IAAI,OAAO,YAAA,KAAiB,QAAQ,EAAE;AAC1C,MAAM,QAAQ,CAAC,YAAA,IAAgB,YAAY;AAC3C,IAAI;;AAEJ,IAAI,gBAAgB,CAAC,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC;AAChD,EAAE;AACF;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,sBAAsB;AACtC,EAAE,WAAW;AACb,EAAE,gBAAgB;AAClB,EAAQ;AACR,EAAE,MAAM,WAAA,GAAc,gBAAgB,CAAC,GAAG,CAAC,WAA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A+B,GAAG,YAAY;AACzD,UAAU,CAAC,+CAA+C,GAAG,cAAc;AAC3E,SAAS,CAAC;AACV,MAAM;AACN;AACA,IAAI,CAAA,CAAE,MAAM,CAAC;AACb,EAAE;AACF;;;;"}
@@ -1,4 +1,3 @@
1
- /* eslint-disable max-lines */
2
1
  /**
3
2
  * AI SDK Telemetry Attributes
4
3
  * Based on https://ai-sdk.dev/docs/ai-sdk-core/telemetry#collected-data
@@ -108,6 +107,10 @@ const AI_PROMPT_MESSAGES_ATTRIBUTE = 'ai.prompt.messages';
108
107
  */
109
108
  const AI_PROMPT_TOOLS_ATTRIBUTE = 'ai.prompt.tools';
110
109
 
110
+ // =============================================================================
111
+ // BASIC LLM SPAN INFORMATION
112
+ // =============================================================================
113
+
111
114
  /**
112
115
  * Basic LLM span information
113
116
  * Multiple spans
@@ -1 +1 @@
1
- {"version":3,"file":"vercel-ai-attributes.js","sources":["../../../../src/tracing/vercel-ai/vercel-ai-attributes.ts"],"sourcesContent":["/* eslint-disable max-lines */\n/**\n * AI SDK Telemetry Attributes\n * Based on https://ai-sdk.dev/docs/ai-sdk-core/telemetry#collected-data\n */\n\n// =============================================================================\n// COMMON ATTRIBUTES\n// =============================================================================\n\n/**\n * Common attribute for operation name across all functions and spans\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#collected-data\n */\nexport const OPERATION_NAME_ATTRIBUTE = 'operation.name';\n\n/**\n * Common attribute for AI operation ID across all functions and spans\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#collected-data\n */\nexport const AI_OPERATION_ID_ATTRIBUTE = 'ai.operationId';\n\n// =============================================================================\n// SHARED ATTRIBUTES\n// =============================================================================\n\n/**\n * `generateText` function - `ai.generateText` span\n * `streamText` function - `ai.streamText` span\n *\n * The prompt that was used when calling the function\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generatetext-function\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#streamtext-function\n */\nexport const AI_PROMPT_ATTRIBUTE = 'ai.prompt';\n\n/**\n * `generateObject` function - `ai.generateObject` span\n * `streamObject` function - `ai.streamObject` span\n *\n * The JSON schema version of the schema that was passed into the function\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generateobject-function\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#streamobject-function\n */\nexport const AI_SCHEMA_ATTRIBUTE = 'ai.schema';\n\n/**\n * `generateObject` function - `ai.generateObject` span\n * `streamObject` function - `ai.streamObject` span\n *\n * The name of the schema that was passed into the function\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generateobject-function\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#streamobject-function\n */\nexport const AI_SCHEMA_NAME_ATTRIBUTE = 'ai.schema.name';\n\n/**\n * `generateObject` function - `ai.generateObject` span\n * `streamObject` function - `ai.streamObject` span\n *\n * The description of the schema that was passed into the function\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generateobject-function\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#streamobject-function\n */\nexport const AI_SCHEMA_DESCRIPTION_ATTRIBUTE = 'ai.schema.description';\n\n/**\n * `generateObject` function - `ai.generateObject` span\n * `streamObject` function - `ai.streamObject` span\n *\n * The object that was generated (stringified JSON)\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generateobject-function\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#streamobject-function\n */\nexport const AI_RESPONSE_OBJECT_ATTRIBUTE = 'ai.response.object';\n\n/**\n * `generateObject` function - `ai.generateObject` span\n * `streamObject` function - `ai.streamObject` span\n *\n * The object generation mode, e.g. `json`\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generateobject-function\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#streamobject-function\n */\nexport const AI_SETTINGS_MODE_ATTRIBUTE = 'ai.settings.mode';\n\n/**\n * `generateObject` function - `ai.generateObject` span\n * `streamObject` function - `ai.streamObject` span\n *\n * The output type that was used, e.g. `object` or `no-schema`\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generateobject-function\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#streamobject-function\n */\nexport const AI_SETTINGS_OUTPUT_ATTRIBUTE = 'ai.settings.output';\n\n/**\n * `embed` function - `ai.embed.doEmbed` span\n * `embedMany` function - `ai.embedMany` span\n *\n * The values that were passed into the function (array)\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#embed-function\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#embedmany-function\n */\nexport const AI_VALUES_ATTRIBUTE = 'ai.values';\n\n/**\n * `embed` function - `ai.embed.doEmbed` span\n * `embedMany` function - `ai.embedMany` span\n *\n * An array of JSON-stringified embeddings\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#embed-function\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#embedmany-function\n */\nexport const AI_EMBEDDINGS_ATTRIBUTE = 'ai.embeddings';\n\n// =============================================================================\n// GENERATETEXT FUNCTION - UNIQUE ATTRIBUTES\n// =============================================================================\n\n/**\n * `generateText` function - `ai.generateText` span\n *\n * The text that was generated\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generatetext-function\n */\nexport const AI_RESPONSE_TEXT_ATTRIBUTE = 'ai.response.text';\n\n/**\n * `generateText` function - `ai.generateText` span\n *\n * The tool calls that were made as part of the generation (stringified JSON)\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generatetext-function\n */\nexport const AI_RESPONSE_TOOL_CALLS_ATTRIBUTE = 'ai.response.toolCalls';\n\n/**\n * `generateText` function - `ai.generateText` span\n *\n * The reason why the generation finished\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generatetext-function\n */\nexport const AI_RESPONSE_FINISH_REASON_ATTRIBUTE = 'ai.response.finishReason';\n\n/**\n * `generateText` function - `ai.generateText` span\n *\n * The maximum number of steps that were set\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generatetext-function\n */\nexport const AI_SETTINGS_MAX_STEPS_ATTRIBUTE = 'ai.settings.maxSteps';\n\n/**\n * `generateText` function - `ai.generateText.doGenerate` span\n *\n * The format of the prompt\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generatetext-function\n */\nexport const AI_PROMPT_FORMAT_ATTRIBUTE = 'ai.prompt.format';\n\n/**\n * `generateText` function - `ai.generateText.doGenerate` span\n *\n * The messages that were passed into the provider\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generatetext-function\n */\nexport const AI_PROMPT_MESSAGES_ATTRIBUTE = 'ai.prompt.messages';\n\n/**\n * `generateText` function - `ai.generateText.doGenerate` span\n *\n * Array of stringified tool definitions\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generatetext-function\n */\nexport const AI_PROMPT_TOOLS_ATTRIBUTE = 'ai.prompt.tools';\n\n/**\n * `generateText` function - `ai.generateText.doGenerate` span\n *\n * The stringified tool choice setting (JSON)\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generatetext-function\n */\nexport const AI_PROMPT_TOOL_CHOICE_ATTRIBUTE = 'ai.prompt.toolChoice';\n\n// =============================================================================\n// STREAMTEXT FUNCTION - UNIQUE ATTRIBUTES\n// =============================================================================\n\n/**\n * `streamText` function - `ai.streamText.doStream` span\n *\n * The time it took to receive the first chunk in milliseconds\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#streamtext-function\n */\nexport const AI_RESPONSE_MS_TO_FIRST_CHUNK_ATTRIBUTE = 'ai.response.msToFirstChunk';\n\n/**\n * `streamText` function - `ai.streamText.doStream` span\n *\n * The time it took to receive the finish part of the LLM stream in milliseconds\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#streamtext-function\n */\nexport const AI_RESPONSE_MS_TO_FINISH_ATTRIBUTE = 'ai.response.msToFinish';\n\n/**\n * `streamText` function - `ai.streamText.doStream` span\n *\n * The average completion tokens per second\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#streamtext-function\n */\nexport const AI_RESPONSE_AVG_COMPLETION_TOKENS_PER_SECOND_ATTRIBUTE = 'ai.response.avgCompletionTokensPerSecond';\n\n// =============================================================================\n// EMBED FUNCTION - UNIQUE ATTRIBUTES\n// =============================================================================\n\n/**\n * `embed` function - `ai.embed` span\n *\n * The value that was passed into the `embed` function\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#embed-function\n */\nexport const AI_VALUE_ATTRIBUTE = 'ai.value';\n\n/**\n * `embed` function - `ai.embed` span\n *\n * A JSON-stringified embedding\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#embed-function\n */\nexport const AI_EMBEDDING_ATTRIBUTE = 'ai.embedding';\n\n// =============================================================================\n// BASIC LLM SPAN INFORMATION\n// =============================================================================\n\n/**\n * Basic LLM span information\n * Multiple spans\n *\n * The functionId that was set through `telemetry.functionId`\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#basic-llm-span-information\n */\nexport const RESOURCE_NAME_ATTRIBUTE = 'resource.name';\n\n/**\n * Basic LLM span information\n * Multiple spans\n *\n * The id of the model\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#basic-llm-span-information\n */\nexport const AI_MODEL_ID_ATTRIBUTE = 'ai.model.id';\n\n/**\n * Basic LLM span information\n * Multiple spans\n *\n * The provider of the model\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#basic-llm-span-information\n */\nexport const AI_MODEL_PROVIDER_ATTRIBUTE = 'ai.model.provider';\n\n/**\n * Basic LLM span information\n * Multiple spans\n *\n * The request headers that were passed in through `headers`\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#basic-llm-span-information\n */\nexport const AI_REQUEST_HEADERS_ATTRIBUTE = 'ai.request.headers';\n\n/**\n * Basic LLM span information\n * Multiple spans\n *\n * Provider specific metadata returned with the generation response\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#basic-llm-span-information\n */\nexport const AI_RESPONSE_PROVIDER_METADATA_ATTRIBUTE = 'ai.response.providerMetadata';\n\n/**\n * Basic LLM span information\n * Multiple spans\n *\n * The maximum number of retries that were set\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#basic-llm-span-information\n */\nexport const AI_SETTINGS_MAX_RETRIES_ATTRIBUTE = 'ai.settings.maxRetries';\n\n/**\n * Basic LLM span information\n * Multiple spans\n *\n * The number of cached input tokens that were used\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#basic-llm-span-information\n */\nexport const AI_USAGE_CACHED_INPUT_TOKENS_ATTRIBUTE = 'ai.usage.cachedInputTokens';\n/**\n * Basic LLM span information\n * Multiple spans\n *\n * The functionId that was set through `telemetry.functionId`\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#basic-llm-span-information\n */\nexport const AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE = 'ai.telemetry.functionId';\n\n/**\n * Basic LLM span information\n * Multiple spans\n *\n * The metadata that was passed in through `telemetry.metadata`\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#basic-llm-span-information\n */\nexport const AI_TELEMETRY_METADATA_ATTRIBUTE = 'ai.telemetry.metadata';\n\n/**\n * Basic LLM span information\n * Multiple spans\n *\n * The number of completion tokens that were used\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#basic-llm-span-information\n */\nexport const AI_USAGE_COMPLETION_TOKENS_ATTRIBUTE = 'ai.usage.completionTokens';\n\n/**\n * Basic LLM span information\n * Multiple spans\n *\n * The number of prompt tokens that were used\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#basic-llm-span-information\n */\nexport const AI_USAGE_PROMPT_TOKENS_ATTRIBUTE = 'ai.usage.promptTokens';\n\n// =============================================================================\n// CALL LLM SPAN INFORMATION\n// =============================================================================\n\n/**\n * Call LLM span information\n * Individual LLM call spans\n *\n * The model that was used to generate the response\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#call-llm-span-information\n */\nexport const AI_RESPONSE_MODEL_ATTRIBUTE = 'ai.response.model';\n\n/**\n * Call LLM span information\n * Individual LLM call spans\n *\n * The id of the response\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#call-llm-span-information\n */\nexport const AI_RESPONSE_ID_ATTRIBUTE = 'ai.response.id';\n\n/**\n * Call LLM span information\n * Individual LLM call spans\n *\n * The timestamp of the response\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#call-llm-span-information\n */\nexport const AI_RESPONSE_TIMESTAMP_ATTRIBUTE = 'ai.response.timestamp';\n\n// =============================================================================\n// SEMANTIC CONVENTIONS FOR GENAI OPERATIONS\n// =============================================================================\n\n/**\n * Semantic Conventions for GenAI operations\n * Individual LLM call spans\n *\n * The provider that was used\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#call-llm-span-information\n */\nexport const GEN_AI_SYSTEM_ATTRIBUTE = 'gen_ai.system';\n\n/**\n * Semantic Conventions for GenAI operations\n * Individual LLM call spans\n *\n * The model that was requested\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#call-llm-span-information\n */\nexport const GEN_AI_REQUEST_MODEL_ATTRIBUTE = 'gen_ai.request.model';\n\n/**\n * Semantic Conventions for GenAI operations\n * Individual LLM call spans\n *\n * The temperature that was set\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#call-llm-span-information\n */\nexport const GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE = 'gen_ai.request.temperature';\n\n/**\n * Semantic Conventions for GenAI operations\n * Individual LLM call spans\n *\n * The maximum number of tokens that were set\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#call-llm-span-information\n */\nexport const GEN_AI_REQUEST_MAX_TOKENS_ATTRIBUTE = 'gen_ai.request.max_tokens';\n\n/**\n * Semantic Conventions for GenAI operations\n * Individual LLM call spans\n *\n * The frequency penalty that was set\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#call-llm-span-information\n */\nexport const GEN_AI_REQUEST_FREQUENCY_PENALTY_ATTRIBUTE = 'gen_ai.request.frequency_penalty';\n\n/**\n * Semantic Conventions for GenAI operations\n * Individual LLM call spans\n *\n * The presence penalty that was set\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#call-llm-span-information\n */\nexport const GEN_AI_REQUEST_PRESENCE_PENALTY_ATTRIBUTE = 'gen_ai.request.presence_penalty';\n\n/**\n * Semantic Conventions for GenAI operations\n * Individual LLM call spans\n *\n * The topK parameter value that was set\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#call-llm-span-information\n */\nexport const GEN_AI_REQUEST_TOP_K_ATTRIBUTE = 'gen_ai.request.top_k';\n\n/**\n * Semantic Conventions for GenAI operations\n * Individual LLM call spans\n *\n * The topP parameter value that was set\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#call-llm-span-information\n */\nexport const GEN_AI_REQUEST_TOP_P_ATTRIBUTE = 'gen_ai.request.top_p';\n\n/**\n * Semantic Conventions for GenAI operations\n * Individual LLM call spans\n *\n * The stop sequences\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#call-llm-span-information\n */\nexport const GEN_AI_REQUEST_STOP_SEQUENCES_ATTRIBUTE = 'gen_ai.request.stop_sequences';\n\n/**\n * Semantic Conventions for GenAI operations\n * Individual LLM call spans\n *\n * The finish reasons that were returned by the provider\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#call-llm-span-information\n */\nexport const GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE = 'gen_ai.response.finish_reasons';\n\n/**\n * Semantic Conventions for GenAI operations\n * Individual LLM call spans\n *\n * The model that was used to generate the response\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#call-llm-span-information\n */\nexport const GEN_AI_RESPONSE_MODEL_ATTRIBUTE = 'gen_ai.response.model';\n\n/**\n * Semantic Conventions for GenAI operations\n * Individual LLM call spans\n *\n * The id of the response\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#call-llm-span-information\n */\nexport const GEN_AI_RESPONSE_ID_ATTRIBUTE = 'gen_ai.response.id';\n\n/**\n * Semantic Conventions for GenAI operations\n * Individual LLM call spans\n *\n * The number of prompt tokens that were used\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#call-llm-span-information\n */\nexport const GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE = 'gen_ai.usage.input_tokens';\n\n/**\n * Semantic Conventions for GenAI operations\n * Individual LLM call spans\n *\n * The number of completion tokens that were used\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#call-llm-span-information\n */\nexport const GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE = 'gen_ai.usage.output_tokens';\n\n// =============================================================================\n// BASIC EMBEDDING SPAN INFORMATION\n// =============================================================================\n\n/**\n * Basic embedding span information\n * Embedding spans\n *\n * The number of tokens that were used\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#basic-embedding-span-information\n */\nexport const AI_USAGE_TOKENS_ATTRIBUTE = 'ai.usage.tokens';\n\n// =============================================================================\n// TOOL CALL SPANS\n// =============================================================================\n\n/**\n * Tool call spans\n * `ai.toolCall` span\n *\n * The name of the tool\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#tool-call-spans\n */\nexport const AI_TOOL_CALL_NAME_ATTRIBUTE = 'ai.toolCall.name';\n\n/**\n * Tool call spans\n * `ai.toolCall` span\n *\n * The id of the tool call\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#tool-call-spans\n */\nexport const AI_TOOL_CALL_ID_ATTRIBUTE = 'ai.toolCall.id';\n\n/**\n * Tool call spans\n * `ai.toolCall` span\n *\n * The parameters of the tool call\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#tool-call-spans\n */\nexport const AI_TOOL_CALL_ARGS_ATTRIBUTE = 'ai.toolCall.args';\n\n/**\n * Tool call spans\n * `ai.toolCall` span\n *\n * The result of the tool call\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#tool-call-spans\n */\nexport const AI_TOOL_CALL_RESULT_ATTRIBUTE = 'ai.toolCall.result';\n\n// =============================================================================\n// SPAN ATTRIBUTE OBJECTS\n// =============================================================================\n\n/**\n * Attributes collected for `ai.generateText` span\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generatetext-function\n */\nexport const AI_GENERATE_TEXT_SPAN_ATTRIBUTES = {\n OPERATION_NAME: OPERATION_NAME_ATTRIBUTE,\n AI_OPERATION_ID: AI_OPERATION_ID_ATTRIBUTE,\n AI_PROMPT: AI_PROMPT_ATTRIBUTE,\n AI_RESPONSE_TEXT: AI_RESPONSE_TEXT_ATTRIBUTE,\n AI_RESPONSE_TOOL_CALLS: AI_RESPONSE_TOOL_CALLS_ATTRIBUTE,\n AI_RESPONSE_FINISH_REASON: AI_RESPONSE_FINISH_REASON_ATTRIBUTE,\n AI_SETTINGS_MAX_STEPS: AI_SETTINGS_MAX_STEPS_ATTRIBUTE,\n // Basic LLM span information\n RESOURCE_NAME: RESOURCE_NAME_ATTRIBUTE,\n AI_MODEL_ID: AI_MODEL_ID_ATTRIBUTE,\n AI_MODEL_PROVIDER: AI_MODEL_PROVIDER_ATTRIBUTE,\n AI_REQUEST_HEADERS: AI_REQUEST_HEADERS_ATTRIBUTE,\n AI_SETTINGS_MAX_RETRIES: AI_SETTINGS_MAX_RETRIES_ATTRIBUTE,\n AI_TELEMETRY_FUNCTION_ID: AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE,\n AI_TELEMETRY_METADATA: AI_TELEMETRY_METADATA_ATTRIBUTE,\n AI_USAGE_COMPLETION_TOKENS: AI_USAGE_COMPLETION_TOKENS_ATTRIBUTE,\n AI_USAGE_PROMPT_TOKENS: AI_USAGE_PROMPT_TOKENS_ATTRIBUTE,\n} as const;\n\n/**\n * Attributes collected for `ai.generateText.doGenerate` span\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generatetext-function\n */\nexport const AI_GENERATE_TEXT_DO_GENERATE_SPAN_ATTRIBUTES = {\n OPERATION_NAME: OPERATION_NAME_ATTRIBUTE,\n AI_OPERATION_ID: AI_OPERATION_ID_ATTRIBUTE,\n AI_PROMPT_FORMAT: AI_PROMPT_FORMAT_ATTRIBUTE,\n AI_PROMPT_MESSAGES: AI_PROMPT_MESSAGES_ATTRIBUTE,\n AI_PROMPT_TOOLS: AI_PROMPT_TOOLS_ATTRIBUTE,\n AI_PROMPT_TOOL_CHOICE: AI_PROMPT_TOOL_CHOICE_ATTRIBUTE,\n // Basic LLM span information\n RESOURCE_NAME: RESOURCE_NAME_ATTRIBUTE,\n AI_MODEL_ID: AI_MODEL_ID_ATTRIBUTE,\n AI_MODEL_PROVIDER: AI_MODEL_PROVIDER_ATTRIBUTE,\n AI_REQUEST_HEADERS: AI_REQUEST_HEADERS_ATTRIBUTE,\n AI_SETTINGS_MAX_RETRIES: AI_SETTINGS_MAX_RETRIES_ATTRIBUTE,\n AI_TELEMETRY_FUNCTION_ID: AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE,\n AI_TELEMETRY_METADATA: AI_TELEMETRY_METADATA_ATTRIBUTE,\n AI_USAGE_COMPLETION_TOKENS: AI_USAGE_COMPLETION_TOKENS_ATTRIBUTE,\n AI_USAGE_PROMPT_TOKENS: AI_USAGE_PROMPT_TOKENS_ATTRIBUTE,\n // Call LLM span information\n AI_RESPONSE_MODEL: AI_RESPONSE_MODEL_ATTRIBUTE,\n AI_RESPONSE_ID: AI_RESPONSE_ID_ATTRIBUTE,\n AI_RESPONSE_TIMESTAMP: AI_RESPONSE_TIMESTAMP_ATTRIBUTE,\n // Semantic Conventions for GenAI operations\n GEN_AI_SYSTEM: GEN_AI_SYSTEM_ATTRIBUTE,\n GEN_AI_REQUEST_MODEL: GEN_AI_REQUEST_MODEL_ATTRIBUTE,\n GEN_AI_REQUEST_TEMPERATURE: GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE,\n GEN_AI_REQUEST_MAX_TOKENS: GEN_AI_REQUEST_MAX_TOKENS_ATTRIBUTE,\n GEN_AI_REQUEST_FREQUENCY_PENALTY: GEN_AI_REQUEST_FREQUENCY_PENALTY_ATTRIBUTE,\n GEN_AI_REQUEST_PRESENCE_PENALTY: GEN_AI_REQUEST_PRESENCE_PENALTY_ATTRIBUTE,\n GEN_AI_REQUEST_TOP_K: GEN_AI_REQUEST_TOP_K_ATTRIBUTE,\n GEN_AI_REQUEST_TOP_P: GEN_AI_REQUEST_TOP_P_ATTRIBUTE,\n GEN_AI_REQUEST_STOP_SEQUENCES: GEN_AI_REQUEST_STOP_SEQUENCES_ATTRIBUTE,\n GEN_AI_RESPONSE_FINISH_REASONS: GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE,\n GEN_AI_RESPONSE_MODEL: GEN_AI_RESPONSE_MODEL_ATTRIBUTE,\n GEN_AI_RESPONSE_ID: GEN_AI_RESPONSE_ID_ATTRIBUTE,\n GEN_AI_USAGE_INPUT_TOKENS: GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE,\n GEN_AI_USAGE_OUTPUT_TOKENS: GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE,\n} as const;\n\n/**\n * Attributes collected for `ai.streamText` span\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#streamtext-function\n */\nexport const AI_STREAM_TEXT_SPAN_ATTRIBUTES = {\n OPERATION_NAME: OPERATION_NAME_ATTRIBUTE,\n AI_OPERATION_ID: AI_OPERATION_ID_ATTRIBUTE,\n AI_PROMPT: AI_PROMPT_ATTRIBUTE,\n // Basic LLM span information\n RESOURCE_NAME: RESOURCE_NAME_ATTRIBUTE,\n AI_MODEL_ID: AI_MODEL_ID_ATTRIBUTE,\n AI_MODEL_PROVIDER: AI_MODEL_PROVIDER_ATTRIBUTE,\n AI_REQUEST_HEADERS: AI_REQUEST_HEADERS_ATTRIBUTE,\n AI_SETTINGS_MAX_RETRIES: AI_SETTINGS_MAX_RETRIES_ATTRIBUTE,\n AI_TELEMETRY_FUNCTION_ID: AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE,\n AI_TELEMETRY_METADATA: AI_TELEMETRY_METADATA_ATTRIBUTE,\n AI_USAGE_COMPLETION_TOKENS: AI_USAGE_COMPLETION_TOKENS_ATTRIBUTE,\n AI_USAGE_PROMPT_TOKENS: AI_USAGE_PROMPT_TOKENS_ATTRIBUTE,\n} as const;\n\n/**\n * Attributes collected for `ai.streamText.doStream` span\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#streamtext-function\n */\nexport const AI_STREAM_TEXT_DO_STREAM_SPAN_ATTRIBUTES = {\n OPERATION_NAME: OPERATION_NAME_ATTRIBUTE,\n AI_OPERATION_ID: AI_OPERATION_ID_ATTRIBUTE,\n AI_RESPONSE_MS_TO_FIRST_CHUNK: AI_RESPONSE_MS_TO_FIRST_CHUNK_ATTRIBUTE,\n AI_RESPONSE_MS_TO_FINISH: AI_RESPONSE_MS_TO_FINISH_ATTRIBUTE,\n AI_RESPONSE_AVG_COMPLETION_TOKENS_PER_SECOND: AI_RESPONSE_AVG_COMPLETION_TOKENS_PER_SECOND_ATTRIBUTE,\n // Basic LLM span information\n RESOURCE_NAME: RESOURCE_NAME_ATTRIBUTE,\n AI_MODEL_ID: AI_MODEL_ID_ATTRIBUTE,\n AI_MODEL_PROVIDER: AI_MODEL_PROVIDER_ATTRIBUTE,\n AI_REQUEST_HEADERS: AI_REQUEST_HEADERS_ATTRIBUTE,\n AI_SETTINGS_MAX_RETRIES: AI_SETTINGS_MAX_RETRIES_ATTRIBUTE,\n AI_TELEMETRY_FUNCTION_ID: AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE,\n AI_TELEMETRY_METADATA: AI_TELEMETRY_METADATA_ATTRIBUTE,\n AI_USAGE_COMPLETION_TOKENS: AI_USAGE_COMPLETION_TOKENS_ATTRIBUTE,\n AI_USAGE_PROMPT_TOKENS: AI_USAGE_PROMPT_TOKENS_ATTRIBUTE,\n // Call LLM span information\n AI_RESPONSE_MODEL: AI_RESPONSE_MODEL_ATTRIBUTE,\n AI_RESPONSE_ID: AI_RESPONSE_ID_ATTRIBUTE,\n AI_RESPONSE_TIMESTAMP: AI_RESPONSE_TIMESTAMP_ATTRIBUTE,\n // Semantic Conventions for GenAI operations\n GEN_AI_SYSTEM: GEN_AI_SYSTEM_ATTRIBUTE,\n GEN_AI_REQUEST_MODEL: GEN_AI_REQUEST_MODEL_ATTRIBUTE,\n GEN_AI_REQUEST_TEMPERATURE: GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE,\n GEN_AI_REQUEST_MAX_TOKENS: GEN_AI_REQUEST_MAX_TOKENS_ATTRIBUTE,\n GEN_AI_REQUEST_FREQUENCY_PENALTY: GEN_AI_REQUEST_FREQUENCY_PENALTY_ATTRIBUTE,\n GEN_AI_REQUEST_PRESENCE_PENALTY: GEN_AI_REQUEST_PRESENCE_PENALTY_ATTRIBUTE,\n GEN_AI_REQUEST_TOP_K: GEN_AI_REQUEST_TOP_K_ATTRIBUTE,\n GEN_AI_REQUEST_TOP_P: GEN_AI_REQUEST_TOP_P_ATTRIBUTE,\n GEN_AI_REQUEST_STOP_SEQUENCES: GEN_AI_REQUEST_STOP_SEQUENCES_ATTRIBUTE,\n GEN_AI_RESPONSE_FINISH_REASONS: GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE,\n GEN_AI_RESPONSE_MODEL: GEN_AI_RESPONSE_MODEL_ATTRIBUTE,\n GEN_AI_RESPONSE_ID: GEN_AI_RESPONSE_ID_ATTRIBUTE,\n GEN_AI_USAGE_INPUT_TOKENS: GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE,\n GEN_AI_USAGE_OUTPUT_TOKENS: GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE,\n} as const;\n\n/**\n * Attributes collected for `ai.generateObject` span\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generateobject-function\n */\nexport const AI_GENERATE_OBJECT_SPAN_ATTRIBUTES = {\n OPERATION_NAME: OPERATION_NAME_ATTRIBUTE,\n AI_OPERATION_ID: AI_OPERATION_ID_ATTRIBUTE,\n AI_SCHEMA: AI_SCHEMA_ATTRIBUTE,\n AI_SCHEMA_NAME: AI_SCHEMA_NAME_ATTRIBUTE,\n AI_SCHEMA_DESCRIPTION: AI_SCHEMA_DESCRIPTION_ATTRIBUTE,\n AI_RESPONSE_OBJECT: AI_RESPONSE_OBJECT_ATTRIBUTE,\n AI_SETTINGS_MODE: AI_SETTINGS_MODE_ATTRIBUTE,\n AI_SETTINGS_OUTPUT: AI_SETTINGS_OUTPUT_ATTRIBUTE,\n // Basic LLM span information\n RESOURCE_NAME: RESOURCE_NAME_ATTRIBUTE,\n AI_MODEL_ID: AI_MODEL_ID_ATTRIBUTE,\n AI_MODEL_PROVIDER: AI_MODEL_PROVIDER_ATTRIBUTE,\n AI_REQUEST_HEADERS: AI_REQUEST_HEADERS_ATTRIBUTE,\n AI_SETTINGS_MAX_RETRIES: AI_SETTINGS_MAX_RETRIES_ATTRIBUTE,\n AI_TELEMETRY_FUNCTION_ID: AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE,\n AI_TELEMETRY_METADATA: AI_TELEMETRY_METADATA_ATTRIBUTE,\n AI_USAGE_COMPLETION_TOKENS: AI_USAGE_COMPLETION_TOKENS_ATTRIBUTE,\n AI_USAGE_PROMPT_TOKENS: AI_USAGE_PROMPT_TOKENS_ATTRIBUTE,\n} as const;\n\n/**\n * Attributes collected for `ai.streamObject` span\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#streamobject-function\n */\nexport const AI_STREAM_OBJECT_SPAN_ATTRIBUTES = {\n OPERATION_NAME: OPERATION_NAME_ATTRIBUTE,\n AI_OPERATION_ID: AI_OPERATION_ID_ATTRIBUTE,\n AI_SCHEMA: AI_SCHEMA_ATTRIBUTE,\n AI_SCHEMA_NAME: AI_SCHEMA_NAME_ATTRIBUTE,\n AI_SCHEMA_DESCRIPTION: AI_SCHEMA_DESCRIPTION_ATTRIBUTE,\n AI_RESPONSE_OBJECT: AI_RESPONSE_OBJECT_ATTRIBUTE,\n AI_SETTINGS_MODE: AI_SETTINGS_MODE_ATTRIBUTE,\n AI_SETTINGS_OUTPUT: AI_SETTINGS_OUTPUT_ATTRIBUTE,\n // Basic LLM span information\n RESOURCE_NAME: RESOURCE_NAME_ATTRIBUTE,\n AI_MODEL_ID: AI_MODEL_ID_ATTRIBUTE,\n AI_MODEL_PROVIDER: AI_MODEL_PROVIDER_ATTRIBUTE,\n AI_REQUEST_HEADERS: AI_REQUEST_HEADERS_ATTRIBUTE,\n AI_SETTINGS_MAX_RETRIES: AI_SETTINGS_MAX_RETRIES_ATTRIBUTE,\n AI_TELEMETRY_FUNCTION_ID: AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE,\n AI_TELEMETRY_METADATA: AI_TELEMETRY_METADATA_ATTRIBUTE,\n AI_USAGE_COMPLETION_TOKENS: AI_USAGE_COMPLETION_TOKENS_ATTRIBUTE,\n AI_USAGE_PROMPT_TOKENS: AI_USAGE_PROMPT_TOKENS_ATTRIBUTE,\n} as const;\n\n/**\n * Attributes collected for `ai.embed` span\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#embed-function\n */\nexport const AI_EMBED_SPAN_ATTRIBUTES = {\n OPERATION_NAME: OPERATION_NAME_ATTRIBUTE,\n AI_OPERATION_ID: AI_OPERATION_ID_ATTRIBUTE,\n AI_VALUE: AI_VALUE_ATTRIBUTE,\n AI_EMBEDDING: AI_EMBEDDING_ATTRIBUTE,\n // Basic LLM span information\n RESOURCE_NAME: RESOURCE_NAME_ATTRIBUTE,\n AI_MODEL_ID: AI_MODEL_ID_ATTRIBUTE,\n AI_MODEL_PROVIDER: AI_MODEL_PROVIDER_ATTRIBUTE,\n AI_REQUEST_HEADERS: AI_REQUEST_HEADERS_ATTRIBUTE,\n AI_SETTINGS_MAX_RETRIES: AI_SETTINGS_MAX_RETRIES_ATTRIBUTE,\n AI_TELEMETRY_FUNCTION_ID: AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE,\n AI_TELEMETRY_METADATA: AI_TELEMETRY_METADATA_ATTRIBUTE,\n // Basic embedding span information\n AI_USAGE_TOKENS: AI_USAGE_TOKENS_ATTRIBUTE,\n} as const;\n\n/**\n * Attributes collected for `ai.embed.doEmbed` span\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#embed-function\n */\nexport const AI_EMBED_DO_EMBED_SPAN_ATTRIBUTES = {\n OPERATION_NAME: OPERATION_NAME_ATTRIBUTE,\n AI_OPERATION_ID: AI_OPERATION_ID_ATTRIBUTE,\n AI_VALUES: AI_VALUES_ATTRIBUTE,\n AI_EMBEDDINGS: AI_EMBEDDINGS_ATTRIBUTE,\n // Basic LLM span information\n RESOURCE_NAME: RESOURCE_NAME_ATTRIBUTE,\n AI_MODEL_ID: AI_MODEL_ID_ATTRIBUTE,\n AI_MODEL_PROVIDER: AI_MODEL_PROVIDER_ATTRIBUTE,\n AI_REQUEST_HEADERS: AI_REQUEST_HEADERS_ATTRIBUTE,\n AI_SETTINGS_MAX_RETRIES: AI_SETTINGS_MAX_RETRIES_ATTRIBUTE,\n AI_TELEMETRY_FUNCTION_ID: AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE,\n AI_TELEMETRY_METADATA: AI_TELEMETRY_METADATA_ATTRIBUTE,\n // Basic embedding span information\n AI_USAGE_TOKENS: AI_USAGE_TOKENS_ATTRIBUTE,\n} as const;\n\n/**\n * Attributes collected for `ai.embedMany` span\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#embedmany-function\n */\nexport const AI_EMBED_MANY_SPAN_ATTRIBUTES = {\n OPERATION_NAME: OPERATION_NAME_ATTRIBUTE,\n AI_OPERATION_ID: AI_OPERATION_ID_ATTRIBUTE,\n AI_VALUES: AI_VALUES_ATTRIBUTE,\n AI_EMBEDDINGS: AI_EMBEDDINGS_ATTRIBUTE,\n // Basic LLM span information\n RESOURCE_NAME: RESOURCE_NAME_ATTRIBUTE,\n AI_MODEL_ID: AI_MODEL_ID_ATTRIBUTE,\n AI_MODEL_PROVIDER: AI_MODEL_PROVIDER_ATTRIBUTE,\n AI_REQUEST_HEADERS: AI_REQUEST_HEADERS_ATTRIBUTE,\n AI_SETTINGS_MAX_RETRIES: AI_SETTINGS_MAX_RETRIES_ATTRIBUTE,\n AI_TELEMETRY_FUNCTION_ID: AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE,\n AI_TELEMETRY_METADATA: AI_TELEMETRY_METADATA_ATTRIBUTE,\n // Basic embedding span information\n AI_USAGE_TOKENS: AI_USAGE_TOKENS_ATTRIBUTE,\n} as const;\n\n/**\n * Attributes collected for `ai.toolCall` span\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#tool-call-spans\n */\nexport const AI_TOOL_CALL_SPAN_ATTRIBUTES = {\n OPERATION_NAME: OPERATION_NAME_ATTRIBUTE,\n AI_OPERATION_ID: AI_OPERATION_ID_ATTRIBUTE,\n AI_TOOL_CALL_NAME: AI_TOOL_CALL_NAME_ATTRIBUTE,\n AI_TOOL_CALL_ID: AI_TOOL_CALL_ID_ATTRIBUTE,\n AI_TOOL_CALL_ARGS: AI_TOOL_CALL_ARGS_ATTRIBUTE,\n AI_TOOL_CALL_RESULT: AI_TOOL_CALL_RESULT_ATTRIBUTE,\n // Basic LLM span information\n RESOURCE_NAME: RESOURCE_NAME_ATTRIBUTE,\n AI_MODEL_ID: AI_MODEL_ID_ATTRIBUTE,\n AI_MODEL_PROVIDER: AI_MODEL_PROVIDER_ATTRIBUTE,\n AI_REQUEST_HEADERS: AI_REQUEST_HEADERS_ATTRIBUTE,\n AI_SETTINGS_MAX_RETRIES: AI_SETTINGS_MAX_RETRIES_ATTRIBUTE,\n AI_TELEMETRY_FUNCTION_ID: AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE,\n AI_TELEMETRY_METADATA: AI_TELEMETRY_METADATA_ATTRIBUTE,\n} as const;\n\n// =============================================================================\n// PROVIDER METADATA\n// =============================================================================\n\n/**\n * OpenAI Provider Metadata\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/openai\n * @see https://github.com/vercel/ai/blob/65e042afde6aad4da9d7a62526ece839eb34f9a5/packages/openai/src/openai-chat-language-model.ts#L397-L416\n * @see https://github.com/vercel/ai/blob/65e042afde6aad4da9d7a62526ece839eb34f9a5/packages/openai/src/responses/openai-responses-language-model.ts#L377C7-L384\n */\nexport interface OpenAiProviderMetadata {\n /**\n * The number of predicted output tokens that were accepted.\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/openai#predicted-outputs\n */\n acceptedPredictionTokens?: number;\n\n /**\n * The number of predicted output tokens that were rejected.\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/openai#predicted-outputs\n */\n rejectedPredictionTokens?: number;\n\n /**\n * The number of reasoning tokens that the model generated.\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/openai#responses-models\n */\n reasoningTokens?: number;\n\n /**\n * The number of prompt tokens that were a cache hit.\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/openai#responses-models\n */\n cachedPromptTokens?: number;\n\n /**\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/openai#responses-models\n *\n * The ID of the response. Can be used to continue a conversation.\n */\n responseId?: string;\n}\n\n/**\n * Anthropic Provider Metadata\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/anthropic\n * @see https://github.com/vercel/ai/blob/65e042afde6aad4da9d7a62526ece839eb34f9a5/packages/anthropic/src/anthropic-messages-language-model.ts#L346-L352\n */\ninterface AnthropicProviderMetadata {\n /**\n * The number of tokens that were used to create the cache.\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/anthropic#cache-control\n */\n cacheCreationInputTokens?: number;\n\n /**\n * The number of tokens that were read from the cache.\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/anthropic#cache-control\n */\n cacheReadInputTokens?: number;\n\n /**\n * Usage metrics for the Anthropic model.\n */\n usage?: {\n input_tokens: number;\n cache_creation_input_tokens?: number;\n cache_read_input_tokens?: number;\n cache_creation?: {\n ephemeral_5m_input_tokens?: number;\n ephemeral_1h_input_tokens?: number;\n };\n output_tokens?: number;\n service_tier?: string;\n };\n}\n\n/**\n * Amazon Bedrock Provider Metadata\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/amazon-bedrock\n * @see https://github.com/vercel/ai/blob/65e042afde6aad4da9d7a62526ece839eb34f9a5/packages/amazon-bedrock/src/bedrock-chat-language-model.ts#L263-L280\n */\ninterface AmazonBedrockProviderMetadata {\n /**\n * @see https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseTrace.html\n */\n trace?: {\n /**\n * The guardrail trace object.\n * @see https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_GuardrailTraceAssessment.html\n *\n * This was purposely left as unknown as it's a complex object. This can be typed in the future\n * if the SDK decides to support bedrock in a more advanced way.\n */\n guardrail?: unknown;\n /**\n * The request's prompt router.\n * @see https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_PromptRouterTrace.html\n */\n promptRouter?: {\n /**\n * The ID of the invoked model.\n */\n invokedModelId?: string;\n };\n };\n usage?: {\n /**\n * The number of tokens that were read from the cache.\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/amazon-bedrock#cache-points\n */\n cacheReadInputTokens?: number;\n\n /**\n * The number of tokens that were written to the cache.\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/amazon-bedrock#cache-points\n */\n cacheWriteInputTokens?: number;\n };\n}\n\n/**\n * Google Generative AI Provider Metadata\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai\n */\nexport interface GoogleGenerativeAIProviderMetadata {\n /**\n * @see https://github.com/vercel/ai/blob/65e042afde6aad4da9d7a62526ece839eb34f9a5/packages/google/src/google-generative-ai-prompt.ts#L28-L30\n */\n groundingMetadata: null | {\n /**\n * Array of search queries used to retrieve information\n * @example [\"What's the weather in Chicago this weekend?\"]\n *\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai#search-grounding\n */\n webSearchQueries: string[] | null;\n /**\n * Contains the main search result content used as an entry point\n * The `renderedContent` field contains the formatted content\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai#search-grounding\n */\n searchEntryPoint?: {\n renderedContent: string;\n } | null;\n /**\n * Contains details about how specific response parts are supported by search results\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai#search-grounding\n */\n groundingSupports: Array<{\n /**\n * Information about the grounded text segment.\n */\n segment: {\n /**\n * The start index of the text segment.\n */\n startIndex?: number | null;\n /**\n * The end index of the text segment.\n */\n endIndex?: number | null;\n /**\n * The actual text segment.\n */\n text?: string | null;\n };\n /**\n * References to supporting search result chunks.\n */\n groundingChunkIndices?: number[] | null;\n /**\n * Confidence scores (0-1) for each supporting chunk.\n */\n confidenceScores?: number[] | null;\n }> | null;\n };\n /**\n * @see https://github.com/vercel/ai/blob/65e042afde6aad4da9d7a62526ece839eb34f9a5/packages/google/src/google-generative-ai-language-model.ts#L620-L627\n * @see https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/configure-safety-filters\n */\n safetyRatings?: null | unknown;\n}\n\n/**\n * DeepSeek Provider Metadata\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/deepseek\n */\ninterface DeepSeekProviderMetadata {\n /**\n * The number of tokens that were cache hits.\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/deepseek#cache-token-usage\n */\n promptCacheHitTokens?: number;\n\n /**\n * The number of tokens that were cache misses.\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/deepseek#cache-token-usage\n */\n promptCacheMissTokens?: number;\n}\n\n/**\n * Perplexity Provider Metadata\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/perplexity\n */\ninterface PerplexityProviderMetadata {\n /**\n * Object containing citationTokens and numSearchQueries metrics\n */\n usage?: {\n citationTokens?: number;\n numSearchQueries?: number;\n };\n /**\n * Array of image URLs when return_images is enabled.\n *\n * You can enable image responses by setting return_images: true in the provider options.\n * This feature is only available to Perplexity Tier-2 users and above.\n */\n images?: Array<{\n imageUrl?: string;\n originUrl?: string;\n height?: number;\n width?: number;\n }>;\n}\n\nexport interface ProviderMetadata {\n openai?: OpenAiProviderMetadata;\n azure?: OpenAiProviderMetadata; // v6: Azure Responses API uses 'azure' key instead of 'openai'\n anthropic?: AnthropicProviderMetadata;\n bedrock?: AmazonBedrockProviderMetadata;\n google?: GoogleGenerativeAIProviderMetadata;\n vertex?: GoogleGenerativeAIProviderMetadata; // v6: Google Vertex uses 'vertex' key instead of 'google'\n deepseek?: DeepSeekProviderMetadata;\n perplexity?: PerplexityProviderMetadata;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACO,MAAM,wBAAA,GAA2B;;AAExC;AACA;AACA;AACA;AACO,MAAM,yBAAA,GAA4B;;AAEzC;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,mBAAA,GAAsB;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,mBAAA,GAAsB;;AAsBnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,4BAAA,GAA+B;;AAsB5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,mBAAA,GAAsB;;AAYnC;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,0BAAA,GAA6B;;AAE1C;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,gCAAA,GAAmC;;AAEhD;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,mCAAA,GAAsC;;AAkBnD;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,4BAAA,GAA+B;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,yBAAA,GAA4B;;AAuEzC;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,qBAAA,GAAwB;;AAoBrC;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,uCAAA,GAA0C;;AAWvD;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,sCAAA,GAAyC;AACtD;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,kCAAA,GAAqC;;AAWlD;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,oCAAA,GAAuC;;AAEpD;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,gCAAA,GAAmC;;AAmKhD;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,yBAAA,GAA4B;;AAEzC;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,2BAAA,GAA8B;;AAE3C;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,yBAAA,GAA4B;;AAEzC;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,2BAAA,GAA8B;;AAE3C;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,6BAAA,GAAgC;;AA2Q7C;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;;;"}
1
+ {"version":3,"file":"vercel-ai-attributes.js","sources":["../../../../src/tracing/vercel-ai/vercel-ai-attributes.ts"],"sourcesContent":["/**\n * AI SDK Telemetry Attributes\n * Based on https://ai-sdk.dev/docs/ai-sdk-core/telemetry#collected-data\n */\n\n// =============================================================================\n// COMMON ATTRIBUTES\n// =============================================================================\n\n/**\n * Common attribute for operation name across all functions and spans\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#collected-data\n */\nexport const OPERATION_NAME_ATTRIBUTE = 'operation.name';\n\n/**\n * Common attribute for AI operation ID across all functions and spans\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#collected-data\n */\nexport const AI_OPERATION_ID_ATTRIBUTE = 'ai.operationId';\n\n// =============================================================================\n// SHARED ATTRIBUTES\n// =============================================================================\n\n/**\n * `generateText` function - `ai.generateText` span\n * `streamText` function - `ai.streamText` span\n *\n * The prompt that was used when calling the function\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generatetext-function\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#streamtext-function\n */\nexport const AI_PROMPT_ATTRIBUTE = 'ai.prompt';\n\n/**\n * `generateObject` function - `ai.generateObject` span\n * `streamObject` function - `ai.streamObject` span\n *\n * The JSON schema version of the schema that was passed into the function\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generateobject-function\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#streamobject-function\n */\nexport const AI_SCHEMA_ATTRIBUTE = 'ai.schema';\n\n/**\n * `generateObject` function - `ai.generateObject` span\n * `streamObject` function - `ai.streamObject` span\n *\n * The object that was generated (stringified JSON)\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generateobject-function\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#streamobject-function\n */\nexport const AI_RESPONSE_OBJECT_ATTRIBUTE = 'ai.response.object';\n\n/**\n * `embed` function - `ai.embed.doEmbed` span\n * `embedMany` function - `ai.embedMany` span\n *\n * The values that were passed into the function (array)\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#embed-function\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#embedmany-function\n */\nexport const AI_VALUES_ATTRIBUTE = 'ai.values';\n\n// =============================================================================\n// GENERATETEXT FUNCTION - UNIQUE ATTRIBUTES\n// =============================================================================\n\n/**\n * `generateText` function - `ai.generateText` span\n *\n * The text that was generated\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generatetext-function\n */\nexport const AI_RESPONSE_TEXT_ATTRIBUTE = 'ai.response.text';\n\n/**\n * `generateText` function - `ai.generateText` span\n *\n * The tool calls that were made as part of the generation (stringified JSON)\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generatetext-function\n */\nexport const AI_RESPONSE_TOOL_CALLS_ATTRIBUTE = 'ai.response.toolCalls';\n\n/**\n * `generateText` function - `ai.generateText` span\n *\n * The reason why the generation finished\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generatetext-function\n */\nexport const AI_RESPONSE_FINISH_REASON_ATTRIBUTE = 'ai.response.finishReason';\n\n/**\n * `generateText` function - `ai.generateText` span\n *\n * The maximum number of steps that were set\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generatetext-function\n */\nexport const AI_SETTINGS_MAX_STEPS_ATTRIBUTE = 'ai.settings.maxSteps';\n\n/**\n * `generateText` function - `ai.generateText.doGenerate` span\n *\n * The messages that were passed into the provider\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generatetext-function\n */\nexport const AI_PROMPT_MESSAGES_ATTRIBUTE = 'ai.prompt.messages';\n\n/**\n * `generateText` function - `ai.generateText.doGenerate` span\n *\n * Array of stringified tool definitions\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#generatetext-function\n */\nexport const AI_PROMPT_TOOLS_ATTRIBUTE = 'ai.prompt.tools';\n\n// =============================================================================\n// BASIC LLM SPAN INFORMATION\n// =============================================================================\n\n/**\n * Basic LLM span information\n * Multiple spans\n *\n * The id of the model\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#basic-llm-span-information\n */\nexport const AI_MODEL_ID_ATTRIBUTE = 'ai.model.id';\n\n/**\n * Basic LLM span information\n * Multiple spans\n *\n * Provider specific metadata returned with the generation response\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#basic-llm-span-information\n */\nexport const AI_RESPONSE_PROVIDER_METADATA_ATTRIBUTE = 'ai.response.providerMetadata';\n\n/**\n * Basic LLM span information\n * Multiple spans\n *\n * The number of cached input tokens that were used\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#basic-llm-span-information\n */\nexport const AI_USAGE_CACHED_INPUT_TOKENS_ATTRIBUTE = 'ai.usage.cachedInputTokens';\n/**\n * Basic LLM span information\n * Multiple spans\n *\n * The functionId that was set through `telemetry.functionId`\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#basic-llm-span-information\n */\nexport const AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE = 'ai.telemetry.functionId';\n\n/**\n * Basic LLM span information\n * Multiple spans\n *\n * The number of completion tokens that were used\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#basic-llm-span-information\n */\nexport const AI_USAGE_COMPLETION_TOKENS_ATTRIBUTE = 'ai.usage.completionTokens';\n\n/**\n * Basic LLM span information\n * Multiple spans\n *\n * The number of prompt tokens that were used\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#basic-llm-span-information\n */\nexport const AI_USAGE_PROMPT_TOKENS_ATTRIBUTE = 'ai.usage.promptTokens';\n\n// =============================================================================\n// CALL LLM SPAN INFORMATION\n// =============================================================================\n\n/**\n * Call LLM span information\n * Individual LLM call spans\n *\n * The model that was used to generate the response\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#call-llm-span-information\n */\nexport const AI_RESPONSE_MODEL_ATTRIBUTE = 'ai.response.model';\n\n/**\n * Call LLM span information\n * Individual LLM call spans\n *\n * The id of the response\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#call-llm-span-information\n */\nexport const AI_RESPONSE_ID_ATTRIBUTE = 'ai.response.id';\n\n/**\n * Call LLM span information\n * Individual LLM call spans\n *\n * The timestamp of the response\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#call-llm-span-information\n */\nexport const AI_RESPONSE_TIMESTAMP_ATTRIBUTE = 'ai.response.timestamp';\n\n// =============================================================================\n// BASIC EMBEDDING SPAN INFORMATION\n// =============================================================================\n\n/**\n * Basic embedding span information\n * Embedding spans\n *\n * The number of tokens that were used\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#basic-embedding-span-information\n */\nexport const AI_USAGE_TOKENS_ATTRIBUTE = 'ai.usage.tokens';\n\n// =============================================================================\n// TOOL CALL SPANS\n// =============================================================================\n\n/**\n * Tool call spans\n * `ai.toolCall` span\n *\n * The name of the tool\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#tool-call-spans\n */\nexport const AI_TOOL_CALL_NAME_ATTRIBUTE = 'ai.toolCall.name';\n\n/**\n * Tool call spans\n * `ai.toolCall` span\n *\n * The id of the tool call\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#tool-call-spans\n */\nexport const AI_TOOL_CALL_ID_ATTRIBUTE = 'ai.toolCall.id';\n\n/**\n * Tool call spans\n * `ai.toolCall` span\n *\n * The parameters of the tool call\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#tool-call-spans\n */\nexport const AI_TOOL_CALL_ARGS_ATTRIBUTE = 'ai.toolCall.args';\n\n/**\n * Tool call spans\n * `ai.toolCall` span\n *\n * The result of the tool call\n * @see https://ai-sdk.dev/docs/ai-sdk-core/telemetry#tool-call-spans\n */\nexport const AI_TOOL_CALL_RESULT_ATTRIBUTE = 'ai.toolCall.result';\n\n// =============================================================================\n// PROVIDER METADATA\n// =============================================================================\n\n/**\n * OpenAI Provider Metadata\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/openai\n * @see https://github.com/vercel/ai/blob/65e042afde6aad4da9d7a62526ece839eb34f9a5/packages/openai/src/openai-chat-language-model.ts#L397-L416\n * @see https://github.com/vercel/ai/blob/65e042afde6aad4da9d7a62526ece839eb34f9a5/packages/openai/src/responses/openai-responses-language-model.ts#L377C7-L384\n */\nexport interface OpenAiProviderMetadata {\n /**\n * The number of predicted output tokens that were accepted.\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/openai#predicted-outputs\n */\n acceptedPredictionTokens?: number;\n\n /**\n * The number of predicted output tokens that were rejected.\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/openai#predicted-outputs\n */\n rejectedPredictionTokens?: number;\n\n /**\n * The number of reasoning tokens that the model generated.\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/openai#responses-models\n */\n reasoningTokens?: number;\n\n /**\n * The number of prompt tokens that were a cache hit.\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/openai#responses-models\n */\n cachedPromptTokens?: number;\n\n /**\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/openai#responses-models\n *\n * The ID of the response. Can be used to continue a conversation.\n */\n responseId?: string;\n}\n\n/**\n * Anthropic Provider Metadata\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/anthropic\n * @see https://github.com/vercel/ai/blob/65e042afde6aad4da9d7a62526ece839eb34f9a5/packages/anthropic/src/anthropic-messages-language-model.ts#L346-L352\n */\ninterface AnthropicProviderMetadata {\n /**\n * The number of tokens that were used to create the cache.\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/anthropic#cache-control\n */\n cacheCreationInputTokens?: number;\n\n /**\n * The number of tokens that were read from the cache.\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/anthropic#cache-control\n */\n cacheReadInputTokens?: number;\n\n /**\n * Usage metrics for the Anthropic model.\n */\n usage?: {\n input_tokens: number;\n cache_creation_input_tokens?: number;\n cache_read_input_tokens?: number;\n cache_creation?: {\n ephemeral_5m_input_tokens?: number;\n ephemeral_1h_input_tokens?: number;\n };\n output_tokens?: number;\n service_tier?: string;\n };\n}\n\n/**\n * Amazon Bedrock Provider Metadata\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/amazon-bedrock\n * @see https://github.com/vercel/ai/blob/65e042afde6aad4da9d7a62526ece839eb34f9a5/packages/amazon-bedrock/src/bedrock-chat-language-model.ts#L263-L280\n */\ninterface AmazonBedrockProviderMetadata {\n /**\n * @see https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseTrace.html\n */\n trace?: {\n /**\n * The guardrail trace object.\n * @see https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_GuardrailTraceAssessment.html\n *\n * This was purposely left as unknown as it's a complex object. This can be typed in the future\n * if the SDK decides to support bedrock in a more advanced way.\n */\n guardrail?: unknown;\n /**\n * The request's prompt router.\n * @see https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_PromptRouterTrace.html\n */\n promptRouter?: {\n /**\n * The ID of the invoked model.\n */\n invokedModelId?: string;\n };\n };\n usage?: {\n /**\n * The number of tokens that were read from the cache.\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/amazon-bedrock#cache-points\n */\n cacheReadInputTokens?: number;\n\n /**\n * The number of tokens that were written to the cache.\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/amazon-bedrock#cache-points\n */\n cacheWriteInputTokens?: number;\n };\n}\n\n/**\n * Google Generative AI Provider Metadata\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai\n */\nexport interface GoogleGenerativeAIProviderMetadata {\n /**\n * @see https://github.com/vercel/ai/blob/65e042afde6aad4da9d7a62526ece839eb34f9a5/packages/google/src/google-generative-ai-prompt.ts#L28-L30\n */\n groundingMetadata: null | {\n /**\n * Array of search queries used to retrieve information\n * @example [\"What's the weather in Chicago this weekend?\"]\n *\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai#search-grounding\n */\n webSearchQueries: string[] | null;\n /**\n * Contains the main search result content used as an entry point\n * The `renderedContent` field contains the formatted content\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai#search-grounding\n */\n searchEntryPoint?: {\n renderedContent: string;\n } | null;\n /**\n * Contains details about how specific response parts are supported by search results\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai#search-grounding\n */\n groundingSupports: Array<{\n /**\n * Information about the grounded text segment.\n */\n segment: {\n /**\n * The start index of the text segment.\n */\n startIndex?: number | null;\n /**\n * The end index of the text segment.\n */\n endIndex?: number | null;\n /**\n * The actual text segment.\n */\n text?: string | null;\n };\n /**\n * References to supporting search result chunks.\n */\n groundingChunkIndices?: number[] | null;\n /**\n * Confidence scores (0-1) for each supporting chunk.\n */\n confidenceScores?: number[] | null;\n }> | null;\n };\n /**\n * @see https://github.com/vercel/ai/blob/65e042afde6aad4da9d7a62526ece839eb34f9a5/packages/google/src/google-generative-ai-language-model.ts#L620-L627\n * @see https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/configure-safety-filters\n */\n safetyRatings?: null | unknown;\n}\n\n/**\n * DeepSeek Provider Metadata\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/deepseek\n */\ninterface DeepSeekProviderMetadata {\n /**\n * The number of tokens that were cache hits.\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/deepseek#cache-token-usage\n */\n promptCacheHitTokens?: number;\n\n /**\n * The number of tokens that were cache misses.\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/deepseek#cache-token-usage\n */\n promptCacheMissTokens?: number;\n}\n\n/**\n * Perplexity Provider Metadata\n * @see https://ai-sdk.dev/providers/ai-sdk-providers/perplexity\n */\ninterface PerplexityProviderMetadata {\n /**\n * Object containing citationTokens and numSearchQueries metrics\n */\n usage?: {\n citationTokens?: number;\n numSearchQueries?: number;\n };\n /**\n * Array of image URLs when return_images is enabled.\n *\n * You can enable image responses by setting return_images: true in the provider options.\n * This feature is only available to Perplexity Tier-2 users and above.\n */\n images?: Array<{\n imageUrl?: string;\n originUrl?: string;\n height?: number;\n width?: number;\n }>;\n}\n\nexport interface ProviderMetadata {\n openai?: OpenAiProviderMetadata;\n azure?: OpenAiProviderMetadata; // v6: Azure Responses API uses 'azure' key instead of 'openai'\n anthropic?: AnthropicProviderMetadata;\n bedrock?: AmazonBedrockProviderMetadata;\n google?: GoogleGenerativeAIProviderMetadata;\n vertex?: GoogleGenerativeAIProviderMetadata; // v6: Google Vertex uses 'vertex' key instead of 'google'\n deepseek?: DeepSeekProviderMetadata;\n perplexity?: PerplexityProviderMetadata;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACO,MAAM,wBAAA,GAA2B;;AAExC;AACA;AACA;AACA;AACO,MAAM,yBAAA,GAA4B;;AAEzC;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,mBAAA,GAAsB;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,mBAAA,GAAsB;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,4BAAA,GAA+B;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,mBAAA,GAAsB;;AAEnC;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,0BAAA,GAA6B;;AAE1C;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,gCAAA,GAAmC;;AAEhD;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,mCAAA,GAAsC;;AAUnD;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,4BAAA,GAA+B;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,yBAAA,GAA4B;;AAEzC;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,qBAAA,GAAwB;;AAErC;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,uCAAA,GAA0C;;AAEvD;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,sCAAA,GAAyC;AACtD;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,kCAAA,GAAqC;;AAElD;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,oCAAA,GAAuC;;AAEpD;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,gCAAA,GAAmC;;AAiChD;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,yBAAA,GAA4B;;AAEzC;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,2BAAA,GAA8B;;AAE3C;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,yBAAA,GAA4B;;AAEzC;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,2BAAA,GAA8B;;AAE3C;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,6BAAA,GAAgC;;AAE7C;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;;;"}
@@ -138,15 +138,14 @@ function getLocationHref() {
138
138
  *
139
139
  * @returns a string representation of the component for the provided DOM element, or `null` if not found
140
140
  */
141
- function getComponentName(elem) {
141
+ function getComponentName(elem, maxTraverseHeight = 5) {
142
142
  // @ts-expect-error WINDOW has HTMLElement
143
143
  if (!WINDOW.HTMLElement) {
144
144
  return null;
145
145
  }
146
146
 
147
147
  let currentElem = elem ;
148
- const MAX_TRAVERSE_HEIGHT = 5;
149
- for (let i = 0; i < MAX_TRAVERSE_HEIGHT; i++) {
148
+ for (let i = 0; i < maxTraverseHeight; i++) {
150
149
  if (!currentElem) {
151
150
  return null;
152
151
  }
@@ -1 +1 @@
1
- {"version":3,"file":"browser.js","sources":["../../../src/utils/browser.ts"],"sourcesContent":["import { isString } from './is';\nimport { GLOBAL_OBJ } from './worldwide';\n\nconst WINDOW = GLOBAL_OBJ as unknown as Window;\n\nconst DEFAULT_MAX_STRING_LENGTH = 80;\n\ntype SimpleNode = {\n parentNode: SimpleNode;\n} | null;\n\n/**\n * Given a child DOM element, returns a query-selector statement describing that\n * and its ancestors\n * e.g. [HTMLElement] => body > div > input#foo.btn[name=baz]\n * @returns generated DOM path\n */\nexport function htmlTreeAsString(\n elem: unknown,\n options: string[] | { keyAttrs?: string[]; maxStringLength?: number } = {},\n): string {\n if (!elem) {\n return '<unknown>';\n }\n\n // try/catch both:\n // - accessing event.target (see getsentry/raven-js#838, #768)\n // - `htmlTreeAsString` because it's complex, and just accessing the DOM incorrectly\n // - can throw an exception in some circumstances.\n try {\n let currentElem = elem as SimpleNode;\n const MAX_TRAVERSE_HEIGHT = 5;\n const out = [];\n let height = 0;\n let len = 0;\n const separator = ' > ';\n const sepLength = separator.length;\n let nextStr;\n const keyAttrs = Array.isArray(options) ? options : options.keyAttrs;\n const maxStringLength = (!Array.isArray(options) && options.maxStringLength) || DEFAULT_MAX_STRING_LENGTH;\n\n while (currentElem && height++ < MAX_TRAVERSE_HEIGHT) {\n nextStr = _htmlElementAsString(currentElem, keyAttrs);\n // bail out if\n // - nextStr is the 'html' element\n // - the length of the string that would be created exceeds maxStringLength\n // (ignore this limit if we are on the first iteration)\n if (nextStr === 'html' || (height > 1 && len + out.length * sepLength + nextStr.length >= maxStringLength)) {\n break;\n }\n\n out.push(nextStr);\n\n len += nextStr.length;\n currentElem = currentElem.parentNode;\n }\n\n return out.reverse().join(separator);\n } catch {\n return '<unknown>';\n }\n}\n\n/**\n * Returns a simple, query-selector representation of a DOM element\n * e.g. [HTMLElement] => input#foo.btn[name=baz]\n * @returns generated DOM path\n */\nfunction _htmlElementAsString(el: unknown, keyAttrs?: string[]): string {\n const elem = el as {\n tagName?: string;\n id?: string;\n className?: string;\n getAttribute(key: string): string;\n };\n\n const out = [];\n\n if (!elem?.tagName) {\n return '';\n }\n\n // @ts-expect-error WINDOW has HTMLElement\n if (WINDOW.HTMLElement) {\n // If using the component name annotation plugin, this value may be available on the DOM node\n if (elem instanceof HTMLElement && elem.dataset) {\n if (elem.dataset['sentryComponent']) {\n return elem.dataset['sentryComponent'];\n }\n if (elem.dataset['sentryElement']) {\n return elem.dataset['sentryElement'];\n }\n }\n }\n\n out.push(elem.tagName.toLowerCase());\n\n // Pairs of attribute keys defined in `serializeAttribute` and their values on element.\n const keyAttrPairs = keyAttrs?.length\n ? keyAttrs.filter(keyAttr => elem.getAttribute(keyAttr)).map(keyAttr => [keyAttr, elem.getAttribute(keyAttr)])\n : null;\n\n if (keyAttrPairs?.length) {\n keyAttrPairs.forEach(keyAttrPair => {\n out.push(`[${keyAttrPair[0]}=\"${keyAttrPair[1]}\"]`);\n });\n } else {\n if (elem.id) {\n out.push(`#${elem.id}`);\n }\n\n const className = elem.className;\n if (className && isString(className)) {\n const classes = className.split(/\\s+/);\n for (const c of classes) {\n out.push(`.${c}`);\n }\n }\n }\n for (const k of ['aria-label', 'type', 'name', 'title', 'alt']) {\n const attr = elem.getAttribute(k);\n if (attr) {\n out.push(`[${k}=\"${attr}\"]`);\n }\n }\n\n return out.join('');\n}\n\n/**\n * A safe form of location.href\n */\nexport function getLocationHref(): string {\n try {\n return WINDOW.document.location.href;\n } catch {\n return '';\n }\n}\n\n/**\n * Given a DOM element, traverses up the tree until it finds the first ancestor node\n * that has the `data-sentry-component` or `data-sentry-element` attribute with `data-sentry-component` taking\n * precedence. This attribute is added at build-time by projects that have the component name annotation plugin installed.\n *\n * @returns a string representation of the component for the provided DOM element, or `null` if not found\n */\nexport function getComponentName(elem: unknown): string | null {\n // @ts-expect-error WINDOW has HTMLElement\n if (!WINDOW.HTMLElement) {\n return null;\n }\n\n let currentElem = elem as SimpleNode;\n const MAX_TRAVERSE_HEIGHT = 5;\n for (let i = 0; i < MAX_TRAVERSE_HEIGHT; i++) {\n if (!currentElem) {\n return null;\n }\n\n if (currentElem instanceof HTMLElement) {\n if (currentElem.dataset['sentryComponent']) {\n return currentElem.dataset['sentryComponent'];\n }\n if (currentElem.dataset['sentryElement']) {\n return currentElem.dataset['sentryElement'];\n }\n }\n\n currentElem = currentElem.parentNode;\n }\n\n return null;\n}\n"],"names":[],"mappings":";;;AAGA,MAAM,MAAA,GAAS,UAAA;;AAEf,MAAM,yBAAA,GAA4B,EAAE;;AAMpC;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,gBAAgB;AAChC,EAAE,IAAI;AACN,EAAE,OAAO,GAAiE,EAAE;AAC5E,EAAU;AACV,EAAE,IAAI,CAAC,IAAI,EAAE;AACb,IAAI,OAAO,WAAW;AACtB,EAAE;;AAEF;AACA;AACA;AACA;AACA,EAAE,IAAI;AACN,IAAI,IAAI,WAAA,GAAc,IAAA;AACtB,IAAI,MAAM,mBAAA,GAAsB,CAAC;AACjC,IAAI,MAAM,GAAA,GAAM,EAAE;AAClB,IAAI,IAAI,MAAA,GAAS,CAAC;AAClB,IAAI,IAAI,GAAA,GAAM,CAAC;AACf,IAAI,MAAM,SAAA,GAAY,KAAK;AAC3B,IAAI,MAAM,SAA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,iBAAA,CAAA;AACA,MAAA;AACA,MAAA,IAAA,WAAA,CAAA,OAAA,CAAA,eAAA,CAAA,EAAA;AACA,QAAA,OAAA,WAAA,CAAA,OAAA,CAAA,eAAA,CAAA;AACA,MAAA;AACA,IAAA;;AAEA,IAAA,WAAA,GAAA,WAAA,CAAA,UAAA;AACA,EAAA;;AAEA,EAAA,OAAA,IAAA;AACA;;;;"}
1
+ {"version":3,"file":"browser.js","sources":["../../../src/utils/browser.ts"],"sourcesContent":["import { isString } from './is';\nimport { GLOBAL_OBJ } from './worldwide';\n\nconst WINDOW = GLOBAL_OBJ as unknown as Window;\n\nconst DEFAULT_MAX_STRING_LENGTH = 80;\n\ntype SimpleNode = {\n parentNode: SimpleNode;\n} | null;\n\n/**\n * Given a child DOM element, returns a query-selector statement describing that\n * and its ancestors\n * e.g. [HTMLElement] => body > div > input#foo.btn[name=baz]\n * @returns generated DOM path\n */\nexport function htmlTreeAsString(\n elem: unknown,\n options: string[] | { keyAttrs?: string[]; maxStringLength?: number } = {},\n): string {\n if (!elem) {\n return '<unknown>';\n }\n\n // try/catch both:\n // - accessing event.target (see getsentry/raven-js#838, #768)\n // - `htmlTreeAsString` because it's complex, and just accessing the DOM incorrectly\n // - can throw an exception in some circumstances.\n try {\n let currentElem = elem as SimpleNode;\n const MAX_TRAVERSE_HEIGHT = 5;\n const out = [];\n let height = 0;\n let len = 0;\n const separator = ' > ';\n const sepLength = separator.length;\n let nextStr;\n const keyAttrs = Array.isArray(options) ? options : options.keyAttrs;\n const maxStringLength = (!Array.isArray(options) && options.maxStringLength) || DEFAULT_MAX_STRING_LENGTH;\n\n while (currentElem && height++ < MAX_TRAVERSE_HEIGHT) {\n nextStr = _htmlElementAsString(currentElem, keyAttrs);\n // bail out if\n // - nextStr is the 'html' element\n // - the length of the string that would be created exceeds maxStringLength\n // (ignore this limit if we are on the first iteration)\n if (nextStr === 'html' || (height > 1 && len + out.length * sepLength + nextStr.length >= maxStringLength)) {\n break;\n }\n\n out.push(nextStr);\n\n len += nextStr.length;\n currentElem = currentElem.parentNode;\n }\n\n return out.reverse().join(separator);\n } catch {\n return '<unknown>';\n }\n}\n\n/**\n * Returns a simple, query-selector representation of a DOM element\n * e.g. [HTMLElement] => input#foo.btn[name=baz]\n * @returns generated DOM path\n */\nfunction _htmlElementAsString(el: unknown, keyAttrs?: string[]): string {\n const elem = el as {\n tagName?: string;\n id?: string;\n className?: string;\n getAttribute(key: string): string;\n };\n\n const out = [];\n\n if (!elem?.tagName) {\n return '';\n }\n\n // @ts-expect-error WINDOW has HTMLElement\n if (WINDOW.HTMLElement) {\n // If using the component name annotation plugin, this value may be available on the DOM node\n if (elem instanceof HTMLElement && elem.dataset) {\n if (elem.dataset['sentryComponent']) {\n return elem.dataset['sentryComponent'];\n }\n if (elem.dataset['sentryElement']) {\n return elem.dataset['sentryElement'];\n }\n }\n }\n\n out.push(elem.tagName.toLowerCase());\n\n // Pairs of attribute keys defined in `serializeAttribute` and their values on element.\n const keyAttrPairs = keyAttrs?.length\n ? keyAttrs.filter(keyAttr => elem.getAttribute(keyAttr)).map(keyAttr => [keyAttr, elem.getAttribute(keyAttr)])\n : null;\n\n if (keyAttrPairs?.length) {\n keyAttrPairs.forEach(keyAttrPair => {\n out.push(`[${keyAttrPair[0]}=\"${keyAttrPair[1]}\"]`);\n });\n } else {\n if (elem.id) {\n out.push(`#${elem.id}`);\n }\n\n const className = elem.className;\n if (className && isString(className)) {\n const classes = className.split(/\\s+/);\n for (const c of classes) {\n out.push(`.${c}`);\n }\n }\n }\n for (const k of ['aria-label', 'type', 'name', 'title', 'alt']) {\n const attr = elem.getAttribute(k);\n if (attr) {\n out.push(`[${k}=\"${attr}\"]`);\n }\n }\n\n return out.join('');\n}\n\n/**\n * A safe form of location.href\n */\nexport function getLocationHref(): string {\n try {\n return WINDOW.document.location.href;\n } catch {\n return '';\n }\n}\n\n/**\n * Given a DOM element, traverses up the tree until it finds the first ancestor node\n * that has the `data-sentry-component` or `data-sentry-element` attribute with `data-sentry-component` taking\n * precedence. This attribute is added at build-time by projects that have the component name annotation plugin installed.\n *\n * @returns a string representation of the component for the provided DOM element, or `null` if not found\n */\nexport function getComponentName(elem: unknown, maxTraverseHeight: number = 5): string | null {\n // @ts-expect-error WINDOW has HTMLElement\n if (!WINDOW.HTMLElement) {\n return null;\n }\n\n let currentElem = elem as SimpleNode;\n for (let i = 0; i < maxTraverseHeight; i++) {\n if (!currentElem) {\n return null;\n }\n\n if (currentElem instanceof HTMLElement) {\n if (currentElem.dataset['sentryComponent']) {\n return currentElem.dataset['sentryComponent'];\n }\n if (currentElem.dataset['sentryElement']) {\n return currentElem.dataset['sentryElement'];\n }\n }\n\n currentElem = currentElem.parentNode;\n }\n\n return null;\n}\n"],"names":[],"mappings":";;;AAGA,MAAM,MAAA,GAAS,UAAA;;AAEf,MAAM,yBAAA,GAA4B,EAAE;;AAMpC;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,gBAAgB;AAChC,EAAE,IAAI;AACN,EAAE,OAAO,GAAiE,EAAE;AAC5E,EAAU;AACV,EAAE,IAAI,CAAC,IAAI,EAAE;AACb,IAAI,OAAO,WAAW;AACtB,EAAE;;AAEF;AACA;AACA;AACA;AACA,EAAE,IAAI;AACN,IAAI,IAAI,WAAA,GAAc,IAAA;AACtB,IAAI,MAAM,mBAAA,GAAsB,CAAC;AACjC,IAAI,MAAM,GAAA,GAAM,EAAE;AAClB,IAAI,IAAI,MAAA,GAAS,CAAC;AAClB,IAAI,IAAI,GAAA,GAAM,CAAC;AACf,IAAI,MAAM,SAAA,GAAY,KAAK;AAC3B,IAAI,MAAM,SAAA,GAAY,SAAS,CAAC,MAAM;AACtC,IAAI,IAAI,OAAO;AACf,IAAI,MAAM,QAAA,GAAW,KAAK,CAAC,OAAO,CAAC,OAAO,CAAA,GAAI,OAAA,GAAU,OAAO,CAAC,QAAQ;AACxE,IAAI,MAAM,eAAA,GAAkB,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,KAAK,O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;;"}
@@ -25,6 +25,12 @@ const SPAN_FLAG_ATTRIBUTE_PREFIX = 'flag.evaluation.';
25
25
  * Copies feature flags that are in current scope context to the event context
26
26
  */
27
27
  function _INTERNAL_copyFlagsFromScopeToEvent(event) {
28
+ if (event.type) {
29
+ // No need to add the flags context to transaction events.
30
+ // Spans already get the flag.evaluation attributes.
31
+ return event;
32
+ }
33
+
28
34
  const scope = getCurrentScope();
29
35
  const flagContext = scope.getScopeData().contexts.flags;
30
36
  const flagBuffer = flagContext ? flagContext.values : [];
@@ -1 +1 @@
1
- {"version":3,"file":"featureFlags.js","sources":["../../../src/utils/featureFlags.ts"],"sourcesContent":["import { getCurrentScope } from '../currentScopes';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { type Event } from '../types-hoist/event';\nimport { debug } from './debug-logger';\nimport { getActiveSpan, spanToJSON } from './spanUtils';\n\n/**\n * Ordered LRU cache for storing feature flags in the scope context. The name\n * of each flag in the buffer is unique, and the output of getAll() is ordered\n * from oldest to newest.\n */\n\nexport type FeatureFlag = { readonly flag: string; readonly result: boolean };\n\n/**\n * Max size of the LRU flag buffer stored in Sentry scope and event contexts.\n */\nexport const _INTERNAL_FLAG_BUFFER_SIZE = 100;\n\n/**\n * Max number of flag evaluations to record per span.\n */\nexport const _INTERNAL_MAX_FLAGS_PER_SPAN = 10;\n\nconst SPAN_FLAG_ATTRIBUTE_PREFIX = 'flag.evaluation.';\n\n/**\n * Copies feature flags that are in current scope context to the event context\n */\nexport function _INTERNAL_copyFlagsFromScopeToEvent(event: Event): Event {\n const scope = getCurrentScope();\n const flagContext = scope.getScopeData().contexts.flags;\n const flagBuffer = flagContext ? flagContext.values : [];\n\n if (!flagBuffer.length) {\n return event;\n }\n\n if (event.contexts === undefined) {\n event.contexts = {};\n }\n event.contexts.flags = { values: [...flagBuffer] };\n return event;\n}\n\n/**\n * Inserts a flag into the current scope's context while maintaining ordered LRU properties.\n * Not thread-safe. After inserting:\n * - The flag buffer is sorted in order of recency, with the newest evaluation at the end.\n * - The names in the buffer are always unique.\n * - The length of the buffer never exceeds `maxSize`.\n *\n * @param name Name of the feature flag to insert.\n * @param value Value of the feature flag.\n * @param maxSize Max number of flags the buffer should store. Default value should always be used in production.\n */\nexport function _INTERNAL_insertFlagToScope(\n name: string,\n value: unknown,\n maxSize: number = _INTERNAL_FLAG_BUFFER_SIZE,\n): void {\n const scopeContexts = getCurrentScope().getScopeData().contexts;\n if (!scopeContexts.flags) {\n scopeContexts.flags = { values: [] };\n }\n const flags = scopeContexts.flags.values;\n _INTERNAL_insertToFlagBuffer(flags, name, value, maxSize);\n}\n\n/**\n * Exported for tests only. Currently only accepts boolean values (otherwise no-op).\n * Inserts a flag into a FeatureFlag array while maintaining the following properties:\n * - Flags are sorted in order of recency, with the newest evaluation at the end.\n * - The flag names are always unique.\n * - The length of the array never exceeds `maxSize`.\n *\n * @param flags The buffer to insert the flag into.\n * @param name Name of the feature flag to insert.\n * @param value Value of the feature flag.\n * @param maxSize Max number of flags the buffer should store. Default value should always be used in production.\n */\nexport function _INTERNAL_insertToFlagBuffer(\n flags: FeatureFlag[],\n name: string,\n value: unknown,\n maxSize: number,\n): void {\n if (typeof value !== 'boolean') {\n return;\n }\n\n if (flags.length > maxSize) {\n DEBUG_BUILD && debug.error(`[Feature Flags] insertToFlagBuffer called on a buffer larger than maxSize=${maxSize}`);\n return;\n }\n\n // Check if the flag is already in the buffer - O(n)\n const index = flags.findIndex(f => f.flag === name);\n\n if (index !== -1) {\n // The flag was found, remove it from its current position - O(n)\n flags.splice(index, 1);\n }\n\n if (flags.length === maxSize) {\n // If at capacity, pop the earliest flag - O(n)\n flags.shift();\n }\n\n // Push the flag to the end - O(1)\n flags.push({\n flag: name,\n result: value,\n });\n}\n\n/**\n * Records a feature flag evaluation for the active span. This is a no-op for non-boolean values.\n * The flag and its value is stored in span attributes with the `flag.evaluation` prefix. Once the\n * unique flags for a span reaches maxFlagsPerSpan, subsequent flags are dropped.\n *\n * @param name Name of the feature flag.\n * @param value Value of the feature flag. Non-boolean values are ignored.\n * @param maxFlagsPerSpan Max number of flags a buffer should store. Default value should always be used in production.\n */\nexport function _INTERNAL_addFeatureFlagToActiveSpan(\n name: string,\n value: unknown,\n maxFlagsPerSpan: number = _INTERNAL_MAX_FLAGS_PER_SPAN,\n): void {\n if (typeof value !== 'boolean') {\n return;\n }\n\n const span = getActiveSpan();\n if (!span) {\n return;\n }\n\n const attributes = spanToJSON(span).data;\n\n // If the flag already exists, always update it\n if (`${SPAN_FLAG_ATTRIBUTE_PREFIX}${name}` in attributes) {\n span.setAttribute(`${SPAN_FLAG_ATTRIBUTE_PREFIX}${name}`, value);\n return;\n }\n\n // Else, add the flag to the span if we have not reached the max number of flags\n const numOfAddedFlags = Object.keys(attributes).filter(key => key.startsWith(SPAN_FLAG_ATTRIBUTE_PREFIX)).length;\n if (numOfAddedFlags < maxFlagsPerSpan) {\n span.setAttribute(`${SPAN_FLAG_ATTRIBUTE_PREFIX}${name}`, value);\n }\n}\n"],"names":[],"mappings":";;;;;AAMA;AACA;AACA;AACA;AACA;;AAIA;AACA;AACA;AACO,MAAM,0BAAA,GAA6B;;AAE1C;AACA;AACA;AACO,MAAM,4BAAA,GAA+B;;AAE5C,MAAM,0BAAA,GAA6B,kBAAkB;;AAErD;AACA;AACA;AACO,SAAS,mCAAmC,CAAC,KAAK,EAAgB;AACzE,EAAE,MAAM,KAAA,GAAQ,eAAe,EAAE;AACjC,EAAE,MAAM,WAAA,GAAc,KAAK,CAAC,YAAY,EAAE,CAAC,QAAQ,CAAC,KAAK;AACzD,EAAE,MAAM,UAAA,GAAa,WAAA,GAAc,WAAW,CAAC,MAAA,GAAS,EAAE;;AAE1D,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE;AAC1B,IAAI,OAAO,KAAK;AAChB,EAAE;;AAEF,EAAE,IAAI,KAAK,CAAC,QAAA,KAAa,SAAS,EAAE;AACpC,IAAI,KAAK,CAAC,QAAA,GAAW,EAAE;AACvB,EAAE;AAC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CAAA;AACA,EAAA;;AAEA,EAAA,IAAA,KAAA,CAAA,MAAA,KAAA,OAAA,EAAA;AACA;AACA,IAAA,KAAA,CAAA,KAAA,EAAA;AACA,EAAA;;AAEA;AACA,EAAA,KAAA,CAAA,IAAA,CAAA;AACA,IAAA,IAAA,EAAA,IAAA;AACA,IAAA,MAAA,EAAA,KAAA;AACA,GAAA,CAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,oCAAA;AACA,EAAA,IAAA;AACA,EAAA,KAAA;AACA,EAAA,eAAA,GAAA,4BAAA;AACA,EAAA;AACA,EAAA,IAAA,OAAA,KAAA,KAAA,SAAA,EAAA;AACA,IAAA;AACA,EAAA;;AAEA,EAAA,MAAA,IAAA,GAAA,aAAA,EAAA;AACA,EAAA,IAAA,CAAA,IAAA,EAAA;AACA,IAAA;AACA,EAAA;;AAEA,EAAA,MAAA,UAAA,GAAA,UAAA,CAAA,IAAA,CAAA,CAAA,IAAA;;AAEA;AACA,EAAA,IAAA,CAAA,EAAA,0BAAA,CAAA,EAAA,IAAA,CAAA,CAAA,IAAA,UAAA,EAAA;AACA,IAAA,IAAA,CAAA,YAAA,CAAA,CAAA,EAAA,0BAAA,CAAA,EAAA,IAAA,CAAA,CAAA,EAAA,KAAA,CAAA;AACA,IAAA;AACA,EAAA;;AAEA;AACA,EAAA,MAAA,eAAA,GAAA,MAAA,CAAA,IAAA,CAAA,UAAA,CAAA,CAAA,MAAA,CAAA,GAAA,IAAA,GAAA,CAAA,UAAA,CAAA,0BAAA,CAAA,CAAA,CAAA,MAAA;AACA,EAAA,IAAA,eAAA,GAAA,eAAA,EAAA;AACA,IAAA,IAAA,CAAA,YAAA,CAAA,CAAA,EAAA,0BAAA,CAAA,EAAA,IAAA,CAAA,CAAA,EAAA,KAAA,CAAA;AACA,EAAA;AACA;;;;"}
1
+ {"version":3,"file":"featureFlags.js","sources":["../../../src/utils/featureFlags.ts"],"sourcesContent":["import { getCurrentScope } from '../currentScopes';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { type Event } from '../types-hoist/event';\nimport { debug } from './debug-logger';\nimport { getActiveSpan, spanToJSON } from './spanUtils';\n\n/**\n * Ordered LRU cache for storing feature flags in the scope context. The name\n * of each flag in the buffer is unique, and the output of getAll() is ordered\n * from oldest to newest.\n */\n\nexport type FeatureFlag = { readonly flag: string; readonly result: boolean };\n\n/**\n * Max size of the LRU flag buffer stored in Sentry scope and event contexts.\n */\nexport const _INTERNAL_FLAG_BUFFER_SIZE = 100;\n\n/**\n * Max number of flag evaluations to record per span.\n */\nexport const _INTERNAL_MAX_FLAGS_PER_SPAN = 10;\n\nconst SPAN_FLAG_ATTRIBUTE_PREFIX = 'flag.evaluation.';\n\n/**\n * Copies feature flags that are in current scope context to the event context\n */\nexport function _INTERNAL_copyFlagsFromScopeToEvent(event: Event): Event {\n if (event.type) {\n // No need to add the flags context to transaction events.\n // Spans already get the flag.evaluation attributes.\n return event;\n }\n\n const scope = getCurrentScope();\n const flagContext = scope.getScopeData().contexts.flags;\n const flagBuffer = flagContext ? flagContext.values : [];\n\n if (!flagBuffer.length) {\n return event;\n }\n\n if (event.contexts === undefined) {\n event.contexts = {};\n }\n event.contexts.flags = { values: [...flagBuffer] };\n return event;\n}\n\n/**\n * Inserts a flag into the current scope's context while maintaining ordered LRU properties.\n * Not thread-safe. After inserting:\n * - The flag buffer is sorted in order of recency, with the newest evaluation at the end.\n * - The names in the buffer are always unique.\n * - The length of the buffer never exceeds `maxSize`.\n *\n * @param name Name of the feature flag to insert.\n * @param value Value of the feature flag.\n * @param maxSize Max number of flags the buffer should store. Default value should always be used in production.\n */\nexport function _INTERNAL_insertFlagToScope(\n name: string,\n value: unknown,\n maxSize: number = _INTERNAL_FLAG_BUFFER_SIZE,\n): void {\n const scopeContexts = getCurrentScope().getScopeData().contexts;\n if (!scopeContexts.flags) {\n scopeContexts.flags = { values: [] };\n }\n const flags = scopeContexts.flags.values;\n _INTERNAL_insertToFlagBuffer(flags, name, value, maxSize);\n}\n\n/**\n * Exported for tests only. Currently only accepts boolean values (otherwise no-op).\n * Inserts a flag into a FeatureFlag array while maintaining the following properties:\n * - Flags are sorted in order of recency, with the newest evaluation at the end.\n * - The flag names are always unique.\n * - The length of the array never exceeds `maxSize`.\n *\n * @param flags The buffer to insert the flag into.\n * @param name Name of the feature flag to insert.\n * @param value Value of the feature flag.\n * @param maxSize Max number of flags the buffer should store. Default value should always be used in production.\n */\nexport function _INTERNAL_insertToFlagBuffer(\n flags: FeatureFlag[],\n name: string,\n value: unknown,\n maxSize: number,\n): void {\n if (typeof value !== 'boolean') {\n return;\n }\n\n if (flags.length > maxSize) {\n DEBUG_BUILD && debug.error(`[Feature Flags] insertToFlagBuffer called on a buffer larger than maxSize=${maxSize}`);\n return;\n }\n\n // Check if the flag is already in the buffer - O(n)\n const index = flags.findIndex(f => f.flag === name);\n\n if (index !== -1) {\n // The flag was found, remove it from its current position - O(n)\n flags.splice(index, 1);\n }\n\n if (flags.length === maxSize) {\n // If at capacity, pop the earliest flag - O(n)\n flags.shift();\n }\n\n // Push the flag to the end - O(1)\n flags.push({\n flag: name,\n result: value,\n });\n}\n\n/**\n * Records a feature flag evaluation for the active span. This is a no-op for non-boolean values.\n * The flag and its value is stored in span attributes with the `flag.evaluation` prefix. Once the\n * unique flags for a span reaches maxFlagsPerSpan, subsequent flags are dropped.\n *\n * @param name Name of the feature flag.\n * @param value Value of the feature flag. Non-boolean values are ignored.\n * @param maxFlagsPerSpan Max number of flags a buffer should store. Default value should always be used in production.\n */\nexport function _INTERNAL_addFeatureFlagToActiveSpan(\n name: string,\n value: unknown,\n maxFlagsPerSpan: number = _INTERNAL_MAX_FLAGS_PER_SPAN,\n): void {\n if (typeof value !== 'boolean') {\n return;\n }\n\n const span = getActiveSpan();\n if (!span) {\n return;\n }\n\n const attributes = spanToJSON(span).data;\n\n // If the flag already exists, always update it\n if (`${SPAN_FLAG_ATTRIBUTE_PREFIX}${name}` in attributes) {\n span.setAttribute(`${SPAN_FLAG_ATTRIBUTE_PREFIX}${name}`, value);\n return;\n }\n\n // Else, add the flag to the span if we have not reached the max number of flags\n const numOfAddedFlags = Object.keys(attributes).filter(key => key.startsWith(SPAN_FLAG_ATTRIBUTE_PREFIX)).length;\n if (numOfAddedFlags < maxFlagsPerSpan) {\n span.setAttribute(`${SPAN_FLAG_ATTRIBUTE_PREFIX}${name}`, value);\n }\n}\n"],"names":[],"mappings":";;;;;AAMA;AACA;AACA;AACA;AACA;;AAIA;AACA;AACA;AACO,MAAM,0BAAA,GAA6B;;AAE1C;AACA;AACA;AACO,MAAM,4BAAA,GAA+B;;AAE5C,MAAM,0BAAA,GAA6B,kBAAkB;;AAErD;AACA;AACA;AACO,SAAS,mCAAmC,CAAC,KAAK,EAAgB;AACzE,EAAE,IAAI,KAAK,CAAC,IAAI,EAAE;AAClB;AACA;AACA,IAAI,OAAO,KAAK;AAChB,EAAE;;AAEF,EAAE,MAAM,KAAA,GAAQ,eAAe,EAAE;AACjC,EAAE,MAAM,WAAA,GAAc,KAAK,CAAC,YAAY,EAAE,CAAC,QAAQ,CAAC,KAAK;AACzD,EAAE,MAAM,UAAA,GAAa,WAAA,GAAc,WAAW,CAAC,MAAA,GAAS,EAAE;;AAE1D,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE;AAC1B,IAAI,OAAO,KAAK;AAChB,EAAE;;AAEF,EAAE,IAAI,KAAK,CAAC,QAAA,KAAa,SAAS,EAAE;AACpC,IAAI,KAAK,CAAC,QAAA,GAAW,EAAE;AACvB,EAAE;AACF,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAA,GAAQ,EAAE,MAAM,EAAE,CAAC,GAAG,UAAU,GAAG;AACpD,EAAE,OAAO,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,2BAA2B;AAC3C,EAAE,IAAI;AACN,EAAE,KAAK;AACP,EAAE,OAAO,GAAW,0BAA0B;A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AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,oCAAA;AACA,EAAA,IAAA;AACA,EAAA,KAAA;AACA,EAAA,eAAA,GAAA,4BAAA;AACA,EAAA;AACA,EAAA,IAAA,OAAA,KAAA,KAAA,SAAA,EAAA;AACA,IAAA;AACA,EAAA;;AAEA,EAAA,MAAA,IAAA,GAAA,aAAA,EAAA;AACA,EAAA,IAAA,CAAA,IAAA,EAAA;AACA,IAAA;AACA,EAAA;;AAEA,EAAA,MAAA,UAAA,GAAA,UAAA,CAAA,IAAA,CAAA,CAAA,IAAA;;AAEA;AACA,EAAA,IAAA,CAAA,EAAA,0BAAA,CAAA,EAAA,IAAA,CAAA,CAAA,IAAA,UAAA,EAAA;AACA,IAAA,IAAA,CAAA,YAAA,CAAA,CAAA,EAAA,0BAAA,CAAA,EAAA,IAAA,CAAA,CAAA,EAAA,KAAA,CAAA;AACA,IAAA;AACA,EAAA;;AAEA;AACA,EAAA,MAAA,eAAA,GAAA,MAAA,CAAA,IAAA,CAAA,UAAA,CAAA,CAAA,MAAA,CAAA,GAAA,IAAA,GAAA,CAAA,UAAA,CAAA,0BAAA,CAAA,CAAA,CAAA,MAAA;AACA,EAAA,IAAA,eAAA,GAAA,eAAA,EAAA;AACA,IAAA,IAAA,CAAA,YAAA,CAAA,CAAA,EAAA,0BAAA,CAAA,EAAA,IAAA,CAAA,CAAA,EAAA,KAAA,CAAA;AACA,EAAA;AACA;;;;"}
@@ -18,6 +18,7 @@ import { isError, isEvent, isInstanceOf, isPrimitive, isElement } from './is.js'
18
18
  * args>)` or `origMethod.apply(this, [<other args>])` (rather than being called directly), again to preserve `this`.
19
19
  * @returns void
20
20
  */
21
+
21
22
  function fill(source, name, replacementFactory) {
22
23
  if (!(name in source)) {
23
24
  return;
@@ -80,6 +81,37 @@ function markFunctionWrapped(wrapped, original) {
80
81
  } catch {} // eslint-disable-line no-empty
81
82
  }
82
83
 
84
+ /**
85
+ * Wrap a method on an object by name, only if it is not already wrapped.
86
+ *
87
+ * Note: to set the wrapped method as a non-enumerable property, pass
88
+ * false as the `enumerable` argument. This could be detected, but only
89
+ * by either walking up the prototype chain, or iterating over all fields
90
+ * in a `for(in)` loop. Neither are an acceptable performance impact for
91
+ * the rare case where we might patch a non-enumerable method.
92
+ */
93
+ function wrapMethod(
94
+ obj,
95
+ field,
96
+ wrapped,
97
+ enumerable = true,
98
+ ) {
99
+ const original = obj[field];
100
+ if (typeof original !== 'function') {
101
+ throw new Error(`Cannot wrap method: ${field} is not a function`);
102
+ }
103
+ if (getOriginalFunction(original)) {
104
+ throw new Error(`Attempting to wrap method ${field} multiple times`);
105
+ }
106
+ markFunctionWrapped(wrapped, original);
107
+ Object.defineProperty(obj, field, {
108
+ writable: true,
109
+ configurable: true,
110
+ enumerable,
111
+ value: wrapped,
112
+ });
113
+ }
114
+
83
115
  /**
84
116
  * This extracts the original function if available. See
85
117
  * `markFunctionWrapped` for more information.
@@ -267,5 +299,5 @@ function objectify(wat) {
267
299
  return objectified;
268
300
  }
269
301
 
270
- export { addNonEnumerableProperty, convertToPlainObject, dropUndefinedKeys, extractExceptionKeysForMessage, fill, getOriginalFunction, markFunctionWrapped, objectify };
302
+ export { addNonEnumerableProperty, convertToPlainObject, dropUndefinedKeys, extractExceptionKeysForMessage, fill, getOriginalFunction, markFunctionWrapped, objectify, wrapMethod };
271
303
  //# sourceMappingURL=object.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"object.js","sources":["../../../src/utils/object.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { DEBUG_BUILD } from '../debug-build';\nimport type { WrappedFunction } from '../types-hoist/wrappedfunction';\nimport { htmlTreeAsString } from './browser';\nimport { debug } from './debug-logger';\nimport { isElement, isError, isEvent, isInstanceOf, isPrimitive } from './is';\n\n/**\n * Replace a method in an object with a wrapped version of itself.\n *\n * If the method on the passed object is not a function, the wrapper will not be applied.\n *\n * @param source An object that contains a method to be wrapped.\n * @param name The name of the method to be wrapped.\n * @param replacementFactory A higher-order function that takes the original version of the given method and returns a\n * wrapped version. Note: The function returned by `replacementFactory` needs to be a non-arrow function, in order to\n * preserve the correct value of `this`, and the original method must be called using `origMethod.call(this, <other\n * args>)` or `origMethod.apply(this, [<other args>])` (rather than being called directly), again to preserve `this`.\n * @returns void\n */\nexport function fill(source: { [key: string]: any }, name: string, replacementFactory: (...args: any[]) => any): void {\n if (!(name in source)) {\n return;\n }\n\n // explicitly casting to unknown because we don't know the type of the method initially at all\n const original = source[name] as unknown;\n\n if (typeof original !== 'function') {\n return;\n }\n\n const wrapped = replacementFactory(original) as WrappedFunction;\n\n // Make sure it's a function first, as we need to attach an empty prototype for `defineProperties` to work\n // otherwise it'll throw \"TypeError: Object.defineProperties called on non-object\"\n if (typeof wrapped === 'function') {\n markFunctionWrapped(wrapped, original);\n }\n\n try {\n source[name] = wrapped;\n } catch {\n DEBUG_BUILD && debug.log(`Failed to replace method \"${name}\" in object`, source);\n }\n}\n\n/**\n * Defines a non-enumerable property on the given object.\n *\n * @param obj The object on which to set the property\n * @param name The name of the property to be set\n * @param value The value to which to set the property\n */\nexport function addNonEnumerableProperty(obj: object, name: string, value: unknown): void {\n try {\n Object.defineProperty(obj, name, {\n // enumerable: false, // the default, so we can save on bundle size by not explicitly setting it\n value,\n writable: true,\n configurable: true,\n });\n } catch {\n DEBUG_BUILD && debug.log(`Failed to add non-enumerable property \"${name}\" to object`, obj);\n }\n}\n\n/**\n * Remembers the original function on the wrapped function and\n * patches up the prototype.\n *\n * @param wrapped the wrapper function\n * @param original the original function that gets wrapped\n */\nexport function markFunctionWrapped(wrapped: WrappedFunction, original: WrappedFunction): void {\n try {\n const proto = original.prototype || {};\n wrapped.prototype = original.prototype = proto;\n addNonEnumerableProperty(wrapped, '__sentry_original__', original);\n } catch {} // eslint-disable-line no-empty\n}\n\n/**\n * This extracts the original function if available. See\n * `markFunctionWrapped` for more information.\n *\n * @param func the function to unwrap\n * @returns the unwrapped version of the function if available.\n */\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport function getOriginalFunction<T extends Function>(func: WrappedFunction<T>): T | undefined {\n return func.__sentry_original__;\n}\n\n/**\n * Transforms any `Error` or `Event` into a plain object with all of their enumerable properties, and some of their\n * non-enumerable properties attached.\n *\n * @param value Initial source that we have to transform in order for it to be usable by the serializer\n * @returns An Event or Error turned into an object - or the value argument itself, when value is neither an Event nor\n * an Error.\n */\nexport function convertToPlainObject<V>(value: V):\n | {\n [ownProps: string]: unknown;\n type: string;\n target: string;\n currentTarget: string;\n detail?: unknown;\n }\n | {\n [ownProps: string]: unknown;\n message: string;\n name: string;\n stack?: string;\n }\n | V {\n if (isError(value)) {\n return {\n message: value.message,\n name: value.name,\n stack: value.stack,\n ...getOwnProperties(value),\n };\n } else if (isEvent(value)) {\n const newObj: {\n [ownProps: string]: unknown;\n type: string;\n target: string;\n currentTarget: string;\n detail?: unknown;\n } = {\n type: value.type,\n target: serializeEventTarget(value.target),\n currentTarget: serializeEventTarget(value.currentTarget),\n ...getOwnProperties(value),\n };\n\n if (typeof CustomEvent !== 'undefined' && isInstanceOf(value, CustomEvent)) {\n newObj.detail = value.detail;\n }\n\n return newObj;\n } else {\n return value;\n }\n}\n\n/** Creates a string representation of the target of an `Event` object */\nfunction serializeEventTarget(target: unknown): string {\n try {\n return isElement(target) ? htmlTreeAsString(target) : Object.prototype.toString.call(target);\n } catch {\n return '<unknown>';\n }\n}\n\n/** Filters out all but an object's own properties */\nfunction getOwnProperties(obj: unknown): { [key: string]: unknown } {\n if (typeof obj === 'object' && obj !== null) {\n return Object.fromEntries(Object.entries(obj));\n }\n return {};\n}\n\n/**\n * Given any captured exception, extract its keys and create a sorted\n * and truncated list that will be used inside the event message.\n * eg. `Non-error exception captured with keys: foo, bar, baz`\n */\nexport function extractExceptionKeysForMessage(exception: Record<string, unknown>): string {\n const keys = Object.keys(convertToPlainObject(exception));\n keys.sort();\n\n return !keys[0] ? '[object has no keys]' : keys.join(', ');\n}\n\n/**\n * Given any object, return a new object having removed all fields whose value was `undefined`.\n * Works recursively on objects and arrays.\n *\n * Attention: This function keeps circular references in the returned object.\n *\n * @deprecated This function is no longer used by the SDK and will be removed in a future major version.\n */\nexport function dropUndefinedKeys<T>(inputValue: T): T {\n // This map keeps track of what already visited nodes map to.\n // Our Set - based memoBuilder doesn't work here because we want to the output object to have the same circular\n // references as the input object.\n const memoizationMap = new Map<unknown, unknown>();\n\n // This function just proxies `_dropUndefinedKeys` to keep the `memoBuilder` out of this function's API\n return _dropUndefinedKeys(inputValue, memoizationMap);\n}\n\nfunction _dropUndefinedKeys<T>(inputValue: T, memoizationMap: Map<unknown, unknown>): T {\n // Early return for primitive values\n if (inputValue === null || typeof inputValue !== 'object') {\n return inputValue;\n }\n\n // Check memo map first for all object types\n const memoVal = memoizationMap.get(inputValue);\n if (memoVal !== undefined) {\n return memoVal as T;\n }\n\n // handle arrays\n if (Array.isArray(inputValue)) {\n const returnValue: unknown[] = [];\n // Store mapping to handle circular references\n memoizationMap.set(inputValue, returnValue);\n\n inputValue.forEach(value => {\n returnValue.push(_dropUndefinedKeys(value, memoizationMap));\n });\n\n return returnValue as unknown as T;\n }\n\n if (isPojo(inputValue)) {\n const returnValue: { [key: string]: unknown } = {};\n // Store mapping to handle circular references\n memoizationMap.set(inputValue, returnValue);\n\n const keys = Object.keys(inputValue);\n\n keys.forEach(key => {\n const val = inputValue[key];\n if (val !== undefined) {\n returnValue[key] = _dropUndefinedKeys(val, memoizationMap);\n }\n });\n\n return returnValue as T;\n }\n\n // For other object types, return as is\n return inputValue;\n}\n\nfunction isPojo(input: unknown): input is Record<string, unknown> {\n // Plain objects have Object as constructor or no constructor\n const constructor = (input as object).constructor;\n return constructor === Object || constructor === undefined;\n}\n\n/**\n * Ensure that something is an object.\n *\n * Turns `undefined` and `null` into `String`s and all other primitives into instances of their respective wrapper\n * classes (String, Boolean, Number, etc.). Acts as the identity function on non-primitives.\n *\n * @param wat The subject of the objectification\n * @returns A version of `wat` which can safely be used with `Object` class methods\n */\nexport function objectify(wat: unknown): typeof Object {\n let objectified;\n switch (true) {\n // this will catch both undefined and null\n case wat == undefined:\n objectified = new String(wat);\n break;\n\n // Though symbols and bigints do have wrapper classes (`Symbol` and `BigInt`, respectively), for whatever reason\n // those classes don't have constructors which can be used with the `new` keyword. We therefore need to cast each as\n // an object in order to wrap it.\n case typeof wat === 'symbol' || typeof wat === 'bigint':\n objectified = Object(wat);\n break;\n\n // this will catch the remaining primitives: `String`, `Number`, and `Boolean`\n case isPrimitive(wat):\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n objectified = new (wat as any).constructor(wat);\n break;\n\n // by process of elimination, at this point we know that `wat` must already be an object\n default:\n objectified = wat;\n break;\n }\n return objectified;\n}\n"],"names":[],"mappings":";;;;;AAAA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,IAAI,CAAC,MAAM,EAA0B,IAAI,EAAU,kBAAkB,EAAiC;AACtH,EAAE,IAAI,EAAE,QAAQ,MAAM,CAAC,EAAE;AACzB,IAAI;AACJ,EAAE;;AAEF;AACA,EAAE,MAAM,QAAA,GAAW,MAAM,CAAC,IAAI,CAAA;;AAE9B,EAAE,IAAI,OAAO,QAAA,KAAa,UAAU,EAAE;AACtC,IAAI;AACJ,EAAE;;AAEF,EAAE,MAAM,OAAA,GAAU,kBAAkB,CAAC,QAAQ,CAAA;;AAE7C;AACA;AACA,EAAE,IAAI,OAAO,OAAA,KAAY,UAAU,EAAE;AACrC,IAAI,mBAAmB,CAAC,OAAO,EAAE,QAAQ,CAAC;AAC1C,EAAE;;AAEF,EAAE,IAAI;AACN,IAAI,MAAM,CAAC,IAAI,CAAA,GAAI,OAAO;AAC1B,EAAE,EAAE,MAAM;AACV,IAAI,WAAA,IAAe,KAAK,CAAC,GAAG,CAAC,CAAC,0BAA0B,EAAE,IAAI,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;AACpF,EAAE;AACF;;AAEA;AACA;AAC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,CAAC,OAAO,CAAC,OAAO;AACxB,MAAM,MAAM,GAAA,GAAM,UAAU,CAAC,GAAG,CAAC;AACjC,MAAM,IAAI,GAAA,KAAQ,SAAS,EAAE;AAC7B,QAAQ,WAAW,CAAC,GAAG,CAAA,GAAI,kBAAkB,CAAC,GAAG,EAAE,cAAc,CAAC;AAClE,MAAM;AACN,IAAI,CAAC,CAAC;;AAEN,IAAI,OAAO,WAAA;AACX,EAAE;;AAEF;AACA,EAAE,OAAO,UAAU;AACnB;;AAEA,SAAS,MAAM,CAAC,KAAK,EAA6C;AAClE;AACA,EAAE,MAAM,WAAA,GAAc,CAAC,KAAA,GAAiB,WAAW;AACnD,EAAE,OAAO,WAAA,KAAgB,UAAU,WAAA,KAAgB,SAAS;AAC5D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,SAAS,CAAC,GAAG,EAA0B;AACvD,EAAE,IAAI,WAAW;AACjB,EAAE,QAAQ,IAAI;AACd;AACA,IAAI,KAAK,GAAA,IAAO,SAAS;AACzB,MAAM,cAAc,IAAI,MAAM,CAAC,GAAG,CAAC;AACnC,MAAM;;AAEN;AACA;AACA;AACA,IAAI,KAAK,OAAO,GAAA,KAAQ,YAAY,OAAO,GAAA,KAAQ,QAAQ;AAC3D,MAAM,WAAA,GAAc,MAAM,CAAC,GAAG,CAAC;AAC/B,MAAM;;AAEN;AACA,IAAI,KAAK,WAAW,CAAC,GAAG,CAAC;AACzB;AACA,MAAM,WAAA,GAAc,IAAI,CAAC,GAAA,GAAY,WAAW,CAAC,GAAG,CAAC;AACrD,MAAM;;AAEN;AACA,IAAI;AACJ,MAAM,WAAA,GAAc,GAAG;AACvB,MAAM;AACN;AACA,EAAE,OAAO,WAAW;AACpB;;;;"}
1
+ {"version":3,"file":"object.js","sources":["../../../src/utils/object.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { DEBUG_BUILD } from '../debug-build';\nimport type { WrappedFunction } from '../types-hoist/wrappedfunction';\nimport { htmlTreeAsString } from './browser';\nimport { debug } from './debug-logger';\nimport { isElement, isError, isEvent, isInstanceOf, isPrimitive } from './is';\n\n/**\n * Replace a method in an object with a wrapped version of itself.\n *\n * If the method on the passed object is not a function, the wrapper will not be applied.\n *\n * @param source An object that contains a method to be wrapped.\n * @param name The name of the method to be wrapped.\n * @param replacementFactory A higher-order function that takes the original version of the given method and returns a\n * wrapped version. Note: The function returned by `replacementFactory` needs to be a non-arrow function, in order to\n * preserve the correct value of `this`, and the original method must be called using `origMethod.call(this, <other\n * args>)` or `origMethod.apply(this, [<other args>])` (rather than being called directly), again to preserve `this`.\n * @returns void\n */\n\nexport function fill(source: { [key: string]: any }, name: string, replacementFactory: (...args: any[]) => any): void {\n if (!(name in source)) {\n return;\n }\n\n // explicitly casting to unknown because we don't know the type of the method initially at all\n const original = source[name] as unknown;\n\n if (typeof original !== 'function') {\n return;\n }\n\n const wrapped = replacementFactory(original) as WrappedFunction;\n\n // Make sure it's a function first, as we need to attach an empty prototype for `defineProperties` to work\n // otherwise it'll throw \"TypeError: Object.defineProperties called on non-object\"\n if (typeof wrapped === 'function') {\n markFunctionWrapped(wrapped, original);\n }\n\n try {\n source[name] = wrapped;\n } catch {\n DEBUG_BUILD && debug.log(`Failed to replace method \"${name}\" in object`, source);\n }\n}\n\n/**\n * Defines a non-enumerable property on the given object.\n *\n * @param obj The object on which to set the property\n * @param name The name of the property to be set\n * @param value The value to which to set the property\n */\nexport function addNonEnumerableProperty(obj: object, name: string, value: unknown): void {\n try {\n Object.defineProperty(obj, name, {\n // enumerable: false, // the default, so we can save on bundle size by not explicitly setting it\n value,\n writable: true,\n configurable: true,\n });\n } catch {\n DEBUG_BUILD && debug.log(`Failed to add non-enumerable property \"${name}\" to object`, obj);\n }\n}\n\n/**\n * Remembers the original function on the wrapped function and\n * patches up the prototype.\n *\n * @param wrapped the wrapper function\n * @param original the original function that gets wrapped\n */\nexport function markFunctionWrapped(wrapped: WrappedFunction, original: WrappedFunction): void {\n try {\n const proto = original.prototype || {};\n wrapped.prototype = original.prototype = proto;\n addNonEnumerableProperty(wrapped, '__sentry_original__', original);\n } catch {} // eslint-disable-line no-empty\n}\n\n/**\n * Wrap a method on an object by name, only if it is not already wrapped.\n *\n * Note: to set the wrapped method as a non-enumerable property, pass\n * false as the `enumerable` argument. This could be detected, but only\n * by either walking up the prototype chain, or iterating over all fields\n * in a `for(in)` loop. Neither are an acceptable performance impact for\n * the rare case where we might patch a non-enumerable method.\n */\nexport function wrapMethod<O extends {}, T extends string & keyof O>(\n obj: O,\n field: T,\n wrapped: WrappedFunction,\n enumerable: boolean = true,\n): void {\n const original = obj[field];\n if (typeof original !== 'function') {\n throw new Error(`Cannot wrap method: ${field} is not a function`);\n }\n if (getOriginalFunction(original)) {\n throw new Error(`Attempting to wrap method ${field} multiple times`);\n }\n markFunctionWrapped(wrapped, original);\n Object.defineProperty(obj, field, {\n writable: true,\n configurable: true,\n enumerable,\n value: wrapped,\n });\n}\n\n/**\n * This extracts the original function if available. See\n * `markFunctionWrapped` for more information.\n *\n * @param func the function to unwrap\n * @returns the unwrapped version of the function if available.\n */\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport function getOriginalFunction<T extends Function>(func: WrappedFunction<T>): T | undefined {\n return func.__sentry_original__;\n}\n\n/**\n * Transforms any `Error` or `Event` into a plain object with all of their enumerable properties, and some of their\n * non-enumerable properties attached.\n *\n * @param value Initial source that we have to transform in order for it to be usable by the serializer\n * @returns An Event or Error turned into an object - or the value argument itself, when value is neither an Event nor\n * an Error.\n */\nexport function convertToPlainObject<V>(value: V):\n | {\n [ownProps: string]: unknown;\n type: string;\n target: string;\n currentTarget: string;\n detail?: unknown;\n }\n | {\n [ownProps: string]: unknown;\n message: string;\n name: string;\n stack?: string;\n }\n | V {\n if (isError(value)) {\n return {\n message: value.message,\n name: value.name,\n stack: value.stack,\n ...getOwnProperties(value),\n };\n } else if (isEvent(value)) {\n const newObj: {\n [ownProps: string]: unknown;\n type: string;\n target: string;\n currentTarget: string;\n detail?: unknown;\n } = {\n type: value.type,\n target: serializeEventTarget(value.target),\n currentTarget: serializeEventTarget(value.currentTarget),\n ...getOwnProperties(value),\n };\n\n if (typeof CustomEvent !== 'undefined' && isInstanceOf(value, CustomEvent)) {\n newObj.detail = value.detail;\n }\n\n return newObj;\n } else {\n return value;\n }\n}\n\n/** Creates a string representation of the target of an `Event` object */\nfunction serializeEventTarget(target: unknown): string {\n try {\n return isElement(target) ? htmlTreeAsString(target) : Object.prototype.toString.call(target);\n } catch {\n return '<unknown>';\n }\n}\n\n/** Filters out all but an object's own properties */\nfunction getOwnProperties(obj: unknown): { [key: string]: unknown } {\n if (typeof obj === 'object' && obj !== null) {\n return Object.fromEntries(Object.entries(obj));\n }\n return {};\n}\n\n/**\n * Given any captured exception, extract its keys and create a sorted\n * and truncated list that will be used inside the event message.\n * eg. `Non-error exception captured with keys: foo, bar, baz`\n */\nexport function extractExceptionKeysForMessage(exception: Record<string, unknown>): string {\n const keys = Object.keys(convertToPlainObject(exception));\n keys.sort();\n\n return !keys[0] ? '[object has no keys]' : keys.join(', ');\n}\n\n/**\n * Given any object, return a new object having removed all fields whose value was `undefined`.\n * Works recursively on objects and arrays.\n *\n * Attention: This function keeps circular references in the returned object.\n *\n * @deprecated This function is no longer used by the SDK and will be removed in a future major version.\n */\nexport function dropUndefinedKeys<T>(inputValue: T): T {\n // This map keeps track of what already visited nodes map to.\n // Our Set - based memoBuilder doesn't work here because we want to the output object to have the same circular\n // references as the input object.\n const memoizationMap = new Map<unknown, unknown>();\n\n // This function just proxies `_dropUndefinedKeys` to keep the `memoBuilder` out of this function's API\n return _dropUndefinedKeys(inputValue, memoizationMap);\n}\n\nfunction _dropUndefinedKeys<T>(inputValue: T, memoizationMap: Map<unknown, unknown>): T {\n // Early return for primitive values\n if (inputValue === null || typeof inputValue !== 'object') {\n return inputValue;\n }\n\n // Check memo map first for all object types\n const memoVal = memoizationMap.get(inputValue);\n if (memoVal !== undefined) {\n return memoVal as T;\n }\n\n // handle arrays\n if (Array.isArray(inputValue)) {\n const returnValue: unknown[] = [];\n // Store mapping to handle circular references\n memoizationMap.set(inputValue, returnValue);\n\n inputValue.forEach(value => {\n returnValue.push(_dropUndefinedKeys(value, memoizationMap));\n });\n\n return returnValue as unknown as T;\n }\n\n if (isPojo(inputValue)) {\n const returnValue: { [key: string]: unknown } = {};\n // Store mapping to handle circular references\n memoizationMap.set(inputValue, returnValue);\n\n const keys = Object.keys(inputValue);\n\n keys.forEach(key => {\n const val = inputValue[key];\n if (val !== undefined) {\n returnValue[key] = _dropUndefinedKeys(val, memoizationMap);\n }\n });\n\n return returnValue as T;\n }\n\n // For other object types, return as is\n return inputValue;\n}\n\nfunction isPojo(input: unknown): input is Record<string, unknown> {\n // Plain objects have Object as constructor or no constructor\n const constructor = (input as object).constructor;\n return constructor === Object || constructor === undefined;\n}\n\n/**\n * Ensure that something is an object.\n *\n * Turns `undefined` and `null` into `String`s and all other primitives into instances of their respective wrapper\n * classes (String, Boolean, Number, etc.). Acts as the identity function on non-primitives.\n *\n * @param wat The subject of the objectification\n * @returns A version of `wat` which can safely be used with `Object` class methods\n */\nexport function objectify(wat: unknown): typeof Object {\n let objectified;\n switch (true) {\n // this will catch both undefined and null\n case wat == undefined:\n objectified = new String(wat);\n break;\n\n // Though symbols and bigints do have wrapper classes (`Symbol` and `BigInt`, respectively), for whatever reason\n // those classes don't have constructors which can be used with the `new` keyword. We therefore need to cast each as\n // an object in order to wrap it.\n case typeof wat === 'symbol' || typeof wat === 'bigint':\n objectified = Object(wat);\n break;\n\n // this will catch the remaining primitives: `String`, `Number`, and `Boolean`\n case isPrimitive(wat):\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n objectified = new (wat as any).constructor(wat);\n break;\n\n // by process of elimination, at this point we know that `wat` must already be an object\n default:\n objectified = wat;\n break;\n }\n return objectified;\n}\n"],"names":[],"mappings":";;;;;AAAA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;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