@encore.dev/sdk 2.0.0-beta.14 → 2.0.0-beta.16

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 (269) hide show
  1. package/README.md +144 -90
  2. package/app_meta.ts +56 -54
  3. package/config/config.test.ts +47 -13
  4. package/config/config.ts +60 -57
  5. package/config/secrets.ts +47 -50
  6. package/config/value.ts +23 -26
  7. package/cron/mod.test.ts +12 -0
  8. package/cron/mod.ts +37 -22
  9. package/dist/app_meta.d.ts +52 -50
  10. package/dist/app_meta.d.ts.map +1 -1
  11. package/dist/app_meta.js +2 -2
  12. package/dist/app_meta.js.map +1 -1
  13. package/dist/config/config.d.ts +58 -55
  14. package/dist/config/config.d.ts.map +1 -1
  15. package/dist/config/config.js +8 -9
  16. package/dist/config/config.js.map +1 -1
  17. package/dist/config/secrets.d.ts +45 -50
  18. package/dist/config/secrets.d.ts.map +1 -1
  19. package/dist/config/secrets.js +11 -9
  20. package/dist/config/secrets.js.map +1 -1
  21. package/dist/config/value.d.ts +20 -23
  22. package/dist/config/value.d.ts.map +1 -1
  23. package/dist/config/value.js +20 -23
  24. package/dist/config/value.js.map +1 -1
  25. package/dist/cron/mod.d.ts +34 -20
  26. package/dist/cron/mod.d.ts.map +1 -1
  27. package/dist/cron/mod.js +13 -13
  28. package/dist/cron/mod.js.map +1 -1
  29. package/dist/frontends/mod.d.ts +20 -19
  30. package/dist/frontends/mod.d.ts.map +1 -1
  31. package/dist/frontends/mod.js +20 -19
  32. package/dist/frontends/mod.js.map +1 -1
  33. package/dist/gateway/errors.d.ts +28 -30
  34. package/dist/gateway/errors.d.ts.map +1 -1
  35. package/dist/gateway/errors.js +29 -31
  36. package/dist/gateway/errors.js.map +1 -1
  37. package/dist/gateway/match.d.ts +54 -54
  38. package/dist/gateway/match.d.ts.map +1 -1
  39. package/dist/gateway/match.js +56 -56
  40. package/dist/gateway/match.js.map +1 -1
  41. package/dist/gateway/middleware.d.ts +62 -64
  42. package/dist/gateway/middleware.d.ts.map +1 -1
  43. package/dist/gateway/middleware.js +1 -1
  44. package/dist/gateway/middleware.js.map +1 -1
  45. package/dist/gateway/mod.d.ts +64 -67
  46. package/dist/gateway/mod.d.ts.map +1 -1
  47. package/dist/gateway/mod.js +72 -76
  48. package/dist/gateway/mod.js.map +1 -1
  49. package/dist/gateway/request.d.ts +138 -134
  50. package/dist/gateway/request.d.ts.map +1 -1
  51. package/dist/gateway/request.js +117 -108
  52. package/dist/gateway/request.js.map +1 -1
  53. package/dist/gateway/serve.d.ts +29 -34
  54. package/dist/gateway/serve.d.ts.map +1 -1
  55. package/dist/gateway/serve.js +51 -56
  56. package/dist/gateway/serve.js.map +1 -1
  57. package/dist/gateways/mod.d.ts +23 -21
  58. package/dist/gateways/mod.d.ts.map +1 -1
  59. package/dist/gateways/mod.js +25 -23
  60. package/dist/gateways/mod.js.map +1 -1
  61. package/dist/internal/otel/http.d.ts +4 -2
  62. package/dist/internal/otel/http.d.ts.map +1 -1
  63. package/dist/internal/otel/http.js +32 -5
  64. package/dist/internal/otel/http.js.map +1 -1
  65. package/dist/internal/runtime/napi/napi.cjs +6 -5
  66. package/dist/internal/runtime/napi/napi.d.cts +58 -16
  67. package/dist/internal/runtime/shutdown.d.ts +75 -57
  68. package/dist/internal/runtime/shutdown.d.ts.map +1 -1
  69. package/dist/internal/runtime/shutdown.js +88 -84
  70. package/dist/internal/runtime/shutdown.js.map +1 -1
  71. package/dist/log/logger.d.ts +43 -37
  72. package/dist/log/logger.d.ts.map +1 -1
  73. package/dist/log/logger.js +26 -25
  74. package/dist/log/logger.js.map +1 -1
  75. package/dist/metrics/mod.d.ts +133 -114
  76. package/dist/metrics/mod.d.ts.map +1 -1
  77. package/dist/metrics/mod.js +109 -101
  78. package/dist/metrics/mod.js.map +1 -1
  79. package/dist/otel.d.ts +6 -3
  80. package/dist/otel.d.ts.map +1 -1
  81. package/dist/otel.js +6 -3
  82. package/dist/otel.js.map +1 -1
  83. package/dist/pubsub/subscription.d.ts +88 -116
  84. package/dist/pubsub/subscription.d.ts.map +1 -1
  85. package/dist/pubsub/subscription.js +14 -17
  86. package/dist/pubsub/subscription.js.map +1 -1
  87. package/dist/pubsub/topic.d.ts +86 -113
  88. package/dist/pubsub/topic.d.ts.map +1 -1
  89. package/dist/pubsub/topic.js +68 -82
  90. package/dist/pubsub/topic.js.map +1 -1
  91. package/dist/redaction/mod.d.ts +62 -0
  92. package/dist/redaction/mod.d.ts.map +1 -0
  93. package/dist/redaction/mod.js +102 -0
  94. package/dist/redaction/mod.js.map +1 -0
  95. package/dist/reqctx/mod.d.ts +83 -86
  96. package/dist/reqctx/mod.d.ts.map +1 -1
  97. package/dist/reqctx/mod.js +39 -41
  98. package/dist/reqctx/mod.js.map +1 -1
  99. package/dist/services/index.d.ts +76 -75
  100. package/dist/services/index.d.ts.map +1 -1
  101. package/dist/services/index.js +73 -71
  102. package/dist/services/index.js.map +1 -1
  103. package/dist/shutdown/mod.d.ts +26 -25
  104. package/dist/shutdown/mod.d.ts.map +1 -1
  105. package/dist/shutdown/mod.js +26 -25
  106. package/dist/shutdown/mod.js.map +1 -1
  107. package/dist/storage/clickhouse/database.d.ts +113 -115
  108. package/dist/storage/clickhouse/database.d.ts.map +1 -1
  109. package/dist/storage/clickhouse/database.js +65 -79
  110. package/dist/storage/clickhouse/database.js.map +1 -1
  111. package/dist/storage/clickhouse/errors.d.ts +25 -26
  112. package/dist/storage/clickhouse/errors.d.ts.map +1 -1
  113. package/dist/storage/clickhouse/errors.js +15 -17
  114. package/dist/storage/clickhouse/errors.js.map +1 -1
  115. package/dist/storage/clickhouse/mod.d.ts +10 -10
  116. package/dist/storage/clickhouse/mod.js +10 -10
  117. package/dist/storage/objects/bucket.d.ts +230 -203
  118. package/dist/storage/objects/bucket.d.ts.map +1 -1
  119. package/dist/storage/objects/bucket.js +146 -106
  120. package/dist/storage/objects/bucket.js.map +1 -1
  121. package/dist/storage/objects/error.d.ts +4 -4
  122. package/dist/storage/objects/error.js +4 -4
  123. package/dist/storage/objects/mod.d.ts +1 -1
  124. package/dist/storage/objects/mod.d.ts.map +1 -1
  125. package/dist/storage/objects/mod.js.map +1 -1
  126. package/dist/storage/objects/refs.d.ts +2 -5
  127. package/dist/storage/objects/refs.d.ts.map +1 -1
  128. package/dist/storage/objects/refs.js.map +1 -1
  129. package/dist/storage/postgres/database.d.ts +124 -149
  130. package/dist/storage/postgres/database.d.ts.map +1 -1
  131. package/dist/storage/postgres/database.js +98 -135
  132. package/dist/storage/postgres/database.js.map +1 -1
  133. package/dist/storage/postgres/errors.d.ts +42 -48
  134. package/dist/storage/postgres/errors.d.ts.map +1 -1
  135. package/dist/storage/postgres/errors.js +44 -51
  136. package/dist/storage/postgres/errors.js.map +1 -1
  137. package/dist/storage/postgres/interval.d.ts +19 -19
  138. package/dist/storage/postgres/interval.d.ts.map +1 -1
  139. package/dist/storage/postgres/interval.js +21 -21
  140. package/dist/storage/postgres/interval.js.map +1 -1
  141. package/dist/storage/redis/bitfield.d.ts +48 -23
  142. package/dist/storage/redis/bitfield.d.ts.map +1 -1
  143. package/dist/storage/redis/bitfield.js +38 -19
  144. package/dist/storage/redis/bitfield.js.map +1 -1
  145. package/dist/storage/redis/command.d.ts +16 -12
  146. package/dist/storage/redis/command.d.ts.map +1 -1
  147. package/dist/storage/redis/command.js +16 -12
  148. package/dist/storage/redis/command.js.map +1 -1
  149. package/dist/storage/redis/commands.d.ts +99 -100
  150. package/dist/storage/redis/commands.d.ts.map +1 -1
  151. package/dist/storage/redis/commands.js +84 -85
  152. package/dist/storage/redis/commands.js.map +1 -1
  153. package/dist/storage/redis/database.d.ts +138 -122
  154. package/dist/storage/redis/database.d.ts.map +1 -1
  155. package/dist/storage/redis/database.js +120 -101
  156. package/dist/storage/redis/database.js.map +1 -1
  157. package/dist/storage/redis/mod.d.ts +52 -48
  158. package/dist/storage/redis/mod.d.ts.map +1 -1
  159. package/dist/storage/redis/mod.js +52 -48
  160. package/dist/storage/redis/mod.js.map +1 -1
  161. package/dist/storage/redis/options.d.ts +26 -24
  162. package/dist/storage/redis/options.d.ts.map +1 -1
  163. package/dist/storage/redis/options.js.map +1 -1
  164. package/dist/storage/redis/pubsub.d.ts +16 -16
  165. package/dist/storage/redis/pubsub.d.ts.map +1 -1
  166. package/dist/storage/redis/pubsub.js +14 -14
  167. package/dist/storage/redis/pubsub.js.map +1 -1
  168. package/dist/storage/redis/reply.d.ts +80 -72
  169. package/dist/storage/redis/reply.d.ts.map +1 -1
  170. package/dist/storage/redis/reply.js +53 -46
  171. package/dist/storage/redis/reply.js.map +1 -1
  172. package/dist/storage/redis/scan.d.ts +4 -4
  173. package/dist/storage/redis/scan.d.ts.map +1 -1
  174. package/dist/storage/redis/scan.js +6 -6
  175. package/dist/storage/redis/scan.js.map +1 -1
  176. package/dist/storage/redis/script.d.ts +28 -21
  177. package/dist/storage/redis/script.d.ts.map +1 -1
  178. package/dist/storage/redis/script.js +29 -22
  179. package/dist/storage/redis/script.js.map +1 -1
  180. package/dist/storage/redis/target.d.ts +17 -1
  181. package/dist/storage/redis/target.d.ts.map +1 -1
  182. package/dist/storage/redis/target.js +30 -1
  183. package/dist/storage/redis/target.js.map +1 -1
  184. package/dist/storage/redis/wire.d.ts +6 -6
  185. package/dist/storage/redis/wire.d.ts.map +1 -1
  186. package/dist/storage/redis/wire.js +6 -6
  187. package/dist/storage/redis/wire.js.map +1 -1
  188. package/dist/testing/mod.d.ts +83 -88
  189. package/dist/testing/mod.d.ts.map +1 -1
  190. package/dist/testing/mod.js +75 -81
  191. package/dist/testing/mod.js.map +1 -1
  192. package/dist/testing/playwright.d.ts +28 -32
  193. package/dist/testing/playwright.d.ts.map +1 -1
  194. package/dist/testing/playwright.js +22 -27
  195. package/dist/testing/playwright.js.map +1 -1
  196. package/dist/testing/puppeteer.d.ts +11 -12
  197. package/dist/testing/puppeteer.d.ts.map +1 -1
  198. package/dist/testing/puppeteer.js +17 -18
  199. package/dist/testing/puppeteer.js.map +1 -1
  200. package/dist/testing/system.d.ts +72 -90
  201. package/dist/testing/system.d.ts.map +1 -1
  202. package/dist/testing/system.js +90 -107
  203. package/dist/testing/system.js.map +1 -1
  204. package/dist/tracing/http.d.ts +2 -1
  205. package/dist/tracing/http.d.ts.map +1 -1
  206. package/dist/tracing/http.js +2 -1
  207. package/dist/tracing/http.js.map +1 -1
  208. package/dist/tracing/node.d.ts.map +1 -1
  209. package/dist/tracing/node.js +1 -1
  210. package/dist/tracing/node.js.map +1 -1
  211. package/dist/tsconfig.build.tsbuildinfo +1 -1
  212. package/frontends/mod.test.ts +6 -2
  213. package/frontends/mod.ts +20 -19
  214. package/gateway/errors.ts +30 -32
  215. package/gateway/match.ts +61 -57
  216. package/gateway/middleware.ts +62 -64
  217. package/gateway/mod.ts +73 -76
  218. package/gateway/request.ts +143 -140
  219. package/gateway/serve.ts +58 -63
  220. package/gateways/mod.ts +25 -23
  221. package/internal/otel/http.test.ts +50 -0
  222. package/internal/otel/http.ts +40 -5
  223. package/internal/runtime/napi/napi.cjs +6 -5
  224. package/internal/runtime/napi/napi.d.cts +58 -16
  225. package/internal/runtime/shutdown.ts +113 -101
  226. package/log/logger.test.ts +8 -0
  227. package/log/logger.ts +48 -45
  228. package/metrics/mod.ts +138 -122
  229. package/otel.ts +6 -3
  230. package/package.json +6 -1
  231. package/pubsub/subscription.ts +93 -123
  232. package/pubsub/topic.ts +96 -130
  233. package/redaction/bridge.test.ts +99 -0
  234. package/redaction/mod.test.ts +188 -0
  235. package/redaction/mod.ts +226 -0
  236. package/reqctx/mod.ts +83 -86
  237. package/services/index.ts +78 -78
  238. package/shutdown/mod.ts +26 -25
  239. package/storage/clickhouse/database.ts +115 -129
  240. package/storage/clickhouse/errors.ts +27 -29
  241. package/storage/clickhouse/mod.ts +10 -10
  242. package/storage/objects/bucket.test.ts +168 -16
  243. package/storage/objects/bucket.ts +336 -247
  244. package/storage/objects/error.ts +4 -4
  245. package/storage/objects/mod.ts +1 -0
  246. package/storage/objects/refs.ts +2 -5
  247. package/storage/postgres/database.ts +131 -164
  248. package/storage/postgres/errors.ts +45 -52
  249. package/storage/postgres/interval.ts +21 -21
  250. package/storage/redis/bitfield.ts +51 -26
  251. package/storage/redis/command.ts +16 -12
  252. package/storage/redis/commands.ts +99 -100
  253. package/storage/redis/database.ts +145 -123
  254. package/storage/redis/mod.ts +52 -48
  255. package/storage/redis/options.ts +26 -24
  256. package/storage/redis/pubsub.ts +14 -14
  257. package/storage/redis/redis.test.ts +17 -2
  258. package/storage/redis/reply.ts +85 -77
  259. package/storage/redis/scan.ts +6 -6
  260. package/storage/redis/script.ts +29 -22
  261. package/storage/redis/target.ts +34 -1
  262. package/storage/redis/wire.ts +8 -8
  263. package/testing/mod.ts +99 -105
  264. package/testing/playwright.ts +32 -37
  265. package/testing/puppeteer.ts +22 -23
  266. package/testing/system.ts +117 -133
  267. package/tracing/http.ts +2 -1
  268. package/tracing/native.test.ts +158 -8
  269. package/tracing/node.ts +1 -0
package/metrics/mod.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  /**
2
- * Metrics: counters, up-down counters, histograms and gauges of what an app
3
- * does.
2
+ * Application metrics: counters, up-down counters, histograms, and gauges.
4
3
  *
5
- * A metric is declared at module level and used wherever the thing it
6
- * measures happens. Its JSDoc comment, else its `description` option, is
7
- * its description:
4
+ * Declare metrics at module level and record to them wherever the measured
5
+ * event occurs. A metric's JSDoc comment is used as its description (falling
6
+ * back to the `description` option):
8
7
  *
9
8
  * ```typescript
10
9
  * import { Counter, Histogram } from "@encore.dev/sdk/metrics";
@@ -19,28 +18,25 @@
19
18
  * uploadSize.record(2048);
20
19
  * ```
21
20
  *
22
- * Each is an instrument of the OpenTelemetry Metrics API
23
- * (`@opentelemetry/api`), of the meter `encore`, named as declared, a
24
- * service's own prefixed with its service's name (`orders_placed` of the
25
- * service `shop` is exported as `shop.orders_placed`), created when it is
26
- * first recorded to, recording through Encore's meter provider whatever the
27
- * global one is. Instruments of the API itself made with it
28
- * (`meterProvider().getMeter(…)`) are exported alongside: observable
29
- * instruments are made with it.
21
+ * Each metric is backed by an OpenTelemetry Metrics API (`@opentelemetry/api`)
22
+ * instrument on the `encore` meter, created lazily on first use and exported
23
+ * through Encore's meter provider regardless of any global provider.
24
+ * Service-scoped metrics are exported with their service name as a prefix
25
+ * (e.g. `orders_placed` in service `shop` is exported as `shop.orders_placed`).
26
+ * Custom OpenTelemetry instruments created via `meterProvider().getMeter(...)`
27
+ * — such as observable instruments — are exported alongside Encore metrics.
30
28
  *
31
- * A metric's `scope` option says who records to it: by default
32
- * (`"service"`) it belongs to the declaring service, which alone records to
33
- * it; a `"shared"` one is shared between services, each that records to it
34
- * tracked as using it; a `"global"` one is the whole app's, recorded to from
35
- * any code, untracked. It is written as a string literal, for Encore to
36
- * read:
29
+ * Use the `scope` option (as a string literal) to control which services can
30
+ * record to a metric:
31
+ * - `"service"` (default): owned by the declaring service alone.
32
+ * - `"shared"`: shared across services, with each recording service tracked.
33
+ * - `"global"`: app-wide and recordable from any code without usage tracking.
37
34
  *
38
35
  * ```typescript
39
36
  * export const signups = new Counter("signups", { scope: "shared" });
40
37
  * ```
41
38
  *
42
- * The `…Group` classes take a label type, whose fields are the attributes of
43
- * what is recorded:
39
+ * Use the `*Group` classes to attach typed labels as metric attributes:
44
40
  *
45
41
  * ```typescript
46
42
  * import { CounterGroup } from "@encore.dev/sdk/metrics";
@@ -55,12 +51,11 @@
55
51
  * requests.with({ method: "GET", status: 200 }).increment();
56
52
  * ```
57
53
  *
58
- * A shared or global metric is declared once in the app, as a shared
59
- * secret is. Other code records to it by importing the declaration, or,
60
- * from another service in another language, binds it by name with
61
- * `named`, which states the declaration's kind and labels and takes its
62
- * scope, unit, description and buckets. A bound metric is exported as
63
- * declared, never prefixed.
54
+ * Like shared secrets, a shared or global metric is declared once in the app.
55
+ * Other services record to it by importing the declaration, or (for example,
56
+ * across languages) by binding it by name with `named(...)`, which inherits the
57
+ * declaration's scope, unit, description, and buckets. Bound metrics are
58
+ * exported as declared without a service prefix:
64
59
  *
65
60
  * ```typescript
66
61
  * import { CounterGroup } from "@encore.dev/sdk/metrics";
@@ -68,8 +63,8 @@
68
63
  * const served = CounterGroup.named<Served>("greetings.served");
69
64
  * ```
70
65
  *
71
- * To hand a metric to other code, pass its `ref()`: it counts as recording
72
- * to it.
66
+ * To pass a metric handle to helper functions or other modules, pass `ref()`
67
+ * (calling `ref()` counts as recording to the metric).
73
68
  *
74
69
  * @module
75
70
  */
@@ -81,50 +76,57 @@ import {StringLiteral} from '../internal/utils/constraints';
81
76
  export {meterProvider};
82
77
  export type {MeterProvider} from '../internal/otel/meter';
83
78
 
84
- /** The options every metric is declared with. */
79
+ /** Common options for declaring a metric. */
85
80
  export interface MetricOptions {
86
- /** Who records to the metric, written as a string literal:
87
- * `"service"`, the default, the declaring service alone, the metric
88
- * exported as `<service>.<name>`; `"shared"`, the services that record to
89
- * it, each tracked as using it; `"global"`, any code, untracked. A shared
90
- * or global metric is exported as declared. */
81
+ /**
82
+ * Controls which services can record to this metric. Must be a string
83
+ * literal:
84
+ * - `"service"` (default): only the declaring service; exported as
85
+ * `<service>.<name>`.
86
+ * - `"shared"`: any service, with each recording service tracked; exported
87
+ * as declared.
88
+ * - `"global"`: any code, untracked; exported as declared.
89
+ */
91
90
  scope?: 'service' | 'shared' | 'global';
92
- /** What the metric measures in, as exported: `"s"`, `"By"`,
93
- * `"{request}"` ([UCUM](https://ucum.org/ucum)). */
91
+ /** Unit of measurement using [UCUM](https://ucum.org/ucum) syntax (e.g. `"s"`, `"By"`, `"{request}"`). */
94
92
  unit?: string;
95
- /** What the metric measures, for one without a JSDoc comment. */
93
+ /** Human-readable description used when the declaration has no JSDoc comment. */
96
94
  description?: string;
97
95
  /**
98
- * Tags that classify the metric, for policies to read: written out as
99
- * string literals, as in `{data: "pci"}`. Keys and values are lowercase
100
- * letters, digits, `_` and `-`, at most 63 characters; a key starts with a
101
- * letter, and not with `encore`, which is reserved. At most 32 tags.
96
+ * Static string-literal tags that classify the metric for policy checks
97
+ * (e.g. `{data: "pci"}`). Keys and values may contain lowercase letters,
98
+ * digits, `_`, and `-`, up to 63 characters. Keys must start with a letter
99
+ * and cannot start with the reserved prefix `encore`. At most 32 tags.
102
100
  */
103
101
  tags?: Record<string, string>;
104
102
  }
105
103
 
106
- /** The options a histogram is declared with. */
104
+ /** Options for declaring a histogram metric. */
107
105
  export interface HistogramOptions extends MetricOptions {
108
- /** The upper bounds of the buckets, increasing: what is recorded is
109
- * counted in the first it is no greater than, or one past the last.
110
- * Without them, the OpenTelemetry defaults. */
106
+ /**
107
+ * Strictly increasing upper bounds for histogram buckets. Each recorded value
108
+ * falls into the first bucket whose bound is greater than or equal to it (or
109
+ * the overflow bucket above the last bound). Uses OpenTelemetry defaults when
110
+ * omitted.
111
+ */
111
112
  buckets?: number[];
112
113
  }
113
114
 
114
- /** A metric group's labels: an interface or type whose fields are strings,
115
- * numbers or booleans. Each field is a label, named as the field in
116
- * snake_case. A number is recorded as an integer, its value floored
117
- * (`Math.floor`): `200.7` is `200`. */
115
+ /**
116
+ * Label type for a metric group: an interface or type whose fields are strings,
117
+ * numbers, or booleans. Field names are converted to `snake_case` attribute
118
+ * keys, and numbers are floored to integers (`Math.floor`, so `200.7` becomes
119
+ * `200`).
120
+ */
118
121
  export type Labels<L> = {[K in keyof L]: string | number | boolean};
119
122
 
120
123
  type Kind = 'counter' | 'upDownCounter' | 'histogram' | 'gauge';
121
124
 
122
- /** A metric's instrument, made when first recorded to. */
125
+ /** Lazily instantiated underlying OpenTelemetry instrument. */
123
126
  class Lazy {
124
127
  private inst?: Recorder;
125
128
 
126
- /** `own`: the declaring service's alone, exported as
127
- * `<service>.<name>`. */
129
+ /** `own`: belongs solely to the declaring service and is exported as `<service>.<name>`. */
128
130
  constructor(
129
131
  private readonly kind: Kind,
130
132
  private readonly name: string,
@@ -160,8 +162,7 @@ class Lazy {
160
162
  }
161
163
  }
162
164
 
163
- /** A `cls` recording to `inst` with `attrs`, attributes as a JSON object's
164
- * text, made without its constructor, which declares a metric. */
165
+ /** Creates an instance of `cls` bound to `inst` and pre-encoded `attrs` without invoking its declaring constructor. */
165
166
  function bind<T>(cls: {prototype: T}, inst: Lazy, attrs?: string): T {
166
167
  return Object.assign(Object.create(cls.prototype as object), {
167
168
  inst,
@@ -169,13 +170,12 @@ function bind<T>(cls: {prototype: T}, inst: Lazy, attrs?: string): T {
169
170
  }) as T;
170
171
  }
171
172
 
172
- /** Whether a metric declared with `opts` is the declaring service's own. */
173
+ /** Reports whether a metric declared with `opts` is service-scoped. */
173
174
  function own(opts: MetricOptions | undefined): boolean {
174
175
  return (opts?.scope ?? 'service') === 'service';
175
176
  }
176
177
 
177
- /** `labels` as attributes, a JSON object's text: keys in snake_case,
178
- * numbers floored. */
178
+ /** Encodes `labels` as a JSON attribute object with `snake_case` keys and floored numeric values. */
179
179
  function attributes(labels: object): string {
180
180
  const out: Record<string, string | number | boolean> = {};
181
181
  for (const [key, value] of Object.entries(labels)) {
@@ -184,7 +184,7 @@ function attributes(labels: object): string {
184
184
  return JSON.stringify(out);
185
185
  }
186
186
 
187
- /** `statusCode` is `status_code`, `HTTPStatus` `http_status`. */
187
+ /** Converts camelCase/PascalCase to snake_case (e.g. `statusCode` -> `status_code`, `HTTPStatus` -> `http_status`). */
188
188
  function snakeCase(s: string): string {
189
189
  return s
190
190
  .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
@@ -198,53 +198,55 @@ function snakeCase(s: string): string {
198
198
  // service, possibly in another language: its kind and labels are the
199
199
  // declaration's, and so are its scope, unit, description and buckets.
200
200
 
201
- /** A number that only goes up: how many times something happened, or how
202
- * much of something there has been. By default it belongs to the declaring
203
- * service, which alone records to it. */
201
+ /**
202
+ * A monotonically increasing metric for counting occurrences or totals.
203
+ * Scoped to the declaring service by default.
204
+ */
204
205
  export class Counter {
205
206
  private readonly inst: Lazy;
206
207
  private readonly attrs?: string;
207
208
 
208
- /** Declares the counter `name`. */
209
+ /** Declares a counter named `name`. */
209
210
  constructor(name: string, opts?: MetricOptions) {
210
211
  this.inst = new Lazy('counter', name, opts, own(opts));
211
212
  }
212
213
 
213
- /** Binds the shared or global counter `name`, declared elsewhere. */
214
+ /** Binds to a shared or global counter declared elsewhere. */
214
215
  static named<N extends string>(name: StringLiteral<N>): Counter {
215
216
  return bind(Counter, new Lazy('counter', name, undefined, false));
216
217
  }
217
218
 
218
- /** Adds one. */
219
+ /** Increments the counter by 1. */
219
220
  increment(): void {
220
221
  this.inst.get().recordEncoded(1, this.attrs);
221
222
  }
222
223
 
223
- /** Adds `n`. A counter does not go down: an amount below zero is
224
- * ignored. */
224
+ /** Adds `n` to the counter. Negative values are ignored. */
225
225
  add(n: number): void {
226
226
  this.inst.get().recordEncoded(n, this.attrs);
227
227
  }
228
228
 
229
- /** The counter itself, to hand to other code. */
229
+ /** Returns this counter handle so it can be passed to other code. */
230
230
  ref(): this {
231
231
  return this;
232
232
  }
233
233
  }
234
234
 
235
- /** A number that goes up and down by what is added to it: how many
236
- * requests are in flight, how many jobs are queued. By default it belongs
237
- * to the declaring service, which alone records to it. */
235
+ /**
236
+ * A metric that can increase or decrease by arbitrary deltas, such as
237
+ * in-flight requests or queued jobs. Scoped to the declaring service by
238
+ * default.
239
+ */
238
240
  export class UpDownCounter {
239
241
  private readonly inst: Lazy;
240
242
  private readonly attrs?: string;
241
243
 
242
- /** Declares the up-down counter `name`. */
244
+ /** Declares an up-down counter named `name`. */
243
245
  constructor(name: string, opts?: MetricOptions) {
244
246
  this.inst = new Lazy('upDownCounter', name, opts, own(opts));
245
247
  }
246
248
 
247
- /** Binds the shared or global up-down counter `name`, declared elsewhere. */
249
+ /** Binds to a shared or global up-down counter declared elsewhere. */
248
250
  static named<N extends string>(name: StringLiteral<N>): UpDownCounter {
249
251
  return bind(
250
252
  UpDownCounter,
@@ -252,40 +254,41 @@ export class UpDownCounter {
252
254
  );
253
255
  }
254
256
 
255
- /** Adds `n`, which may be below zero. */
257
+ /** Adds `n` (positive or negative) to the counter. */
256
258
  add(n: number): void {
257
259
  this.inst.get().recordEncoded(n, this.attrs);
258
260
  }
259
261
 
260
- /** Adds one. */
262
+ /** Increments the counter by 1. */
261
263
  increment(): void {
262
264
  this.inst.get().recordEncoded(1, this.attrs);
263
265
  }
264
266
 
265
- /** Takes away one. */
267
+ /** Decrements the counter by 1. */
266
268
  decrement(): void {
267
269
  this.inst.get().recordEncoded(-1, this.attrs);
268
270
  }
269
271
 
270
- /** The up-down counter itself, to hand to other code. */
272
+ /** Returns this up-down counter handle so it can be passed to other code. */
271
273
  ref(): this {
272
274
  return this;
273
275
  }
274
276
  }
275
277
 
276
- /** A number that is what it was last set to: what something is right now.
277
- * By default it belongs to the declaring service, which alone records to
278
- * it. */
278
+ /**
279
+ * A metric that records the latest instantaneous value of something. Scoped to
280
+ * the declaring service by default.
281
+ */
279
282
  export class Gauge {
280
283
  private readonly inst: Lazy;
281
284
  private readonly attrs?: string;
282
285
 
283
- /** Declares the gauge `name`. */
286
+ /** Declares a gauge named `name`. */
284
287
  constructor(name: string, opts?: MetricOptions) {
285
288
  this.inst = new Lazy('gauge', name, opts, own(opts));
286
289
  }
287
290
 
288
- /** Binds the shared or global gauge `name`, declared elsewhere. */
291
+ /** Binds to a shared or global gauge declared elsewhere. */
289
292
  static named<N extends string>(name: StringLiteral<N>): Gauge {
290
293
  return bind(Gauge, new Lazy('gauge', name, undefined, false));
291
294
  }
@@ -295,35 +298,36 @@ export class Gauge {
295
298
  this.inst.get().recordEncoded(value, this.attrs);
296
299
  }
297
300
 
298
- /** The gauge itself, to hand to other code. */
301
+ /** Returns this gauge handle so it can be passed to other code. */
299
302
  ref(): this {
300
303
  return this;
301
304
  }
302
305
  }
303
306
 
304
- /** How what is recorded is distributed: how long requests take, how large
305
- * uploads are. By default it belongs to the declaring service, which alone
306
- * records to it. */
307
+ /**
308
+ * A metric that records the distribution of values, such as request latencies
309
+ * or upload sizes. Scoped to the declaring service by default.
310
+ */
307
311
  export class Histogram {
308
312
  private readonly inst: Lazy;
309
313
  private readonly attrs?: string;
310
314
 
311
- /** Declares the histogram `name`. */
315
+ /** Declares a histogram named `name`. */
312
316
  constructor(name: string, opts?: HistogramOptions) {
313
317
  this.inst = new Lazy('histogram', name, opts, own(opts));
314
318
  }
315
319
 
316
- /** Binds the shared or global histogram `name`, declared elsewhere. */
320
+ /** Binds to a shared or global histogram declared elsewhere. */
317
321
  static named<N extends string>(name: StringLiteral<N>): Histogram {
318
322
  return bind(Histogram, new Lazy('histogram', name, undefined, false));
319
323
  }
320
324
 
321
- /** Records `value`. */
325
+ /** Records `value` in the histogram. */
322
326
  record(value: number): void {
323
327
  this.inst.get().recordEncoded(value, this.attrs);
324
328
  }
325
329
 
326
- /** The histogram itself, to hand to other code. */
330
+ /** Returns this histogram handle so it can be passed to other code. */
327
331
  ref(): this {
328
332
  return this;
329
333
  }
@@ -334,46 +338,50 @@ export class Histogram {
334
338
  // the name is a plain `string`, and the parser's check is the only one it
335
339
  // gets.
336
340
 
337
- /** A counter for each combination of the labels `L`. By default it
338
- * belongs to the declaring service, which alone records to it. */
341
+ /**
342
+ * A labeled group of {@link Counter} metrics keyed by `L`. Scoped to the
343
+ * declaring service by default.
344
+ */
339
345
  export class CounterGroup<L extends Labels<L>> {
340
346
  private readonly inst: Lazy;
341
347
 
342
- /** Declares the counter group `name`. */
348
+ /** Declares a counter group named `name`. */
343
349
  constructor(name: string, opts?: MetricOptions) {
344
350
  this.inst = new Lazy('counter', name, opts, own(opts));
345
351
  }
346
352
 
347
- /** Binds the shared or global counter group `name`, declared elsewhere,
348
- * whose labels are `L`. */
353
+ /** Binds to a shared or global counter group declared elsewhere with labels `L`. */
349
354
  static named<L extends Labels<L>>(name: string): CounterGroup<L> {
350
355
  return bind(CounterGroup, new Lazy('counter', name, undefined, false));
351
356
  }
352
357
 
353
- /** The counter for `labels`. Worth keeping where it is used often:
354
- * making it encodes the labels' attributes. */
358
+ /**
359
+ * Returns a {@link Counter} bound to `labels`. Cache the returned handle on
360
+ * hot paths to avoid re-encoding the label attributes.
361
+ */
355
362
  with(labels: L): Counter {
356
363
  return bind(Counter, this.inst, attributes(labels));
357
364
  }
358
365
 
359
- /** The group itself, to hand to other code. */
366
+ /** Returns this metric group handle so it can be passed to other code. */
360
367
  ref(): this {
361
368
  return this;
362
369
  }
363
370
  }
364
371
 
365
- /** An up-down counter for each combination of the labels `L`. By default it
366
- * belongs to the declaring service, which alone records to it. */
372
+ /**
373
+ * A labeled group of {@link UpDownCounter} metrics keyed by `L`. Scoped to the
374
+ * declaring service by default.
375
+ */
367
376
  export class UpDownCounterGroup<L extends Labels<L>> {
368
377
  private readonly inst: Lazy;
369
378
 
370
- /** Declares the up-down counter group `name`. */
379
+ /** Declares an up-down counter group named `name`. */
371
380
  constructor(name: string, opts?: MetricOptions) {
372
381
  this.inst = new Lazy('upDownCounter', name, opts, own(opts));
373
382
  }
374
383
 
375
- /** Binds the shared or global up-down counter group `name`, declared elsewhere,
376
- * whose labels are `L`. */
384
+ /** Binds to a shared or global up-down counter group declared elsewhere with labels `L`. */
377
385
  static named<L extends Labels<L>>(name: string): UpDownCounterGroup<L> {
378
386
  return bind(
379
387
  UpDownCounterGroup,
@@ -381,69 +389,77 @@ export class UpDownCounterGroup<L extends Labels<L>> {
381
389
  );
382
390
  }
383
391
 
384
- /** The up-down counter for `labels`. Worth keeping where it is used often:
385
- * making it encodes the labels' attributes. */
392
+ /**
393
+ * Returns an {@link UpDownCounter} bound to `labels`. Cache the returned
394
+ * handle on hot paths to avoid re-encoding the label attributes.
395
+ */
386
396
  with(labels: L): UpDownCounter {
387
397
  return bind(UpDownCounter, this.inst, attributes(labels));
388
398
  }
389
399
 
390
- /** The group itself, to hand to other code. */
400
+ /** Returns this metric group handle so it can be passed to other code. */
391
401
  ref(): this {
392
402
  return this;
393
403
  }
394
404
  }
395
405
 
396
- /** A gauge for each combination of the labels `L`. By default it
397
- * belongs to the declaring service, which alone records to it. */
406
+ /**
407
+ * A labeled group of {@link Gauge} metrics keyed by `L`. Scoped to the
408
+ * declaring service by default.
409
+ */
398
410
  export class GaugeGroup<L extends Labels<L>> {
399
411
  private readonly inst: Lazy;
400
412
 
401
- /** Declares the gauge group `name`. */
413
+ /** Declares a gauge group named `name`. */
402
414
  constructor(name: string, opts?: MetricOptions) {
403
415
  this.inst = new Lazy('gauge', name, opts, own(opts));
404
416
  }
405
417
 
406
- /** Binds the shared or global gauge group `name`, declared elsewhere,
407
- * whose labels are `L`. */
418
+ /** Binds to a shared or global gauge group declared elsewhere with labels `L`. */
408
419
  static named<L extends Labels<L>>(name: string): GaugeGroup<L> {
409
420
  return bind(GaugeGroup, new Lazy('gauge', name, undefined, false));
410
421
  }
411
422
 
412
- /** The gauge for `labels`. Worth keeping where it is used often:
413
- * making it encodes the labels' attributes. */
423
+ /**
424
+ * Returns a {@link Gauge} bound to `labels`. Cache the returned handle on
425
+ * hot paths to avoid re-encoding the label attributes.
426
+ */
414
427
  with(labels: L): Gauge {
415
428
  return bind(Gauge, this.inst, attributes(labels));
416
429
  }
417
430
 
418
- /** The group itself, to hand to other code. */
431
+ /** Returns this metric group handle so it can be passed to other code. */
419
432
  ref(): this {
420
433
  return this;
421
434
  }
422
435
  }
423
436
 
424
- /** A histogram for each combination of the labels `L`. By default it
425
- * belongs to the declaring service, which alone records to it. */
437
+ /**
438
+ * A labeled group of {@link Histogram} metrics keyed by `L`. Scoped to the
439
+ * declaring service by default.
440
+ */
426
441
  export class HistogramGroup<L extends Labels<L>> {
427
442
  private readonly inst: Lazy;
428
443
 
429
- /** Declares the histogram group `name`. */
444
+ /** Declares a histogram group named `name`. */
430
445
  constructor(name: string, opts?: HistogramOptions) {
431
446
  this.inst = new Lazy('histogram', name, opts, own(opts));
432
447
  }
433
448
 
434
- /** Binds the shared or global histogram group `name`, declared elsewhere,
435
- * whose labels are `L`. */
449
+ /** Binds to a shared or global histogram group declared elsewhere with labels `L`. */
436
450
  static named<L extends Labels<L>>(name: string): HistogramGroup<L> {
437
451
  return bind(HistogramGroup, new Lazy('histogram', name, undefined, false));
438
452
  }
439
453
 
440
- /** The histogram for `labels`. Worth keeping where it is used often:
441
- * making it encodes the labels' attributes. */
454
+ /**
455
+ * Returns a {@link Histogram} bound to `labels`. Cache the returned handle
456
+ * on hot paths to avoid re-encoding the label attributes.
457
+ */
442
458
  with(labels: L): Histogram {
443
459
  return bind(Histogram, this.inst, attributes(labels));
444
460
  }
445
461
 
446
- /** The group itself, to hand to other code. */
462
+ /** Returns this metric group handle so it can be passed to other code. */
447
463
  ref(): this {
448
464
  return this;
449
465
  }
package/otel.ts CHANGED
@@ -8,9 +8,12 @@ export type {TracerProvider};
8
8
 
9
9
  let tracers: TracerProvider | undefined;
10
10
 
11
- /** Encore's tracer provider, recording into the runtime's telemetry
12
- * pipeline. Encore records its own spans without it; pass it to an
13
- * instrumentation, or register it with `trace.setGlobalTracerProvider`. */
11
+ /**
12
+ * Returns Encore's OpenTelemetry `TracerProvider`, which records spans into the
13
+ * runtime's telemetry pipeline. Encore records its own spans automatically;
14
+ * pass this provider to third-party instrumentations or register it with
15
+ * `trace.setGlobalTracerProvider`.
16
+ */
14
17
  export function tracerProvider(): TracerProvider {
15
18
  tracers ??= new TracerProvider(RT.telemetry());
16
19
  return tracers;
package/package.json CHANGED
@@ -75,6 +75,11 @@
75
75
  "default": "./dist/pubsub/mod.js",
76
76
  "types": "./dist/pubsub/mod.d.ts"
77
77
  },
78
+ "./redaction": {
79
+ "bun": "./redaction/mod.ts",
80
+ "default": "./dist/redaction/mod.js",
81
+ "types": "./dist/redaction/mod.d.ts"
82
+ },
78
83
  "./reqctx": {
79
84
  "bun": "./reqctx/mod.ts",
80
85
  "default": "./dist/reqctx/mod.js",
@@ -206,5 +211,5 @@
206
211
  },
207
212
  "sideEffects": false,
208
213
  "type": "module",
209
- "version": "2.0.0-beta.14"
214
+ "version": "2.0.0-beta.16"
210
215
  }