@sentry/core 10.47.0 → 10.48.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 (316) 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/index.js +44 -13
  8. package/build/cjs/index.js.map +1 -1
  9. package/build/cjs/integration.js +6 -0
  10. package/build/cjs/integration.js.map +1 -1
  11. package/build/cjs/integrations/express/index.js +206 -0
  12. package/build/cjs/integrations/express/index.js.map +1 -0
  13. package/build/cjs/integrations/express/patch-layer.js +251 -0
  14. package/build/cjs/integrations/express/patch-layer.js.map +1 -0
  15. package/build/cjs/integrations/express/request-layer-store.js +25 -0
  16. package/build/cjs/integrations/express/request-layer-store.js.map +1 -0
  17. package/build/cjs/integrations/express/set-sdk-processing-metadata.js +17 -0
  18. package/build/cjs/integrations/express/set-sdk-processing-metadata.js.map +1 -0
  19. package/build/cjs/integrations/express/types.js +17 -0
  20. package/build/cjs/integrations/express/types.js.map +1 -0
  21. package/build/cjs/integrations/express/utils.js +238 -0
  22. package/build/cjs/integrations/express/utils.js.map +1 -0
  23. package/build/cjs/integrations/mcp-server/correlation.js +5 -1
  24. package/build/cjs/integrations/mcp-server/correlation.js.map +1 -1
  25. package/build/cjs/integrations/mcp-server/handlers.js +18 -10
  26. package/build/cjs/integrations/mcp-server/handlers.js.map +1 -1
  27. package/build/cjs/integrations/mcp-server/index.js +2 -1
  28. package/build/cjs/integrations/mcp-server/index.js.map +1 -1
  29. package/build/cjs/integrations/mcp-server/transport.js +1 -1
  30. package/build/cjs/integrations/mcp-server/transport.js.map +1 -1
  31. package/build/cjs/integrations/mcp-server/validation.js +7 -5
  32. package/build/cjs/integrations/mcp-server/validation.js.map +1 -1
  33. package/build/cjs/integrations/spanStreaming.js +48 -0
  34. package/build/cjs/integrations/spanStreaming.js.map +1 -0
  35. package/build/cjs/semanticAttributes.js +35 -3
  36. package/build/cjs/semanticAttributes.js.map +1 -1
  37. package/build/cjs/tracing/ai/gen-ai-attributes.js +9 -65
  38. package/build/cjs/tracing/ai/gen-ai-attributes.js.map +1 -1
  39. package/build/cjs/tracing/ai/utils.js +50 -0
  40. package/build/cjs/tracing/ai/utils.js.map +1 -1
  41. package/build/cjs/tracing/anthropic-ai/index.js +1 -12
  42. package/build/cjs/tracing/anthropic-ai/index.js.map +1 -1
  43. package/build/cjs/tracing/anthropic-ai/streaming.js +2 -100
  44. package/build/cjs/tracing/anthropic-ai/streaming.js.map +1 -1
  45. package/build/cjs/tracing/dynamicSamplingContext.js +2 -1
  46. package/build/cjs/tracing/dynamicSamplingContext.js.map +1 -1
  47. package/build/cjs/tracing/google-genai/constants.js +1 -6
  48. package/build/cjs/tracing/google-genai/constants.js.map +1 -1
  49. package/build/cjs/tracing/google-genai/index.js +24 -30
  50. package/build/cjs/tracing/google-genai/index.js.map +1 -1
  51. package/build/cjs/tracing/google-genai/streaming.js +2 -23
  52. package/build/cjs/tracing/google-genai/streaming.js.map +1 -1
  53. package/build/cjs/tracing/langchain/embeddings.js +132 -0
  54. package/build/cjs/tracing/langchain/embeddings.js.map +1 -0
  55. package/build/cjs/tracing/langchain/index.js.map +1 -1
  56. package/build/cjs/tracing/openai/index.js +2 -29
  57. package/build/cjs/tracing/openai/index.js.map +1 -1
  58. package/build/cjs/tracing/openai/streaming.js +3 -34
  59. package/build/cjs/tracing/openai/streaming.js.map +1 -1
  60. package/build/cjs/tracing/openai/utils.js +78 -204
  61. package/build/cjs/tracing/openai/utils.js.map +1 -1
  62. package/build/cjs/tracing/sentryNonRecordingSpan.js +7 -0
  63. package/build/cjs/tracing/sentryNonRecordingSpan.js.map +1 -1
  64. package/build/cjs/tracing/sentrySpan.js +39 -0
  65. package/build/cjs/tracing/sentrySpan.js.map +1 -1
  66. package/build/cjs/tracing/spans/beforeSendSpan.js +43 -0
  67. package/build/cjs/tracing/spans/beforeSendSpan.js.map +1 -0
  68. package/build/cjs/tracing/spans/captureSpan.js +126 -0
  69. package/build/cjs/tracing/spans/captureSpan.js.map +1 -0
  70. package/build/cjs/tracing/spans/envelope.js +38 -0
  71. package/build/cjs/tracing/spans/envelope.js.map +1 -0
  72. package/build/cjs/tracing/spans/estimateSize.js +41 -0
  73. package/build/cjs/tracing/spans/estimateSize.js.map +1 -0
  74. package/build/cjs/tracing/spans/hasSpanStreamingEnabled.js +11 -0
  75. package/build/cjs/tracing/spans/hasSpanStreamingEnabled.js.map +1 -0
  76. package/build/cjs/tracing/spans/spanBuffer.js +158 -0
  77. package/build/cjs/tracing/spans/spanBuffer.js.map +1 -0
  78. package/build/cjs/tracing/trace.js +83 -13
  79. package/build/cjs/tracing/trace.js.map +1 -1
  80. package/build/cjs/tracing/vercel-ai/utils.js +1 -4
  81. package/build/cjs/tracing/vercel-ai/utils.js.map +1 -1
  82. package/build/cjs/utils/featureFlags.js +6 -0
  83. package/build/cjs/utils/featureFlags.js.map +1 -1
  84. package/build/cjs/utils/object.js +33 -0
  85. package/build/cjs/utils/object.js.map +1 -1
  86. package/build/cjs/utils/spanUtils.js +116 -13
  87. package/build/cjs/utils/spanUtils.js.map +1 -1
  88. package/build/cjs/utils/stacktrace.js +3 -1
  89. package/build/cjs/utils/stacktrace.js.map +1 -1
  90. package/build/cjs/utils/string.js +3 -0
  91. package/build/cjs/utils/string.js.map +1 -1
  92. package/build/cjs/utils/version.js +1 -1
  93. package/build/esm/attributes.js +43 -1
  94. package/build/esm/attributes.js.map +1 -1
  95. package/build/esm/client.js +8 -1
  96. package/build/esm/client.js.map +1 -1
  97. package/build/esm/envelope.js +2 -1
  98. package/build/esm/envelope.js.map +1 -1
  99. package/build/esm/index.js +10 -2
  100. package/build/esm/index.js.map +1 -1
  101. package/build/esm/integration.js +6 -0
  102. package/build/esm/integration.js.map +1 -1
  103. package/build/esm/integrations/express/index.js +202 -0
  104. package/build/esm/integrations/express/index.js.map +1 -0
  105. package/build/esm/integrations/express/patch-layer.js +249 -0
  106. package/build/esm/integrations/express/patch-layer.js.map +1 -0
  107. package/build/esm/integrations/express/request-layer-store.js +22 -0
  108. package/build/esm/integrations/express/request-layer-store.js.map +1 -0
  109. package/build/esm/integrations/express/set-sdk-processing-metadata.js +15 -0
  110. package/build/esm/integrations/express/set-sdk-processing-metadata.js.map +1 -0
  111. package/build/esm/integrations/express/types.js +10 -0
  112. package/build/esm/integrations/express/types.js.map +1 -0
  113. package/build/esm/integrations/express/utils.js +225 -0
  114. package/build/esm/integrations/express/utils.js.map +1 -0
  115. package/build/esm/integrations/mcp-server/correlation.js +5 -1
  116. package/build/esm/integrations/mcp-server/correlation.js.map +1 -1
  117. package/build/esm/integrations/mcp-server/handlers.js +18 -10
  118. package/build/esm/integrations/mcp-server/handlers.js.map +1 -1
  119. package/build/esm/integrations/mcp-server/index.js +2 -1
  120. package/build/esm/integrations/mcp-server/index.js.map +1 -1
  121. package/build/esm/integrations/mcp-server/transport.js +1 -1
  122. package/build/esm/integrations/mcp-server/transport.js.map +1 -1
  123. package/build/esm/integrations/mcp-server/validation.js +7 -5
  124. package/build/esm/integrations/mcp-server/validation.js.map +1 -1
  125. package/build/esm/integrations/spanStreaming.js +46 -0
  126. package/build/esm/integrations/spanStreaming.js.map +1 -0
  127. package/build/esm/package.json +1 -1
  128. package/build/esm/semanticAttributes.js +26 -4
  129. package/build/esm/semanticAttributes.js.map +1 -1
  130. package/build/esm/tracing/ai/gen-ai-attributes.js +8 -56
  131. package/build/esm/tracing/ai/gen-ai-attributes.js.map +1 -1
  132. package/build/esm/tracing/ai/utils.js +51 -2
  133. package/build/esm/tracing/ai/utils.js.map +1 -1
  134. package/build/esm/tracing/anthropic-ai/index.js +2 -13
  135. package/build/esm/tracing/anthropic-ai/index.js.map +1 -1
  136. package/build/esm/tracing/anthropic-ai/streaming.js +3 -101
  137. package/build/esm/tracing/anthropic-ai/streaming.js.map +1 -1
  138. package/build/esm/tracing/dynamicSamplingContext.js +2 -1
  139. package/build/esm/tracing/dynamicSamplingContext.js.map +1 -1
  140. package/build/esm/tracing/google-genai/constants.js +2 -5
  141. package/build/esm/tracing/google-genai/constants.js.map +1 -1
  142. package/build/esm/tracing/google-genai/index.js +25 -31
  143. package/build/esm/tracing/google-genai/index.js.map +1 -1
  144. package/build/esm/tracing/google-genai/streaming.js +2 -23
  145. package/build/esm/tracing/google-genai/streaming.js.map +1 -1
  146. package/build/esm/tracing/langchain/embeddings.js +129 -0
  147. package/build/esm/tracing/langchain/embeddings.js.map +1 -0
  148. package/build/esm/tracing/langchain/index.js.map +1 -1
  149. package/build/esm/tracing/openai/index.js +3 -30
  150. package/build/esm/tracing/openai/index.js.map +1 -1
  151. package/build/esm/tracing/openai/streaming.js +4 -35
  152. package/build/esm/tracing/openai/streaming.js.map +1 -1
  153. package/build/esm/tracing/openai/utils.js +79 -196
  154. package/build/esm/tracing/openai/utils.js.map +1 -1
  155. package/build/esm/tracing/sentryNonRecordingSpan.js +7 -0
  156. package/build/esm/tracing/sentryNonRecordingSpan.js.map +1 -1
  157. package/build/esm/tracing/sentrySpan.js +40 -1
  158. package/build/esm/tracing/sentrySpan.js.map +1 -1
  159. package/build/esm/tracing/spans/beforeSendSpan.js +40 -0
  160. package/build/esm/tracing/spans/beforeSendSpan.js.map +1 -0
  161. package/build/esm/tracing/spans/captureSpan.js +122 -0
  162. package/build/esm/tracing/spans/captureSpan.js.map +1 -0
  163. package/build/esm/tracing/spans/envelope.js +36 -0
  164. package/build/esm/tracing/spans/envelope.js.map +1 -0
  165. package/build/esm/tracing/spans/estimateSize.js +39 -0
  166. package/build/esm/tracing/spans/estimateSize.js.map +1 -0
  167. package/build/esm/tracing/spans/hasSpanStreamingEnabled.js +9 -0
  168. package/build/esm/tracing/spans/hasSpanStreamingEnabled.js.map +1 -0
  169. package/build/esm/tracing/spans/spanBuffer.js +156 -0
  170. package/build/esm/tracing/spans/spanBuffer.js.map +1 -0
  171. package/build/esm/tracing/trace.js +84 -14
  172. package/build/esm/tracing/trace.js.map +1 -1
  173. package/build/esm/tracing/vercel-ai/utils.js +2 -5
  174. package/build/esm/tracing/vercel-ai/utils.js.map +1 -1
  175. package/build/esm/utils/featureFlags.js +6 -0
  176. package/build/esm/utils/featureFlags.js.map +1 -1
  177. package/build/esm/utils/object.js +33 -1
  178. package/build/esm/utils/object.js.map +1 -1
  179. package/build/esm/utils/spanUtils.js +112 -14
  180. package/build/esm/utils/spanUtils.js.map +1 -1
  181. package/build/esm/utils/stacktrace.js +3 -1
  182. package/build/esm/utils/stacktrace.js.map +1 -1
  183. package/build/esm/utils/string.js +3 -0
  184. package/build/esm/utils/string.js.map +1 -1
  185. package/build/esm/utils/version.js +1 -1
  186. package/build/types/attributes.d.ts +5 -0
  187. package/build/types/attributes.d.ts.map +1 -1
  188. package/build/types/client.d.ts +35 -1
  189. package/build/types/client.d.ts.map +1 -1
  190. package/build/types/envelope.d.ts.map +1 -1
  191. package/build/types/index.d.ts +12 -4
  192. package/build/types/index.d.ts.map +1 -1
  193. package/build/types/integration.d.ts.map +1 -1
  194. package/build/types/integrations/express/index.d.ts +75 -0
  195. package/build/types/integrations/express/index.d.ts.map +1 -0
  196. package/build/types/integrations/express/patch-layer.d.ts +32 -0
  197. package/build/types/integrations/express/patch-layer.d.ts.map +1 -0
  198. package/build/types/integrations/express/request-layer-store.d.ts +32 -0
  199. package/build/types/integrations/express/request-layer-store.d.ts.map +1 -0
  200. package/build/types/integrations/express/set-sdk-processing-metadata.d.ts +35 -0
  201. package/build/types/integrations/express/set-sdk-processing-metadata.d.ts.map +1 -0
  202. package/build/types/integrations/express/types.d.ts +154 -0
  203. package/build/types/integrations/express/types.d.ts.map +1 -0
  204. package/build/types/integrations/express/utils.d.ts +93 -0
  205. package/build/types/integrations/express/utils.d.ts.map +1 -0
  206. package/build/types/integrations/mcp-server/correlation.d.ts +2 -1
  207. package/build/types/integrations/mcp-server/correlation.d.ts.map +1 -1
  208. package/build/types/integrations/mcp-server/handlers.d.ts +9 -4
  209. package/build/types/integrations/mcp-server/handlers.d.ts.map +1 -1
  210. package/build/types/integrations/mcp-server/index.d.ts +2 -1
  211. package/build/types/integrations/mcp-server/index.d.ts.map +1 -1
  212. package/build/types/integrations/mcp-server/types.d.ts +40 -7
  213. package/build/types/integrations/mcp-server/types.d.ts.map +1 -1
  214. package/build/types/integrations/mcp-server/validation.d.ts +4 -1
  215. package/build/types/integrations/mcp-server/validation.d.ts.map +1 -1
  216. package/build/types/integrations/spanStreaming.d.ts +2 -0
  217. package/build/types/integrations/spanStreaming.d.ts.map +1 -0
  218. package/build/types/semanticAttributes.d.ts +23 -3
  219. package/build/types/semanticAttributes.d.ts.map +1 -1
  220. package/build/types/tracing/ai/gen-ai-attributes.d.ts +6 -38
  221. package/build/types/tracing/ai/gen-ai-attributes.d.ts.map +1 -1
  222. package/build/types/tracing/ai/utils.d.ts +21 -2
  223. package/build/types/tracing/ai/utils.d.ts.map +1 -1
  224. package/build/types/tracing/anthropic-ai/index.d.ts.map +1 -1
  225. package/build/types/tracing/anthropic-ai/streaming.d.ts.map +1 -1
  226. package/build/types/tracing/dynamicSamplingContext.d.ts.map +1 -1
  227. package/build/types/tracing/google-genai/constants.d.ts +1 -3
  228. package/build/types/tracing/google-genai/constants.d.ts.map +1 -1
  229. package/build/types/tracing/google-genai/index.d.ts.map +1 -1
  230. package/build/types/tracing/google-genai/streaming.d.ts.map +1 -1
  231. package/build/types/tracing/index.d.ts +1 -0
  232. package/build/types/tracing/index.d.ts.map +1 -1
  233. package/build/types/tracing/langchain/embeddings.d.ts +27 -0
  234. package/build/types/tracing/langchain/embeddings.d.ts.map +1 -0
  235. package/build/types/tracing/langchain/index.d.ts +1 -0
  236. package/build/types/tracing/langchain/index.d.ts.map +1 -1
  237. package/build/types/tracing/openai/index.d.ts.map +1 -1
  238. package/build/types/tracing/openai/streaming.d.ts.map +1 -1
  239. package/build/types/tracing/openai/utils.d.ts +4 -49
  240. package/build/types/tracing/openai/utils.d.ts.map +1 -1
  241. package/build/types/tracing/sentryNonRecordingSpan.d.ts +12 -1
  242. package/build/types/tracing/sentryNonRecordingSpan.d.ts.map +1 -1
  243. package/build/types/tracing/sentrySpan.d.ts +10 -1
  244. package/build/types/tracing/sentrySpan.d.ts.map +1 -1
  245. package/build/types/tracing/spans/beforeSendSpan.d.ts +35 -0
  246. package/build/types/tracing/spans/beforeSendSpan.d.ts.map +1 -0
  247. package/build/types/tracing/spans/captureSpan.d.ts +26 -0
  248. package/build/types/tracing/spans/captureSpan.d.ts.map +1 -0
  249. package/build/types/tracing/spans/envelope.d.ts +8 -0
  250. package/build/types/tracing/spans/envelope.d.ts.map +1 -0
  251. package/build/types/tracing/spans/estimateSize.d.ts +12 -0
  252. package/build/types/tracing/spans/estimateSize.d.ts.map +1 -0
  253. package/build/types/tracing/spans/hasSpanStreamingEnabled.d.ts +6 -0
  254. package/build/types/tracing/spans/hasSpanStreamingEnabled.d.ts.map +1 -0
  255. package/build/types/tracing/spans/spanBuffer.d.ts +60 -0
  256. package/build/types/tracing/spans/spanBuffer.d.ts.map +1 -0
  257. package/build/types/tracing/trace.d.ts.map +1 -1
  258. package/build/types/tracing/vercel-ai/utils.d.ts.map +1 -1
  259. package/build/types/types-hoist/envelope.d.ts +22 -2
  260. package/build/types/types-hoist/envelope.d.ts.map +1 -1
  261. package/build/types/types-hoist/integration.d.ts +8 -0
  262. package/build/types/types-hoist/integration.d.ts.map +1 -1
  263. package/build/types/types-hoist/link.d.ts +2 -2
  264. package/build/types/types-hoist/link.d.ts.map +1 -1
  265. package/build/types/types-hoist/options.d.ts +26 -2
  266. package/build/types/types-hoist/options.d.ts.map +1 -1
  267. package/build/types/types-hoist/span.d.ts +35 -0
  268. package/build/types/types-hoist/span.d.ts.map +1 -1
  269. package/build/types/utils/featureFlags.d.ts.map +1 -1
  270. package/build/types/utils/object.d.ts +10 -0
  271. package/build/types/utils/object.d.ts.map +1 -1
  272. package/build/types/utils/spanUtils.d.ts +27 -2
  273. package/build/types/utils/spanUtils.d.ts.map +1 -1
  274. package/build/types/utils/stacktrace.d.ts.map +1 -1
  275. package/build/types/utils/string.d.ts +2 -2
  276. package/build/types/utils/string.d.ts.map +1 -1
  277. package/build/types-ts3.8/attributes.d.ts +5 -0
  278. package/build/types-ts3.8/client.d.ts +35 -1
  279. package/build/types-ts3.8/index.d.ts +12 -4
  280. package/build/types-ts3.8/integrations/express/index.d.ts +75 -0
  281. package/build/types-ts3.8/integrations/express/patch-layer.d.ts +32 -0
  282. package/build/types-ts3.8/integrations/express/request-layer-store.d.ts +32 -0
  283. package/build/types-ts3.8/integrations/express/set-sdk-processing-metadata.d.ts +35 -0
  284. package/build/types-ts3.8/integrations/express/types.d.ts +154 -0
  285. package/build/types-ts3.8/integrations/express/utils.d.ts +96 -0
  286. package/build/types-ts3.8/integrations/mcp-server/correlation.d.ts +2 -1
  287. package/build/types-ts3.8/integrations/mcp-server/handlers.d.ts +9 -4
  288. package/build/types-ts3.8/integrations/mcp-server/index.d.ts +2 -1
  289. package/build/types-ts3.8/integrations/mcp-server/types.d.ts +40 -7
  290. package/build/types-ts3.8/integrations/mcp-server/validation.d.ts +4 -1
  291. package/build/types-ts3.8/integrations/spanStreaming.d.ts +2 -0
  292. package/build/types-ts3.8/semanticAttributes.d.ts +23 -3
  293. package/build/types-ts3.8/tracing/ai/gen-ai-attributes.d.ts +6 -38
  294. package/build/types-ts3.8/tracing/ai/utils.d.ts +21 -2
  295. package/build/types-ts3.8/tracing/google-genai/constants.d.ts +1 -3
  296. package/build/types-ts3.8/tracing/index.d.ts +1 -0
  297. package/build/types-ts3.8/tracing/langchain/embeddings.d.ts +27 -0
  298. package/build/types-ts3.8/tracing/langchain/index.d.ts +1 -0
  299. package/build/types-ts3.8/tracing/openai/utils.d.ts +4 -49
  300. package/build/types-ts3.8/tracing/sentryNonRecordingSpan.d.ts +12 -1
  301. package/build/types-ts3.8/tracing/sentrySpan.d.ts +10 -1
  302. package/build/types-ts3.8/tracing/spans/beforeSendSpan.d.ts +35 -0
  303. package/build/types-ts3.8/tracing/spans/captureSpan.d.ts +26 -0
  304. package/build/types-ts3.8/tracing/spans/envelope.d.ts +8 -0
  305. package/build/types-ts3.8/tracing/spans/estimateSize.d.ts +12 -0
  306. package/build/types-ts3.8/tracing/spans/hasSpanStreamingEnabled.d.ts +6 -0
  307. package/build/types-ts3.8/tracing/spans/spanBuffer.d.ts +60 -0
  308. package/build/types-ts3.8/types-hoist/envelope.d.ts +22 -2
  309. package/build/types-ts3.8/types-hoist/integration.d.ts +8 -0
  310. package/build/types-ts3.8/types-hoist/link.d.ts +2 -2
  311. package/build/types-ts3.8/types-hoist/options.d.ts +26 -2
  312. package/build/types-ts3.8/types-hoist/span.d.ts +35 -0
  313. package/build/types-ts3.8/utils/object.d.ts +10 -0
  314. package/build/types-ts3.8/utils/spanUtils.d.ts +27 -2
  315. package/build/types-ts3.8/utils/string.d.ts +2 -2
  316. package/package.json +1 -1
@@ -0,0 +1,225 @@
1
+ import { getStoredLayers } from './request-layer-store.js';
2
+ import { ExpressLayerType_ROUTER, ATTR_EXPRESS_TYPE, ATTR_EXPRESS_NAME, ExpressLayerType_REQUEST_HANDLER, ExpressLayerType_MIDDLEWARE } from './types.js';
3
+ import { stringMatchesSomePattern } from '../../utils/string.js';
4
+
5
+ /**
6
+ * Converts a user-provided error value into an error and error message pair
7
+ *
8
+ * @param error - User-provided error value
9
+ * @returns Both an Error or string representation of the value and an error message
10
+ */
11
+ const asErrorAndMessage = (error) =>
12
+ error instanceof Error ? [error, error.message] : [String(error), String(error)];
13
+
14
+ /**
15
+ * Checks if a route contains parameter patterns (e.g., :id, :userId)
16
+ * which are valid even if they don't exactly match the original URL
17
+ */
18
+ function isRoutePattern(route) {
19
+ return route.includes(':') || route.includes('*');
20
+ }
21
+
22
+ /**
23
+ * Parse express layer context to retrieve a name and attributes.
24
+ * @param route The route of the layer
25
+ * @param layer Express layer
26
+ * @param [layerPath] if present, the path on which the layer has been mounted
27
+ */
28
+ const getLayerMetadata = (
29
+ route,
30
+ layer,
31
+ layerPath,
32
+
33
+ ) => {
34
+ if (layer.name === 'router') {
35
+ const maybeRouterPath = getRouterPath('', layer);
36
+ const extractedRouterPath = maybeRouterPath ? maybeRouterPath : layerPath || route || '/';
37
+
38
+ return {
39
+ attributes: {
40
+ [ATTR_EXPRESS_NAME]: extractedRouterPath,
41
+ [ATTR_EXPRESS_TYPE]: ExpressLayerType_ROUTER,
42
+ },
43
+ name: `router - ${extractedRouterPath}`,
44
+ };
45
+ } else if (layer.name === 'bound dispatch' || layer.name === 'handle') {
46
+ return {
47
+ attributes: {
48
+ [ATTR_EXPRESS_NAME]: (route || layerPath) ?? 'request handler',
49
+ [ATTR_EXPRESS_TYPE]: ExpressLayerType_REQUEST_HANDLER,
50
+ },
51
+ name: `request handler${layer.path ? ` - ${route || layerPath}` : ''}`,
52
+ };
53
+ } else {
54
+ return {
55
+ attributes: {
56
+ [ATTR_EXPRESS_NAME]: layer.name,
57
+ [ATTR_EXPRESS_TYPE]: ExpressLayerType_MIDDLEWARE,
58
+ },
59
+ name: `middleware - ${layer.name}`,
60
+ };
61
+ }
62
+ };
63
+
64
+ /**
65
+ * Recursively search the router path from layer stack
66
+ * @param path The path to reconstruct
67
+ * @param layer The layer to reconstruct from
68
+ * @returns The reconstructed path
69
+ */
70
+ const getRouterPath = (path, layer) => {
71
+ const stackLayer = Array.isArray(layer.handle?.stack) ? layer.handle?.stack?.[0] : undefined;
72
+
73
+ if (stackLayer?.route?.path) {
74
+ return `${path}${stackLayer.route.path}`;
75
+ }
76
+
77
+ if (stackLayer && Array.isArray(stackLayer?.handle?.stack)) {
78
+ return getRouterPath(path, stackLayer);
79
+ }
80
+
81
+ return path;
82
+ };
83
+
84
+ /**
85
+ * Check whether the given request is ignored by configuration
86
+ * It will not re-throw exceptions from `list` provided by the client
87
+ * @param constant e.g URL of request
88
+ * @param [list] List of ignore patterns
89
+ * @param [onException] callback for doing something when an exception has
90
+ * occurred
91
+ */
92
+
93
+ const isLayerIgnored = (
94
+ name,
95
+ type,
96
+ config,
97
+ ) => {
98
+ if (Array.isArray(config?.ignoreLayersType) && config?.ignoreLayersType?.includes(type)) {
99
+ return true;
100
+ }
101
+ if (!Array.isArray(config?.ignoreLayers)) {
102
+ return false;
103
+ }
104
+ try {
105
+ return stringMatchesSomePattern(name, config.ignoreLayers, true);
106
+ } catch {}
107
+
108
+ return false;
109
+ };
110
+
111
+ /**
112
+ * Extracts the actual matched route from Express request for OpenTelemetry instrumentation.
113
+ * Returns the route that should be used as the http.route attribute.
114
+ *
115
+ * @param req - The Express request object with layers store
116
+ * @param constructedRoute - The constructed route from `getConstructedRoute`
117
+ * @returns The matched route string or undefined if no valid route is found
118
+ */
119
+ function getActualMatchedRoute(req, constructedRoute) {
120
+ const layersStore = getStoredLayers(req);
121
+
122
+ // If no layers are stored, no route can be determined
123
+ if (layersStore.length === 0) {
124
+ return undefined;
125
+ }
126
+
127
+ // Handle root path case - if all paths are root, only return root if originalUrl is also root
128
+ // The layer store also includes root paths in case a non-existing url was requested
129
+ if (layersStore.every(path => path === '/')) {
130
+ return req.originalUrl === '/' ? '/' : undefined;
131
+ }
132
+
133
+ if (constructedRoute === '*') {
134
+ return constructedRoute;
135
+ }
136
+
137
+ // For RegExp routes or route arrays, return the constructed route
138
+ // This handles the case where the route is defined using RegExp or an array
139
+ if (
140
+ constructedRoute.includes('/') &&
141
+ (constructedRoute.includes(',') ||
142
+ constructedRoute.includes('\\') ||
143
+ constructedRoute.includes('*') ||
144
+ constructedRoute.includes('['))
145
+ ) {
146
+ return constructedRoute;
147
+ }
148
+
149
+ // Ensure route starts with '/' if it doesn't already
150
+ const normalizedRoute = constructedRoute.startsWith('/') ? constructedRoute : `/${constructedRoute}`;
151
+
152
+ // Validate that this appears to be a matched route
153
+ // A route is considered matched if:
154
+ // 1. We have a constructed route
155
+ // 2. The original URL matches or starts with our route pattern
156
+ const isValidRoute =
157
+ normalizedRoute.length > 0 &&
158
+ (req.originalUrl === normalizedRoute ||
159
+ req.originalUrl.startsWith(normalizedRoute) ||
160
+ isRoutePattern(normalizedRoute));
161
+
162
+ return isValidRoute ? normalizedRoute : undefined;
163
+ }
164
+
165
+ function getConstructedRoute(req) {
166
+ const layersStore = getStoredLayers(req);
167
+
168
+ let constructedRoute = '';
169
+ for (const path of layersStore) {
170
+ if (path === '/' || path === '/*') {
171
+ continue;
172
+ }
173
+ constructedRoute += !constructedRoute || constructedRoute.endsWith('/') ? path : `/${path}`;
174
+ }
175
+
176
+ return constructedRoute.replace(/\/{2,}/g, '/');
177
+ }
178
+
179
+ const getLayerPath = (args) => {
180
+ const firstArg = args[0];
181
+
182
+ if (Array.isArray(firstArg)) {
183
+ return firstArg.map(arg => extractLayerPathSegment(arg) || '').join(',');
184
+ }
185
+
186
+ return extractLayerPathSegment(firstArg );
187
+ };
188
+
189
+ const extractLayerPathSegment = (arg) =>
190
+ typeof arg === 'string' ? arg : arg instanceof RegExp || typeof arg === 'number' ? String(arg) : undefined;
191
+
192
+ // v5 we instrument Router.prototype
193
+ // v4 we instrument Router itself
194
+ const isExpressWithRouterPrototype = (express) =>
195
+ isExpressRouterPrototype((express )?.Router?.prototype);
196
+
197
+ // In Express v4, Router is a function (not a plain object), so we need to accept both
198
+ const isExpressRouterPrototype = (routerProto) =>
199
+ (typeof routerProto === 'object' || typeof routerProto === 'function') &&
200
+ !!routerProto &&
201
+ 'route' in routerProto &&
202
+ typeof (routerProto ).route === 'function';
203
+
204
+ const isExpressWithoutRouterPrototype = (express) =>
205
+ isExpressRouterPrototype((express ).Router) && !isExpressWithRouterPrototype(express);
206
+
207
+ // dynamic puts the default on .default, require or normal import are fine
208
+ const hasDefaultProp = (
209
+ express,
210
+
211
+ ) => !!express && typeof express === 'object' && 'default' in express && typeof express.default === 'function';
212
+
213
+ function getStatusCodeFromResponse(error) {
214
+ const statusCode = error.status || error.statusCode || error.status_code || error.output?.statusCode;
215
+ return statusCode ? parseInt(statusCode , 10) : 500;
216
+ }
217
+
218
+ /** Returns true if response code is internal server error */
219
+ function defaultShouldHandleError(error) {
220
+ const status = getStatusCodeFromResponse(error);
221
+ return status >= 500;
222
+ }
223
+
224
+ export { asErrorAndMessage, defaultShouldHandleError, getActualMatchedRoute, getConstructedRoute, getLayerMetadata, getLayerPath, getRouterPath, hasDefaultProp, isExpressWithRouterPrototype, isExpressWithoutRouterPrototype, isLayerIgnored, isRoutePattern };
225
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sources":["../../../../src/integrations/express/utils.ts"],"sourcesContent":["/**\n * Platform-portable Express tracing integration.\n *\n * @module\n *\n * This Sentry integration is a derivative work based on the OpenTelemetry\n * Express instrumentation.\n *\n * <https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-express>\n *\n * Extended under the terms of the Apache 2.0 license linked below:\n *\n * ----\n *\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { SpanAttributes } from '../../types-hoist/span';\nimport { getStoredLayers } from './request-layer-store';\nimport type {\n ExpressExport,\n ExpressIntegrationOptions,\n ExpressLayer,\n ExpressLayerType,\n ExpressRequest,\n LayerPathSegment,\n MiddlewareError,\n ExpressRouterv4,\n ExpressExportv5,\n ExpressExportv4,\n} from './types';\nimport {\n ATTR_EXPRESS_NAME,\n ATTR_EXPRESS_TYPE,\n ExpressLayerType_MIDDLEWARE,\n ExpressLayerType_REQUEST_HANDLER,\n ExpressLayerType_ROUTER,\n} from './types';\nimport { stringMatchesSomePattern } from '../../utils/string';\n\n/**\n * Converts a user-provided error value into an error and error message pair\n *\n * @param error - User-provided error value\n * @returns Both an Error or string representation of the value and an error message\n */\nexport const asErrorAndMessage = (error: unknown): [string | Error, string] =>\n error instanceof Error ? [error, error.message] : [String(error), String(error)];\n\n/**\n * Checks if a route contains parameter patterns (e.g., :id, :userId)\n * which are valid even if they don't exactly match the original URL\n */\nexport function isRoutePattern(route: string): boolean {\n return route.includes(':') || route.includes('*');\n}\n\n/**\n * Parse express layer context to retrieve a name and attributes.\n * @param route The route of the layer\n * @param layer Express layer\n * @param [layerPath] if present, the path on which the layer has been mounted\n */\nexport const getLayerMetadata = (\n route: string,\n layer: ExpressLayer,\n layerPath?: string,\n): {\n attributes: SpanAttributes & { [ATTR_EXPRESS_NAME]: string; [ATTR_EXPRESS_TYPE]: ExpressLayerType };\n name: string;\n} => {\n if (layer.name === 'router') {\n const maybeRouterPath = getRouterPath('', layer);\n const extractedRouterPath = maybeRouterPath ? maybeRouterPath : layerPath || route || '/';\n\n return {\n attributes: {\n [ATTR_EXPRESS_NAME]: extractedRouterPath,\n [ATTR_EXPRESS_TYPE]: ExpressLayerType_ROUTER,\n },\n name: `router - ${extractedRouterPath}`,\n };\n } else if (layer.name === 'bound dispatch' || layer.name === 'handle') {\n return {\n attributes: {\n [ATTR_EXPRESS_NAME]: (route || layerPath) ?? 'request handler',\n [ATTR_EXPRESS_TYPE]: ExpressLayerType_REQUEST_HANDLER,\n },\n name: `request handler${layer.path ? ` - ${route || layerPath}` : ''}`,\n };\n } else {\n return {\n attributes: {\n [ATTR_EXPRESS_NAME]: layer.name,\n [ATTR_EXPRESS_TYPE]: ExpressLayerType_MIDDLEWARE,\n },\n name: `middleware - ${layer.name}`,\n };\n }\n};\n\n/**\n * Recursively search the router path from layer stack\n * @param path The path to reconstruct\n * @param layer The layer to reconstruct from\n * @returns The reconstructed path\n */\nexport const getRouterPath = (path: string, layer: ExpressLayer): string => {\n const stackLayer = Array.isArray(layer.handle?.stack) ? layer.handle?.stack?.[0] : undefined;\n\n if (stackLayer?.route?.path) {\n return `${path}${stackLayer.route.path}`;\n }\n\n if (stackLayer && Array.isArray(stackLayer?.handle?.stack)) {\n return getRouterPath(path, stackLayer);\n }\n\n return path;\n};\n\n/**\n * Check whether the given request is ignored by configuration\n * It will not re-throw exceptions from `list` provided by the client\n * @param constant e.g URL of request\n * @param [list] List of ignore patterns\n * @param [onException] callback for doing something when an exception has\n * occurred\n */\nexport type ExpressIsLayerIgnoredOptions = Pick<ExpressIntegrationOptions, 'ignoreLayersType' | 'ignoreLayers'>;\nexport const isLayerIgnored = (\n name: string,\n type: ExpressLayerType,\n config?: ExpressIsLayerIgnoredOptions,\n): boolean => {\n if (Array.isArray(config?.ignoreLayersType) && config?.ignoreLayersType?.includes(type)) {\n return true;\n }\n if (!Array.isArray(config?.ignoreLayers)) {\n return false;\n }\n try {\n return stringMatchesSomePattern(name, config.ignoreLayers, true);\n } catch {}\n\n return false;\n};\n\n/**\n * Extracts the actual matched route from Express request for OpenTelemetry instrumentation.\n * Returns the route that should be used as the http.route attribute.\n *\n * @param req - The Express request object with layers store\n * @param constructedRoute - The constructed route from `getConstructedRoute`\n * @returns The matched route string or undefined if no valid route is found\n */\nexport function getActualMatchedRoute(req: ExpressRequest, constructedRoute: string): string | undefined {\n const layersStore = getStoredLayers(req);\n\n // If no layers are stored, no route can be determined\n if (layersStore.length === 0) {\n return undefined;\n }\n\n // Handle root path case - if all paths are root, only return root if originalUrl is also root\n // The layer store also includes root paths in case a non-existing url was requested\n if (layersStore.every(path => path === '/')) {\n return req.originalUrl === '/' ? '/' : undefined;\n }\n\n if (constructedRoute === '*') {\n return constructedRoute;\n }\n\n // For RegExp routes or route arrays, return the constructed route\n // This handles the case where the route is defined using RegExp or an array\n if (\n constructedRoute.includes('/') &&\n (constructedRoute.includes(',') ||\n constructedRoute.includes('\\\\') ||\n constructedRoute.includes('*') ||\n constructedRoute.includes('['))\n ) {\n return constructedRoute;\n }\n\n // Ensure route starts with '/' if it doesn't already\n const normalizedRoute = constructedRoute.startsWith('/') ? constructedRoute : `/${constructedRoute}`;\n\n // Validate that this appears to be a matched route\n // A route is considered matched if:\n // 1. We have a constructed route\n // 2. The original URL matches or starts with our route pattern\n const isValidRoute =\n normalizedRoute.length > 0 &&\n (req.originalUrl === normalizedRoute ||\n req.originalUrl.startsWith(normalizedRoute) ||\n isRoutePattern(normalizedRoute));\n\n return isValidRoute ? normalizedRoute : undefined;\n}\n\nexport function getConstructedRoute(req: ExpressRequest) {\n const layersStore: string[] = getStoredLayers(req);\n\n let constructedRoute: string = '';\n for (const path of layersStore) {\n if (path === '/' || path === '/*') {\n continue;\n }\n constructedRoute += !constructedRoute || constructedRoute.endsWith('/') ? path : `/${path}`;\n }\n\n return constructedRoute.replace(/\\/{2,}/g, '/');\n}\n\nexport const getLayerPath = (args: unknown[]): string | undefined => {\n const firstArg = args[0];\n\n if (Array.isArray(firstArg)) {\n return firstArg.map(arg => extractLayerPathSegment(arg) || '').join(',');\n }\n\n return extractLayerPathSegment(firstArg as LayerPathSegment);\n};\n\nconst extractLayerPathSegment = (arg: LayerPathSegment): string | undefined =>\n typeof arg === 'string' ? arg : arg instanceof RegExp || typeof arg === 'number' ? String(arg) : undefined;\n\n// v5 we instrument Router.prototype\n// v4 we instrument Router itself\nexport const isExpressWithRouterPrototype = (express: unknown): express is ExpressExportv5 =>\n isExpressRouterPrototype((express as ExpressExportv5)?.Router?.prototype);\n\n// In Express v4, Router is a function (not a plain object), so we need to accept both\nconst isExpressRouterPrototype = (routerProto?: unknown): routerProto is ExpressRouterv4 =>\n (typeof routerProto === 'object' || typeof routerProto === 'function') &&\n !!routerProto &&\n 'route' in routerProto &&\n typeof (routerProto as ExpressRouterv4).route === 'function';\n\nexport const isExpressWithoutRouterPrototype = (express: unknown): express is ExpressExportv4 =>\n isExpressRouterPrototype((express as ExpressExportv4).Router) && !isExpressWithRouterPrototype(express);\n\n// dynamic puts the default on .default, require or normal import are fine\nexport const hasDefaultProp = (\n express: unknown,\n): express is {\n [k: string]: unknown;\n default: ExpressExport;\n} => !!express && typeof express === 'object' && 'default' in express && typeof express.default === 'function';\n\nfunction getStatusCodeFromResponse(error: MiddlewareError): number {\n const statusCode = error.status || error.statusCode || error.status_code || error.output?.statusCode;\n return statusCode ? parseInt(statusCode as string, 10) : 500;\n}\n\n/** Returns true if response code is internal server error */\nexport function defaultShouldHandleError(error: MiddlewareError): boolean {\n const status = getStatusCodeFromResponse(error);\n return status >= 500;\n}\n"],"names":[],"mappings":";;;;AAoDA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,iBAAA,GAAoB,CAAC,KAAK;AACvC,EAAE,KAAA,YAAiB,KAAA,GAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAA,GAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC;;AAEjF;AACA;AACA;AACA;AACO,SAAS,cAAc,CAAC,KAAK,EAAmB;AACvD,EAAE,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAA,IAAK,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;AACnD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,mBAAmB;AAChC,EAAE,KAAK;AACP,EAAE,KAAK;AACP,EAAE,SAAS;;AAIX,KAAK;AACL,EAAE,IAAI,KAAK,CAAC,IAAA,KAAS,QAAQ,EAAE;AAC/B,IAAI,MAAM,kBAAkB,aAAa,CAAC,EAAE,EAAE,KAAK,CAAC;AACpD,IAAI,MAAM,mBAAA,GAAsB,eAAA,GAAkB,eAAA,GAAkB,SAAA,IAAa,KAAA,IAAS,GAAG;;AAE7F,IAAI,OAAO;AACX,MAAM,UAAU,EAAE;AAClB,QAAQ,CAAC,iBAAiB,GAAG,mBAAmB;AAChD,QAAQ,CAAC,iBAAiB,GAAG,uBAAuB;AACpD,OAAO;AACP,MAAM,IAAI,EAAE,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAA;AACA,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,wBAAA,CAAA,KAAA,EAAA;AACA,EAAA,MAAA,MAAA,GAAA,yBAAA,CAAA,KAAA,CAAA;AACA,EAAA,OAAA,MAAA,IAAA,GAAA;AACA;;;;"}
@@ -80,19 +80,23 @@ function storeSpanForRequest(transport, requestId, span, method) {
80
80
  * @param requestId - Request identifier
81
81
  * @param result - Execution result for attribute extraction
82
82
  * @param options - Resolved MCP options
83
+ * @param hasError - Whether the JSON-RPC response contained an error
83
84
  */
84
85
  function completeSpanWithResults(
85
86
  transport,
86
87
  requestId,
87
88
  result,
88
89
  options,
90
+ hasError = false,
89
91
  ) {
90
92
  const spanMap = getOrCreateSpanMap(transport);
91
93
  const spanData = spanMap.get(requestId);
92
94
  if (spanData) {
93
95
  const { span, method } = spanData;
94
96
 
95
- if (method === 'initialize') {
97
+ if (hasError) {
98
+ span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });
99
+ } else if (method === 'initialize') {
96
100
  const sessionData = extractSessionDataFromInitializeResponse(result);
97
101
  const serverAttributes = buildServerAttributesFromInfo(sessionData.serverInfo);
98
102
 
@@ -1 +1 @@
1
- {"version":3,"file":"correlation.js","sources":["../../../../src/integrations/mcp-server/correlation.ts"],"sourcesContent":["/**\n * Request-span correlation system for MCP server instrumentation\n *\n * Handles mapping requestId to span data for correlation with handler execution.\n *\n * Uses sessionId as the primary key for stateful transports. This handles the wrapper\n * transport pattern (e.g., NodeStreamableHTTPServerTransport wrapping WebStandardStreamableHTTPServerTransport)\n * where onmessage and send may receive different `this` values but share the same sessionId.\n *\n * Falls back to WeakMap by transport instance for stateless transports (no sessionId).\n */\n\nimport { SPAN_STATUS_ERROR } from '../../tracing';\nimport type { Span } from '../../types-hoist/span';\nimport { MCP_PROTOCOL_VERSION_ATTRIBUTE } from './attributes';\nimport { extractPromptResultAttributes, extractToolResultAttributes } from './resultExtraction';\nimport { buildServerAttributesFromInfo, extractSessionDataFromInitializeResponse } from './sessionExtraction';\nimport type { MCPTransport, RequestId, RequestSpanMapValue, ResolvedMcpOptions } from './types';\n\n/**\n * Session-scoped correlation for stateful transports (with sessionId)\n * @internal Using sessionId as key handles wrapper transport patterns where\n * different transport objects share the same logical session\n */\nconst sessionToSpanMap = new Map<string, Map<RequestId, RequestSpanMapValue>>();\n\n/**\n * Transport-scoped correlation fallback for stateless transports (no sessionId)\n * @internal WeakMap allows automatic cleanup when transport is garbage collected\n */\nconst statelessSpanMap = new WeakMap<MCPTransport, Map<RequestId, RequestSpanMapValue>>();\n\n/**\n * Gets or creates the span map for a transport, using sessionId when available\n * @internal\n * @param transport - MCP transport instance\n * @returns Span map for the transport/session\n */\nfunction getOrCreateSpanMap(transport: MCPTransport): Map<RequestId, RequestSpanMapValue> {\n const sessionId = transport.sessionId;\n\n if (sessionId) {\n // Stateful transport - use sessionId as key (handles wrapper pattern)\n let spanMap = sessionToSpanMap.get(sessionId);\n if (!spanMap) {\n spanMap = new Map();\n sessionToSpanMap.set(sessionId, spanMap);\n }\n return spanMap;\n }\n\n // Stateless fallback - use transport instance as key\n let spanMap = statelessSpanMap.get(transport);\n if (!spanMap) {\n spanMap = new Map();\n statelessSpanMap.set(transport, spanMap);\n }\n return spanMap;\n}\n\n/**\n * Stores span context for later correlation with handler execution\n * @param transport - MCP transport instance\n * @param requestId - Request identifier\n * @param span - Active span to correlate\n * @param method - MCP method name\n */\nexport function storeSpanForRequest(transport: MCPTransport, requestId: RequestId, span: Span, method: string): void {\n const spanMap = getOrCreateSpanMap(transport);\n spanMap.set(requestId, {\n span,\n method,\n // oxlint-disable-next-line sdk/no-unsafe-random-apis\n startTime: Date.now(),\n });\n}\n\n/**\n * Completes span with results and cleans up correlation\n * @param transport - MCP transport instance\n * @param requestId - Request identifier\n * @param result - Execution result for attribute extraction\n * @param options - Resolved MCP options\n */\nexport function completeSpanWithResults(\n transport: MCPTransport,\n requestId: RequestId,\n result: unknown,\n options: ResolvedMcpOptions,\n): void {\n const spanMap = getOrCreateSpanMap(transport);\n const spanData = spanMap.get(requestId);\n if (spanData) {\n const { span, method } = spanData;\n\n if (method === 'initialize') {\n const sessionData = extractSessionDataFromInitializeResponse(result);\n const serverAttributes = buildServerAttributesFromInfo(sessionData.serverInfo);\n\n const initAttributes: Record<string, string | number> = {\n ...serverAttributes,\n };\n if (sessionData.protocolVersion) {\n initAttributes[MCP_PROTOCOL_VERSION_ATTRIBUTE] = sessionData.protocolVersion;\n }\n\n span.setAttributes(initAttributes);\n } else if (method === 'tools/call') {\n const toolAttributes = extractToolResultAttributes(result, options.recordOutputs);\n span.setAttributes(toolAttributes);\n } else if (method === 'prompts/get') {\n const promptAttributes = extractPromptResultAttributes(result, options.recordOutputs);\n span.setAttributes(promptAttributes);\n }\n\n span.end();\n spanMap.delete(requestId);\n }\n}\n\n/**\n * Cleans up pending spans for a specific transport (when that transport closes)\n * @param transport - MCP transport instance\n */\nexport function cleanupPendingSpansForTransport(transport: MCPTransport): void {\n const sessionId = transport.sessionId;\n\n // Try sessionId-based cleanup first (for stateful transports)\n if (sessionId) {\n const spanMap = sessionToSpanMap.get(sessionId);\n if (spanMap) {\n for (const [, spanData] of spanMap) {\n spanData.span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: 'cancelled',\n });\n spanData.span.end();\n }\n sessionToSpanMap.delete(sessionId);\n }\n return;\n }\n\n // Fallback to transport-based cleanup (for stateless transports)\n const spanMap = statelessSpanMap.get(transport);\n if (spanMap) {\n for (const [, spanData] of spanMap) {\n spanData.span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: 'cancelled',\n });\n spanData.span.end();\n }\n spanMap.clear();\n // Note: WeakMap entries are automatically cleaned up when transport is GC'd\n }\n}\n"],"names":[],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AASA;AACA;AACA;AACA;AACA;AACA,MAAM,gBAAA,GAAmB,IAAI,GAAG,EAA+C;;AAE/E;AACA;AACA;AACA;AACA,MAAM,gBAAA,GAAmB,IAAI,OAAO,EAAqD;;AAEzF;A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,MAAM,GAAG,QAAQ,CAAA,IAAK,OAAO,EAAE;AAC1C,QAAQ,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC;AAChC,UAAU,IAAI,EAAE,iBAAiB;AACjC,UAAU,OAAO,EAAE,WAAW;AAC9B,SAAS,CAAC;AACV,QAAQ,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE;AAC3B,MAAM;AACN,MAAM,gBAAgB,CAAC,MAAM,CAAC,SAAS,CAAC;AACxC,IAAI;AACJ,IAAI;AACJ,EAAE;;AAEF;AACA,EAAE,MAAM,UAAU,gBAAgB,CAAC,GAAG,CAAC,SAAS,CAAC;AACjD,EAAE,IAAI,OAAO,EAAE;AACf,IAAI,KAAK,MAAM,GAAG,QAAQ,CAAA,IAAK,OAAO,EAAE;AACxC,MAAM,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC;AAC9B,QAAQ,IAAI,EAAE,iBAAiB;AAC/B,QAAQ,OAAO,EAAE,WAAW;AAC5B,OAAO,CAAC;AACR,MAAM,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE;AACzB,IAAI;AACJ,IAAI,OAAO,CAAC,KAAK,EAAE;AACnB;AACA,EAAE;AACF;;;;"}
1
+ {"version":3,"file":"correlation.js","sources":["../../../../src/integrations/mcp-server/correlation.ts"],"sourcesContent":["/**\n * Request-span correlation system for MCP server instrumentation\n *\n * Handles mapping requestId to span data for correlation with handler execution.\n *\n * Uses sessionId as the primary key for stateful transports. This handles the wrapper\n * transport pattern (e.g., NodeStreamableHTTPServerTransport wrapping WebStandardStreamableHTTPServerTransport)\n * where onmessage and send may receive different `this` values but share the same sessionId.\n *\n * Falls back to WeakMap by transport instance for stateless transports (no sessionId).\n */\n\nimport { SPAN_STATUS_ERROR } from '../../tracing';\nimport type { Span } from '../../types-hoist/span';\nimport { MCP_PROTOCOL_VERSION_ATTRIBUTE } from './attributes';\nimport { extractPromptResultAttributes, extractToolResultAttributes } from './resultExtraction';\nimport { buildServerAttributesFromInfo, extractSessionDataFromInitializeResponse } from './sessionExtraction';\nimport type { MCPTransport, RequestId, RequestSpanMapValue, ResolvedMcpOptions } from './types';\n\n/**\n * Session-scoped correlation for stateful transports (with sessionId)\n * @internal Using sessionId as key handles wrapper transport patterns where\n * different transport objects share the same logical session\n */\nconst sessionToSpanMap = new Map<string, Map<RequestId, RequestSpanMapValue>>();\n\n/**\n * Transport-scoped correlation fallback for stateless transports (no sessionId)\n * @internal WeakMap allows automatic cleanup when transport is garbage collected\n */\nconst statelessSpanMap = new WeakMap<MCPTransport, Map<RequestId, RequestSpanMapValue>>();\n\n/**\n * Gets or creates the span map for a transport, using sessionId when available\n * @internal\n * @param transport - MCP transport instance\n * @returns Span map for the transport/session\n */\nfunction getOrCreateSpanMap(transport: MCPTransport): Map<RequestId, RequestSpanMapValue> {\n const sessionId = transport.sessionId;\n\n if (sessionId) {\n // Stateful transport - use sessionId as key (handles wrapper pattern)\n let spanMap = sessionToSpanMap.get(sessionId);\n if (!spanMap) {\n spanMap = new Map();\n sessionToSpanMap.set(sessionId, spanMap);\n }\n return spanMap;\n }\n\n // Stateless fallback - use transport instance as key\n let spanMap = statelessSpanMap.get(transport);\n if (!spanMap) {\n spanMap = new Map();\n statelessSpanMap.set(transport, spanMap);\n }\n return spanMap;\n}\n\n/**\n * Stores span context for later correlation with handler execution\n * @param transport - MCP transport instance\n * @param requestId - Request identifier\n * @param span - Active span to correlate\n * @param method - MCP method name\n */\nexport function storeSpanForRequest(transport: MCPTransport, requestId: RequestId, span: Span, method: string): void {\n const spanMap = getOrCreateSpanMap(transport);\n spanMap.set(requestId, {\n span,\n method,\n // oxlint-disable-next-line sdk/no-unsafe-random-apis\n startTime: Date.now(),\n });\n}\n\n/**\n * Completes span with results and cleans up correlation\n * @param transport - MCP transport instance\n * @param requestId - Request identifier\n * @param result - Execution result for attribute extraction\n * @param options - Resolved MCP options\n * @param hasError - Whether the JSON-RPC response contained an error\n */\nexport function completeSpanWithResults(\n transport: MCPTransport,\n requestId: RequestId,\n result: unknown,\n options: ResolvedMcpOptions,\n hasError = false,\n): void {\n const spanMap = getOrCreateSpanMap(transport);\n const spanData = spanMap.get(requestId);\n if (spanData) {\n const { span, method } = spanData;\n\n if (hasError) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n } else if (method === 'initialize') {\n const sessionData = extractSessionDataFromInitializeResponse(result);\n const serverAttributes = buildServerAttributesFromInfo(sessionData.serverInfo);\n\n const initAttributes: Record<string, string | number> = {\n ...serverAttributes,\n };\n if (sessionData.protocolVersion) {\n initAttributes[MCP_PROTOCOL_VERSION_ATTRIBUTE] = sessionData.protocolVersion;\n }\n\n span.setAttributes(initAttributes);\n } else if (method === 'tools/call') {\n const toolAttributes = extractToolResultAttributes(result, options.recordOutputs);\n span.setAttributes(toolAttributes);\n } else if (method === 'prompts/get') {\n const promptAttributes = extractPromptResultAttributes(result, options.recordOutputs);\n span.setAttributes(promptAttributes);\n }\n\n span.end();\n spanMap.delete(requestId);\n }\n}\n\n/**\n * Cleans up pending spans for a specific transport (when that transport closes)\n * @param transport - MCP transport instance\n */\nexport function cleanupPendingSpansForTransport(transport: MCPTransport): void {\n const sessionId = transport.sessionId;\n\n // Try sessionId-based cleanup first (for stateful transports)\n if (sessionId) {\n const spanMap = sessionToSpanMap.get(sessionId);\n if (spanMap) {\n for (const [, spanData] of spanMap) {\n spanData.span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: 'cancelled',\n });\n spanData.span.end();\n }\n sessionToSpanMap.delete(sessionId);\n }\n return;\n }\n\n // Fallback to transport-based cleanup (for stateless transports)\n const spanMap = statelessSpanMap.get(transport);\n if (spanMap) {\n for (const [, spanData] of spanMap) {\n spanData.span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: 'cancelled',\n });\n spanData.span.end();\n }\n spanMap.clear();\n // Note: WeakMap entries are automatically cleaned up when transport is GC'd\n }\n}\n"],"names":[],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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GAAG,EAAE;AACd,IAAI,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC;AAC7B,EAAE;AACF;;AAEA;AACA;AACA;AACA;AACO,SAAS,+BAA+B,CAAC,SAAS,EAAsB;AAC/E,EAAE,MAAM,SAAA,GAAY,SAAS,CAAC,SAAS;;AAEvC;AACA,EAAE,IAAI,SAAS,EAAE;AACjB,IAAI,MAAM,UAAU,gBAAgB,CAAC,GAAG,CAAC,SAAS,CAAC;AACnD,IAAI,IAAI,OAAO,EAAE;AACjB,MAAM,KAAK,MAAM,GAAG,QAAQ,CAAA,IAAK,OAAO,EAAE;AAC1C,QAAQ,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC;AAChC,UAAU,IAAI,EAAE,iBAAiB;AACjC,UAAU,OAAO,EAAE,WAAW;AAC9B,SAAS,CAAC;AACV,QAAQ,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE;AAC3B,MAAM;AACN,MAAM,gBAAgB,CAAC,MAAM,CAAC,SAAS,CAAC;AACxC,IAAI;AACJ,IAAI;AACJ,EAAE;;AAEF;AACA,EAAE,MAAM,UAAU,gBAAgB,CAAC,GAAG,CAAC,SAAS,CAAC;AACjD,EAAE,IAAI,OAAO,EAAE;AACf,IAAI,KAAK,MAAM,GAAG,QAAQ,CAAA,IAAK,OAAO,EAAE;AACxC,MAAM,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC;AAC9B,QAAQ,IAAI,EAAE,iBAAiB;AAC/B,QAAQ,OAAO,EAAE,WAAW;AAC5B,OAAO,CAAC;AACR,MAAM,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE;AACzB,IAAI;AACJ,IAAI,OAAO,CAAC,KAAK,EAAE;AACnB;AACA,EAAE;AACF;;;;"}
@@ -96,7 +96,7 @@ function captureHandlerError(error, methodName, handlerName) {
96
96
  try {
97
97
  const extraData = {};
98
98
 
99
- if (methodName === 'tool') {
99
+ if (methodName === 'tool' || methodName === 'registerTool') {
100
100
  extraData.tool_name = handlerName;
101
101
 
102
102
  if (
@@ -114,10 +114,10 @@ function captureHandlerError(error, methodName, handlerName) {
114
114
  } else {
115
115
  captureError(error, 'tool_execution', extraData);
116
116
  }
117
- } else if (methodName === 'resource') {
117
+ } else if (methodName === 'resource' || methodName === 'registerResource') {
118
118
  extraData.resource_uri = handlerName;
119
119
  captureError(error, 'resource_execution', extraData);
120
- } else if (methodName === 'prompt') {
120
+ } else if (methodName === 'prompt' || methodName === 'registerPrompt') {
121
121
  extraData.prompt_name = handlerName;
122
122
  captureError(error, 'prompt_execution', extraData);
123
123
  }
@@ -127,31 +127,39 @@ function captureHandlerError(error, methodName, handlerName) {
127
127
  }
128
128
 
129
129
  /**
130
- * Wraps tool handlers to associate them with request spans
130
+ * Wraps tool handlers to associate them with request spans.
131
+ * Instruments both `tool` (legacy API) and `registerTool` (new API) if present.
131
132
  * @param serverInstance - MCP server instance
132
133
  */
133
134
  function wrapToolHandlers(serverInstance) {
134
- wrapMethodHandler(serverInstance, 'tool');
135
+ if (typeof serverInstance.tool === 'function') wrapMethodHandler(serverInstance, 'tool');
136
+ if (typeof serverInstance.registerTool === 'function') wrapMethodHandler(serverInstance, 'registerTool');
135
137
  }
136
138
 
137
139
  /**
138
- * Wraps resource handlers to associate them with request spans
140
+ * Wraps resource handlers to associate them with request spans.
141
+ * Instruments both `resource` (legacy API) and `registerResource` (new API) if present.
139
142
  * @param serverInstance - MCP server instance
140
143
  */
141
144
  function wrapResourceHandlers(serverInstance) {
142
- wrapMethodHandler(serverInstance, 'resource');
145
+ if (typeof serverInstance.resource === 'function') wrapMethodHandler(serverInstance, 'resource');
146
+ if (typeof serverInstance.registerResource === 'function') wrapMethodHandler(serverInstance, 'registerResource');
143
147
  }
144
148
 
145
149
  /**
146
- * Wraps prompt handlers to associate them with request spans
150
+ * Wraps prompt handlers to associate them with request spans.
151
+ * Instruments both `prompt` (legacy API) and `registerPrompt` (new API) if present.
147
152
  * @param serverInstance - MCP server instance
148
153
  */
149
154
  function wrapPromptHandlers(serverInstance) {
150
- wrapMethodHandler(serverInstance, 'prompt');
155
+ if (typeof serverInstance.prompt === 'function') wrapMethodHandler(serverInstance, 'prompt');
156
+ if (typeof serverInstance.registerPrompt === 'function') wrapMethodHandler(serverInstance, 'registerPrompt');
151
157
  }
152
158
 
153
159
  /**
154
- * Wraps all MCP handler types (tool, resource, prompt) for span correlation
160
+ * Wraps all MCP handler types for span correlation.
161
+ * Supports both the legacy API (`tool`, `resource`, `prompt`) and the newer API
162
+ * (`registerTool`, `registerResource`, `registerPrompt`), instrumenting whichever methods are present.
155
163
  * @param serverInstance - MCP server instance
156
164
  */
157
165
  function wrapAllMCPHandlers(serverInstance) {
@@ -1 +1 @@
1
- {"version":3,"file":"handlers.js","sources":["../../../../src/integrations/mcp-server/handlers.ts"],"sourcesContent":["/**\n * Handler method wrapping for MCP server instrumentation\n *\n * Provides automatic error capture and span correlation for tool, resource,\n * and prompt handlers.\n */\n\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { debug } from '../../utils/debug-logger';\nimport { fill } from '../../utils/object';\nimport { captureError } from './errorCapture';\nimport type { MCPHandler, MCPServerInstance } from './types';\n\n/**\n * Generic function to wrap MCP server method handlers\n * @internal\n * @param serverInstance - MCP server instance\n * @param methodName - Method name to wrap (tool, resource, prompt)\n */\nfunction wrapMethodHandler(serverInstance: MCPServerInstance, methodName: keyof MCPServerInstance): void {\n fill(serverInstance, methodName, originalMethod => {\n return function (this: MCPServerInstance, name: string, ...args: unknown[]) {\n const handler = args[args.length - 1];\n\n if (typeof handler !== 'function') {\n return (originalMethod as (...args: unknown[]) => unknown).call(this, name, ...args);\n }\n\n const wrappedHandler = createWrappedHandler(handler as MCPHandler, methodName, name);\n return (originalMethod as (...args: unknown[]) => unknown).call(this, name, ...args.slice(0, -1), wrappedHandler);\n };\n });\n}\n\n/**\n * Creates a wrapped handler with span correlation and error capture\n * @internal\n * @param originalHandler - Original handler function\n * @param methodName - MCP method name\n * @param handlerName - Handler identifier\n * @returns Wrapped handler function\n */\nfunction createWrappedHandler(originalHandler: MCPHandler, methodName: keyof MCPServerInstance, handlerName: string) {\n return function (this: unknown, ...handlerArgs: unknown[]): unknown {\n try {\n return createErrorCapturingHandler.call(this, originalHandler, methodName, handlerName, handlerArgs);\n } catch (error) {\n DEBUG_BUILD && debug.warn('MCP handler wrapping failed:', error);\n return originalHandler.apply(this, handlerArgs);\n }\n };\n}\n\n/**\n * Creates an error-capturing wrapper for handler execution\n * @internal\n * @param originalHandler - Original handler function\n * @param methodName - MCP method name\n * @param handlerName - Handler identifier\n * @param handlerArgs - Handler arguments\n * @param extraHandlerData - Additional handler context\n * @returns Handler execution result\n */\nfunction createErrorCapturingHandler(\n this: MCPServerInstance,\n originalHandler: MCPHandler,\n methodName: keyof MCPServerInstance,\n handlerName: string,\n handlerArgs: unknown[],\n): unknown {\n try {\n const result = originalHandler.apply(this, handlerArgs);\n\n if (result && typeof result === 'object' && typeof (result as { then?: unknown }).then === 'function') {\n return Promise.resolve(result).catch(error => {\n captureHandlerError(error, methodName, handlerName);\n throw error;\n });\n }\n\n return result;\n } catch (error) {\n captureHandlerError(error as Error, methodName, handlerName);\n throw error;\n }\n}\n\n/**\n * Captures handler execution errors based on handler type\n * @internal\n * @param error - Error to capture\n * @param methodName - MCP method name\n * @param handlerName - Handler identifier\n */\nfunction captureHandlerError(error: Error, methodName: keyof MCPServerInstance, handlerName: string): void {\n try {\n const extraData: Record<string, unknown> = {};\n\n if (methodName === 'tool') {\n extraData.tool_name = handlerName;\n\n if (\n error.name === 'ProtocolValidationError' ||\n error.message.includes('validation') ||\n error.message.includes('protocol')\n ) {\n captureError(error, 'validation', extraData);\n } else if (\n error.name === 'ServerTimeoutError' ||\n error.message.includes('timed out') ||\n error.message.includes('timeout')\n ) {\n captureError(error, 'timeout', extraData);\n } else {\n captureError(error, 'tool_execution', extraData);\n }\n } else if (methodName === 'resource') {\n extraData.resource_uri = handlerName;\n captureError(error, 'resource_execution', extraData);\n } else if (methodName === 'prompt') {\n extraData.prompt_name = handlerName;\n captureError(error, 'prompt_execution', extraData);\n }\n } catch (_captureErr) {\n // noop\n }\n}\n\n/**\n * Wraps tool handlers to associate them with request spans\n * @param serverInstance - MCP server instance\n */\nexport function wrapToolHandlers(serverInstance: MCPServerInstance): void {\n wrapMethodHandler(serverInstance, 'tool');\n}\n\n/**\n * Wraps resource handlers to associate them with request spans\n * @param serverInstance - MCP server instance\n */\nexport function wrapResourceHandlers(serverInstance: MCPServerInstance): void {\n wrapMethodHandler(serverInstance, 'resource');\n}\n\n/**\n * Wraps prompt handlers to associate them with request spans\n * @param serverInstance - MCP server instance\n */\nexport function wrapPromptHandlers(serverInstance: MCPServerInstance): void {\n wrapMethodHandler(serverInstance, 'prompt');\n}\n\n/**\n * Wraps all MCP handler types (tool, resource, prompt) for span correlation\n * @param serverInstance - MCP server instance\n */\nexport function wrapAllMCPHandlers(serverInstance: MCPServerInstance): void {\n wrapToolHandlers(serverInstance);\n wrapResourceHandlers(serverInstance);\n wrapPromptHandlers(serverInstance);\n}\n"],"names":[],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,iBAAiB,CAAC,cAAc,EAAqB,UAAU,EAAiC;AACzG,EAAE,IAAI,CAAC,cAAc,EAAE,UAAU,EAAE,kBAAkB;AACrD,IAAI,OAAO,WAAmC,IAAI,EAAU,GAAG,IAAI,EAAa;AAChF,MAAM,MAAM,OAAA,GAAU,IAAI,CAAC,IAAI,CAAC,MAAA,GAAS,CAAC,CAAC;;AAE3C,MAAM,IAAI,OAAO,OAAA,KAAY,UAAU,EAAE;AACzC,QAAQ,OAAO,CAAC,cAAA,GAAmD,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;AAC5F,MAAM;;AAEN,MAAM,MAAM,cAAA,GAAiB,oBAAoB,CAAC,UAAuB,UAAU,EAAE,IAAI,CAAC;AAC1F,MAAM,OAAO,CAAC,cAAA,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WAAA,GAAc,WAAW;AACzC,MAAM,YAAY,CAAC,KAAK,EAAE,kBAAkB,EAAE,SAAS,CAAC;AACxD,IAAI;AACJ,EAAE,CAAA,CAAE,OAAO,WAAW,EAAE;AACxB;AACA,EAAE;AACF;;AAEA;AACA;AACA;AACA;AACO,SAAS,gBAAgB,CAAC,cAAc,EAA2B;AAC1E,EAAE,iBAAiB,CAAC,cAAc,EAAE,MAAM,CAAC;AAC3C;;AAEA;AACA;AACA;AACA;AACO,SAAS,oBAAoB,CAAC,cAAc,EAA2B;AAC9E,EAAE,iBAAiB,CAAC,cAAc,EAAE,UAAU,CAAC;AAC/C;;AAEA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,cAAc,EAA2B;AAC5E,EAAE,iBAAiB,CAAC,cAAc,EAAE,QAAQ,CAAC;AAC7C;;AAEA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,cAAc,EAA2B;AAC5E,EAAE,gBAAgB,CAAC,cAAc,CAAC;AAClC,EAAE,oBAAoB,CAAC,cAAc,CAAC;AACtC,EAAE,kBAAkB,CAAC,cAAc,CAAC;AACpC;;;;"}
1
+ {"version":3,"file":"handlers.js","sources":["../../../../src/integrations/mcp-server/handlers.ts"],"sourcesContent":["/**\n * Handler method wrapping for MCP server instrumentation\n *\n * Provides automatic error capture and span correlation for tool, resource,\n * and prompt handlers.\n */\n\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { debug } from '../../utils/debug-logger';\nimport { fill } from '../../utils/object';\nimport { captureError } from './errorCapture';\nimport type { MCPHandler, MCPServerInstance } from './types';\n\n/**\n * Generic function to wrap MCP server method handlers\n * @internal\n * @param serverInstance - MCP server instance\n * @param methodName - Method name to wrap (tool, resource, prompt)\n */\nfunction wrapMethodHandler(serverInstance: MCPServerInstance, methodName: keyof MCPServerInstance): void {\n fill(serverInstance, methodName, originalMethod => {\n return function (this: MCPServerInstance, name: string, ...args: unknown[]) {\n const handler = args[args.length - 1];\n\n if (typeof handler !== 'function') {\n return (originalMethod as (...args: unknown[]) => unknown).call(this, name, ...args);\n }\n\n const wrappedHandler = createWrappedHandler(handler as MCPHandler, methodName, name);\n return (originalMethod as (...args: unknown[]) => unknown).call(this, name, ...args.slice(0, -1), wrappedHandler);\n };\n });\n}\n\n/**\n * Creates a wrapped handler with span correlation and error capture\n * @internal\n * @param originalHandler - Original handler function\n * @param methodName - MCP method name\n * @param handlerName - Handler identifier\n * @returns Wrapped handler function\n */\nfunction createWrappedHandler(originalHandler: MCPHandler, methodName: keyof MCPServerInstance, handlerName: string) {\n return function (this: unknown, ...handlerArgs: unknown[]): unknown {\n try {\n return createErrorCapturingHandler.call(this, originalHandler, methodName, handlerName, handlerArgs);\n } catch (error) {\n DEBUG_BUILD && debug.warn('MCP handler wrapping failed:', error);\n return originalHandler.apply(this, handlerArgs);\n }\n };\n}\n\n/**\n * Creates an error-capturing wrapper for handler execution\n * @internal\n * @param originalHandler - Original handler function\n * @param methodName - MCP method name\n * @param handlerName - Handler identifier\n * @param handlerArgs - Handler arguments\n * @param extraHandlerData - Additional handler context\n * @returns Handler execution result\n */\nfunction createErrorCapturingHandler(\n this: MCPServerInstance,\n originalHandler: MCPHandler,\n methodName: keyof MCPServerInstance,\n handlerName: string,\n handlerArgs: unknown[],\n): unknown {\n try {\n const result = originalHandler.apply(this, handlerArgs);\n\n if (result && typeof result === 'object' && typeof (result as { then?: unknown }).then === 'function') {\n return Promise.resolve(result).catch(error => {\n captureHandlerError(error, methodName, handlerName);\n throw error;\n });\n }\n\n return result;\n } catch (error) {\n captureHandlerError(error as Error, methodName, handlerName);\n throw error;\n }\n}\n\n/**\n * Captures handler execution errors based on handler type\n * @internal\n * @param error - Error to capture\n * @param methodName - MCP method name\n * @param handlerName - Handler identifier\n */\nfunction captureHandlerError(error: Error, methodName: keyof MCPServerInstance, handlerName: string): void {\n try {\n const extraData: Record<string, unknown> = {};\n\n if (methodName === 'tool' || methodName === 'registerTool') {\n extraData.tool_name = handlerName;\n\n if (\n error.name === 'ProtocolValidationError' ||\n error.message.includes('validation') ||\n error.message.includes('protocol')\n ) {\n captureError(error, 'validation', extraData);\n } else if (\n error.name === 'ServerTimeoutError' ||\n error.message.includes('timed out') ||\n error.message.includes('timeout')\n ) {\n captureError(error, 'timeout', extraData);\n } else {\n captureError(error, 'tool_execution', extraData);\n }\n } else if (methodName === 'resource' || methodName === 'registerResource') {\n extraData.resource_uri = handlerName;\n captureError(error, 'resource_execution', extraData);\n } else if (methodName === 'prompt' || methodName === 'registerPrompt') {\n extraData.prompt_name = handlerName;\n captureError(error, 'prompt_execution', extraData);\n }\n } catch (_captureErr) {\n // noop\n }\n}\n\n/**\n * Wraps tool handlers to associate them with request spans.\n * Instruments both `tool` (legacy API) and `registerTool` (new API) if present.\n * @param serverInstance - MCP server instance\n */\nexport function wrapToolHandlers(serverInstance: MCPServerInstance): void {\n if (typeof serverInstance.tool === 'function') wrapMethodHandler(serverInstance, 'tool');\n if (typeof serverInstance.registerTool === 'function') wrapMethodHandler(serverInstance, 'registerTool');\n}\n\n/**\n * Wraps resource handlers to associate them with request spans.\n * Instruments both `resource` (legacy API) and `registerResource` (new API) if present.\n * @param serverInstance - MCP server instance\n */\nexport function wrapResourceHandlers(serverInstance: MCPServerInstance): void {\n if (typeof serverInstance.resource === 'function') wrapMethodHandler(serverInstance, 'resource');\n if (typeof serverInstance.registerResource === 'function') wrapMethodHandler(serverInstance, 'registerResource');\n}\n\n/**\n * Wraps prompt handlers to associate them with request spans.\n * Instruments both `prompt` (legacy API) and `registerPrompt` (new API) if present.\n * @param serverInstance - MCP server instance\n */\nexport function wrapPromptHandlers(serverInstance: MCPServerInstance): void {\n if (typeof serverInstance.prompt === 'function') wrapMethodHandler(serverInstance, 'prompt');\n if (typeof serverInstance.registerPrompt === 'function') wrapMethodHandler(serverInstance, 'registerPrompt');\n}\n\n/**\n * Wraps all MCP handler types for span correlation.\n * Supports both the legacy API (`tool`, `resource`, `prompt`) and the newer API\n * (`registerTool`, `registerResource`, `registerPrompt`), instrumenting whichever methods are present.\n * @param serverInstance - MCP server instance\n */\nexport function wrapAllMCPHandlers(serverInstance: MCPServerInstance): void {\n wrapToolHandlers(serverInstance);\n wrapResourceHandlers(serverInstance);\n wrapPromptHandlers(serverInstance);\n}\n"],"names":[],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,iBAAiB,CAAC,cAAc,EAAqB,UAAU,EAAiC;AACzG,EAAE,IAAI,CAAC,cAAc,EAAE,UAAU,EAAE,kBAAkB;AACrD,IAAI,OAAO,WAAmC,IAAI,EAAU,GAAG,IAAI,EAAa;AAChF,MAAM,MAAM,OAAA,GAAU,IAAI,CAAC,IAAI,CAAC,MAAA,GAAS,CAAC,CAAC;;AAE3C,MAAM,IAAI,OAAO,OAAA,KAAY,UAAU,EAAE;AACzC,QAAQ,OAAO,CAAC,cAAA,GAAmD,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;AAC5F,MAAM;;AAEN,MAAM,MAAM,cAAA,GAAiB,oBAAoB,CAAC,UAAuB,UAAU,EAAE,IAAI,CAAC;AAC1F,MAAM,OAAO,CAAC,cAAA,GAAmD,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,cAAc,CAAC;AACvH,IAAI,CAAC;AACL,EAAE,CAAC,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,oBAAoB,CAAC,eAAe,EAAc,UAAU,EAA2B,WAAW,EAAU;AACrH,EAAE,OAAO,WAAyB,GAAG,WAAW,EAAsB;AACtE,IAAI,IAAI;AACR,MAAM,OAAO,2BAA2B,CAAC,IAAI,CAAC,IAAI,EAAE,eAAe,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,CAAC;AAC1G,IAAI,CAAA,CAAE,OAAO,KAAK,EAAE;AACp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,cAAc,EAAE,cAAc,CAAC;AAC1G;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,oBAAoB,CAAC,cAAc,EAA2B;AAC9E,EAAE,IAAI,OAAO,cAAc,CAAC,QAAA,KAAa,UAAU,EAAE,iBAAiB,CAAC,cAAc,EAAE,UAAU,CAAC;AAClG,EAAE,IAAI,OAAO,cAAc,CAAC,gBAAA,KAAqB,UAAU,EAAE,iBAAiB,CAAC,cAAc,EAAE,kBAAkB,CAAC;AAClH;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,cAAc,EAA2B;AAC5E,EAAE,IAAI,OAAO,cAAc,CAAC,MAAA,KAAW,UAAU,EAAE,iBAAiB,CAAC,cAAc,EAAE,QAAQ,CAAC;AAC9F,EAAE,IAAI,OAAO,cAAc,CAAC,cAAA,KAAmB,UAAU,EAAE,iBAAiB,CAAC,cAAc,EAAE,gBAAgB,CAAC;AAC9G;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,cAAc,EAA2B;AAC5E,EAAE,gBAAgB,CAAC,cAAc,CAAC;AAClC,EAAE,oBAAoB,CAAC,cAAc,CAAC;AACtC,EAAE,kBAAkB,CAAC,cAAc,CAAC;AACpC;;;;"}
@@ -13,7 +13,8 @@ const wrappedMcpServerInstances = new WeakSet();
13
13
  /**
14
14
  * Wraps a MCP Server instance from the `@modelcontextprotocol/sdk` package with Sentry instrumentation.
15
15
  *
16
- * Compatible with versions `^1.9.0` of the `@modelcontextprotocol/sdk` package.
16
+ * Compatible with versions `^1.9.0` of the `@modelcontextprotocol/sdk` package (legacy `tool`/`resource`/`prompt` API)
17
+ * and versions that expose the newer `registerTool`/`registerResource`/`registerPrompt` API (introduced in 1.x, sole API in 2.x).
17
18
  * Automatically instruments transport methods and handler functions for comprehensive monitoring.
18
19
  *
19
20
  * @example
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/integrations/mcp-server/index.ts"],"sourcesContent":["import { getClient } from '../../currentScopes';\nimport { fill } from '../../utils/object';\nimport { wrapAllMCPHandlers } from './handlers';\nimport { wrapTransportError, wrapTransportOnClose, wrapTransportOnMessage, wrapTransportSend } from './transport';\nimport type { MCPServerInstance, McpServerWrapperOptions, MCPTransport, ResolvedMcpOptions } from './types';\nimport { validateMcpServerInstance } from './validation';\n\n/**\n * Tracks wrapped MCP server instances to prevent double-wrapping\n * @internal\n */\nconst wrappedMcpServerInstances = new WeakSet();\n\n/**\n * Wraps a MCP Server instance from the `@modelcontextprotocol/sdk` package with Sentry instrumentation.\n *\n * Compatible with versions `^1.9.0` of the `@modelcontextprotocol/sdk` package.\n * Automatically instruments transport methods and handler functions for comprehensive monitoring.\n *\n * @example\n * ```typescript\n * import * as Sentry from '@sentry/core';\n * import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\n * import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';\n *\n * // Default: inputs/outputs captured based on sendDefaultPii option\n * const server = Sentry.wrapMcpServerWithSentry(\n * new McpServer({ name: \"my-server\", version: \"1.0.0\" })\n * );\n *\n * // Explicitly control input/output capture\n * const server = Sentry.wrapMcpServerWithSentry(\n * new McpServer({ name: \"my-server\", version: \"1.0.0\" }),\n * { recordInputs: true, recordOutputs: false }\n * );\n *\n * const transport = new StreamableHTTPServerTransport();\n * await server.connect(transport);\n * ```\n *\n * @param mcpServerInstance - MCP server instance to instrument\n * @param options - Optional configuration for recording inputs and outputs\n * @returns Instrumented server instance (same reference)\n */\nexport function wrapMcpServerWithSentry<S extends object>(mcpServerInstance: S, options?: McpServerWrapperOptions): S {\n if (wrappedMcpServerInstances.has(mcpServerInstance)) {\n return mcpServerInstance;\n }\n\n if (!validateMcpServerInstance(mcpServerInstance)) {\n return mcpServerInstance;\n }\n\n const serverInstance = mcpServerInstance as MCPServerInstance;\n const client = getClient();\n const sendDefaultPii = Boolean(client?.getOptions().sendDefaultPii);\n\n const resolvedOptions: ResolvedMcpOptions = {\n recordInputs: options?.recordInputs ?? sendDefaultPii,\n recordOutputs: options?.recordOutputs ?? sendDefaultPii,\n };\n\n fill(serverInstance, 'connect', originalConnect => {\n return async function (this: MCPServerInstance, transport: MCPTransport, ...restArgs: unknown[]) {\n const result = await (originalConnect as (...args: unknown[]) => Promise<unknown>).call(\n this,\n transport,\n ...restArgs,\n );\n\n wrapTransportOnMessage(transport, resolvedOptions);\n wrapTransportSend(transport, resolvedOptions);\n wrapTransportOnClose(transport);\n wrapTransportError(transport);\n\n return result;\n };\n });\n\n wrapAllMCPHandlers(serverInstance);\n\n wrappedMcpServerInstances.add(mcpServerInstance);\n return mcpServerInstance;\n}\n"],"names":[],"mappings":";;;;;;AAOA;AACA;AACA;AACA;AACA,MAAM,yBAAA,GAA4B,IAAI,OAAO,EAAE;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,uBAAuB,CAAmB,iBAAiB,EAAK,OAAO,EAA+B;AACtH,EAAE,IAAI,yBAAyB,CAAC,GAAG,CAAC,iBAAiB,CAAC,EAAE;AACxD,IAAI,OAAO,iBAAiB;AAC5B,EAAE;;AAEF,EAAE,IAAI,CAAC,yBAAyB,CAAC,iBAAiB,CAAC,EAAE;AACrD,IAAI,OAAO,iBAAiB;AAC5B,EAAE;;AAEF,EAAE,MAAM,cAAA,GAAiB,iBAAA;AACzB,EAAE,MAAM,MAAA,GAAS,SAAS,EAAE;AAC5B,EAAE,MAAM,cAAA,GAAiB,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,cAAc,CAAC;;AAErE,EAAE,MAAM,eAAe,GAAuB;AAC9C,IAAI,YAAY,EAAE,OAAO,EAAE,YAAA,IAAgB,cAAc;AACzD,IAAI,aAAa,EAAE,OAAO,EAAE,aAAA,IAAiB,cAAc;AAC3D,GAAG;;AAEH,EAAE,IAAI,CAAC,cAAc,EAAE,SAAS,EAAE,mBAAmB;AACrD,IAAI,OAAO,iBAAyC,SAAS,EAAgB,GAAG,QAAQ,EAAa;AACrG,MAAM,MAAM,SAAS,MAAM,CAAC,eAAA,GAA6D,IAAI;AAC7F,QAAQ,IAAI;AACZ,QAAQ,SAAS;AACjB,QAAQ,GAAG,QAAQ;AACnB,OAAO;;AAEP,MAAM,sBAAsB,CAAC,SAAS,EAAE,eAAe,CAAC;AACxD,MAAM,iBAAiB,CAAC,SAAS,EAAE,eAAe,CAAC;AACnD,MAAM,oBAAoB,CAAC,SAAS,CAAC;AACrC,MAAM,kBAAkB,CAAC,SAAS,CAAC;;AAEnC,MAAM,OAAO,MAAM;AACnB,IAAI,CAAC;AACL,EAAE,CAAC,CAAC;;AAEJ,EAAE,kBAAkB,CAAC,cAAc,CAAC;;AAEpC,EAAE,yBAAyB,CAAC,GAAG,CAAC,iBAAiB,CAAC;AAClD,EAAE,OAAO,iBAAiB;AAC1B;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/integrations/mcp-server/index.ts"],"sourcesContent":["import { getClient } from '../../currentScopes';\nimport { fill } from '../../utils/object';\nimport { wrapAllMCPHandlers } from './handlers';\nimport { wrapTransportError, wrapTransportOnClose, wrapTransportOnMessage, wrapTransportSend } from './transport';\nimport type { MCPServerInstance, McpServerWrapperOptions, MCPTransport, ResolvedMcpOptions } from './types';\nimport { validateMcpServerInstance } from './validation';\n\n/**\n * Tracks wrapped MCP server instances to prevent double-wrapping\n * @internal\n */\nconst wrappedMcpServerInstances = new WeakSet();\n\n/**\n * Wraps a MCP Server instance from the `@modelcontextprotocol/sdk` package with Sentry instrumentation.\n *\n * Compatible with versions `^1.9.0` of the `@modelcontextprotocol/sdk` package (legacy `tool`/`resource`/`prompt` API)\n * and versions that expose the newer `registerTool`/`registerResource`/`registerPrompt` API (introduced in 1.x, sole API in 2.x).\n * Automatically instruments transport methods and handler functions for comprehensive monitoring.\n *\n * @example\n * ```typescript\n * import * as Sentry from '@sentry/core';\n * import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\n * import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';\n *\n * // Default: inputs/outputs captured based on sendDefaultPii option\n * const server = Sentry.wrapMcpServerWithSentry(\n * new McpServer({ name: \"my-server\", version: \"1.0.0\" })\n * );\n *\n * // Explicitly control input/output capture\n * const server = Sentry.wrapMcpServerWithSentry(\n * new McpServer({ name: \"my-server\", version: \"1.0.0\" }),\n * { recordInputs: true, recordOutputs: false }\n * );\n *\n * const transport = new StreamableHTTPServerTransport();\n * await server.connect(transport);\n * ```\n *\n * @param mcpServerInstance - MCP server instance to instrument\n * @param options - Optional configuration for recording inputs and outputs\n * @returns Instrumented server instance (same reference)\n */\nexport function wrapMcpServerWithSentry<S extends object>(mcpServerInstance: S, options?: McpServerWrapperOptions): S {\n if (wrappedMcpServerInstances.has(mcpServerInstance)) {\n return mcpServerInstance;\n }\n\n if (!validateMcpServerInstance(mcpServerInstance)) {\n return mcpServerInstance;\n }\n\n const serverInstance = mcpServerInstance as MCPServerInstance;\n const client = getClient();\n const sendDefaultPii = Boolean(client?.getOptions().sendDefaultPii);\n\n const resolvedOptions: ResolvedMcpOptions = {\n recordInputs: options?.recordInputs ?? sendDefaultPii,\n recordOutputs: options?.recordOutputs ?? sendDefaultPii,\n };\n\n fill(serverInstance, 'connect', originalConnect => {\n return async function (this: MCPServerInstance, transport: MCPTransport, ...restArgs: unknown[]) {\n const result = await (originalConnect as (...args: unknown[]) => Promise<unknown>).call(\n this,\n transport,\n ...restArgs,\n );\n\n wrapTransportOnMessage(transport, resolvedOptions);\n wrapTransportSend(transport, resolvedOptions);\n wrapTransportOnClose(transport);\n wrapTransportError(transport);\n\n return result;\n };\n });\n\n wrapAllMCPHandlers(serverInstance);\n\n wrappedMcpServerInstances.add(mcpServerInstance);\n return mcpServerInstance;\n}\n"],"names":[],"mappings":";;;;;;A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C;;AAEnC,MAAM,OAAO,MAAM;AACnB,IAAI,CAAC;AACL,EAAE,CAAC,CAAC;;AAEJ,EAAE,kBAAkB,CAAC,cAAc,CAAC;;AAEpC,EAAE,yBAAyB,CAAC,GAAG,CAAC,iBAAiB,CAAC;AAClD,EAAE,OAAO,iBAAiB;AAC1B;;;;"}
@@ -113,7 +113,7 @@ function wrapTransportSend(transport, options) {
113
113
  }
114
114
  }
115
115
 
116
- completeSpanWithResults(this, message.id, message.result, options);
116
+ completeSpanWithResults(this, message.id, message.result, options, !!message.error);
117
117
  }
118
118
  }
119
119
 
@@ -1 +1 @@
1
- {"version":3,"file":"transport.js","sources":["../../../../src/integrations/mcp-server/transport.ts"],"sourcesContent":["/**\n * Transport layer instrumentation for MCP server\n *\n * Handles message interception and response correlation.\n * @see https://modelcontextprotocol.io/specification/2025-06-18/basic/transports\n */\n\nimport { getIsolationScope, withIsolationScope } from '../../currentScopes';\nimport { startInactiveSpan, withActiveSpan } from '../../tracing';\nimport { fill } from '../../utils/object';\nimport { MCP_PROTOCOL_VERSION_ATTRIBUTE } from './attributes';\nimport { cleanupPendingSpansForTransport, completeSpanWithResults, storeSpanForRequest } from './correlation';\nimport { captureError } from './errorCapture';\nimport {\n buildClientAttributesFromInfo,\n extractSessionDataFromInitializeRequest,\n extractSessionDataFromInitializeResponse,\n} from './sessionExtraction';\nimport {\n cleanupSessionDataForTransport,\n storeSessionDataForTransport,\n updateSessionDataForTransport,\n} from './sessionManagement';\nimport { buildMcpServerSpanConfig, createMcpNotificationSpan, createMcpOutgoingNotificationSpan } from './spans';\nimport type { ExtraHandlerData, MCPTransport, ResolvedMcpOptions, SessionData } from './types';\nimport { isJsonRpcNotification, isJsonRpcRequest, isJsonRpcResponse, isValidContentItem } from './validation';\n\n/**\n * Wraps transport.onmessage to create spans for incoming messages.\n * For \"initialize\" requests, extracts and stores client info and protocol version\n * in the session data for the transport.\n * @param transport - MCP transport instance to wrap\n * @param options - Resolved MCP options\n */\nexport function wrapTransportOnMessage(transport: MCPTransport, options: ResolvedMcpOptions): void {\n if (transport.onmessage) {\n fill(transport, 'onmessage', originalOnMessage => {\n return function (this: MCPTransport, message: unknown, extra?: unknown) {\n if (isJsonRpcRequest(message)) {\n const isInitialize = message.method === 'initialize';\n let initSessionData: SessionData | undefined;\n\n if (isInitialize) {\n try {\n initSessionData = extractSessionDataFromInitializeRequest(message);\n storeSessionDataForTransport(this, initSessionData);\n } catch {\n // noop\n }\n }\n\n const isolationScope = getIsolationScope().clone();\n\n return withIsolationScope(isolationScope, () => {\n const spanConfig = buildMcpServerSpanConfig(message, this, extra as ExtraHandlerData, options);\n const span = startInactiveSpan(spanConfig);\n\n // For initialize requests, add client info directly to span (works even for stateless transports)\n if (isInitialize && initSessionData) {\n span.setAttributes({\n ...buildClientAttributesFromInfo(initSessionData.clientInfo),\n ...(initSessionData.protocolVersion && {\n [MCP_PROTOCOL_VERSION_ATTRIBUTE]: initSessionData.protocolVersion,\n }),\n });\n }\n\n storeSpanForRequest(this, message.id, span, message.method);\n\n return withActiveSpan(span, () => {\n return (originalOnMessage as (...args: unknown[]) => unknown).call(this, message, extra);\n });\n });\n }\n\n if (isJsonRpcNotification(message)) {\n return createMcpNotificationSpan(message, this, extra as ExtraHandlerData, options, () => {\n return (originalOnMessage as (...args: unknown[]) => unknown).call(this, message, extra);\n });\n }\n\n return (originalOnMessage as (...args: unknown[]) => unknown).call(this, message, extra);\n };\n });\n }\n}\n\n/**\n * Wraps transport.send to handle outgoing messages and response correlation.\n * For \"initialize\" responses, extracts and stores protocol version and server info\n * in the session data for the transport.\n * @param transport - MCP transport instance to wrap\n * @param options - Resolved MCP options\n */\nexport function wrapTransportSend(transport: MCPTransport, options: ResolvedMcpOptions): void {\n if (transport.send) {\n fill(transport, 'send', originalSend => {\n return async function (this: MCPTransport, ...args: unknown[]) {\n const [message] = args;\n\n if (isJsonRpcNotification(message)) {\n return createMcpOutgoingNotificationSpan(message, this, options, () => {\n return (originalSend as (...args: unknown[]) => unknown).call(this, ...args);\n });\n }\n\n if (isJsonRpcResponse(message)) {\n if (message.id !== null && message.id !== undefined) {\n if (message.error) {\n captureJsonRpcErrorResponse(message.error);\n }\n\n if (isValidContentItem(message.result)) {\n if (message.result.protocolVersion || message.result.serverInfo) {\n try {\n const serverData = extractSessionDataFromInitializeResponse(message.result);\n updateSessionDataForTransport(this, serverData);\n } catch {\n // noop\n }\n }\n }\n\n completeSpanWithResults(this, message.id, message.result, options);\n }\n }\n\n return (originalSend as (...args: unknown[]) => unknown).call(this, ...args);\n };\n });\n }\n}\n\n/**\n * Wraps transport.onclose to clean up pending spans for this transport only\n * @param transport - MCP transport instance to wrap\n */\nexport function wrapTransportOnClose(transport: MCPTransport): void {\n if (transport.onclose) {\n fill(transport, 'onclose', originalOnClose => {\n return function (this: MCPTransport, ...args: unknown[]) {\n cleanupPendingSpansForTransport(this);\n cleanupSessionDataForTransport(this);\n return (originalOnClose as (...args: unknown[]) => unknown).call(this, ...args);\n };\n });\n }\n}\n\n/**\n * Wraps transport error handlers to capture connection errors\n * @param transport - MCP transport instance to wrap\n */\nexport function wrapTransportError(transport: MCPTransport): void {\n if (transport.onerror) {\n fill(transport, 'onerror', (originalOnError: (error: Error) => void) => {\n return function (this: MCPTransport, error: Error) {\n captureTransportError(error);\n return originalOnError.call(this, error);\n };\n });\n }\n}\n\n/**\n * Captures JSON-RPC error responses for server-side errors.\n * @see https://www.jsonrpc.org/specification#error_object\n * @internal\n * @param errorResponse - JSON-RPC error response\n */\nfunction captureJsonRpcErrorResponse(errorResponse: unknown): void {\n try {\n if (errorResponse && typeof errorResponse === 'object' && 'code' in errorResponse && 'message' in errorResponse) {\n const jsonRpcError = errorResponse as { code: number; message: string; data?: unknown };\n\n const isServerError =\n jsonRpcError.code === -32603 || (jsonRpcError.code >= -32099 && jsonRpcError.code <= -32000);\n\n if (isServerError) {\n const error = new Error(jsonRpcError.message);\n error.name = `JsonRpcError_${jsonRpcError.code}`;\n\n captureError(error, 'protocol');\n }\n }\n } catch {\n // noop\n }\n}\n\n/**\n * Captures transport connection errors\n * @internal\n * @param error - Transport error\n */\nfunction captureTransportError(error: Error): void {\n try {\n captureError(error, 'transport');\n } catch {\n // noop\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;;;AAsBA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,sBAAsB,CAAC,SAAS,EAAgB,OAAO,EAA4B;AACnG,EAAE,IAAI,SAAS,CAAC,SAAS,EAAE;AAC3B,IAAI,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,qBAAqB;AACtD,MAAM,OAAO,WAA8B,OAAO,EAAW,KAAK,EAAY;AAC9E,QAAQ,IAAI,gBAAgB,CAAC,OAAO,CAAC,EAAE;AACvC,UAAU,MAAM,YAAA,GAAe,OAAO,CAAC,MAAA,KAAW,YAAY;AAC9D,UAAU,IAAI,eAAe;;AAE7B,UAAU,IAAI,YAAY,EAAE;AAC5B,YAAY,IAAI;AAChB,cAAc,eAAA,GAAkB,uCAAuC,CAAC,OAAO,CAAC;AAChF,cAAc,4BAA4B,CAAC,IAAI,EAAE,eAAe,CAAC;AACjE,YAAY,EAAE,MAAM;AACpB;AACA,YAAY;AACZ,UAAU;;AAEV,UAAU,MAAM,iBAAiB,iBAAiB,EAAE,CAAC,KAAK,EAAE;;AAE5D,UAAU,OAAO,kBAAkB,CAAC,cAAc,EAAE,MAAM;AAC1D,YAAY,MAAM,UAAA,GAAa,wBAAwB,CAAC,OAAO,EAAE,IAAI,EAAE,KAAA,GAA2B,OAAO,CAAC;AAC1G,YAAY,MAAM,IAAA,GAAO,iBAAiB,CAAC,UAAU,CAAC;;AAEtD;AACA,YAAY,IAAI,YAAA,IAAgB,eAAe,EAAE;AACjD,cAAc,IAAI,CAAC,aAAa,CAAC;AACjC,gBAAgB,GAAG,6BAA6B,CAAC,eAAe,CAAC,UAAU,CAAC;AAC5E,gBAAgB,IAAI,eAAe,CAAC,mBAAmB;AAC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AAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,SAAA,qBAAA,CAAA,KAAA,EAAA;AACA,EAAA,IAAA;AACA,IAAA,YAAA,CAAA,KAAA,EAAA,WAAA,CAAA;AACA,EAAA,CAAA,CAAA,MAAA;AACA;AACA,EAAA;AACA;;;;"}
1
+ {"version":3,"file":"transport.js","sources":["../../../../src/integrations/mcp-server/transport.ts"],"sourcesContent":["/**\n * Transport layer instrumentation for MCP server\n *\n * Handles message interception and response correlation.\n * @see https://modelcontextprotocol.io/specification/2025-06-18/basic/transports\n */\n\nimport { getIsolationScope, withIsolationScope } from '../../currentScopes';\nimport { startInactiveSpan, withActiveSpan } from '../../tracing';\nimport { fill } from '../../utils/object';\nimport { MCP_PROTOCOL_VERSION_ATTRIBUTE } from './attributes';\nimport { cleanupPendingSpansForTransport, completeSpanWithResults, storeSpanForRequest } from './correlation';\nimport { captureError } from './errorCapture';\nimport {\n buildClientAttributesFromInfo,\n extractSessionDataFromInitializeRequest,\n extractSessionDataFromInitializeResponse,\n} from './sessionExtraction';\nimport {\n cleanupSessionDataForTransport,\n storeSessionDataForTransport,\n updateSessionDataForTransport,\n} from './sessionManagement';\nimport { buildMcpServerSpanConfig, createMcpNotificationSpan, createMcpOutgoingNotificationSpan } from './spans';\nimport type { ExtraHandlerData, MCPTransport, ResolvedMcpOptions, SessionData } from './types';\nimport { isJsonRpcNotification, isJsonRpcRequest, isJsonRpcResponse, isValidContentItem } from './validation';\n\n/**\n * Wraps transport.onmessage to create spans for incoming messages.\n * For \"initialize\" requests, extracts and stores client info and protocol version\n * in the session data for the transport.\n * @param transport - MCP transport instance to wrap\n * @param options - Resolved MCP options\n */\nexport function wrapTransportOnMessage(transport: MCPTransport, options: ResolvedMcpOptions): void {\n if (transport.onmessage) {\n fill(transport, 'onmessage', originalOnMessage => {\n return function (this: MCPTransport, message: unknown, extra?: unknown) {\n if (isJsonRpcRequest(message)) {\n const isInitialize = message.method === 'initialize';\n let initSessionData: SessionData | undefined;\n\n if (isInitialize) {\n try {\n initSessionData = extractSessionDataFromInitializeRequest(message);\n storeSessionDataForTransport(this, initSessionData);\n } catch {\n // noop\n }\n }\n\n const isolationScope = getIsolationScope().clone();\n\n return withIsolationScope(isolationScope, () => {\n const spanConfig = buildMcpServerSpanConfig(message, this, extra as ExtraHandlerData, options);\n const span = startInactiveSpan(spanConfig);\n\n // For initialize requests, add client info directly to span (works even for stateless transports)\n if (isInitialize && initSessionData) {\n span.setAttributes({\n ...buildClientAttributesFromInfo(initSessionData.clientInfo),\n ...(initSessionData.protocolVersion && {\n [MCP_PROTOCOL_VERSION_ATTRIBUTE]: initSessionData.protocolVersion,\n }),\n });\n }\n\n storeSpanForRequest(this, message.id, span, message.method);\n\n return withActiveSpan(span, () => {\n return (originalOnMessage as (...args: unknown[]) => unknown).call(this, message, extra);\n });\n });\n }\n\n if (isJsonRpcNotification(message)) {\n return createMcpNotificationSpan(message, this, extra as ExtraHandlerData, options, () => {\n return (originalOnMessage as (...args: unknown[]) => unknown).call(this, message, extra);\n });\n }\n\n return (originalOnMessage as (...args: unknown[]) => unknown).call(this, message, extra);\n };\n });\n }\n}\n\n/**\n * Wraps transport.send to handle outgoing messages and response correlation.\n * For \"initialize\" responses, extracts and stores protocol version and server info\n * in the session data for the transport.\n * @param transport - MCP transport instance to wrap\n * @param options - Resolved MCP options\n */\nexport function wrapTransportSend(transport: MCPTransport, options: ResolvedMcpOptions): void {\n if (transport.send) {\n fill(transport, 'send', originalSend => {\n return async function (this: MCPTransport, ...args: unknown[]) {\n const [message] = args;\n\n if (isJsonRpcNotification(message)) {\n return createMcpOutgoingNotificationSpan(message, this, options, () => {\n return (originalSend as (...args: unknown[]) => unknown).call(this, ...args);\n });\n }\n\n if (isJsonRpcResponse(message)) {\n if (message.id !== null && message.id !== undefined) {\n if (message.error) {\n captureJsonRpcErrorResponse(message.error);\n }\n\n if (isValidContentItem(message.result)) {\n if (message.result.protocolVersion || message.result.serverInfo) {\n try {\n const serverData = extractSessionDataFromInitializeResponse(message.result);\n updateSessionDataForTransport(this, serverData);\n } catch {\n // noop\n }\n }\n }\n\n completeSpanWithResults(this, message.id, message.result, options, !!message.error);\n }\n }\n\n return (originalSend as (...args: unknown[]) => unknown).call(this, ...args);\n };\n });\n }\n}\n\n/**\n * Wraps transport.onclose to clean up pending spans for this transport only\n * @param transport - MCP transport instance to wrap\n */\nexport function wrapTransportOnClose(transport: MCPTransport): void {\n if (transport.onclose) {\n fill(transport, 'onclose', originalOnClose => {\n return function (this: MCPTransport, ...args: unknown[]) {\n cleanupPendingSpansForTransport(this);\n cleanupSessionDataForTransport(this);\n return (originalOnClose as (...args: unknown[]) => unknown).call(this, ...args);\n };\n });\n }\n}\n\n/**\n * Wraps transport error handlers to capture connection errors\n * @param transport - MCP transport instance to wrap\n */\nexport function wrapTransportError(transport: MCPTransport): void {\n if (transport.onerror) {\n fill(transport, 'onerror', (originalOnError: (error: Error) => void) => {\n return function (this: MCPTransport, error: Error) {\n captureTransportError(error);\n return originalOnError.call(this, error);\n };\n });\n }\n}\n\n/**\n * Captures JSON-RPC error responses for server-side errors.\n * @see https://www.jsonrpc.org/specification#error_object\n * @internal\n * @param errorResponse - JSON-RPC error response\n */\nfunction captureJsonRpcErrorResponse(errorResponse: unknown): void {\n try {\n if (errorResponse && typeof errorResponse === 'object' && 'code' in errorResponse && 'message' in errorResponse) {\n const jsonRpcError = errorResponse as { code: number; message: string; data?: unknown };\n\n const isServerError =\n jsonRpcError.code === -32603 || (jsonRpcError.code >= -32099 && jsonRpcError.code <= -32000);\n\n if (isServerError) {\n const error = new Error(jsonRpcError.message);\n error.name = `JsonRpcError_${jsonRpcError.code}`;\n\n captureError(error, 'protocol');\n }\n }\n } catch {\n // noop\n }\n}\n\n/**\n * Captures transport connection errors\n * @internal\n * @param error - Transport error\n */\nfunction captureTransportError(error: Error): void {\n try {\n captureError(error, 'transport');\n } catch {\n // noop\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAAA;AACA;AACA;AAC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AA,CAAA,CAAA,MAAA;AACA;AACA,EAAA;AACA;;;;"}
@@ -57,7 +57,10 @@ function isJsonRpcResponse(message) {
57
57
  }
58
58
 
59
59
  /**
60
- * Validates MCP server instance with type checking
60
+ * Validates MCP server instance with type checking.
61
+ * Accepts both the legacy API (`tool`, `resource`, `prompt`) used in SDK 1.x
62
+ * and the newer API (`registerTool`, `registerResource`, `registerPrompt`) introduced
63
+ * alongside the legacy API in SDK 1.x and made the only option in SDK 2.x.
61
64
  * @param instance - Object to validate as MCP server instance
62
65
  * @returns True if instance has required MCP server methods
63
66
  */
@@ -65,10 +68,9 @@ function validateMcpServerInstance(instance) {
65
68
  if (
66
69
  typeof instance === 'object' &&
67
70
  instance !== null &&
68
- 'resource' in instance &&
69
- 'tool' in instance &&
70
- 'prompt' in instance &&
71
- 'connect' in instance
71
+ 'connect' in instance &&
72
+ (('tool' in instance && 'resource' in instance && 'prompt' in instance) ||
73
+ ('registerTool' in instance && 'registerResource' in instance && 'registerPrompt' in instance))
72
74
  ) {
73
75
  return true;
74
76
  }
@@ -1 +1 @@
1
- {"version":3,"file":"validation.js","sources":["../../../../src/integrations/mcp-server/validation.ts"],"sourcesContent":["/**\n * Message validation functions for MCP server instrumentation\n *\n * Provides JSON-RPC 2.0 message type validation and MCP server instance validation.\n */\n\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { debug } from '../../utils/debug-logger';\nimport type { JsonRpcNotification, JsonRpcRequest, JsonRpcResponse } from './types';\n\n/**\n * Validates if a message is a JSON-RPC request\n * @param message - Message to validate\n * @returns True if message is a JSON-RPC request\n */\nexport function isJsonRpcRequest(message: unknown): message is JsonRpcRequest {\n return (\n typeof message === 'object' &&\n message !== null &&\n 'jsonrpc' in message &&\n (message as JsonRpcRequest).jsonrpc === '2.0' &&\n 'method' in message &&\n 'id' in message\n );\n}\n\n/**\n * Validates if a message is a JSON-RPC notification\n * @param message - Message to validate\n * @returns True if message is a JSON-RPC notification\n */\nexport function isJsonRpcNotification(message: unknown): message is JsonRpcNotification {\n return (\n typeof message === 'object' &&\n message !== null &&\n 'jsonrpc' in message &&\n (message as JsonRpcNotification).jsonrpc === '2.0' &&\n 'method' in message &&\n !('id' in message)\n );\n}\n\n/**\n * Validates if a message is a JSON-RPC response\n * @param message - Message to validate\n * @returns True if message is a JSON-RPC response\n */\nexport function isJsonRpcResponse(message: unknown): message is JsonRpcResponse {\n return (\n typeof message === 'object' &&\n message !== null &&\n 'jsonrpc' in message &&\n (message as { jsonrpc: string }).jsonrpc === '2.0' &&\n 'id' in message &&\n ('result' in message || 'error' in message)\n );\n}\n\n/**\n * Validates MCP server instance with type checking\n * @param instance - Object to validate as MCP server instance\n * @returns True if instance has required MCP server methods\n */\nexport function validateMcpServerInstance(instance: unknown): boolean {\n if (\n typeof instance === 'object' &&\n instance !== null &&\n 'resource' in instance &&\n 'tool' in instance &&\n 'prompt' in instance &&\n 'connect' in instance\n ) {\n return true;\n }\n DEBUG_BUILD && debug.warn('Did not patch MCP server. Interface is incompatible.');\n return false;\n}\n\n/**\n * Check if the item is a valid content item\n * @param item - The item to check\n * @returns True if the item is a valid content item, false otherwise\n */\nexport function isValidContentItem(item: unknown): item is Record<string, unknown> {\n return item != null && typeof item === 'object';\n}\n"],"names":[],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;;;AAMA;AACA;AACA;AACA;AACA;AACO,SAAS,gBAAgB,CAAC,OAAO,EAAsC;AAC9E,EAAE;AACF,IAAI,OAAO,OAAA,KAAY,QAAA;AACvB,IAAI,OAAA,KAAY,IAAA;AAChB,IAAI,SAAA,IAAa,OAAA;AACjB,IAAI,CAAC,OAAA,GAA2B,OAAA,KAAY,KAAA;AAC5C,IAAI,QAAA,IAAY,OAAA;AAChB,IAAI,QAAQ;AACZ;AACA;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,qBAAqB,CAAC,OAAO,EAA2C;AACxF,EAAE;AACF,IAAI,OAAO,OAAA,KAAY,QAAA;AACvB,IAAI,OAAA,KAAY,IAAA;AAChB,IAAI,SAAA,IAAa,OAAA;AACjB,IAAI,CAAC,OAAA,GAAgC,OAAA,KAAY,KAAA;AACjD,IAAI,QAAA,IAAY,OAAA;AAChB,IAAI,EAAE,IAAA,IAAQ,OAAO;AACrB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,iBAAiB,CAAC,OAAO,EAAuC;AAChF,EAAE;AACF,IAAI,OAAO,OAAA,KAAY,QAAA;AACvB,IAAI,OAAA,KAAY,IAAA;AAChB,IAAI,SAAA,IAAa,OAAA;AACjB,IAAI,CAAC,OAAA,GAAgC,OAAA,KAAY,KAAA;AACjD,IAAI,IAAA,IAAQ,OAAA;AACZ,KAAK,QAAA,IAAY,WAAW,OAAA,IAAW,OAAO;AAC9C;AACA;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,yBAAyB,CAAC,QAAQ,EAAoB;AACtE,EAAE;AACF,IAAI,OAAO,QAAA,KAAa,QAAA;AACxB,IAAI,QAAA,KAAa,IAAA;AACjB,IAAI,UAAA,IAAc,QAAA;AAClB,IAAI,MAAA,IAAU,QAAA;AACd,IAAI,QAAA,IAAY,QAAA;AAChB,IAAI,aAAa;AACjB,IAAI;AACJ,IAAI,OAAO,IAAI;AACf,EAAE;AACF,EAAE,eAAe,KAAK,CAAC,IAAI,CAAC,sDAAsD,CAAC;AACnF,EAAE,OAAO,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,IAAI,EAA4C;AACnF,EAAE,OAAO,QAAQ,IAAA,IAAQ,OAAO,IAAA,KAAS,QAAQ;AACjD;;;;"}
1
+ {"version":3,"file":"validation.js","sources":["../../../../src/integrations/mcp-server/validation.ts"],"sourcesContent":["/**\n * Message validation functions for MCP server instrumentation\n *\n * Provides JSON-RPC 2.0 message type validation and MCP server instance validation.\n */\n\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { debug } from '../../utils/debug-logger';\nimport type { JsonRpcNotification, JsonRpcRequest, JsonRpcResponse } from './types';\n\n/**\n * Validates if a message is a JSON-RPC request\n * @param message - Message to validate\n * @returns True if message is a JSON-RPC request\n */\nexport function isJsonRpcRequest(message: unknown): message is JsonRpcRequest {\n return (\n typeof message === 'object' &&\n message !== null &&\n 'jsonrpc' in message &&\n (message as JsonRpcRequest).jsonrpc === '2.0' &&\n 'method' in message &&\n 'id' in message\n );\n}\n\n/**\n * Validates if a message is a JSON-RPC notification\n * @param message - Message to validate\n * @returns True if message is a JSON-RPC notification\n */\nexport function isJsonRpcNotification(message: unknown): message is JsonRpcNotification {\n return (\n typeof message === 'object' &&\n message !== null &&\n 'jsonrpc' in message &&\n (message as JsonRpcNotification).jsonrpc === '2.0' &&\n 'method' in message &&\n !('id' in message)\n );\n}\n\n/**\n * Validates if a message is a JSON-RPC response\n * @param message - Message to validate\n * @returns True if message is a JSON-RPC response\n */\nexport function isJsonRpcResponse(message: unknown): message is JsonRpcResponse {\n return (\n typeof message === 'object' &&\n message !== null &&\n 'jsonrpc' in message &&\n (message as { jsonrpc: string }).jsonrpc === '2.0' &&\n 'id' in message &&\n ('result' in message || 'error' in message)\n );\n}\n\n/**\n * Validates MCP server instance with type checking.\n * Accepts both the legacy API (`tool`, `resource`, `prompt`) used in SDK 1.x\n * and the newer API (`registerTool`, `registerResource`, `registerPrompt`) introduced\n * alongside the legacy API in SDK 1.x and made the only option in SDK 2.x.\n * @param instance - Object to validate as MCP server instance\n * @returns True if instance has required MCP server methods\n */\nexport function validateMcpServerInstance(instance: unknown): boolean {\n if (\n typeof instance === 'object' &&\n instance !== null &&\n 'connect' in instance &&\n (('tool' in instance && 'resource' in instance && 'prompt' in instance) ||\n ('registerTool' in instance && 'registerResource' in instance && 'registerPrompt' in instance))\n ) {\n return true;\n }\n DEBUG_BUILD && debug.warn('Did not patch MCP server. Interface is incompatible.');\n return false;\n}\n\n/**\n * Check if the item is a valid content item\n * @param item - The item to check\n * @returns True if the item is a valid content item, false otherwise\n */\nexport function isValidContentItem(item: unknown): item is Record<string, unknown> {\n return item != null && typeof item === 'object';\n}\n"],"names":[],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;;;AAMA;AACA;AACA;AACA;AACA;AACO,SAAS,gBAAgB,CAAC,OAAO,EAAsC;AAC9E,EAAE;AACF,IAAI,OAAO,OAAA,KAAY,QAAA;AACvB,IAAI,OAAA,KAAY,IAAA;AAChB,IAAI,SAAA,IAAa,OAAA;AACjB,IAAI,CAAC,OAAA,GAA2B,OAAA,KAAY,KAAA;AAC5C,IAAI,QAAA,IAAY,OAAA;AAChB,IAAI,QAAQ;AACZ;AACA;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,qBAAqB,CAAC,OAAO,EAA2C;AACxF,EAAE;AACF,IAAI,OAAO,OAAA,KAAY,QAAA;AACvB,IAAI,OAAA,KAAY,IAAA;AAChB,IAAI,SAAA,IAAa,OAAA;AACjB,IAAI,CAAC,OAAA,GAAgC,OAAA,KAAY,KAAA;AACjD,IAAI,QAAA,IAAY,OAAA;AAChB,IAAI,EAAE,IAAA,IAAQ,OAAO;AACrB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,iBAAiB,CAAC,OAAO,EAAuC;AAChF,EAAE;AACF,IAAI,OAAO,OAAA,KAAY,QAAA;AACvB,IAAI,OAAA,KAAY,IAAA;AAChB,IAAI,SAAA,IAAa,OAAA;AACjB,IAAI,CAAC,OAAA,GAAgC,OAAA,KAAY,KAAA;AACjD,IAAI,IAAA,IAAQ,OAAA;AACZ,KAAK,QAAA,IAAY,WAAW,OAAA,IAAW,OAAO;AAC9C;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,yBAAyB,CAAC,QAAQ,EAAoB;AACtE,EAAE;AACF,IAAI,OAAO,QAAA,KAAa,QAAA;AACxB,IAAI,QAAA,KAAa,IAAA;AACjB,IAAI,SAAA,IAAa,QAAA;AACjB,KAAK,CAAC,MAAA,IAAU,QAAA,IAAY,UAAA,IAAc,QAAA,IAAY,QAAA,I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