effect 4.1.5 → 4.1.7

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 (441) hide show
  1. package/ai-docs/package.json +2 -2
  2. package/dist/Channel.d.ts +104 -7
  3. package/dist/Channel.d.ts.map +1 -1
  4. package/dist/Channel.js +73 -4
  5. package/dist/Channel.js.map +1 -1
  6. package/dist/Codegen.d.ts +7 -2
  7. package/dist/Codegen.d.ts.map +1 -1
  8. package/dist/Codegen.js +7 -2
  9. package/dist/Codegen.js.map +1 -1
  10. package/dist/Config.d.ts +1 -1
  11. package/dist/Config.d.ts.map +1 -1
  12. package/dist/Config.js +5 -3
  13. package/dist/Config.js.map +1 -1
  14. package/dist/Context.d.ts.map +1 -1
  15. package/dist/Context.js +79 -31
  16. package/dist/Context.js.map +1 -1
  17. package/dist/Cron.d.ts.map +1 -1
  18. package/dist/Cron.js +10 -9
  19. package/dist/Cron.js.map +1 -1
  20. package/dist/Effect.d.ts +139 -18
  21. package/dist/Effect.d.ts.map +1 -1
  22. package/dist/Effect.js +10 -2
  23. package/dist/Effect.js.map +1 -1
  24. package/dist/Equal.d.ts +4 -4
  25. package/dist/Equal.d.ts.map +1 -1
  26. package/dist/Equal.js +78 -66
  27. package/dist/Equal.js.map +1 -1
  28. package/dist/Formatter.js +4 -4
  29. package/dist/Formatter.js.map +1 -1
  30. package/dist/Hash.d.ts.map +1 -1
  31. package/dist/Hash.js +34 -41
  32. package/dist/Hash.js.map +1 -1
  33. package/dist/LayerRef.d.ts +1 -1
  34. package/dist/LayerRef.d.ts.map +1 -1
  35. package/dist/LayerRef.js +3 -3
  36. package/dist/LayerRef.js.map +1 -1
  37. package/dist/Logger.d.ts +37 -13
  38. package/dist/Logger.d.ts.map +1 -1
  39. package/dist/Logger.js +39 -10
  40. package/dist/Logger.js.map +1 -1
  41. package/dist/Match.d.ts +23 -23
  42. package/dist/Match.d.ts.map +1 -1
  43. package/dist/Match.js.map +1 -1
  44. package/dist/Metric.d.ts.map +1 -1
  45. package/dist/Metric.js +3 -4
  46. package/dist/Metric.js.map +1 -1
  47. package/dist/Order.js +1 -1
  48. package/dist/Order.js.map +1 -1
  49. package/dist/Pool.d.ts.map +1 -1
  50. package/dist/Pool.js +49 -21
  51. package/dist/Pool.js.map +1 -1
  52. package/dist/Predicate.d.ts.map +1 -1
  53. package/dist/Predicate.js +2 -1
  54. package/dist/Predicate.js.map +1 -1
  55. package/dist/Scheduler.d.ts.map +1 -1
  56. package/dist/Scheduler.js +15 -9
  57. package/dist/Scheduler.js.map +1 -1
  58. package/dist/Schema.d.ts +41 -0
  59. package/dist/Schema.d.ts.map +1 -1
  60. package/dist/Schema.js +51 -390
  61. package/dist/Schema.js.map +1 -1
  62. package/dist/SchemaAST.d.ts +2 -2
  63. package/dist/SchemaAST.d.ts.map +1 -1
  64. package/dist/SchemaAST.js +199 -98
  65. package/dist/SchemaAST.js.map +1 -1
  66. package/dist/SchemaParser.d.ts.map +1 -1
  67. package/dist/SchemaParser.js +29 -50
  68. package/dist/SchemaParser.js.map +1 -1
  69. package/dist/ScopedCache.d.ts.map +1 -1
  70. package/dist/ScopedCache.js +6 -4
  71. package/dist/ScopedCache.js.map +1 -1
  72. package/dist/Stream.d.ts +128 -5
  73. package/dist/Stream.d.ts.map +1 -1
  74. package/dist/Stream.js +124 -29
  75. package/dist/Stream.js.map +1 -1
  76. package/dist/String.js +1 -1
  77. package/dist/String.js.map +1 -1
  78. package/dist/Tracer.d.ts +10 -0
  79. package/dist/Tracer.d.ts.map +1 -1
  80. package/dist/Tracer.js +3 -4
  81. package/dist/Tracer.js.map +1 -1
  82. package/dist/ai/McpClient.d.ts +68 -4
  83. package/dist/ai/McpClient.d.ts.map +1 -1
  84. package/dist/ai/McpClient.js +100 -17
  85. package/dist/ai/McpClient.js.map +1 -1
  86. package/dist/ai/McpClientError.d.ts +46 -4
  87. package/dist/ai/McpClientError.d.ts.map +1 -1
  88. package/dist/ai/McpClientError.js +38 -3
  89. package/dist/ai/McpClientError.js.map +1 -1
  90. package/dist/ai/McpServer.d.ts +158 -7
  91. package/dist/ai/McpServer.d.ts.map +1 -1
  92. package/dist/ai/McpServer.js +103 -49
  93. package/dist/ai/McpServer.js.map +1 -1
  94. package/dist/ai/Prompt.d.ts +3 -1
  95. package/dist/ai/Prompt.d.ts.map +1 -1
  96. package/dist/ai/Prompt.js +17 -3
  97. package/dist/ai/Prompt.js.map +1 -1
  98. package/dist/ai/Skill.d.ts +172 -0
  99. package/dist/ai/Skill.d.ts.map +1 -0
  100. package/dist/ai/Skill.js +209 -0
  101. package/dist/ai/Skill.js.map +1 -0
  102. package/dist/ai/index.d.ts +5 -0
  103. package/dist/ai/index.d.ts.map +1 -1
  104. package/dist/ai/index.js +5 -0
  105. package/dist/ai/index.js.map +1 -1
  106. package/dist/ai/internal/mcpProtocol/v2024_11_05.js +9 -7
  107. package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
  108. package/dist/ai/internal/mcpProtocol/v2025_03_26.js +12 -11
  109. package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
  110. package/dist/ai/internal/mcpProtocol/v2025_06_18.js +18 -17
  111. package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
  112. package/dist/ai/internal/mcpProtocol/v2025_11_25.js +19 -18
  113. package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
  114. package/dist/ai/internal/mcpProtocol/v2026_07_28.js +1 -1
  115. package/dist/ai/internal/mcpProtocol/v2026_07_28.js.map +1 -1
  116. package/dist/ai/internal/mcpProtocol.js +11 -0
  117. package/dist/ai/internal/mcpProtocol.js.map +1 -1
  118. package/dist/ai/internal/mcpRuntime.js +29 -17
  119. package/dist/ai/internal/mcpRuntime.js.map +1 -1
  120. package/dist/ai/internal/mcpSchema/v2024_11_05.js +2 -1
  121. package/dist/ai/internal/mcpSchema/v2024_11_05.js.map +1 -1
  122. package/dist/ai/internal/mcpSchema/v2025_03_26.js +1 -8
  123. package/dist/ai/internal/mcpSchema/v2025_03_26.js.map +1 -1
  124. package/dist/ai/internal/mcpSchema/v2025_06_18.js +5 -9
  125. package/dist/ai/internal/mcpSchema/v2025_06_18.js.map +1 -1
  126. package/dist/ai/internal/mcpSchema/v2025_11_25.js +1 -8
  127. package/dist/ai/internal/mcpSchema/v2025_11_25.js.map +1 -1
  128. package/dist/ai/internal/mcpSchema/v2026_07_28.js +4 -3
  129. package/dist/ai/internal/mcpSchema/v2026_07_28.js.map +1 -1
  130. package/dist/cluster/ClusterCron.d.ts +5 -20
  131. package/dist/cluster/ClusterCron.d.ts.map +1 -1
  132. package/dist/cluster/ClusterCron.js +16 -4
  133. package/dist/cluster/ClusterCron.js.map +1 -1
  134. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  135. package/dist/cluster/ClusterWorkflowEngine.js +155 -83
  136. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  137. package/dist/cluster/MessageStorage.d.ts +56 -0
  138. package/dist/cluster/MessageStorage.d.ts.map +1 -1
  139. package/dist/cluster/MessageStorage.js +18 -2
  140. package/dist/cluster/MessageStorage.js.map +1 -1
  141. package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
  142. package/dist/cluster/SqlMessageStorage.js +48 -23
  143. package/dist/cluster/SqlMessageStorage.js.map +1 -1
  144. package/dist/cluster/internal/entityActivation.js +2 -0
  145. package/dist/cluster/internal/entityActivation.js.map +1 -1
  146. package/dist/cluster/internal/entityManager.js +8 -5
  147. package/dist/cluster/internal/entityManager.js.map +1 -1
  148. package/dist/encoding/Base64.js +5 -1
  149. package/dist/encoding/Base64.js.map +1 -1
  150. package/dist/encoding/Base64Url.d.ts.map +1 -1
  151. package/dist/encoding/Base64Url.js +6 -1
  152. package/dist/encoding/Base64Url.js.map +1 -1
  153. package/dist/encoding/Hex.js +7 -5
  154. package/dist/encoding/Hex.js.map +1 -1
  155. package/dist/encoding/Xml.d.ts +38 -9
  156. package/dist/encoding/Xml.d.ts.map +1 -1
  157. package/dist/encoding/Xml.js +63 -31
  158. package/dist/encoding/Xml.js.map +1 -1
  159. package/dist/http/FetchHttpClient.d.ts +2 -1
  160. package/dist/http/FetchHttpClient.d.ts.map +1 -1
  161. package/dist/http/FetchHttpClient.js +14 -10
  162. package/dist/http/FetchHttpClient.js.map +1 -1
  163. package/dist/http/Headers.d.ts +201 -3
  164. package/dist/http/Headers.d.ts.map +1 -1
  165. package/dist/http/Headers.js +205 -3
  166. package/dist/http/Headers.js.map +1 -1
  167. package/dist/http/HttpClient.d.ts.map +1 -1
  168. package/dist/http/HttpClient.js +11 -7
  169. package/dist/http/HttpClient.js.map +1 -1
  170. package/dist/http/HttpClientError.d.ts +1 -0
  171. package/dist/http/HttpClientError.d.ts.map +1 -1
  172. package/dist/http/HttpClientError.js +32 -9
  173. package/dist/http/HttpClientError.js.map +1 -1
  174. package/dist/http/HttpClientRequest.d.ts +46 -0
  175. package/dist/http/HttpClientRequest.d.ts.map +1 -1
  176. package/dist/http/HttpClientRequest.js +15 -0
  177. package/dist/http/HttpClientRequest.js.map +1 -1
  178. package/dist/http/HttpClientResponse.d.ts +132 -0
  179. package/dist/http/HttpClientResponse.d.ts.map +1 -1
  180. package/dist/http/HttpClientResponse.js +83 -0
  181. package/dist/http/HttpClientResponse.js.map +1 -1
  182. package/dist/http/HttpEffect.d.ts.map +1 -1
  183. package/dist/http/HttpEffect.js +31 -2
  184. package/dist/http/HttpEffect.js.map +1 -1
  185. package/dist/http/HttpMiddleware.js +1 -1
  186. package/dist/http/HttpMiddleware.js.map +1 -1
  187. package/dist/http/HttpServerError.d.ts +1 -1
  188. package/dist/http/HttpServerError.js +1 -1
  189. package/dist/http/HttpServerResponse.d.ts +118 -0
  190. package/dist/http/HttpServerResponse.d.ts.map +1 -1
  191. package/dist/http/HttpServerResponse.js +43 -0
  192. package/dist/http/HttpServerResponse.js.map +1 -1
  193. package/dist/http/Multipart.d.ts.map +1 -1
  194. package/dist/http/Multipart.js +0 -5
  195. package/dist/http/Multipart.js.map +1 -1
  196. package/dist/http/MultipartParser/internal/contentType.d.ts +6 -0
  197. package/dist/http/MultipartParser/internal/contentType.d.ts.map +1 -1
  198. package/dist/http/MultipartParser/internal/contentType.js +1 -1
  199. package/dist/http/MultipartParser/internal/contentType.js.map +1 -1
  200. package/dist/http/internal/clientPath.d.ts +2 -0
  201. package/dist/http/internal/clientPath.d.ts.map +1 -0
  202. package/dist/http/internal/clientPath.js +24 -0
  203. package/dist/http/internal/clientPath.js.map +1 -0
  204. package/dist/http/internal/redactedPath.js +2 -0
  205. package/dist/http/internal/redactedPath.js.map +1 -1
  206. package/dist/http/internal/tracing.js +5 -3
  207. package/dist/http/internal/tracing.js.map +1 -1
  208. package/dist/http-api/HttpApi.d.ts +2 -2
  209. package/dist/http-api/HttpApi.d.ts.map +1 -1
  210. package/dist/http-api/HttpApi.js +30 -7
  211. package/dist/http-api/HttpApi.js.map +1 -1
  212. package/dist/http-api/HttpApiBuilder.d.ts.map +1 -1
  213. package/dist/http-api/HttpApiBuilder.js +5 -2
  214. package/dist/http-api/HttpApiBuilder.js.map +1 -1
  215. package/dist/http-api/HttpApiClient.d.ts.map +1 -1
  216. package/dist/http-api/HttpApiClient.js +23 -6
  217. package/dist/http-api/HttpApiClient.js.map +1 -1
  218. package/dist/http-api/internal/redactedKeys.d.ts +2 -0
  219. package/dist/http-api/internal/redactedKeys.d.ts.map +1 -0
  220. package/dist/http-api/internal/redactedKeys.js +37 -0
  221. package/dist/http-api/internal/redactedKeys.js.map +1 -0
  222. package/dist/internal/base64.js +34 -2
  223. package/dist/internal/base64.js.map +1 -1
  224. package/dist/internal/core.js +60 -43
  225. package/dist/internal/core.js.map +1 -1
  226. package/dist/internal/dateTime.js +35 -17
  227. package/dist/internal/dateTime.js.map +1 -1
  228. package/dist/internal/effect.js +60 -52
  229. package/dist/internal/effect.js.map +1 -1
  230. package/dist/internal/equal.js +44 -13
  231. package/dist/internal/equal.js.map +1 -1
  232. package/dist/internal/fiberCachedKeys.d.ts +2 -0
  233. package/dist/internal/fiberCachedKeys.d.ts.map +1 -0
  234. package/dist/internal/fiberCachedKeys.js +48 -0
  235. package/dist/internal/fiberCachedKeys.js.map +1 -0
  236. package/dist/internal/hashMap.js +1 -1
  237. package/dist/internal/hashMap.js.map +1 -1
  238. package/dist/internal/matcher.js +17 -17
  239. package/dist/internal/matcher.js.map +1 -1
  240. package/dist/internal/predicate.d.ts +2 -0
  241. package/dist/internal/predicate.d.ts.map +1 -0
  242. package/dist/internal/predicate.js +10 -0
  243. package/dist/internal/predicate.js.map +1 -0
  244. package/dist/internal/references.js +8 -11
  245. package/dist/internal/references.js.map +1 -1
  246. package/dist/internal/schema/schemaCodegen.js +3 -2
  247. package/dist/internal/schema/schemaCodegen.js.map +1 -1
  248. package/dist/internal/schema/schemaCodegenBuiltIns.d.ts +2 -0
  249. package/dist/internal/schema/schemaCodegenBuiltIns.d.ts.map +1 -0
  250. package/dist/internal/schema/schemaCodegenBuiltIns.js +425 -0
  251. package/dist/internal/schema/schemaCodegenBuiltIns.js.map +1 -0
  252. package/dist/internal/schema/toEquivalence.js +3 -4
  253. package/dist/internal/schema/toEquivalence.js.map +1 -1
  254. package/dist/internal/version.js +1 -1
  255. package/dist/jose/JoseError.d.ts +51 -1
  256. package/dist/jose/JoseError.d.ts.map +1 -1
  257. package/dist/jose/JoseError.js +25 -18
  258. package/dist/jose/JoseError.js.map +1 -1
  259. package/dist/jose/internal/compact.js +10 -5
  260. package/dist/jose/internal/compact.js.map +1 -1
  261. package/dist/observability/Otlp.d.ts +19 -0
  262. package/dist/observability/Otlp.d.ts.map +1 -1
  263. package/dist/observability/Otlp.js +10 -0
  264. package/dist/observability/Otlp.js.map +1 -1
  265. package/dist/observability/OtlpExporter.d.ts +49 -13
  266. package/dist/observability/OtlpExporter.d.ts.map +1 -1
  267. package/dist/observability/OtlpExporter.js +135 -54
  268. package/dist/observability/OtlpExporter.js.map +1 -1
  269. package/dist/observability/OtlpLogger.d.ts +14 -0
  270. package/dist/observability/OtlpLogger.d.ts.map +1 -1
  271. package/dist/observability/OtlpLogger.js +10 -2
  272. package/dist/observability/OtlpLogger.js.map +1 -1
  273. package/dist/observability/OtlpMetrics.d.ts.map +1 -1
  274. package/dist/observability/OtlpMetrics.js +2 -0
  275. package/dist/observability/OtlpMetrics.js.map +1 -1
  276. package/dist/observability/OtlpTracer.d.ts +14 -0
  277. package/dist/observability/OtlpTracer.d.ts.map +1 -1
  278. package/dist/observability/OtlpTracer.js +10 -2
  279. package/dist/observability/OtlpTracer.js.map +1 -1
  280. package/dist/persistence/KeyValueStore.d.ts.map +1 -1
  281. package/dist/persistence/KeyValueStore.js +6 -4
  282. package/dist/persistence/KeyValueStore.js.map +1 -1
  283. package/dist/reactivity/Atom.d.ts.map +1 -1
  284. package/dist/reactivity/Atom.js +10 -9
  285. package/dist/reactivity/Atom.js.map +1 -1
  286. package/dist/rpc/RpcClient.d.ts.map +1 -1
  287. package/dist/rpc/RpcClient.js +32 -1
  288. package/dist/rpc/RpcClient.js.map +1 -1
  289. package/dist/rpc/RpcGroup.d.ts +1 -1
  290. package/dist/rpc/RpcGroup.d.ts.map +1 -1
  291. package/dist/rpc/RpcGroup.js +4 -0
  292. package/dist/rpc/RpcGroup.js.map +1 -1
  293. package/dist/sql/Migrator.d.ts.map +1 -1
  294. package/dist/sql/Migrator.js +2 -5
  295. package/dist/sql/Migrator.js.map +1 -1
  296. package/dist/sql/SqlClient.d.ts.map +1 -1
  297. package/dist/sql/SqlClient.js +5 -1
  298. package/dist/sql/SqlClient.js.map +1 -1
  299. package/dist/sql/Statement.d.ts +23 -0
  300. package/dist/sql/Statement.d.ts.map +1 -1
  301. package/dist/sql/Statement.js +30 -5
  302. package/dist/sql/Statement.js.map +1 -1
  303. package/dist/workers/Worker.d.ts +21 -0
  304. package/dist/workers/Worker.d.ts.map +1 -1
  305. package/dist/workers/Worker.js +23 -0
  306. package/dist/workers/Worker.js.map +1 -1
  307. package/dist/workflow/Activity.d.ts +18 -0
  308. package/dist/workflow/Activity.d.ts.map +1 -1
  309. package/dist/workflow/Activity.js +13 -4
  310. package/dist/workflow/Activity.js.map +1 -1
  311. package/dist/workflow/Workflow.d.ts +10 -9
  312. package/dist/workflow/Workflow.d.ts.map +1 -1
  313. package/dist/workflow/Workflow.js +33 -22
  314. package/dist/workflow/Workflow.js.map +1 -1
  315. package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
  316. package/dist/workflow/WorkflowEngine.js +26 -12
  317. package/dist/workflow/WorkflowEngine.js.map +1 -1
  318. package/dist/workflow/internal/retry.d.ts +2 -0
  319. package/dist/workflow/internal/retry.d.ts.map +1 -0
  320. package/dist/workflow/internal/retry.js +11 -0
  321. package/dist/workflow/internal/retry.js.map +1 -0
  322. package/dist/workflow/internal/scope.d.ts +2 -0
  323. package/dist/workflow/internal/scope.d.ts.map +1 -0
  324. package/dist/workflow/internal/scope.js +26 -0
  325. package/dist/workflow/internal/scope.js.map +1 -0
  326. package/package.json +3 -3
  327. package/src/Channel.ts +105 -8
  328. package/src/Codegen.ts +7 -2
  329. package/src/Config.ts +6 -3
  330. package/src/Context.ts +108 -50
  331. package/src/Cron.ts +11 -10
  332. package/src/Effect.ts +224 -48
  333. package/src/Equal.ts +93 -80
  334. package/src/Formatter.ts +4 -4
  335. package/src/Hash.ts +49 -48
  336. package/src/LayerRef.ts +6 -4
  337. package/src/Logger.ts +68 -25
  338. package/src/Match.ts +78 -50
  339. package/src/Metric.ts +4 -4
  340. package/src/Order.ts +1 -1
  341. package/src/Pool.ts +62 -33
  342. package/src/Predicate.ts +2 -5
  343. package/src/Scheduler.ts +27 -10
  344. package/src/Schema.ts +79 -296
  345. package/src/SchemaAST.ts +231 -157
  346. package/src/SchemaParser.ts +40 -57
  347. package/src/ScopedCache.ts +6 -4
  348. package/src/Stream.ts +167 -33
  349. package/src/String.ts +1 -1
  350. package/src/Tracer.ts +11 -2
  351. package/src/ai/McpClient.ts +157 -15
  352. package/src/ai/McpClientError.ts +55 -4
  353. package/src/ai/McpServer.ts +318 -91
  354. package/src/ai/Prompt.ts +20 -3
  355. package/src/ai/Skill.ts +236 -0
  356. package/src/ai/index.ts +6 -0
  357. package/src/ai/internal/mcpProtocol/v2024_11_05.ts +8 -13
  358. package/src/ai/internal/mcpProtocol/v2025_03_26.ts +13 -15
  359. package/src/ai/internal/mcpProtocol/v2025_06_18.ts +21 -23
  360. package/src/ai/internal/mcpProtocol/v2025_11_25.ts +22 -24
  361. package/src/ai/internal/mcpProtocol/v2026_07_28.ts +1 -1
  362. package/src/ai/internal/mcpProtocol.ts +15 -0
  363. package/src/ai/internal/mcpRuntime.ts +36 -13
  364. package/src/ai/internal/mcpSchema/v2024_11_05.ts +2 -1
  365. package/src/ai/internal/mcpSchema/v2025_03_26.ts +1 -9
  366. package/src/ai/internal/mcpSchema/v2025_06_18.ts +3 -10
  367. package/src/ai/internal/mcpSchema/v2025_11_25.ts +1 -9
  368. package/src/ai/internal/mcpSchema/v2026_07_28.ts +6 -8
  369. package/src/cluster/ClusterCron.ts +31 -20
  370. package/src/cluster/ClusterWorkflowEngine.ts +172 -96
  371. package/src/cluster/MessageStorage.ts +51 -2
  372. package/src/cluster/SqlMessageStorage.ts +88 -36
  373. package/src/cluster/internal/entityActivation.ts +6 -0
  374. package/src/cluster/internal/entityManager.ts +8 -4
  375. package/src/encoding/Base64.ts +5 -1
  376. package/src/encoding/Base64Url.ts +6 -1
  377. package/src/encoding/Hex.ts +5 -5
  378. package/src/encoding/Xml.ts +96 -26
  379. package/src/http/FetchHttpClient.ts +8 -5
  380. package/src/http/Headers.ts +309 -3
  381. package/src/http/HttpClient.ts +19 -7
  382. package/src/http/HttpClientError.ts +42 -9
  383. package/src/http/HttpClientRequest.ts +51 -0
  384. package/src/http/HttpClientResponse.ts +156 -0
  385. package/src/http/HttpEffect.ts +23 -3
  386. package/src/http/HttpMiddleware.ts +1 -1
  387. package/src/http/HttpServerError.ts +1 -1
  388. package/src/http/HttpServerResponse.ts +126 -0
  389. package/src/http/Multipart.ts +0 -5
  390. package/src/http/MultipartParser/internal/contentType.ts +1 -1
  391. package/src/http/internal/clientPath.ts +39 -0
  392. package/src/http/internal/redactedPath.ts +4 -0
  393. package/src/http/internal/tracing.ts +6 -3
  394. package/src/http-api/HttpApi.ts +29 -8
  395. package/src/http-api/HttpApiBuilder.ts +7 -2
  396. package/src/http-api/HttpApiClient.ts +30 -7
  397. package/src/http-api/internal/redactedKeys.ts +40 -0
  398. package/src/internal/base64.ts +57 -2
  399. package/src/internal/core.ts +80 -44
  400. package/src/internal/dateTime.ts +43 -24
  401. package/src/internal/effect.ts +115 -157
  402. package/src/internal/equal.ts +73 -17
  403. package/src/internal/fiberCachedKeys.ts +81 -0
  404. package/src/internal/hashMap.ts +1 -1
  405. package/src/internal/matcher.ts +34 -113
  406. package/src/internal/predicate.ts +10 -0
  407. package/src/internal/references.ts +21 -14
  408. package/src/internal/schema/schemaCodegen.ts +5 -4
  409. package/src/internal/schema/schemaCodegenBuiltIns.ts +343 -0
  410. package/src/internal/schema/toEquivalence.ts +3 -5
  411. package/src/internal/version.ts +1 -1
  412. package/src/jose/JoseError.ts +34 -0
  413. package/src/jose/internal/compact.ts +14 -5
  414. package/src/observability/Otlp.ts +29 -0
  415. package/src/observability/OtlpExporter.ts +206 -75
  416. package/src/observability/OtlpLogger.ts +24 -2
  417. package/src/observability/OtlpMetrics.ts +2 -0
  418. package/src/observability/OtlpTracer.ts +24 -3
  419. package/src/persistence/KeyValueStore.ts +17 -14
  420. package/src/reactivity/Atom.ts +12 -18
  421. package/src/rpc/RpcClient.ts +26 -1
  422. package/src/rpc/RpcGroup.ts +4 -1
  423. package/src/sql/Migrator.ts +2 -11
  424. package/src/sql/SqlClient.ts +14 -8
  425. package/src/sql/Statement.ts +48 -12
  426. package/src/workers/Worker.ts +25 -0
  427. package/src/workflow/Activity.ts +28 -4
  428. package/src/workflow/Workflow.ts +68 -44
  429. package/src/workflow/WorkflowEngine.ts +38 -15
  430. package/src/workflow/internal/retry.ts +12 -0
  431. package/src/workflow/internal/scope.ts +36 -0
  432. package/dist/internal/hash.d.ts +0 -2
  433. package/dist/internal/hash.d.ts.map +0 -1
  434. package/dist/internal/hash.js +0 -11
  435. package/dist/internal/hash.js.map +0 -1
  436. package/dist/internal/metric.d.ts +0 -2
  437. package/dist/internal/metric.d.ts.map +0 -1
  438. package/dist/internal/metric.js +0 -3
  439. package/dist/internal/metric.js.map +0 -1
  440. package/src/internal/hash.ts +0 -11
  441. package/src/internal/metric.ts +0 -2
@@ -13,19 +13,21 @@ import { Clock } from "../Clock.ts"
13
13
  import * as Context from "../Context.ts"
14
14
  import * as Duration from "../Duration.ts"
15
15
  import * as Effect from "../Effect.ts"
16
- import * as Fiber from "../Fiber.ts"
17
- import * as FiberSet from "../FiberSet.ts"
16
+ import type * as Fiber from "../Fiber.ts"
18
17
  import { identity } from "../Function.ts"
19
18
  import * as Headers from "../http/Headers.ts"
20
19
  import type { HttpBody } from "../http/HttpBody.ts"
21
20
  import * as HttpClient from "../http/HttpClient.ts"
22
21
  import * as HttpClientError from "../http/HttpClientError.ts"
23
22
  import * as HttpClientRequest from "../http/HttpClientRequest.ts"
23
+ import * as Count from "../internal/count.ts"
24
24
  import * as Latch from "../Latch.ts"
25
25
  import * as Layer from "../Layer.ts"
26
+ import * as MutableList from "../MutableList.ts"
26
27
  import * as Result from "../Result.ts"
27
28
  import * as Schedule from "../Schedule.ts"
28
29
  import * as Scope from "../Scope.ts"
30
+ import type { Concurrency } from "../Types.ts"
29
31
  import * as Version from "../Version.ts"
30
32
 
31
33
  // A missing or invalid Retry-After falls back to a fixed delay.
@@ -60,11 +62,15 @@ const policy = Schedule.forever.pipe(
60
62
  *
61
63
  * **Details**
62
64
  *
63
- * Every exporter created by `make` registers its export operation here, so a
64
- * single `flush` drains all signals sharing the registry. `flush` returns only
65
- * after the exports it initiated have settled, cannot fail, and respects each
66
- * exporter's temporary-disable window. Wrap it with `Effect.timeoutOption` to
67
- * bound its duration at the call site.
65
+ * Every exporter created by `make` registers its flush operation here, so a
66
+ * single `flush` drains all signals sharing the registry concurrently while
67
+ * each exporter respects its own `concurrency` limit. For each exporter,
68
+ * `flush` returns once every export already in flight when it was called has
69
+ * settled and every item accepted before the call has been sent or discarded by
70
+ * a failed export (or after one fresh snapshot settles when `exportEmpty` is
71
+ * enabled). `flush` cannot fail and respects each exporter's temporary-disable
72
+ * window. Wrap it with `Effect.timeoutOption` to bound its duration at the call
73
+ * site.
68
74
  *
69
75
  * @stability unstable
70
76
  * @category services
@@ -76,8 +82,16 @@ export class Flusher extends Context.Service<Flusher, {
76
82
  *
77
83
  * **Details**
78
84
  *
85
+ * Each exporter runs up to its configured `concurrency` exports at a time.
86
+ * `flush` waits for every export already in flight when called to settle and
87
+ * drains items accepted before the call (items pushed while a flush is
88
+ * running may be included in a batch, but `flush` does not wait for them).
89
+ * Interrupting `flush` only stops the wait without cancelling in-flight
90
+ * exports or dropping queued items.
91
+ *
79
92
  * There is no built-in timeout; use `Effect.timeoutOption` to bound the
80
- * operation. Exporters in their 60-second `disabledUntil` window are skipped.
93
+ * operation. Exporters in their 60-second `disabledUntil` window start no new
94
+ * exports while still awaiting any export already in flight.
81
95
  *
82
96
  * **Example** (Flushing exporters)
83
97
  *
@@ -114,9 +128,10 @@ export class Flusher extends Context.Service<Flusher, {
114
128
  * Registration is scoped — an exporter is removed from the registry when its
115
129
  * own scope closes. Flushing with an empty registry is a no-op.
116
130
  *
117
- * Note that `flush` cannot await an export that was already in flight when it
118
- * was called (for example one started by the export interval); it only waits
119
- * for the exports it initiates.
131
+ * For each registered exporter, `flush` awaits all exports already in flight
132
+ * when it was called and drains every item accepted before the call (or sends
133
+ * one fresh snapshot when `exportEmpty` is enabled). Interrupting `flush` only
134
+ * stops waiting and does not cancel in-flight exports or drop queued items.
120
135
  *
121
136
  * @stability unstable
122
137
  * @category layers
@@ -150,10 +165,13 @@ export const layerFlusher: Layer.Layer<Flusher> = Layer.sync(Flusher, () => {
150
165
  *
151
166
  * **Details**
152
167
  *
153
- * The exporter buffers pushed data, periodically posts encoded batches to the
154
- * configured URL, retries transient failures, temporarily disables exporting
155
- * after unhandled failures, and flushes during scope finalization up to
156
- * `shutdownTimeout`.
168
+ * The exporter buffers pending pushed items up to `maxQueueSize` (dropping new
169
+ * arrivals on overflow and notifying `onDrop`), sends FIFO batches of at most
170
+ * `maxBatchSize` with up to `concurrency` exports (including retries) in flight
171
+ * at a time, temporarily disables exporting after unhandled failures, and
172
+ * drains remaining items during scope finalization up to `shutdownTimeout`.
173
+ * `maxQueueSize` bounds only pending queued items, not batches already in
174
+ * flight.
157
175
  *
158
176
  * The export interval starts with the first push and stops once an export
159
177
  * empties the buffer, so an idle exporter keeps no timer pending. With
@@ -178,6 +196,25 @@ export const make: (
178
196
  readonly label: string
179
197
  readonly exportInterval: Duration.Input
180
198
  readonly maxBatchSize: number | "disabled"
199
+ /**
200
+ * Maximum number of pending items buffered in the queue. Does not count
201
+ * items already dequeued into in-flight export batches. New items pushed
202
+ * while the queue is full are dropped and reported to `onDrop`.
203
+ *
204
+ * Defaults to `2048` (or `maxBatchSize` if larger).
205
+ */
206
+ readonly maxQueueSize?: number | undefined
207
+ /**
208
+ * Maximum number of export requests (including retries) allowed in flight
209
+ * concurrently, or `"unbounded"` for no limit.
210
+ *
211
+ * Defaults to `4`.
212
+ */
213
+ readonly concurrency?: Concurrency | undefined
214
+ /**
215
+ * Synchronous callback invoked when items are dropped due to queue overflow.
216
+ */
217
+ readonly onDrop?: ((count: number) => void) | undefined
181
218
  readonly exportEmpty?: boolean | undefined
182
219
  readonly body: (data: Array<any>) => readonly [body: HttpBody, onSuccess: Effect.Effect<void>]
183
220
  readonly shutdownTimeout: Duration.Input
@@ -191,6 +228,15 @@ export const make: (
191
228
  const clock = Context.get(services, Clock)
192
229
  const scope = Context.get(services, Scope.Scope)
193
230
  const exportInterval = Duration.max(Duration.fromInputUnsafe(options.exportInterval), Duration.zero)
231
+ const batchLimit = options.maxBatchSize === "disabled" ? Infinity : Count.normalizeNonEmpty(options.maxBatchSize)
232
+ const maxQueueSize = options.maxQueueSize === undefined || Number.isNaN(options.maxQueueSize)
233
+ ? Number.isFinite(batchLimit) ? Math.max(2048, batchLimit) : 2048
234
+ : Count.normalize(options.maxQueueSize)
235
+ const concurrency = options.concurrency === "unbounded"
236
+ ? Infinity
237
+ : options.concurrency === undefined || Number.isNaN(options.concurrency)
238
+ ? 4
239
+ : Count.normalizeNonEmpty(options.concurrency)
194
240
 
195
241
  const client = Context.get(services, HttpClient.HttpClient).pipe(
196
242
  HttpClient.tap((response) => Effect.ignore(response.arrayBuffer)),
@@ -211,93 +257,178 @@ export const make: (
211
257
 
212
258
  const request = HttpClientRequest.post(options.url, { headers })
213
259
  const exportsEmpty = options.maxBatchSize === "disabled" && options.exportEmpty === true
214
- let buffer: Array<any> = []
260
+ const queue = MutableList.make<any>()
215
261
  let disabledUntil: number | undefined = undefined
262
+ let closed = false
216
263
  const isDisabled = () => {
217
264
  if (disabledUntil === undefined) return false
218
265
  if (clock.currentTimeMillisUnsafe() < disabledUntil) return true
219
266
  disabledUntil = undefined
220
267
  return false
221
268
  }
269
+ const isStopped = () => closed || isDisabled()
270
+
271
+ // Progress is counted in items, or in snapshots when `exportsEmpty` is set:
272
+ // `requested` is how far callers asked to drain and `started` is how far the
273
+ // batches dequeued so far reach. `inFlight` maps each working fiber to the
274
+ // offset its batch starts at. Offsets only grow and a `Map` keeps insertion
275
+ // order, so its first entry is the earliest export in flight and everything
276
+ // before it has settled, even when batches complete out of order.
277
+ let requested = 0
278
+ let started = 0
279
+ const inFlight = new Map<Fiber.Fiber<unknown, unknown>, number>()
280
+ const settled = () => closed ? Infinity : inFlight.values().next().value ?? started
222
281
 
223
- const runExport = Effect.suspend(() => {
224
- if (isDisabled() || (buffer.length === 0 && !exportsEmpty)) {
225
- return Effect.void
282
+ interface Waiter {
283
+ readonly target: number
284
+ readonly resume: (effect: Effect.Effect<void>) => void
285
+ }
286
+ const waiters = new Set<Waiter>()
287
+ const notifyWaiters = () => {
288
+ const reached = settled()
289
+ for (const waiter of waiters) {
290
+ if (reached >= waiter.target) {
291
+ waiters.delete(waiter)
292
+ waiter.resume(Effect.void)
293
+ }
226
294
  }
227
- const items = buffer
228
- buffer = []
229
- const [body, onSuccess] = options.body(items)
230
- const batchRequest = HttpClientRequest.setBody(request, body)
231
- // Compress before client.execute so transient retries reuse the encoded bytes.
232
- const response = options.compression === "gzip"
233
- ? HttpClientRequest.compressBody(batchRequest, "gzip").pipe(Effect.flatMap(client.execute))
234
- : client.execute(batchRequest)
235
- return response.pipe(
236
- Effect.andThen(onSuccess),
237
- Effect.asVoid,
238
- Effect.withTracerEnabled(false)
239
- )
240
- }).pipe(
241
- Effect.catchCause((cause) => {
242
- if (disabledUntil !== undefined) return Effect.void
243
- disabledUntil = clock.currentTimeMillisUnsafe() + 60_000
244
- buffer = []
245
- return Effect.logWarning("Disabling exporter for 60 seconds", cause)
246
- }),
247
- Effect.annotateLogs({
248
- package: "@effect/opentelemetry",
249
- module: options.label
295
+ }
296
+ const awaitSettled = (target: number): Effect.Effect<void> =>
297
+ Effect.callback((resume) => {
298
+ if (settled() >= target) return resume(Effect.void)
299
+ const waiter: Waiter = { target, resume }
300
+ waiters.add(waiter)
301
+ return Effect.sync(() => {
302
+ waiters.delete(waiter)
303
+ })
250
304
  })
251
- )
252
305
 
253
- const exportFibers = yield* FiberSet.make<void, never>()
254
- const runExportFork = yield* FiberSet.runtime(exportFibers)<never>()
306
+ // `armed` is open while there is something to export. It changes in the
307
+ // same synchronous step as the queue check, so a push is never stranded.
308
+ const armed = yield* Latch.make(exportsEmpty)
309
+ const wake = yield* Latch.make()
255
310
 
256
- yield* Scope.addFinalizer(
257
- scope,
311
+ const exportBatch = (items: Array<any>): Effect.Effect<void> =>
258
312
  Effect.suspend(() => {
259
- if (disabledUntil !== undefined) return Effect.void
260
- runExportFork(runExport)
261
- return FiberSet.awaitEmpty(exportFibers)
313
+ const [body, onSuccess] = options.body(items)
314
+ const batchRequest = HttpClientRequest.setBody(request, body)
315
+ // Compress before client.execute so transient retries reuse the encoded bytes.
316
+ const response = options.compression === "gzip"
317
+ ? HttpClientRequest.compressBody(batchRequest, "gzip").pipe(Effect.flatMap(client.execute))
318
+ : client.execute(batchRequest)
319
+ return response.pipe(
320
+ Effect.andThen(onSuccess),
321
+ Effect.withTracerEnabled(false)
322
+ )
262
323
  }).pipe(
263
- Effect.ignore,
264
- Effect.interruptible,
265
- Effect.timeoutOption(options.shutdownTimeout)
324
+ Effect.catchCause((cause) => {
325
+ MutableList.clear(queue)
326
+ // Nothing queued or requested will start now. Count it as started so
327
+ // waiters only wait for the exports still in flight.
328
+ requested = started = Math.max(started, requested)
329
+ if (isDisabled()) return Effect.void
330
+ disabledUntil = clock.currentTimeMillisUnsafe() + 60_000
331
+ return Effect.logWarning("Disabling exporter for 60 seconds", cause)
332
+ }),
333
+ Effect.annotateLogs({
334
+ package: "@effect/opentelemetry",
335
+ module: options.label
336
+ })
266
337
  )
267
- )
268
338
 
269
- // `armed` is open while there is something to export. It changes in the
270
- // same synchronous step as the buffer check, so a push is never stranded.
271
- const armed = yield* Latch.make(exportsEmpty)
272
- const wake = yield* Latch.make()
273
- const disarmIfEmpty = Effect.sync(() => {
274
- if (exportsEmpty || buffer.length > 0 || !armed.closeUnsafe()) return
275
- wake.openUnsafe()
339
+ // Up to `concurrency` workers run on demand while there is work. The
340
+ // exporter owns them, so interrupting a flush never cancels a request.
341
+ const canStart = () =>
342
+ inFlight.size < concurrency && !isStopped() && (requested > started || queue.length >= batchLimit)
343
+ const workerLoop: Effect.Effect<void> = Effect.withFiber((fiber) => {
344
+ if (!canStart()) return Effect.void
345
+ const items = MutableList.takeN(queue, batchLimit)
346
+ inFlight.set(fiber, started)
347
+ started += exportsEmpty ? 1 : items.length
348
+ // `exit` keeps the worker alive if the failure handler itself dies, for
349
+ // example when a logger throws.
350
+ return Effect.exit(exportBatch(items)).pipe(
351
+ Effect.ensuring(Effect.sync(() => {
352
+ inFlight.delete(fiber)
353
+ if (inFlight.size === 0 && !exportsEmpty && queue.length === 0 && armed.closeUnsafe()) {
354
+ wake.openUnsafe()
355
+ }
356
+ notifyWaiters()
357
+ })),
358
+ Effect.andThen(workerLoop)
359
+ )
276
360
  })
277
- // Forked after the shutdown finalizer, so the loop stops before the shutdown flush.
278
- if (Duration.isFinite(exportInterval)) {
279
- yield* Effect.gen(function*() {
361
+ const runFork = Effect.runForkWith(services)
362
+ // A worker normally claims its batch before `runFork` returns. Stop when it
363
+ // has not, so a scheduler that yields first cannot make this loop spin.
364
+ const startWorkers = () => {
365
+ while (canStart() && inFlight.has(runFork(workerLoop))) {
366
+ // keep starting workers
367
+ }
368
+ }
369
+
370
+ // Exports everything accepted so far, or one fresh snapshot, and waits for
371
+ // it to settle together with every export already in flight. During cooldown,
372
+ // no new export starts, but any surviving in-flight export is still awaited.
373
+ const drain: Effect.Effect<void> = Effect.suspend(() => {
374
+ if (isStopped()) return awaitSettled(started)
375
+ const target = started + (exportsEmpty ? 1 : queue.length)
376
+ requested = Math.max(requested, target)
377
+ startWorkers()
378
+ return awaitSettled(target)
379
+ })
380
+
381
+ const timer = Duration.isFinite(exportInterval)
382
+ ? runFork(Effect.gen(function*() {
280
383
  while (true) {
281
384
  wake.closeUnsafe()
282
385
  yield* armed.await
283
- yield* Effect.race(Effect.sleep(exportInterval), wake.await)
284
- yield* Fiber.await(yield* FiberSet.run(exportFibers, runExport))
285
- yield* disarmIfEmpty
386
+ const expired = yield* Effect.race(
387
+ Effect.as(Effect.sleep(exportInterval), true),
388
+ Effect.as(wake.await, false)
389
+ )
390
+ if (expired) yield* drain
286
391
  }
287
- }).pipe(Effect.forkIn(scope))
288
- }
289
- const exportNow = Effect.andThen(runExport, disarmIfEmpty)
392
+ }))
393
+ : undefined
394
+
395
+ // A single finalizer stops the timer, drains, then stops active workers in
396
+ // that order even in a parallel scope. Workers are interrupted without
397
+ // waiting for them, so shutdown ends at `shutdownTimeout` even if the HTTP
398
+ // client is uninterruptible.
399
+ yield* Scope.addFinalizer(
400
+ scope,
401
+ Effect.suspend(() => {
402
+ timer?.interruptUnsafe()
403
+ return drain.pipe(
404
+ Effect.interruptible,
405
+ Effect.timeoutOption(options.shutdownTimeout),
406
+ Effect.andThen(Effect.sync(() => {
407
+ closed = true
408
+ MutableList.clear(queue)
409
+ notifyWaiters()
410
+ for (const fiber of inFlight.keys()) {
411
+ fiber.interruptUnsafe()
412
+ }
413
+ }))
414
+ )
415
+ })
416
+ )
290
417
 
291
418
  const flusher = yield* Flusher
292
- yield* flusher.register(exportNow)
419
+ yield* flusher.register(drain)
293
420
 
294
421
  return {
295
422
  push(data) {
296
423
  // With no idle timer, the next push ends the disabled window.
297
- if (isDisabled()) return
298
- buffer.push(data)
299
- if (options.maxBatchSize !== "disabled" && buffer.length >= options.maxBatchSize) {
300
- runExportFork(exportNow)
424
+ if (isStopped()) return
425
+ if (queue.length >= maxQueueSize) {
426
+ options.onDrop?.(1)
427
+ return
428
+ }
429
+ MutableList.append(queue, data)
430
+ if (queue.length >= batchLimit) {
431
+ startWorkers()
301
432
  } else {
302
433
  armed.openUnsafe()
303
434
  }
@@ -24,6 +24,7 @@ import type * as LogLevel from "../LogLevel.ts"
24
24
  import * as Option from "../Option.ts"
25
25
  import { CurrentLogAnnotations, CurrentLogSpans } from "../References.ts"
26
26
  import type * as Scope from "../Scope.ts"
27
+ import type { Concurrency } from "../Types.ts"
27
28
  import * as Version from "../Version.ts"
28
29
  import * as OtlpEnv from "./internal/otlpEnv.ts"
29
30
  import * as Exporter from "./OtlpExporter.ts"
@@ -60,6 +61,11 @@ export const make: (
60
61
  readonly compression?: "gzip" | "none" | undefined
61
62
  readonly exportInterval?: Duration.Input | undefined
62
63
  readonly maxBatchSize?: number | undefined
64
+ /** Maximum pending queued log records (does not include in-flight batches). */
65
+ readonly maxQueueSize?: number | undefined
66
+ /** Maximum concurrent export requests, or `"unbounded"`. Defaults to `4`. */
67
+ readonly concurrency?: Concurrency | undefined
68
+ readonly onDrop?: ((count: number) => void) | undefined
63
69
  readonly shutdownTimeout?: Duration.Input | undefined
64
70
  readonly excludeLogSpans?: boolean | undefined
65
71
  }
@@ -81,6 +87,9 @@ export const make: (
81
87
  headers: options.headers,
82
88
  compression: options.compression,
83
89
  maxBatchSize: options.maxBatchSize ?? 1000,
90
+ maxQueueSize: options.maxQueueSize,
91
+ concurrency: options.concurrency,
92
+ onDrop: options.onDrop,
84
93
  exportInterval: options.exportInterval ?? Duration.seconds(1),
85
94
  body: (data) => [
86
95
  serialization.logs({
@@ -132,6 +141,11 @@ export const layer = (options: {
132
141
  readonly compression?: "gzip" | "none" | undefined
133
142
  readonly exportInterval?: Duration.Input | undefined
134
143
  readonly maxBatchSize?: number | undefined
144
+ /** Maximum pending queued log records (does not include in-flight batches). */
145
+ readonly maxQueueSize?: number | undefined
146
+ /** Maximum concurrent export requests, or `"unbounded"`. Defaults to `4`. */
147
+ readonly concurrency?: Concurrency | undefined
148
+ readonly onDrop?: ((count: number) => void) | undefined
135
149
  readonly shutdownTimeout?: Duration.Input | undefined
136
150
  readonly excludeLogSpans?: boolean | undefined
137
151
  readonly mergeWithExisting?: boolean | undefined
@@ -161,6 +175,9 @@ export const layerFromConfig = (options?: {
161
175
  readonly attributes?: Record<string, unknown>
162
176
  } | undefined
163
177
  readonly headers?: Headers.Input | undefined
178
+ /** Maximum concurrent export requests, or `"unbounded"`. Defaults to `4`. */
179
+ readonly concurrency?: Concurrency | undefined
180
+ readonly onDrop?: ((count: number) => void) | undefined
164
181
  readonly excludeLogSpans?: boolean | undefined
165
182
  readonly mergeWithExisting?: boolean | undefined
166
183
  }): Layer.Layer<Exporter.Flusher, never, HttpClient.HttpClient | OtlpSerialization> =>
@@ -182,7 +199,8 @@ export const layerFromConfig = (options?: {
182
199
  logsTimeout,
183
200
  exportTimeout,
184
201
  scheduleDelay,
185
- maxBatchSize
202
+ maxBatchSize,
203
+ maxQueueSize
186
204
  } = yield* Config.all({
187
205
  baseCompression: Config.option(Config.Literals(["gzip", "none"], "OTEL_EXPORTER_OTLP_COMPRESSION")),
188
206
  compression: Config.option(Config.Literals(["gzip", "none"], "OTEL_EXPORTER_OTLP_LOGS_COMPRESSION")),
@@ -190,7 +208,8 @@ export const layerFromConfig = (options?: {
190
208
  logsTimeout: Config.option(Config.Int("OTEL_EXPORTER_OTLP_LOGS_TIMEOUT")),
191
209
  exportTimeout: Config.option(Config.Int("OTEL_BLRP_EXPORT_TIMEOUT")),
192
210
  scheduleDelay: Config.option(Config.Int("OTEL_BLRP_SCHEDULE_DELAY")),
193
- maxBatchSize: Config.option(Config.Int("OTEL_BLRP_MAX_EXPORT_BATCH_SIZE"))
211
+ maxBatchSize: Config.option(Config.Int("OTEL_BLRP_MAX_EXPORT_BATCH_SIZE")),
212
+ maxQueueSize: Config.option(Config.Int("OTEL_BLRP_MAX_QUEUE_SIZE"))
194
213
  })
195
214
 
196
215
  const shutdownTimeout = Option.firstSomeOf([logsTimeout, baseTimeout, exportTimeout]).pipe(
@@ -205,6 +224,9 @@ export const layerFromConfig = (options?: {
205
224
  compression: Option.getOrElse(Option.firstSomeOf([compression, baseCompression]), () => "none" as const),
206
225
  exportInterval: Option.getOrUndefined(exportInterval),
207
226
  maxBatchSize: Option.getOrUndefined(maxBatchSize),
227
+ maxQueueSize: Option.getOrUndefined(maxQueueSize),
228
+ concurrency: options?.concurrency,
229
+ onDrop: options?.onDrop,
208
230
  shutdownTimeout: Option.getOrUndefined(shutdownTimeout),
209
231
  excludeLogSpans: options?.excludeLogSpans,
210
232
  mergeWithExisting: options?.mergeWithExisting
@@ -396,6 +396,8 @@ export const make: (options: {
396
396
  headers: options.headers,
397
397
  compression: options.compression,
398
398
  maxBatchSize: "disabled",
399
+ // Each snapshot builds on the last one committed, so they go out one at a time.
400
+ concurrency: 1,
399
401
  exportEmpty: true,
400
402
  exportInterval: options.exportInterval ?? Duration.seconds(10),
401
403
  body: snapshot,
@@ -25,7 +25,7 @@ import * as Layer from "../Layer.ts"
25
25
  import * as Option from "../Option.ts"
26
26
  import type * as Scope from "../Scope.ts"
27
27
  import * as Tracer from "../Tracer.ts"
28
- import type { ExtractTag } from "../Types.ts"
28
+ import type { Concurrency, ExtractTag } from "../Types.ts"
29
29
  import * as Version from "../Version.ts"
30
30
  import * as OtlpEnv from "./internal/otlpEnv.ts"
31
31
  import * as Exporter from "./OtlpExporter.ts"
@@ -62,6 +62,11 @@ export const make: (
62
62
  readonly compression?: "gzip" | "none" | undefined
63
63
  readonly exportInterval?: Duration.Input | undefined
64
64
  readonly maxBatchSize?: number | undefined
65
+ /** Maximum pending queued spans (does not include in-flight batches). */
66
+ readonly maxQueueSize?: number | undefined
67
+ /** Maximum concurrent export requests, or `"unbounded"`. Defaults to `4`. */
68
+ readonly concurrency?: Concurrency | undefined
69
+ readonly onDrop?: ((count: number) => void) | undefined
65
70
  readonly context?: (<X>(primitive: Tracer.EffectPrimitive<X>, span: Tracer.AnySpan) => X) | undefined
66
71
  readonly shutdownTimeout?: Duration.Input | undefined
67
72
  }
@@ -84,6 +89,9 @@ export const make: (
84
89
  compression: options.compression,
85
90
  exportInterval: options.exportInterval ?? Duration.seconds(5),
86
91
  maxBatchSize: options.maxBatchSize ?? 1000,
92
+ maxQueueSize: options.maxQueueSize,
93
+ concurrency: options.concurrency,
94
+ onDrop: options.onDrop,
87
95
  body(spans) {
88
96
  const data: TraceData = {
89
97
  resourceSpans: [{
@@ -141,6 +149,11 @@ export const layer: (options: {
141
149
  readonly compression?: "gzip" | "none" | undefined
142
150
  readonly exportInterval?: Duration.Input | undefined
143
151
  readonly maxBatchSize?: number | undefined
152
+ /** Maximum pending queued spans (does not include in-flight batches). */
153
+ readonly maxQueueSize?: number | undefined
154
+ /** Maximum concurrent export requests, or `"unbounded"`. Defaults to `4`. */
155
+ readonly concurrency?: Concurrency | undefined
156
+ readonly onDrop?: ((count: number) => void) | undefined
144
157
  readonly context?: (<X>(primitive: Tracer.EffectPrimitive<X>, span: Tracer.AnySpan) => X) | undefined
145
158
  readonly shutdownTimeout?: Duration.Input | undefined
146
159
  }) => Layer.Layer<Exporter.Flusher, never, OtlpSerialization | HttpClient.HttpClient> = flow(
@@ -170,6 +183,9 @@ export const layerFromConfig = (options?: {
170
183
  readonly attributes?: Record<string, unknown>
171
184
  } | undefined
172
185
  readonly headers?: Headers.Input | undefined
186
+ /** Maximum concurrent export requests, or `"unbounded"`. Defaults to `4`. */
187
+ readonly concurrency?: Concurrency | undefined
188
+ readonly onDrop?: ((count: number) => void) | undefined
173
189
  readonly context?: (<X>(primitive: Tracer.EffectPrimitive<X>, span: Tracer.AnySpan) => X) | undefined
174
190
  }): Layer.Layer<Exporter.Flusher, never, HttpClient.HttpClient | OtlpSerialization> =>
175
191
  Effect.gen(function*() {
@@ -190,7 +206,8 @@ export const layerFromConfig = (options?: {
190
206
  tracesTimeout,
191
207
  exportTimeout,
192
208
  scheduleDelay,
193
- maxBatchSize
209
+ maxBatchSize,
210
+ maxQueueSize
194
211
  } = yield* Config.all({
195
212
  baseCompression: Config.option(Config.Literals(["gzip", "none"], "OTEL_EXPORTER_OTLP_COMPRESSION")),
196
213
  compression: Config.option(Config.Literals(["gzip", "none"], "OTEL_EXPORTER_OTLP_TRACES_COMPRESSION")),
@@ -202,7 +219,8 @@ export const layerFromConfig = (options?: {
202
219
  Config.map(Duration.millis)
203
220
  )
204
221
  ),
205
- maxBatchSize: Config.option(Config.Int("OTEL_BSP_MAX_EXPORT_BATCH_SIZE"))
222
+ maxBatchSize: Config.option(Config.Int("OTEL_BSP_MAX_EXPORT_BATCH_SIZE")),
223
+ maxQueueSize: Config.option(Config.Int("OTEL_BSP_MAX_QUEUE_SIZE"))
206
224
  })
207
225
 
208
226
  const shutdownTimeout = Option.firstSomeOf([tracesTimeout, baseTimeout, exportTimeout]).pipe(
@@ -216,6 +234,9 @@ export const layerFromConfig = (options?: {
216
234
  compression: Option.getOrElse(Option.firstSomeOf([compression, baseCompression]), () => "none" as const),
217
235
  exportInterval: Option.getOrUndefined(scheduleDelay),
218
236
  maxBatchSize: Option.getOrUndefined(maxBatchSize),
237
+ maxQueueSize: Option.getOrUndefined(maxQueueSize),
238
+ concurrency: options?.concurrency,
239
+ onDrop: options?.onDrop,
219
240
  context: options?.context,
220
241
  shutdownTimeout: Option.getOrUndefined(shutdownTimeout)
221
242
  })
@@ -432,6 +432,8 @@ export const layerMemory: Layer.Layer<KeyValueStore> = Layer.sync(KeyValueStore)
432
432
  })
433
433
  })
434
434
 
435
+ const utf8Decoder = new TextDecoder("utf-8", { ignoreBOM: true })
436
+
435
437
  /**
436
438
  * Provides a `KeyValueStore` backed by files in the specified directory.
437
439
  *
@@ -476,18 +478,20 @@ export const layerFileSystem = (
476
478
  return make({
477
479
  get: (key: string) =>
478
480
  withKeyPath("get", key, (path) =>
479
- Effect.catchTag(
480
- fs.readFileString(path),
481
- "PlatformError",
482
- (cause) =>
483
- cause.reason._tag === "NotFound" ? Effect.undefined : Effect.fail(
484
- new KeyValueStoreError({
485
- method: "get",
486
- key,
487
- message: `Unable to get item with key ${key}`,
488
- cause
489
- })
490
- )
481
+ fs.readFile(path).pipe(
482
+ Effect.map((bytes) => utf8Decoder.decode(bytes)),
483
+ Effect.catchTag(
484
+ "PlatformError",
485
+ (cause) =>
486
+ cause.reason._tag === "NotFound" ? Effect.undefined : Effect.fail(
487
+ new KeyValueStoreError({
488
+ method: "get",
489
+ key,
490
+ message: `Unable to get item with key ${key}`,
491
+ cause
492
+ })
493
+ )
494
+ )
491
495
  )),
492
496
  getUint8Array: (key: string) =>
493
497
  withKeyPath("getUint8Array", key, (path) =>
@@ -735,7 +739,6 @@ export const layerSql = (
735
739
  })
736
740
 
737
741
  const encoder = new TextEncoder()
738
- const decoder = new TextDecoder()
739
742
  const ValueTypeString = 0
740
743
  const ValueTypeUint8Array = 1
741
744
 
@@ -762,7 +765,7 @@ export const layerSql = (
762
765
  const row = rows[0]
763
766
  switch (row.value_type) {
764
767
  case ValueTypeString:
765
- return Effect.succeed(decoder.decode(row.value))
768
+ return Effect.succeed(utf8Decoder.decode(row.value))
766
769
  case ValueTypeUint8Array:
767
770
  return Effect.succeed(Base64.encode(row.value))
768
771
  default: