@fedify/fedify 2.0.0-dev.1690 → 2.0.0-dev.170

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 (317) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +70 -34
  3. package/dist/{assert_rejects-DiIiJbZn.js → assert_rejects-Ce45JcFg.js} +1 -1
  4. package/dist/{assert_is_error-BPGph1Jx.js → assert_throws-BNXdRGWP.js} +31 -1
  5. package/dist/{builder-CYOcDUkj.js → builder-_MVsWtsS.js} +9 -8
  6. package/dist/{client-bgSdkFa2.d.ts → client-CUTUGgvJ.d.ts} +19 -19
  7. package/dist/{client-CnOdwLLN.js → client-Dg7OfUDA.js} +28 -23
  8. package/dist/{client-CegPX0Rn.d.cts → client-by-PEGAJ.d.cts} +19 -19
  9. package/dist/compat/mod.cjs +1 -1
  10. package/dist/compat/mod.d.cts +6 -12
  11. package/dist/compat/mod.d.ts +6 -12
  12. package/dist/compat/mod.js +1 -1
  13. package/dist/compat/transformers.test.js +19 -18
  14. package/dist/context-Bns6uTJq.js +109 -0
  15. package/dist/{context-ByZprN0S.d.ts → context-C7vzWilY.d.ts} +314 -182
  16. package/dist/{context-C5BsZkDr.d.cts → context-CrB9RFy5.d.cts} +314 -182
  17. package/dist/deno-DhWON59o.js +117 -0
  18. package/dist/{testing-BWNCAbL-.js → dist-B5f6a8Tt.js} +90 -111
  19. package/dist/{authdocloader-Brax1A32.js → docloader-Cni79dmb.js} +17 -8
  20. package/dist/{esm-DnIzfEj0.js → esm-DGl7uK1r.js} +32 -17
  21. package/dist/federation/builder.test.js +11 -11
  22. package/dist/federation/collection.test.js +5 -8
  23. package/dist/federation/handler.test.js +111 -24
  24. package/dist/federation/idempotency.test.js +24 -24
  25. package/dist/federation/inbox.test.js +5 -6
  26. package/dist/federation/keycache.test.js +4 -5
  27. package/dist/federation/kv.test.js +60 -9
  28. package/dist/federation/middleware.test.js +102 -101
  29. package/dist/federation/mod.cjs +8 -12
  30. package/dist/federation/mod.d.cts +7 -13
  31. package/dist/federation/mod.d.ts +7 -13
  32. package/dist/federation/mod.js +8 -13
  33. package/dist/federation/mq.test.js +9 -10
  34. package/dist/federation/negotiation.test.js +5 -8
  35. package/dist/federation/retry.test.js +2 -4
  36. package/dist/federation/router.test.js +6 -8
  37. package/dist/federation/send.test.js +55 -15
  38. package/dist/{webfinger/handler.test.js → federation/webfinger.test.js} +25 -24
  39. package/dist/{federation-H2_En3j5.cjs → federation-B431K2gm.cjs} +22 -0
  40. package/dist/{federation-D1U8YY9t.js → federation-BbZwNNWj.js} +28 -6
  41. package/dist/{http-C7vbQwbz.cjs → http-7RQPvAkX.cjs} +410 -14
  42. package/dist/{http-BxbM8sEy.js → http-CZXlv4xU.js} +371 -11
  43. package/dist/{http-D-e6AFwR.d.cts → http-ClB3pLcL.d.cts} +2 -2
  44. package/dist/{http-BNOYnVsU.js → http-CwsBL5_A.js} +3 -2
  45. package/dist/{http-D6Uj2x2y.d.ts → http-DLBDPal9.d.ts} +2 -2
  46. package/dist/{inbox-BRru9pX3.js → inbox-CukSCwad.js} +2 -1
  47. package/dist/{key-1KXru8Ug.js → key-DKkHKzvg.js} +3 -2
  48. package/dist/{keycache-CN61iGVj.js → keycache-DRxpZ5r9.js} +1 -1
  49. package/dist/{keys-BPdFKgiy.js → keys-ZbcByPg9.js} +2 -1
  50. package/dist/{kv-63Cil1MD.d.cts → kv-B4vFhIYL.d.cts} +30 -1
  51. package/dist/{kv-C7sopW2E.d.ts → kv-CYySNrsn.d.ts} +30 -1
  52. package/dist/{kv-CRZrzyXm.js → kv-QzKcOQgP.js} +22 -0
  53. package/dist/kv-cache-BEeqyGER.js +107 -0
  54. package/dist/kv-cache-BVA7CrnS.cjs +134 -0
  55. package/dist/kv-cache-HDuc4ZaJ.js +122 -0
  56. package/dist/{ld-Dv8DNNAT.js → ld-CM6OO5ar.js} +4 -2
  57. package/dist/middleware--i9t8nKh.js +26 -0
  58. package/dist/middleware-C567nJlD.cjs +12 -0
  59. package/dist/middleware-D9oWuacw.js +12 -0
  60. package/dist/{middleware-DY9B2lL8.js → middleware-DXRcwk_y.js} +185 -192
  61. package/dist/{middleware-BmoOlgc1.cjs → middleware-TufpQUzj.cjs} +251 -241
  62. package/dist/{middleware-Bz_A2jeJ.js → middleware-eDeNdyRA.js} +195 -191
  63. package/dist/mod-0p9zUdzg.d.cts +107 -0
  64. package/dist/mod-0qnPv4EC.d.cts +62 -0
  65. package/dist/{mod-Djzcw2ry.d.cts → mod-BrS8tiad.d.cts} +3 -3
  66. package/dist/mod-C3SOvTD1.d.ts +64 -0
  67. package/dist/{mod-8DMWKtQE.d.cts → mod-D6pS5_xJ.d.cts} +4 -4
  68. package/dist/{mod-BhUKmBJD.d.ts → mod-jOa7W503.d.ts} +3 -3
  69. package/dist/{mod-D6hQoxC5.d.ts → mod-waqu-BL_.d.ts} +4 -4
  70. package/dist/mod-xc20HhMD.d.ts +109 -0
  71. package/dist/mod.cjs +17 -112
  72. package/dist/mod.d.cts +11 -17
  73. package/dist/mod.d.ts +11 -17
  74. package/dist/mod.js +11 -17
  75. package/dist/nodeinfo/client.test.js +7 -10
  76. package/dist/nodeinfo/handler.test.js +23 -23
  77. package/dist/nodeinfo/mod.cjs +2 -3
  78. package/dist/nodeinfo/mod.d.cts +2 -4
  79. package/dist/nodeinfo/mod.d.ts +2 -4
  80. package/dist/nodeinfo/mod.js +2 -3
  81. package/dist/nodeinfo/types.test.js +6 -9
  82. package/dist/otel/exporter.test.js +893 -0
  83. package/dist/otel/mod.cjs +256 -0
  84. package/dist/otel/mod.d.cts +230 -0
  85. package/dist/otel/mod.d.ts +232 -0
  86. package/dist/otel/mod.js +255 -0
  87. package/dist/{owner-e3FYDhsk.js → owner-BOEfZQv2.js} +45 -8
  88. package/dist/{owner-hd9lvQcP.d.ts → owner-BgI8C-VY.d.ts} +2 -3
  89. package/dist/{owner-BN_tO3cY.d.cts → owner-C-zfmVAD.d.cts} +2 -3
  90. package/dist/{proof-B-eqv0Ug.cjs → proof-CaDQpGJD.cjs} +69 -33
  91. package/dist/{proof-DfgvA3al.js → proof-iYIDiv8I.js} +47 -11
  92. package/dist/{proof-6gFMwMNJ.js → proof-iw6KtIyj.js} +3 -2
  93. package/dist/router-D9eI0s4b.js +118 -0
  94. package/dist/{send-Tl9NOnmO.js → send-Bn8o0mjW.js} +9 -4
  95. package/dist/sig/http.test.js +11 -13
  96. package/dist/sig/key.test.js +9 -11
  97. package/dist/sig/ld.test.js +8 -10
  98. package/dist/sig/mod.cjs +7 -11
  99. package/dist/sig/mod.d.cts +3 -7
  100. package/dist/sig/mod.d.ts +3 -7
  101. package/dist/sig/mod.js +3 -7
  102. package/dist/sig/owner.test.js +33 -12
  103. package/dist/sig/proof.test.js +13 -14
  104. package/dist/testing/mod.d.ts +183 -7194
  105. package/dist/testing/mod.js +4 -4
  106. package/dist/{transformers-CoBS-oFG.cjs → transformers-BjBg6Lag.cjs} +2 -2
  107. package/dist/{transformers-BFT6d7J5.js → transformers-N_ip_y4P.js} +2 -2
  108. package/dist/{types-DqxyTxOf.js → types-8l28uC8o.js} +31 -26
  109. package/dist/{types-zqdWZh4O.cjs → types-B6z6CqIz.cjs} +33 -28
  110. package/dist/{types-BSuWJsOm.js → types-CPz01LGH.js} +3 -3
  111. package/dist/{runtime/authdocloader.test.js → utils/docloader.test.js} +13 -15
  112. package/dist/utils/kv-cache.test.js +211 -0
  113. package/dist/utils/mod.cjs +10 -0
  114. package/dist/utils/mod.d.cts +4 -0
  115. package/dist/utils/mod.d.ts +6 -0
  116. package/dist/utils/mod.js +9 -0
  117. package/package.json +34 -75
  118. package/dist/actor-Be0ThtXy.cjs +0 -42609
  119. package/dist/actor-ChbPLm6n.js +0 -42135
  120. package/dist/actor-D6K058Tb.d.cts +0 -128
  121. package/dist/actor-DuCeRiNh.js +0 -146
  122. package/dist/actor-T6RyhRgk.d.ts +0 -130
  123. package/dist/assert_throws-BOO88avQ.js +0 -39
  124. package/dist/authdocloader-CrxhFL8e.js +0 -52
  125. package/dist/authdocloader-OSn_teLV.cjs +0 -58
  126. package/dist/denokv-Bv33Xxea.js +0 -57
  127. package/dist/docloader-CCqXeagZ.cjs +0 -4861
  128. package/dist/docloader-CxWcuWqQ.d.ts +0 -221
  129. package/dist/docloader-D-MrRyHl.d.cts +0 -219
  130. package/dist/docloader-XK3y2jn5.js +0 -4795
  131. package/dist/fixtures/activitypub.academy/users/brauca_darradiul.json +0 -83
  132. package/dist/fixtures/example.com/announce.json +0 -6
  133. package/dist/fixtures/example.com/collection.json +0 -19
  134. package/dist/fixtures/example.com/create.json +0 -6
  135. package/dist/fixtures/example.com/cross-origin-actor.json +0 -6
  136. package/dist/fixtures/example.com/hong-gildong.json +0 -11
  137. package/dist/fixtures/example.com/invite.json +0 -7
  138. package/dist/fixtures/example.com/key.json +0 -7
  139. package/dist/fixtures/example.com/key2.json +0 -6
  140. package/dist/fixtures/example.com/object.json +0 -6
  141. package/dist/fixtures/example.com/orderedcollectionpage.json +0 -24
  142. package/dist/fixtures/example.com/paged/a.json +0 -13
  143. package/dist/fixtures/example.com/paged/b.json +0 -16
  144. package/dist/fixtures/example.com/paged-collection.json +0 -6
  145. package/dist/fixtures/example.com/person.json +0 -22
  146. package/dist/fixtures/example.com/person2.json +0 -40
  147. package/dist/fixtures/example.com/test.json +0 -5
  148. package/dist/fixtures/example.com/users/handle.json +0 -16
  149. package/dist/fixtures/example.com/wrong-type.json +0 -3
  150. package/dist/fixtures/media.example.com/avatars/test-avatar.jpg.json +0 -6
  151. package/dist/fixtures/oeee.cafe/ap/users/3609fd4e-d51d-4db8-9f04-4189815864dd.json +0 -24
  152. package/dist/fixtures/remote.domain/users/bob.json +0 -20
  153. package/dist/fixtures/server.example/users/alice.json +0 -20
  154. package/dist/fixtures/w3id.org/identity/v1.json +0 -152
  155. package/dist/fixtures/w3id.org/security/data-integrity/v1.json +0 -74
  156. package/dist/fixtures/w3id.org/security/multikey/v1.json +0 -35
  157. package/dist/fixtures/w3id.org/security/v1.json +0 -50
  158. package/dist/fixtures/wizard.casa/users/hongminhee.json +0 -69
  159. package/dist/fixtures/www.w3.org/ns/activitystreams.json +0 -379
  160. package/dist/fixtures/www.w3.org/ns/did/v1.json +0 -58
  161. package/dist/key-B3uag-rz.js +0 -10
  162. package/dist/key-BiBmb1Yy.cjs +0 -10
  163. package/dist/key-DK_nfU4I.js +0 -10
  164. package/dist/key-Z6ceKnZC.cjs +0 -290
  165. package/dist/key-jyNTxCvK.js +0 -260
  166. package/dist/lookup-BPviO8ij.js +0 -131
  167. package/dist/lookup-hnMAAU5r.cjs +0 -137
  168. package/dist/lookup-pV0JOsuV.js +0 -331
  169. package/dist/middleware-CI0-zw4U.js +0 -26
  170. package/dist/middleware-QNK-W-jE.cjs +0 -17
  171. package/dist/middleware-_vjt6FWU.js +0 -17
  172. package/dist/mod-CerN_Sza.d.ts +0 -104
  173. package/dist/mod-Cj1tHXBR.d.cts +0 -102
  174. package/dist/mod-CxkWO3Mg.d.cts +0 -307
  175. package/dist/mod-DBzN0aCM.d.ts +0 -115
  176. package/dist/mod-DlU8ISoa.d.ts +0 -309
  177. package/dist/mod-FZd39qVq.d.cts +0 -1
  178. package/dist/mod-g0xFzAP9.d.ts +0 -2
  179. package/dist/mod-jQ4OODsl.d.cts +0 -113
  180. package/dist/mq-B7R1Q-M5.d.cts +0 -140
  181. package/dist/mq-CRGm1e_F.d.ts +0 -143
  182. package/dist/runtime/docloader.test.js +0 -522
  183. package/dist/runtime/key.test.js +0 -103
  184. package/dist/runtime/langstr.test.d.ts +0 -3
  185. package/dist/runtime/langstr.test.js +0 -39
  186. package/dist/runtime/link.test.d.ts +0 -3
  187. package/dist/runtime/link.test.js +0 -61
  188. package/dist/runtime/mod.cjs +0 -25
  189. package/dist/runtime/mod.d.cts +0 -6
  190. package/dist/runtime/mod.d.ts +0 -8
  191. package/dist/runtime/mod.js +0 -13
  192. package/dist/runtime/multibase/multibase.test.d.ts +0 -3
  193. package/dist/runtime/multibase/multibase.test.js +0 -358
  194. package/dist/runtime/url.test.d.ts +0 -3
  195. package/dist/runtime/url.test.js +0 -45
  196. package/dist/src/vocab/accept.yaml +0 -15
  197. package/dist/src/vocab/activity.yaml +0 -98
  198. package/dist/src/vocab/add.yaml +0 -16
  199. package/dist/src/vocab/announce.yaml +0 -30
  200. package/dist/src/vocab/application.yaml +0 -324
  201. package/dist/src/vocab/arrive.yaml +0 -15
  202. package/dist/src/vocab/article.yaml +0 -46
  203. package/dist/src/vocab/audio.yaml +0 -11
  204. package/dist/src/vocab/block.yaml +0 -16
  205. package/dist/src/vocab/chatmessage.yaml +0 -50
  206. package/dist/src/vocab/collection.yaml +0 -154
  207. package/dist/src/vocab/collectionpage.yaml +0 -55
  208. package/dist/src/vocab/create.yaml +0 -28
  209. package/dist/src/vocab/dataintegrityproof.yaml +0 -56
  210. package/dist/src/vocab/delete.yaml +0 -27
  211. package/dist/src/vocab/didservice.yaml +0 -22
  212. package/dist/src/vocab/dislike.yaml +0 -14
  213. package/dist/src/vocab/document.yaml +0 -31
  214. package/dist/src/vocab/emoji.yaml +0 -12
  215. package/dist/src/vocab/emojireact.yaml +0 -17
  216. package/dist/src/vocab/endpoints.yaml +0 -85
  217. package/dist/src/vocab/event.yaml +0 -11
  218. package/dist/src/vocab/export.yaml +0 -9
  219. package/dist/src/vocab/flag.yaml +0 -15
  220. package/dist/src/vocab/follow.yaml +0 -19
  221. package/dist/src/vocab/group.yaml +0 -324
  222. package/dist/src/vocab/hashtag.yaml +0 -14
  223. package/dist/src/vocab/ignore.yaml +0 -14
  224. package/dist/src/vocab/image.yaml +0 -9
  225. package/dist/src/vocab/intransitiveactivity.yaml +0 -15
  226. package/dist/src/vocab/invite.yaml +0 -14
  227. package/dist/src/vocab/join.yaml +0 -14
  228. package/dist/src/vocab/key.yaml +0 -28
  229. package/dist/src/vocab/leave.yaml +0 -14
  230. package/dist/src/vocab/like.yaml +0 -16
  231. package/dist/src/vocab/link.yaml +0 -101
  232. package/dist/src/vocab/listen.yaml +0 -12
  233. package/dist/src/vocab/mention.yaml +0 -9
  234. package/dist/src/vocab/move.yaml +0 -15
  235. package/dist/src/vocab/multikey.yaml +0 -36
  236. package/dist/src/vocab/note.yaml +0 -48
  237. package/dist/src/vocab/object.yaml +0 -404
  238. package/dist/src/vocab/offer.yaml +0 -15
  239. package/dist/src/vocab/orderedcollection.yaml +0 -39
  240. package/dist/src/vocab/orderedcollectionpage.yaml +0 -50
  241. package/dist/src/vocab/organization.yaml +0 -324
  242. package/dist/src/vocab/page.yaml +0 -11
  243. package/dist/src/vocab/person.yaml +0 -324
  244. package/dist/src/vocab/place.yaml +0 -75
  245. package/dist/src/vocab/profile.yaml +0 -26
  246. package/dist/src/vocab/propertyvalue.yaml +0 -32
  247. package/dist/src/vocab/question.yaml +0 -103
  248. package/dist/src/vocab/read.yaml +0 -13
  249. package/dist/src/vocab/reject.yaml +0 -14
  250. package/dist/src/vocab/relationship.yaml +0 -52
  251. package/dist/src/vocab/remove.yaml +0 -14
  252. package/dist/src/vocab/service.yaml +0 -324
  253. package/dist/src/vocab/source.yaml +0 -26
  254. package/dist/src/vocab/tentativeaccept.yaml +0 -14
  255. package/dist/src/vocab/tentativereject.yaml +0 -14
  256. package/dist/src/vocab/tombstone.yaml +0 -24
  257. package/dist/src/vocab/travel.yaml +0 -16
  258. package/dist/src/vocab/undo.yaml +0 -26
  259. package/dist/src/vocab/update.yaml +0 -58
  260. package/dist/src/vocab/video.yaml +0 -11
  261. package/dist/src/vocab/view.yaml +0 -13
  262. package/dist/testing/docloader.test.js +0 -24
  263. package/dist/type-C69ZBu7f.js +0 -47010
  264. package/dist/vocab/actor.test.d.ts +0 -3
  265. package/dist/vocab/actor.test.js +0 -5965
  266. package/dist/vocab/lookup.test.d.ts +0 -3
  267. package/dist/vocab/lookup.test.js +0 -456
  268. package/dist/vocab/mod.cjs +0 -87
  269. package/dist/vocab/mod.d.cts +0 -6
  270. package/dist/vocab/mod.d.ts +0 -8
  271. package/dist/vocab/mod.js +0 -10
  272. package/dist/vocab/schema.yaml +0 -247
  273. package/dist/vocab/type.test.d.ts +0 -3
  274. package/dist/vocab/type.test.js +0 -25
  275. package/dist/vocab/vocab.test.d.ts +0 -3
  276. package/dist/vocab/vocab.test.js +0 -3787
  277. package/dist/vocab-B39-pFl9.cjs +0 -291
  278. package/dist/vocab-BI0Ak5lL.d.ts +0 -14924
  279. package/dist/vocab-BWoeZsME.js +0 -255
  280. package/dist/vocab-Dw1-yVGg.d.cts +0 -14922
  281. package/dist/webfinger/handler.test.d.ts +0 -3
  282. package/dist/webfinger/lookup.test.d.ts +0 -3
  283. package/dist/webfinger/lookup.test.js +0 -195
  284. package/dist/webfinger/mod.cjs +0 -9
  285. package/dist/webfinger/mod.d.cts +0 -4
  286. package/dist/webfinger/mod.d.ts +0 -6
  287. package/dist/webfinger/mod.js +0 -9
  288. package/dist/webfinger-BjOEdFPs.cjs +0 -4
  289. package/dist/webfinger-De_bU0iE.js +0 -4
  290. package/dist/x/cfworkers.cjs +0 -100
  291. package/dist/x/cfworkers.d.cts +0 -59
  292. package/dist/x/cfworkers.d.ts +0 -61
  293. package/dist/x/cfworkers.js +0 -98
  294. package/dist/x/cfworkers.test.d.ts +0 -3
  295. package/dist/x/cfworkers.test.js +0 -179
  296. package/dist/x/hono.cjs +0 -61
  297. package/dist/x/hono.d.cts +0 -54
  298. package/dist/x/hono.d.ts +0 -56
  299. package/dist/x/hono.js +0 -60
  300. package/dist/x/sveltekit.cjs +0 -69
  301. package/dist/x/sveltekit.d.cts +0 -46
  302. package/dist/x/sveltekit.d.ts +0 -48
  303. package/dist/x/sveltekit.js +0 -68
  304. /package/dist/{assert_not_equals-f3m3epl3.js → assert_not_equals-C80BG-_5.js} +0 -0
  305. /package/dist/{runtime/authdocloader.test.d.ts → federation/webfinger.test.d.ts} +0 -0
  306. /package/dist/{mod-1pDWKvUL.d.ts → mod-1E3W847c.d.ts} +0 -0
  307. /package/dist/{mod-C2tOeRkN.d.cts → mod-C81L6_lQ.d.cts} +0 -0
  308. /package/dist/{nodeinfo-DfycQ8Wf.js → nodeinfo-BlLsRSiT.js} +0 -0
  309. /package/dist/{nodeinfo-Co9lJrWl.cjs → nodeinfo-DuMYTpbZ.cjs} +0 -0
  310. /package/dist/{runtime/docloader.test.d.ts → otel/exporter.test.d.ts} +0 -0
  311. /package/dist/{runtime-DPYEDf-o.js → sig-CwuONEzF.js} +0 -0
  312. /package/dist/{runtime-C58AJWSv.cjs → sig-DeXX2xnj.cjs} +0 -0
  313. /package/dist/{std__assert-X-_kMxKM.js → std__assert-DWivtrGR.js} +0 -0
  314. /package/dist/{testing → utils}/docloader.test.d.ts +0 -0
  315. /package/dist/{runtime/key.test.d.ts → utils/kv-cache.test.d.ts} +0 -0
  316. /package/dist/{sig-ByHXzqUi.cjs → utils-Db0ZmjcD.cjs} +0 -0
  317. /package/dist/{sig-Cj3tk-ig.js → utils-Wranxuoe.js} +0 -0
@@ -0,0 +1,893 @@
1
+
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+ globalThis.addEventListener = () => {};
5
+
6
+ import { test } from "../dist-B5f6a8Tt.js";
7
+ import { assertEquals } from "../assert_equals-DSbWqCm3.js";
8
+ import "../assert-MZs1qjMx.js";
9
+ import "../assert_instance_of-DHz7EHNU.js";
10
+ import { MemoryKvStore } from "../kv-QzKcOQgP.js";
11
+ import "../std__assert-DWivtrGR.js";
12
+ import "../assert_rejects-Ce45JcFg.js";
13
+ import "../assert_throws-BNXdRGWP.js";
14
+ import "../assert_not_equals-C80BG-_5.js";
15
+ import { getLogger } from "@logtape/logtape";
16
+ import { ExportResultCode } from "@opentelemetry/core";
17
+ import { SpanKind, SpanStatusCode, TraceFlags } from "@opentelemetry/api";
18
+
19
+ //#region src/otel/exporter.ts
20
+ /**
21
+ * A SpanExporter that persists ActivityPub activity traces to a
22
+ * {@link KvStore}. This enables distributed tracing across multiple
23
+ * nodes in a Fedify deployment.
24
+ *
25
+ * The exporter captures activity data from OpenTelemetry span events
26
+ * (`activitypub.activity.received` and `activitypub.activity.sent`)
27
+ * and stores them in the KvStore with trace context preserved.
28
+ *
29
+ * @example Basic usage with MemoryKvStore
30
+ * ```typescript ignore
31
+ * import { MemoryKvStore } from "@fedify/fedify";
32
+ * import { FedifySpanExporter } from "@fedify/fedify/otel";
33
+ * import {
34
+ * BasicTracerProvider,
35
+ * SimpleSpanProcessor,
36
+ * } from "@opentelemetry/sdk-trace-base";
37
+ *
38
+ * const kv = new MemoryKvStore();
39
+ * const exporter = new FedifySpanExporter(kv, {
40
+ * ttl: Temporal.Duration.from({ hours: 1 }),
41
+ * });
42
+ *
43
+ * const provider = new BasicTracerProvider({
44
+ * spanProcessors: [new SimpleSpanProcessor(exporter)],
45
+ * });
46
+ * ```
47
+ *
48
+ * @example Querying stored traces
49
+ * ```typescript ignore
50
+ * import { MemoryKvStore } from "@fedify/fedify";
51
+ * import { FedifySpanExporter } from "@fedify/fedify/otel";
52
+ *
53
+ * const kv = new MemoryKvStore();
54
+ * const exporter = new FedifySpanExporter(kv);
55
+ * const traceId = "abc123";
56
+ *
57
+ * // Get all activities for a specific trace
58
+ * const activities = await exporter.getActivitiesByTraceId(traceId);
59
+ *
60
+ * // Get recent traces
61
+ * const recentTraces = await exporter.getRecentTraces({ limit: 100 });
62
+ * ```
63
+ *
64
+ * @since 1.10.0
65
+ */
66
+ var FedifySpanExporter = class {
67
+ #kv;
68
+ #ttl;
69
+ #keyPrefix;
70
+ /**
71
+ * Creates a new FedifySpanExporter.
72
+ *
73
+ * @param kv The KvStore to persist trace data to.
74
+ * @param options Configuration options.
75
+ */
76
+ constructor(kv, options) {
77
+ this.#kv = kv;
78
+ this.#ttl = options?.ttl;
79
+ this.#keyPrefix = options?.keyPrefix ?? ["fedify", "traces"];
80
+ }
81
+ /**
82
+ * Exports spans to the KvStore.
83
+ *
84
+ * @param spans The spans to export.
85
+ * @param resultCallback Callback to invoke with the export result.
86
+ */
87
+ export(spans, resultCallback) {
88
+ this.#exportAsync(spans).then(() => resultCallback({ code: ExportResultCode.SUCCESS })).catch((error) => {
89
+ getLogger([
90
+ "fedify",
91
+ "otel",
92
+ "exporter"
93
+ ]).error("Failed to export spans to KvStore: {error}", { error });
94
+ resultCallback({ code: ExportResultCode.FAILED });
95
+ });
96
+ }
97
+ async #exportAsync(spans) {
98
+ const storeOperations = [];
99
+ for (const span of spans) {
100
+ const records = this.#extractRecords(span);
101
+ for (const record of records) storeOperations.push(this.#storeRecord(record));
102
+ }
103
+ const results = await Promise.allSettled(storeOperations);
104
+ const rejected = results.filter((r) => r.status === "rejected");
105
+ if (rejected.length > 0) throw new AggregateError(rejected.map((r) => r.reason), "Failed to store one or more trace activity records.");
106
+ }
107
+ #extractRecords(span) {
108
+ const records = [];
109
+ const spanContext = span.spanContext();
110
+ const traceId = spanContext.traceId;
111
+ const spanId = spanContext.spanId;
112
+ const parentSpanId = span.parentSpanContext?.spanId;
113
+ for (const event of span.events) if (event.name === "activitypub.activity.received") {
114
+ const record = this.#extractInboundRecord(event, traceId, spanId, parentSpanId);
115
+ if (record != null) records.push(record);
116
+ } else if (event.name === "activitypub.activity.sent") {
117
+ const record = this.#extractOutboundRecord(event, traceId, spanId, parentSpanId);
118
+ if (record != null) records.push(record);
119
+ }
120
+ return records;
121
+ }
122
+ #extractInboundRecord(event, traceId, spanId, parentSpanId) {
123
+ const attrs = event.attributes;
124
+ if (attrs == null) return null;
125
+ const activityJson = attrs["activitypub.activity.json"];
126
+ if (typeof activityJson !== "string") return null;
127
+ let activityType = "Unknown";
128
+ let activityId;
129
+ let actorId;
130
+ try {
131
+ const activity = JSON.parse(activityJson);
132
+ activityType = activity.type ?? "Unknown";
133
+ activityId = activity.id;
134
+ if (typeof activity.actor === "string") actorId = activity.actor;
135
+ else if (activity.actor != null && typeof activity.actor.id === "string") actorId = activity.actor.id;
136
+ } catch {}
137
+ const verified = attrs["activitypub.activity.verified"];
138
+ const httpSigVerified = attrs["http_signatures.verified"];
139
+ const httpSigKeyId = attrs["http_signatures.key_id"];
140
+ const ldSigVerified = attrs["ld_signatures.verified"];
141
+ let signatureDetails;
142
+ if (typeof httpSigVerified === "boolean" || typeof ldSigVerified === "boolean") signatureDetails = {
143
+ httpSignaturesVerified: httpSigVerified === true,
144
+ httpSignaturesKeyId: typeof httpSigKeyId === "string" && httpSigKeyId !== "" ? httpSigKeyId : void 0,
145
+ ldSignaturesVerified: ldSigVerified === true
146
+ };
147
+ return {
148
+ traceId,
149
+ spanId,
150
+ parentSpanId,
151
+ direction: "inbound",
152
+ activityType,
153
+ activityId,
154
+ actorId,
155
+ activityJson,
156
+ verified: typeof verified === "boolean" ? verified : void 0,
157
+ signatureDetails,
158
+ timestamp: (/* @__PURE__ */ new Date(event.time[0] * 1e3 + event.time[1] / 1e6)).toISOString()
159
+ };
160
+ }
161
+ #extractOutboundRecord(event, traceId, spanId, parentSpanId) {
162
+ const attrs = event.attributes;
163
+ if (attrs == null) return null;
164
+ const activityJson = attrs["activitypub.activity.json"];
165
+ if (typeof activityJson !== "string") return null;
166
+ let activityType = "Unknown";
167
+ let activityId;
168
+ let actorId;
169
+ try {
170
+ const activity = JSON.parse(activityJson);
171
+ activityType = activity.type ?? "Unknown";
172
+ activityId = activity.id;
173
+ if (typeof activity.actor === "string") actorId = activity.actor;
174
+ else if (activity.actor != null && typeof activity.actor.id === "string") actorId = activity.actor.id;
175
+ } catch {}
176
+ const inboxUrl = attrs["activitypub.inbox.url"];
177
+ const explicitActivityId = attrs["activitypub.activity.id"];
178
+ return {
179
+ traceId,
180
+ spanId,
181
+ parentSpanId,
182
+ direction: "outbound",
183
+ activityType,
184
+ activityId: activityId ?? (typeof explicitActivityId === "string" && explicitActivityId !== "" ? explicitActivityId : void 0),
185
+ actorId,
186
+ activityJson,
187
+ timestamp: (/* @__PURE__ */ new Date(event.time[0] * 1e3 + event.time[1] / 1e6)).toISOString(),
188
+ inboxUrl: typeof inboxUrl === "string" ? inboxUrl : void 0
189
+ };
190
+ }
191
+ async #storeRecord(record) {
192
+ const options = this.#ttl != null ? { ttl: this.#ttl } : void 0;
193
+ const key = [
194
+ ...this.#keyPrefix,
195
+ record.traceId,
196
+ record.spanId
197
+ ];
198
+ await this.#kv.set(key, record, options);
199
+ await this.#updateTraceSummary(record, options);
200
+ }
201
+ async #setWithCasRetry(key, transform, options) {
202
+ if (this.#kv.cas != null) for (let attempt = 0; attempt < 3; attempt++) {
203
+ const existing$1 = await this.#kv.get(key);
204
+ const newValue$1 = transform(existing$1);
205
+ if (await this.#kv.cas(key, existing$1, newValue$1, options)) return;
206
+ }
207
+ const existing = await this.#kv.get(key);
208
+ const newValue = transform(existing);
209
+ await this.#kv.set(key, newValue, options);
210
+ }
211
+ async #updateTraceSummary(record, options) {
212
+ const summaryKey = [
213
+ ...this.#keyPrefix,
214
+ "_summaries",
215
+ record.traceId
216
+ ];
217
+ await this.#setWithCasRetry(summaryKey, (existing) => {
218
+ const activityCount = existing != null ? existing.activityCount + 1 : 1;
219
+ const activityTypes = existing != null ? existing.activityTypes.includes(record.activityType) ? existing.activityTypes : [...existing.activityTypes, record.activityType] : [record.activityType];
220
+ return {
221
+ traceId: existing?.traceId ?? record.traceId,
222
+ timestamp: existing?.timestamp ?? record.timestamp,
223
+ activityCount,
224
+ activityTypes
225
+ };
226
+ }, options);
227
+ }
228
+ /**
229
+ * Gets all activity records for a specific trace ID.
230
+ *
231
+ * @param traceId The trace ID to query.
232
+ * @returns An array of activity records belonging to the trace.
233
+ */
234
+ async getActivitiesByTraceId(traceId) {
235
+ const prefix = [...this.#keyPrefix, traceId];
236
+ const records = [];
237
+ for await (const entry of this.#kv.list(prefix)) records.push(entry.value);
238
+ return records;
239
+ }
240
+ /**
241
+ * Gets recent traces with summary information.
242
+ *
243
+ * @param options Options for the query.
244
+ * @returns An array of trace summaries.
245
+ */
246
+ async getRecentTraces(options) {
247
+ const summaryPrefix = [...this.#keyPrefix, "_summaries"];
248
+ const summaries = [];
249
+ for await (const entry of this.#kv.list(summaryPrefix)) summaries.push(entry.value);
250
+ summaries.sort((a, b) => b.timestamp.localeCompare(a.timestamp));
251
+ if (options?.limit != null) return summaries.slice(0, options.limit);
252
+ return summaries;
253
+ }
254
+ /**
255
+ * Forces the exporter to flush any buffered data.
256
+ * This is a no-op because we write directly to the KvStore without buffering.
257
+ */
258
+ async forceFlush() {}
259
+ /**
260
+ * Shuts down the exporter.
261
+ */
262
+ async shutdown() {}
263
+ };
264
+
265
+ //#endregion
266
+ //#region src/otel/exporter.test.ts
267
+ function createMockSpan(options) {
268
+ const traceId = options.traceId ?? "0123456789abcdef0123456789abcdef";
269
+ const spanId = options.spanId ?? "0123456789abcdef";
270
+ const spanContext = {
271
+ traceId,
272
+ spanId,
273
+ traceFlags: TraceFlags.SAMPLED
274
+ };
275
+ const parentSpanContext = options.parentSpanId ? {
276
+ traceId,
277
+ spanId: options.parentSpanId,
278
+ traceFlags: TraceFlags.SAMPLED
279
+ } : void 0;
280
+ return {
281
+ name: options.name ?? "test-span",
282
+ kind: SpanKind.INTERNAL,
283
+ spanContext: () => spanContext,
284
+ parentSpanContext,
285
+ startTime: [17e8, 0],
286
+ endTime: [1700000001, 0],
287
+ status: { code: SpanStatusCode.OK },
288
+ attributes: {},
289
+ links: [],
290
+ events: options.events ?? [],
291
+ duration: [1, 0],
292
+ ended: true,
293
+ resource: {
294
+ attributes: {},
295
+ getRawAttributes: () => [],
296
+ merge: () => ({
297
+ attributes: {},
298
+ getRawAttributes: () => [],
299
+ merge: () => null
300
+ })
301
+ },
302
+ instrumentationScope: { name: "test" },
303
+ droppedAttributesCount: 0,
304
+ droppedEventsCount: 0,
305
+ droppedLinksCount: 0
306
+ };
307
+ }
308
+ function createActivityReceivedEvent(options) {
309
+ return {
310
+ name: "activitypub.activity.received",
311
+ time: [17e8, 5e8],
312
+ attributes: {
313
+ "activitypub.activity.json": options.activityJson,
314
+ "activitypub.activity.verified": options.verified ?? true,
315
+ "ld_signatures.verified": options.ldSigVerified ?? false,
316
+ "http_signatures.verified": options.httpSigVerified ?? true,
317
+ "http_signatures.key_id": options.httpSigKeyId ?? ""
318
+ }
319
+ };
320
+ }
321
+ function createActivitySentEvent(options) {
322
+ return {
323
+ name: "activitypub.activity.sent",
324
+ time: [17e8, 5e8],
325
+ attributes: {
326
+ "activitypub.activity.json": options.activityJson,
327
+ "activitypub.inbox.url": options.inboxUrl,
328
+ "activitypub.activity.id": options.activityId ?? ""
329
+ }
330
+ };
331
+ }
332
+ test("FedifySpanExporter", async (t) => {
333
+ await t.step("constructor accepts KvStore with list()", () => {
334
+ const kv = new MemoryKvStore();
335
+ const exporter = new FedifySpanExporter(kv);
336
+ assertEquals(exporter instanceof FedifySpanExporter, true);
337
+ });
338
+ await t.step("export() stores inbound activity from span event", async () => {
339
+ const kv = new MemoryKvStore();
340
+ const exporter = new FedifySpanExporter(kv);
341
+ const traceId = "trace123";
342
+ const spanId = "span456";
343
+ const activity = {
344
+ "@context": "https://www.w3.org/ns/activitystreams",
345
+ type: "Create",
346
+ id: "https://example.com/activities/123",
347
+ actor: "https://example.com/users/alice",
348
+ object: {
349
+ type: "Note",
350
+ content: "Hello!"
351
+ }
352
+ };
353
+ const activityJson = JSON.stringify(activity);
354
+ const span = createMockSpan({
355
+ traceId,
356
+ spanId,
357
+ name: "activitypub.inbox",
358
+ events: [createActivityReceivedEvent({
359
+ activityJson,
360
+ verified: true,
361
+ httpSigVerified: true
362
+ })]
363
+ });
364
+ await new Promise((resolve) => {
365
+ exporter.export([span], (result) => {
366
+ assertEquals(result.code, 0);
367
+ resolve();
368
+ });
369
+ });
370
+ const activities = await exporter.getActivitiesByTraceId(traceId);
371
+ assertEquals(activities.length, 1);
372
+ assertEquals(activities[0].traceId, traceId);
373
+ assertEquals(activities[0].spanId, spanId);
374
+ assertEquals(activities[0].direction, "inbound");
375
+ assertEquals(activities[0].activityType, activity.type);
376
+ assertEquals(activities[0].activityId, activity.id);
377
+ assertEquals(activities[0].activityJson, activityJson);
378
+ assertEquals(activities[0].verified, true);
379
+ });
380
+ await t.step("export() stores outbound activity from span event", async () => {
381
+ const kv = new MemoryKvStore();
382
+ const exporter = new FedifySpanExporter(kv);
383
+ const traceId = "trace789";
384
+ const spanId = "span012";
385
+ const inboxUrl = "https://example.com/users/alice/inbox";
386
+ const activity = {
387
+ "@context": "https://www.w3.org/ns/activitystreams",
388
+ type: "Follow",
389
+ id: "https://myserver.com/activities/789",
390
+ actor: "https://myserver.com/users/bob",
391
+ object: "https://example.com/users/alice"
392
+ };
393
+ const activityJson = JSON.stringify(activity);
394
+ const span = createMockSpan({
395
+ traceId,
396
+ spanId,
397
+ name: "activitypub.send_activity",
398
+ events: [createActivitySentEvent({
399
+ activityJson,
400
+ inboxUrl,
401
+ activityId: activity.id
402
+ })]
403
+ });
404
+ await new Promise((resolve) => {
405
+ exporter.export([span], (result) => {
406
+ assertEquals(result.code, 0);
407
+ resolve();
408
+ });
409
+ });
410
+ const activities = await exporter.getActivitiesByTraceId(traceId);
411
+ assertEquals(activities.length, 1);
412
+ assertEquals(activities[0].traceId, traceId);
413
+ assertEquals(activities[0].spanId, spanId);
414
+ assertEquals(activities[0].direction, "outbound");
415
+ assertEquals(activities[0].activityType, activity.type);
416
+ assertEquals(activities[0].activityId, activity.id);
417
+ assertEquals(activities[0].inboxUrl, inboxUrl);
418
+ });
419
+ await t.step("export() ignores spans without activity events", async () => {
420
+ const kv = new MemoryKvStore();
421
+ const exporter = new FedifySpanExporter(kv);
422
+ const span = createMockSpan({
423
+ traceId: "trace999",
424
+ spanId: "span999",
425
+ name: "some-other-span",
426
+ events: []
427
+ });
428
+ await new Promise((resolve) => {
429
+ exporter.export([span], (result) => {
430
+ assertEquals(result.code, 0);
431
+ resolve();
432
+ });
433
+ });
434
+ const activities = await exporter.getActivitiesByTraceId("trace999");
435
+ assertEquals(activities.length, 0);
436
+ });
437
+ await t.step("export() stores multiple activities from same trace", async () => {
438
+ const kv = new MemoryKvStore();
439
+ const exporter = new FedifySpanExporter(kv);
440
+ const inboundActivity = JSON.stringify({
441
+ "@context": "https://www.w3.org/ns/activitystreams",
442
+ type: "Create",
443
+ id: "https://example.com/activities/1"
444
+ });
445
+ const outboundActivity = JSON.stringify({
446
+ "@context": "https://www.w3.org/ns/activitystreams",
447
+ type: "Accept",
448
+ id: "https://myserver.com/activities/2"
449
+ });
450
+ const span1 = createMockSpan({
451
+ traceId: "multitrace",
452
+ spanId: "span1",
453
+ name: "activitypub.inbox",
454
+ events: [createActivityReceivedEvent({ activityJson: inboundActivity })]
455
+ });
456
+ const span2 = createMockSpan({
457
+ traceId: "multitrace",
458
+ spanId: "span2",
459
+ parentSpanId: "span1",
460
+ name: "activitypub.send_activity",
461
+ events: [createActivitySentEvent({
462
+ activityJson: outboundActivity,
463
+ inboxUrl: "https://example.com/inbox"
464
+ })]
465
+ });
466
+ await new Promise((resolve) => {
467
+ exporter.export([span1, span2], (result) => {
468
+ assertEquals(result.code, 0);
469
+ resolve();
470
+ });
471
+ });
472
+ const activities = await exporter.getActivitiesByTraceId("multitrace");
473
+ assertEquals(activities.length, 2);
474
+ const inbound = activities.find((a) => a.direction === "inbound");
475
+ const outbound = activities.find((a) => a.direction === "outbound");
476
+ assertEquals(inbound?.activityType, "Create");
477
+ assertEquals(outbound?.activityType, "Accept");
478
+ assertEquals(outbound?.parentSpanId, "span1");
479
+ });
480
+ await t.step("getRecentTraces() returns recent traces", async () => {
481
+ const kv = new MemoryKvStore();
482
+ const exporter = new FedifySpanExporter(kv);
483
+ for (let i = 0; i < 5; i++) {
484
+ const activityJson = JSON.stringify({
485
+ "@context": "https://www.w3.org/ns/activitystreams",
486
+ type: "Create",
487
+ id: `https://example.com/activities/${i}`
488
+ });
489
+ const span = createMockSpan({
490
+ traceId: `trace-${i}`,
491
+ spanId: `span-${i}`,
492
+ name: "activitypub.inbox",
493
+ events: [createActivityReceivedEvent({ activityJson })]
494
+ });
495
+ await new Promise((resolve) => {
496
+ exporter.export([span], () => resolve());
497
+ });
498
+ }
499
+ const traces = await exporter.getRecentTraces({ limit: 3 });
500
+ assertEquals(traces.length, 3);
501
+ });
502
+ await t.step("getRecentTraces() returns all traces when limit not specified", async () => {
503
+ const kv = new MemoryKvStore();
504
+ const exporter = new FedifySpanExporter(kv);
505
+ for (let i = 0; i < 3; i++) {
506
+ const activityJson = JSON.stringify({
507
+ "@context": "https://www.w3.org/ns/activitystreams",
508
+ type: "Create",
509
+ id: `https://example.com/activities/${i}`
510
+ });
511
+ const span = createMockSpan({
512
+ traceId: `all-trace-${i}`,
513
+ spanId: `span-${i}`,
514
+ name: "activitypub.inbox",
515
+ events: [createActivityReceivedEvent({ activityJson })]
516
+ });
517
+ await new Promise((resolve) => {
518
+ exporter.export([span], () => resolve());
519
+ });
520
+ }
521
+ const traces = await exporter.getRecentTraces();
522
+ assertEquals(traces.length >= 3, true);
523
+ });
524
+ await t.step("forceFlush() returns resolved promise", async () => {
525
+ const kv = new MemoryKvStore();
526
+ const exporter = new FedifySpanExporter(kv);
527
+ await exporter.forceFlush();
528
+ });
529
+ await t.step("shutdown() completes successfully", async () => {
530
+ const kv = new MemoryKvStore();
531
+ const exporter = new FedifySpanExporter(kv);
532
+ await exporter.shutdown();
533
+ });
534
+ await t.step("works with custom KvStore implementation", async () => {
535
+ const storedData = {};
536
+ const kv = {
537
+ get: (key) => {
538
+ const k = JSON.stringify(key);
539
+ return Promise.resolve(storedData[k]);
540
+ },
541
+ set: (key, value) => {
542
+ const k = JSON.stringify(key);
543
+ storedData[k] = value;
544
+ return Promise.resolve();
545
+ },
546
+ delete: (key) => {
547
+ const k = JSON.stringify(key);
548
+ delete storedData[k];
549
+ return Promise.resolve();
550
+ },
551
+ async *list(prefix) {
552
+ for (const [encodedKey, value] of Object.entries(storedData)) {
553
+ const key = JSON.parse(encodedKey);
554
+ if (prefix != null) {
555
+ if (key.length < prefix.length) continue;
556
+ if (!prefix.every((p, i) => key[i] === p)) continue;
557
+ }
558
+ yield {
559
+ key,
560
+ value
561
+ };
562
+ }
563
+ }
564
+ };
565
+ const exporter = new FedifySpanExporter(kv);
566
+ const activityJson = JSON.stringify({
567
+ "@context": "https://www.w3.org/ns/activitystreams",
568
+ type: "Like",
569
+ id: "https://example.com/activities/like"
570
+ });
571
+ const span = createMockSpan({
572
+ traceId: "cas-trace",
573
+ spanId: "cas-span",
574
+ name: "activitypub.inbox",
575
+ events: [createActivityReceivedEvent({ activityJson })]
576
+ });
577
+ await new Promise((resolve) => {
578
+ exporter.export([span], (result) => {
579
+ assertEquals(result.code, 0);
580
+ resolve();
581
+ });
582
+ });
583
+ const activities = await exporter.getActivitiesByTraceId("cas-trace");
584
+ assertEquals(activities.length, 1);
585
+ assertEquals(activities[0].activityType, "Like");
586
+ });
587
+ await t.step("TTL option is respected", async () => {
588
+ const kv = new MemoryKvStore();
589
+ const exporter = new FedifySpanExporter(kv, { ttl: Temporal.Duration.from({ hours: 1 }) });
590
+ const activityJson = JSON.stringify({
591
+ "@context": "https://www.w3.org/ns/activitystreams",
592
+ type: "Create"
593
+ });
594
+ const span = createMockSpan({
595
+ traceId: "ttl-trace",
596
+ spanId: "ttl-span",
597
+ name: "activitypub.inbox",
598
+ events: [createActivityReceivedEvent({ activityJson })]
599
+ });
600
+ await new Promise((resolve) => {
601
+ exporter.export([span], () => resolve());
602
+ });
603
+ const activities = await exporter.getActivitiesByTraceId("ttl-trace");
604
+ assertEquals(activities.length, 1);
605
+ });
606
+ await t.step("keyPrefix option customizes storage keys", async () => {
607
+ const kv = new MemoryKvStore();
608
+ const exporter = new FedifySpanExporter(kv, { keyPrefix: ["custom", "prefix"] });
609
+ const activityJson = JSON.stringify({
610
+ "@context": "https://www.w3.org/ns/activitystreams",
611
+ type: "Announce"
612
+ });
613
+ const span = createMockSpan({
614
+ traceId: "prefix-trace",
615
+ spanId: "prefix-span",
616
+ name: "activitypub.inbox",
617
+ events: [createActivityReceivedEvent({ activityJson })]
618
+ });
619
+ await new Promise((resolve) => {
620
+ exporter.export([span], () => resolve());
621
+ });
622
+ const activities = await exporter.getActivitiesByTraceId("prefix-trace");
623
+ assertEquals(activities.length, 1);
624
+ assertEquals(activities[0].activityType, "Announce");
625
+ });
626
+ await t.step("separate exporter instances share state via same KvStore (distributed simulation)", async () => {
627
+ const sharedKv = new MemoryKvStore();
628
+ const webServerExporter = new FedifySpanExporter(sharedKv);
629
+ const workerExporter = new FedifySpanExporter(sharedKv);
630
+ const dashboardExporter = new FedifySpanExporter(sharedKv);
631
+ const inboundActivity = JSON.stringify({
632
+ "@context": "https://www.w3.org/ns/activitystreams",
633
+ type: "Follow",
634
+ id: "https://remote.example/activities/follow-1",
635
+ actor: "https://remote.example/users/alice",
636
+ object: "https://local.example/users/bob"
637
+ });
638
+ const inboxSpan = createMockSpan({
639
+ traceId: "distributed-trace-001",
640
+ spanId: "inbox-span",
641
+ name: "activitypub.inbox",
642
+ events: [createActivityReceivedEvent({
643
+ activityJson: inboundActivity,
644
+ verified: true
645
+ })]
646
+ });
647
+ await new Promise((resolve) => {
648
+ webServerExporter.export([inboxSpan], () => resolve());
649
+ });
650
+ const outboundActivity = JSON.stringify({
651
+ "@context": "https://www.w3.org/ns/activitystreams",
652
+ type: "Accept",
653
+ id: "https://local.example/activities/accept-1",
654
+ actor: "https://local.example/users/bob",
655
+ object: "https://remote.example/activities/follow-1"
656
+ });
657
+ const sendSpan = createMockSpan({
658
+ traceId: "distributed-trace-001",
659
+ spanId: "send-span",
660
+ parentSpanId: "inbox-span",
661
+ name: "activitypub.send_activity",
662
+ events: [createActivitySentEvent({
663
+ activityJson: outboundActivity,
664
+ inboxUrl: "https://remote.example/users/alice/inbox",
665
+ activityId: "https://local.example/activities/accept-1"
666
+ })]
667
+ });
668
+ await new Promise((resolve) => {
669
+ workerExporter.export([sendSpan], () => resolve());
670
+ });
671
+ const activities = await dashboardExporter.getActivitiesByTraceId("distributed-trace-001");
672
+ assertEquals(activities.length, 2);
673
+ const follow = activities.find((a) => a.activityType === "Follow");
674
+ const accept = activities.find((a) => a.activityType === "Accept");
675
+ assertEquals(follow != null, true);
676
+ assertEquals(follow?.direction, "inbound");
677
+ assertEquals(follow?.verified, true);
678
+ assertEquals(accept != null, true);
679
+ assertEquals(accept?.direction, "outbound");
680
+ assertEquals(accept?.inboxUrl, "https://remote.example/users/alice/inbox");
681
+ assertEquals(accept?.parentSpanId, "inbox-span");
682
+ const recentTraces = await dashboardExporter.getRecentTraces();
683
+ const ourTrace = recentTraces.find((t$1) => t$1.traceId === "distributed-trace-001");
684
+ assertEquals(ourTrace != null, true);
685
+ assertEquals(ourTrace?.activityCount, 2);
686
+ assertEquals(ourTrace?.activityTypes.includes("Follow"), true);
687
+ assertEquals(ourTrace?.activityTypes.includes("Accept"), true);
688
+ });
689
+ await t.step("multiple workers writing to same trace concurrently", async () => {
690
+ const sharedKv = new MemoryKvStore();
691
+ const workers = [
692
+ new FedifySpanExporter(sharedKv),
693
+ new FedifySpanExporter(sharedKv),
694
+ new FedifySpanExporter(sharedKv)
695
+ ];
696
+ const traceId = "concurrent-fanout-trace";
697
+ const exportPromises = workers.map((worker, i) => {
698
+ const activityJson = JSON.stringify({
699
+ "@context": "https://www.w3.org/ns/activitystreams",
700
+ type: "Create",
701
+ id: "https://local.example/activities/post-1"
702
+ });
703
+ const span = createMockSpan({
704
+ traceId,
705
+ spanId: `worker-${i}-span`,
706
+ name: "activitypub.send_activity",
707
+ events: [createActivitySentEvent({
708
+ activityJson,
709
+ inboxUrl: `https://follower-${i}.example/inbox`
710
+ })]
711
+ });
712
+ return new Promise((resolve) => {
713
+ worker.export([span], () => resolve());
714
+ });
715
+ });
716
+ await Promise.all(exportPromises);
717
+ const dashboard = new FedifySpanExporter(sharedKv);
718
+ const activities = await dashboard.getActivitiesByTraceId(traceId);
719
+ assertEquals(activities.length, 3);
720
+ const inboxUrls = activities.map((a) => a.inboxUrl).sort();
721
+ assertEquals(inboxUrls, [
722
+ "https://follower-0.example/inbox",
723
+ "https://follower-1.example/inbox",
724
+ "https://follower-2.example/inbox"
725
+ ]);
726
+ });
727
+ await t.step("extracts actorId from activity with string actor", async () => {
728
+ const kv = new MemoryKvStore();
729
+ const exporter = new FedifySpanExporter(kv);
730
+ const activityJson = JSON.stringify({
731
+ "@context": "https://www.w3.org/ns/activitystreams",
732
+ type: "Create",
733
+ id: "https://example.com/activities/123",
734
+ actor: "https://example.com/users/alice",
735
+ object: {
736
+ type: "Note",
737
+ content: "Hello!"
738
+ }
739
+ });
740
+ const span = createMockSpan({
741
+ traceId: "actor-string-trace",
742
+ spanId: "span1",
743
+ name: "activitypub.inbox",
744
+ events: [createActivityReceivedEvent({ activityJson })]
745
+ });
746
+ await new Promise((resolve) => {
747
+ exporter.export([span], () => resolve());
748
+ });
749
+ const activities = await exporter.getActivitiesByTraceId("actor-string-trace");
750
+ assertEquals(activities.length, 1);
751
+ assertEquals(activities[0].actorId, "https://example.com/users/alice");
752
+ });
753
+ await t.step("extracts actorId from activity with object actor", async () => {
754
+ const kv = new MemoryKvStore();
755
+ const exporter = new FedifySpanExporter(kv);
756
+ const activityJson = JSON.stringify({
757
+ "@context": "https://www.w3.org/ns/activitystreams",
758
+ type: "Create",
759
+ id: "https://example.com/activities/456",
760
+ actor: {
761
+ type: "Person",
762
+ id: "https://example.com/users/bob",
763
+ name: "Bob"
764
+ },
765
+ object: {
766
+ type: "Note",
767
+ content: "Hello!"
768
+ }
769
+ });
770
+ const span = createMockSpan({
771
+ traceId: "actor-object-trace",
772
+ spanId: "span1",
773
+ name: "activitypub.inbox",
774
+ events: [createActivityReceivedEvent({ activityJson })]
775
+ });
776
+ await new Promise((resolve) => {
777
+ exporter.export([span], () => resolve());
778
+ });
779
+ const activities = await exporter.getActivitiesByTraceId("actor-object-trace");
780
+ assertEquals(activities.length, 1);
781
+ assertEquals(activities[0].actorId, "https://example.com/users/bob");
782
+ });
783
+ await t.step("extracts actorId from outbound activity", async () => {
784
+ const kv = new MemoryKvStore();
785
+ const exporter = new FedifySpanExporter(kv);
786
+ const activityJson = JSON.stringify({
787
+ "@context": "https://www.w3.org/ns/activitystreams",
788
+ type: "Follow",
789
+ id: "https://myserver.com/activities/789",
790
+ actor: "https://myserver.com/users/charlie",
791
+ object: "https://example.com/users/alice"
792
+ });
793
+ const span = createMockSpan({
794
+ traceId: "outbound-actor-trace",
795
+ spanId: "span1",
796
+ name: "activitypub.send_activity",
797
+ events: [createActivitySentEvent({
798
+ activityJson,
799
+ inboxUrl: "https://example.com/users/alice/inbox"
800
+ })]
801
+ });
802
+ await new Promise((resolve) => {
803
+ exporter.export([span], () => resolve());
804
+ });
805
+ const activities = await exporter.getActivitiesByTraceId("outbound-actor-trace");
806
+ assertEquals(activities.length, 1);
807
+ assertEquals(activities[0].actorId, "https://myserver.com/users/charlie");
808
+ });
809
+ await t.step("extracts signature verification details for inbound activity", async () => {
810
+ const kv = new MemoryKvStore();
811
+ const exporter = new FedifySpanExporter(kv);
812
+ const activityJson = JSON.stringify({
813
+ "@context": "https://www.w3.org/ns/activitystreams",
814
+ type: "Create",
815
+ id: "https://example.com/activities/sig-test",
816
+ actor: "https://example.com/users/alice"
817
+ });
818
+ const span = createMockSpan({
819
+ traceId: "sig-details-trace",
820
+ spanId: "span1",
821
+ name: "activitypub.inbox",
822
+ events: [createActivityReceivedEvent({
823
+ activityJson,
824
+ verified: true,
825
+ httpSigVerified: true,
826
+ httpSigKeyId: "https://example.com/users/alice#main-key",
827
+ ldSigVerified: false
828
+ })]
829
+ });
830
+ await new Promise((resolve) => {
831
+ exporter.export([span], () => resolve());
832
+ });
833
+ const activities = await exporter.getActivitiesByTraceId("sig-details-trace");
834
+ assertEquals(activities.length, 1);
835
+ assertEquals(activities[0].verified, true);
836
+ assertEquals(activities[0].signatureDetails != null, true);
837
+ assertEquals(activities[0].signatureDetails?.httpSignaturesVerified, true);
838
+ assertEquals(activities[0].signatureDetails?.httpSignaturesKeyId, "https://example.com/users/alice#main-key");
839
+ assertEquals(activities[0].signatureDetails?.ldSignaturesVerified, false);
840
+ });
841
+ await t.step("signature details with LD signatures verified", async () => {
842
+ const kv = new MemoryKvStore();
843
+ const exporter = new FedifySpanExporter(kv);
844
+ const activityJson = JSON.stringify({
845
+ "@context": "https://www.w3.org/ns/activitystreams",
846
+ type: "Delete",
847
+ id: "https://example.com/activities/ld-sig-test",
848
+ actor: "https://example.com/users/alice"
849
+ });
850
+ const span = createMockSpan({
851
+ traceId: "ld-sig-trace",
852
+ spanId: "span1",
853
+ name: "activitypub.inbox",
854
+ events: [createActivityReceivedEvent({
855
+ activityJson,
856
+ verified: true,
857
+ httpSigVerified: false,
858
+ ldSigVerified: true
859
+ })]
860
+ });
861
+ await new Promise((resolve) => {
862
+ exporter.export([span], () => resolve());
863
+ });
864
+ const activities = await exporter.getActivitiesByTraceId("ld-sig-trace");
865
+ assertEquals(activities.length, 1);
866
+ assertEquals(activities[0].signatureDetails?.httpSignaturesVerified, false);
867
+ assertEquals(activities[0].signatureDetails?.ldSignaturesVerified, true);
868
+ });
869
+ await t.step("handles activity without actor field", async () => {
870
+ const kv = new MemoryKvStore();
871
+ const exporter = new FedifySpanExporter(kv);
872
+ const activityJson = JSON.stringify({
873
+ "@context": "https://www.w3.org/ns/activitystreams",
874
+ type: "Delete",
875
+ id: "https://example.com/activities/no-actor",
876
+ object: "https://example.com/posts/123"
877
+ });
878
+ const span = createMockSpan({
879
+ traceId: "no-actor-trace",
880
+ spanId: "span1",
881
+ name: "activitypub.inbox",
882
+ events: [createActivityReceivedEvent({ activityJson })]
883
+ });
884
+ await new Promise((resolve) => {
885
+ exporter.export([span], () => resolve());
886
+ });
887
+ const activities = await exporter.getActivitiesByTraceId("no-actor-trace");
888
+ assertEquals(activities.length, 1);
889
+ assertEquals(activities[0].actorId, void 0);
890
+ });
891
+ });
892
+
893
+ //#endregion