@encore.dev/sdk 2.0.0-beta.15 → 2.0.0-beta.17
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.
- package/README.md +111 -101
- package/app_meta.ts +56 -54
- package/config/config.ts +60 -57
- package/config/secrets.ts +45 -52
- package/config/value.ts +23 -26
- package/cron/mod.ts +28 -29
- package/dist/app_meta.d.ts +52 -50
- package/dist/app_meta.d.ts.map +1 -1
- package/dist/app_meta.js +2 -2
- package/dist/app_meta.js.map +1 -1
- package/dist/config/config.d.ts +58 -55
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +8 -9
- package/dist/config/config.js.map +1 -1
- package/dist/config/secrets.d.ts +45 -52
- package/dist/config/secrets.d.ts.map +1 -1
- package/dist/config/secrets.js +8 -9
- package/dist/config/secrets.js.map +1 -1
- package/dist/config/value.d.ts +20 -23
- package/dist/config/value.d.ts.map +1 -1
- package/dist/config/value.js +20 -23
- package/dist/config/value.js.map +1 -1
- package/dist/cron/mod.d.ts +26 -27
- package/dist/cron/mod.d.ts.map +1 -1
- package/dist/cron/mod.js +13 -14
- package/dist/cron/mod.js.map +1 -1
- package/dist/frontends/mod.d.ts +20 -19
- package/dist/frontends/mod.d.ts.map +1 -1
- package/dist/frontends/mod.js +20 -19
- package/dist/frontends/mod.js.map +1 -1
- package/dist/gateway/errors.d.ts +28 -30
- package/dist/gateway/errors.d.ts.map +1 -1
- package/dist/gateway/errors.js +29 -31
- package/dist/gateway/errors.js.map +1 -1
- package/dist/gateway/match.d.ts +54 -54
- package/dist/gateway/match.d.ts.map +1 -1
- package/dist/gateway/match.js +56 -56
- package/dist/gateway/match.js.map +1 -1
- package/dist/gateway/middleware.d.ts +62 -64
- package/dist/gateway/middleware.d.ts.map +1 -1
- package/dist/gateway/middleware.js +1 -1
- package/dist/gateway/middleware.js.map +1 -1
- package/dist/gateway/mod.d.ts +64 -67
- package/dist/gateway/mod.d.ts.map +1 -1
- package/dist/gateway/mod.js +72 -76
- package/dist/gateway/mod.js.map +1 -1
- package/dist/gateway/request.d.ts +138 -134
- package/dist/gateway/request.d.ts.map +1 -1
- package/dist/gateway/request.js +117 -108
- package/dist/gateway/request.js.map +1 -1
- package/dist/gateway/serve.d.ts +29 -34
- package/dist/gateway/serve.d.ts.map +1 -1
- package/dist/gateway/serve.js +51 -56
- package/dist/gateway/serve.js.map +1 -1
- package/dist/gateways/mod.d.ts +23 -21
- package/dist/gateways/mod.d.ts.map +1 -1
- package/dist/gateways/mod.js +25 -23
- package/dist/gateways/mod.js.map +1 -1
- package/dist/internal/runtime/napi/napi.cjs +1 -1
- package/dist/internal/runtime/napi/napi.d.cts +10 -3
- package/dist/internal/runtime/shutdown.d.ts +75 -57
- package/dist/internal/runtime/shutdown.d.ts.map +1 -1
- package/dist/internal/runtime/shutdown.js +88 -84
- package/dist/internal/runtime/shutdown.js.map +1 -1
- package/dist/log/logger.d.ts +43 -37
- package/dist/log/logger.d.ts.map +1 -1
- package/dist/log/logger.js +26 -25
- package/dist/log/logger.js.map +1 -1
- package/dist/metrics/mod.d.ts +133 -114
- package/dist/metrics/mod.d.ts.map +1 -1
- package/dist/metrics/mod.js +109 -101
- package/dist/metrics/mod.js.map +1 -1
- package/dist/otel.d.ts +6 -3
- package/dist/otel.d.ts.map +1 -1
- package/dist/otel.js +6 -3
- package/dist/otel.js.map +1 -1
- package/dist/pubsub/subscription.d.ts +88 -116
- package/dist/pubsub/subscription.d.ts.map +1 -1
- package/dist/pubsub/subscription.js +14 -17
- package/dist/pubsub/subscription.js.map +1 -1
- package/dist/pubsub/topic.d.ts +86 -113
- package/dist/pubsub/topic.d.ts.map +1 -1
- package/dist/pubsub/topic.js +68 -82
- package/dist/pubsub/topic.js.map +1 -1
- package/dist/reqctx/mod.d.ts +83 -86
- package/dist/reqctx/mod.d.ts.map +1 -1
- package/dist/reqctx/mod.js +39 -41
- package/dist/reqctx/mod.js.map +1 -1
- package/dist/services/index.d.ts +76 -75
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +73 -71
- package/dist/services/index.js.map +1 -1
- package/dist/shutdown/mod.d.ts +26 -25
- package/dist/shutdown/mod.d.ts.map +1 -1
- package/dist/shutdown/mod.js +26 -25
- package/dist/shutdown/mod.js.map +1 -1
- package/dist/storage/clickhouse/database.d.ts +113 -115
- package/dist/storage/clickhouse/database.d.ts.map +1 -1
- package/dist/storage/clickhouse/database.js +65 -79
- package/dist/storage/clickhouse/database.js.map +1 -1
- package/dist/storage/clickhouse/errors.d.ts +25 -26
- package/dist/storage/clickhouse/errors.d.ts.map +1 -1
- package/dist/storage/clickhouse/errors.js +15 -17
- package/dist/storage/clickhouse/errors.js.map +1 -1
- package/dist/storage/clickhouse/mod.d.ts +10 -10
- package/dist/storage/clickhouse/mod.js +10 -10
- package/dist/storage/objects/bucket.d.ts +196 -225
- package/dist/storage/objects/bucket.d.ts.map +1 -1
- package/dist/storage/objects/bucket.js +71 -84
- package/dist/storage/objects/bucket.js.map +1 -1
- package/dist/storage/objects/error.d.ts +4 -4
- package/dist/storage/objects/error.js +4 -4
- package/dist/storage/postgres/database.d.ts +124 -149
- package/dist/storage/postgres/database.d.ts.map +1 -1
- package/dist/storage/postgres/database.js +98 -135
- package/dist/storage/postgres/database.js.map +1 -1
- package/dist/storage/postgres/errors.d.ts +42 -48
- package/dist/storage/postgres/errors.d.ts.map +1 -1
- package/dist/storage/postgres/errors.js +44 -51
- package/dist/storage/postgres/errors.js.map +1 -1
- package/dist/storage/postgres/interval.d.ts +19 -19
- package/dist/storage/postgres/interval.d.ts.map +1 -1
- package/dist/storage/postgres/interval.js +21 -21
- package/dist/storage/postgres/interval.js.map +1 -1
- package/dist/storage/redis/bitfield.d.ts +48 -23
- package/dist/storage/redis/bitfield.d.ts.map +1 -1
- package/dist/storage/redis/bitfield.js +38 -19
- package/dist/storage/redis/bitfield.js.map +1 -1
- package/dist/storage/redis/command.d.ts +16 -12
- package/dist/storage/redis/command.d.ts.map +1 -1
- package/dist/storage/redis/command.js +16 -12
- package/dist/storage/redis/command.js.map +1 -1
- package/dist/storage/redis/commands.d.ts +99 -100
- package/dist/storage/redis/commands.d.ts.map +1 -1
- package/dist/storage/redis/commands.js +84 -85
- package/dist/storage/redis/commands.js.map +1 -1
- package/dist/storage/redis/database.d.ts +138 -122
- package/dist/storage/redis/database.d.ts.map +1 -1
- package/dist/storage/redis/database.js +120 -101
- package/dist/storage/redis/database.js.map +1 -1
- package/dist/storage/redis/mod.d.ts +52 -48
- package/dist/storage/redis/mod.d.ts.map +1 -1
- package/dist/storage/redis/mod.js +52 -48
- package/dist/storage/redis/mod.js.map +1 -1
- package/dist/storage/redis/options.d.ts +26 -24
- package/dist/storage/redis/options.d.ts.map +1 -1
- package/dist/storage/redis/options.js.map +1 -1
- package/dist/storage/redis/pubsub.d.ts +16 -16
- package/dist/storage/redis/pubsub.d.ts.map +1 -1
- package/dist/storage/redis/pubsub.js +14 -14
- package/dist/storage/redis/pubsub.js.map +1 -1
- package/dist/storage/redis/reply.d.ts +80 -72
- package/dist/storage/redis/reply.d.ts.map +1 -1
- package/dist/storage/redis/reply.js +53 -46
- package/dist/storage/redis/reply.js.map +1 -1
- package/dist/storage/redis/scan.d.ts +4 -4
- package/dist/storage/redis/scan.d.ts.map +1 -1
- package/dist/storage/redis/scan.js +6 -6
- package/dist/storage/redis/scan.js.map +1 -1
- package/dist/storage/redis/script.d.ts +28 -21
- package/dist/storage/redis/script.d.ts.map +1 -1
- package/dist/storage/redis/script.js +29 -22
- package/dist/storage/redis/script.js.map +1 -1
- package/dist/storage/redis/target.d.ts +17 -1
- package/dist/storage/redis/target.d.ts.map +1 -1
- package/dist/storage/redis/target.js +30 -1
- package/dist/storage/redis/target.js.map +1 -1
- package/dist/storage/redis/wire.d.ts +6 -6
- package/dist/storage/redis/wire.d.ts.map +1 -1
- package/dist/storage/redis/wire.js +6 -6
- package/dist/storage/redis/wire.js.map +1 -1
- package/dist/testing/mod.d.ts +83 -88
- package/dist/testing/mod.d.ts.map +1 -1
- package/dist/testing/mod.js +75 -81
- package/dist/testing/mod.js.map +1 -1
- package/dist/testing/playwright.d.ts +28 -32
- package/dist/testing/playwright.d.ts.map +1 -1
- package/dist/testing/playwright.js +22 -27
- package/dist/testing/playwright.js.map +1 -1
- package/dist/testing/puppeteer.d.ts +11 -12
- package/dist/testing/puppeteer.d.ts.map +1 -1
- package/dist/testing/puppeteer.js +17 -18
- package/dist/testing/puppeteer.js.map +1 -1
- package/dist/testing/system.d.ts +72 -90
- package/dist/testing/system.d.ts.map +1 -1
- package/dist/testing/system.js +90 -107
- package/dist/testing/system.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/frontends/mod.test.ts +6 -2
- package/frontends/mod.ts +20 -19
- package/gateway/errors.ts +30 -32
- package/gateway/match.ts +61 -57
- package/gateway/middleware.ts +62 -64
- package/gateway/mod.ts +73 -76
- package/gateway/request.ts +143 -140
- package/gateway/serve.ts +58 -63
- package/gateways/mod.ts +25 -23
- package/internal/runtime/napi/napi.cjs +1 -1
- package/internal/runtime/napi/napi.d.cts +10 -3
- package/internal/runtime/shutdown.ts +113 -101
- package/log/logger.test.ts +8 -0
- package/log/logger.ts +48 -45
- package/metrics/mod.ts +138 -122
- package/otel.ts +6 -3
- package/package.json +1 -1
- package/pubsub/subscription.ts +93 -123
- package/pubsub/topic.ts +96 -130
- package/reqctx/mod.ts +83 -86
- package/services/index.ts +78 -78
- package/shutdown/mod.ts +26 -25
- package/storage/clickhouse/database.ts +115 -129
- package/storage/clickhouse/errors.ts +27 -29
- package/storage/clickhouse/mod.ts +10 -10
- package/storage/objects/bucket.ts +209 -239
- package/storage/objects/error.ts +4 -4
- package/storage/postgres/database.ts +131 -164
- package/storage/postgres/errors.ts +45 -52
- package/storage/postgres/interval.ts +21 -21
- package/storage/redis/bitfield.ts +51 -26
- package/storage/redis/command.ts +16 -12
- package/storage/redis/commands.ts +99 -100
- package/storage/redis/database.ts +145 -123
- package/storage/redis/mod.ts +52 -48
- package/storage/redis/options.ts +26 -24
- package/storage/redis/pubsub.ts +14 -14
- package/storage/redis/redis.test.ts +17 -2
- package/storage/redis/reply.ts +85 -77
- package/storage/redis/scan.ts +6 -6
- package/storage/redis/script.ts +29 -22
- package/storage/redis/target.ts +34 -1
- package/storage/redis/wire.ts +8 -8
- package/testing/mod.ts +99 -105
- package/testing/playwright.ts +32 -37
- package/testing/puppeteer.ts +22 -23
- package/testing/system.ts +117 -133
package/metrics/mod.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* does.
|
|
2
|
+
* Application metrics: counters, up-down counters, histograms, and gauges.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
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
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
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
|
|
72
|
-
* to
|
|
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
|
-
/**
|
|
79
|
+
/** Common options for declaring a metric. */
|
|
85
80
|
export interface MetricOptions {
|
|
86
|
-
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
93
|
+
/** Human-readable description used when the declaration has no JSDoc comment. */
|
|
96
94
|
description?: string;
|
|
97
95
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
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
|
-
/**
|
|
104
|
+
/** Options for declaring a histogram metric. */
|
|
107
105
|
export interface HistogramOptions extends MetricOptions {
|
|
108
|
-
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
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
|
-
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* (`Math.floor
|
|
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
|
-
/**
|
|
125
|
+
/** Lazily instantiated underlying OpenTelemetry instrument. */
|
|
123
126
|
class Lazy {
|
|
124
127
|
private inst?: Recorder;
|
|
125
128
|
|
|
126
|
-
/** `own`: the declaring service
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
|
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`
|
|
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
|
-
/**
|
|
202
|
-
*
|
|
203
|
-
*
|
|
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
|
|
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
|
|
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
|
-
/**
|
|
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
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
236
|
-
*
|
|
237
|
-
*
|
|
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
|
|
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
|
|
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
|
|
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
|
-
/**
|
|
262
|
+
/** Increments the counter by 1. */
|
|
261
263
|
increment(): void {
|
|
262
264
|
this.inst.get().recordEncoded(1, this.attrs);
|
|
263
265
|
}
|
|
264
266
|
|
|
265
|
-
/**
|
|
267
|
+
/** Decrements the counter by 1. */
|
|
266
268
|
decrement(): void {
|
|
267
269
|
this.inst.get().recordEncoded(-1, this.attrs);
|
|
268
270
|
}
|
|
269
271
|
|
|
270
|
-
/**
|
|
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
|
-
/**
|
|
277
|
-
*
|
|
278
|
-
*
|
|
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
|
|
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
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
305
|
-
*
|
|
306
|
-
*
|
|
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
|
|
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
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
338
|
-
*
|
|
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
|
|
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
|
|
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
|
-
/**
|
|
354
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
366
|
-
*
|
|
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
|
|
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
|
|
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
|
-
/**
|
|
385
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
397
|
-
*
|
|
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
|
|
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
|
|
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
|
-
/**
|
|
413
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
425
|
-
*
|
|
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
|
|
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
|
|
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
|
-
/**
|
|
441
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
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