@encore.dev/sdk 2.0.0-beta.15 → 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.
- 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/README.md
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
# Encore JavaScript/TypeScript Infra SDK (
|
|
1
|
+
# Encore JavaScript/TypeScript Infra SDK (`@encore.dev/sdk`)
|
|
2
2
|
|
|
3
|
-
This package
|
|
4
|
-
against the Encore API.
|
|
3
|
+
This package provides the Encore JavaScript/TypeScript SDK for building applications with Encore's infrastructure primitives.
|
|
5
4
|
|
|
6
5
|
## Telemetry redaction
|
|
7
6
|
|
|
8
|
-
`redactor()` applies the deployed policy to copies without emitting telemetry.
|
|
7
|
+
`redactor()` applies the deployed redaction policy to copies of payloads and metadata without emitting telemetry.
|
|
9
8
|
|
|
10
9
|
```typescript
|
|
11
10
|
import {redactor} from '@encore.dev/sdk/redaction';
|
|
@@ -29,16 +28,17 @@ const delivered = redact.topic('submitted').delivery('worker', jsonBytes);
|
|
|
29
28
|
```
|
|
30
29
|
|
|
31
30
|
Headers, metadata, and trailers are iterables of `[string, string]` pairs.
|
|
32
|
-
gRPC binary metadata uses base64 wire
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
`requestUrl()` returns nullable `route`, `path`, and `query` strings.
|
|
40
|
-
no leading `?`. Never replace null fields or omitted/withheld payloads
|
|
41
|
-
original values. Server spans use these safe URL fields without raw
|
|
31
|
+
gRPC binary metadata uses base64 wire values. HTTP exchanges return
|
|
32
|
+
`{headers, body?}`; gRPC exchanges return `{metadata, message?}` and preserve
|
|
33
|
+
supplied response trailers as `trailers`. Omitting `body` or `message` skips
|
|
34
|
+
payload capture, while passing empty bytes still requests capture. Payloads use
|
|
35
|
+
the `omit`, `withheld`, or `recorded` status tags; only `recorded` contains
|
|
36
|
+
safe `body` bytes and a `truncated` flag.
|
|
37
|
+
|
|
38
|
+
`requestUrl()` returns nullable `route`, `path`, and `query` strings. `query`
|
|
39
|
+
has no leading `?`. Never replace `null` fields or omitted/withheld payloads
|
|
40
|
+
with original values. Server spans use these safe URL fields without raw
|
|
41
|
+
fallbacks.
|
|
42
42
|
|
|
43
43
|
## Postgres handles
|
|
44
44
|
|
|
@@ -54,18 +54,20 @@ async function findOrder(queries: Queryable, id: number) {
|
|
|
54
54
|
const order = await findOrder(db.read(), 1);
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
Use `read({ primary: true })`, `write()`, or `admin()` to select access
|
|
58
|
-
passing a database to another function. `DatabaseRef`,
|
|
59
|
-
`Transaction` implement `Queryable`; the `Database`
|
|
60
|
-
Direct operations on the declaration
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
Use `read({ primary: true })`, `write()`, or `admin()` to select an access mode
|
|
58
|
+
before passing a database handle to another function. `DatabaseRef`,
|
|
59
|
+
`Connection`, and `Transaction` implement `Queryable`; the `Database`
|
|
60
|
+
declaration itself does not. Direct operations on the `Database` declaration
|
|
61
|
+
infer writer access. Handles share the declaration's connection pool.
|
|
62
|
+
|
|
63
|
+
A `read()` handle runs on read-only connections, so writes fail with SQLSTATE
|
|
64
|
+
`25006` and its transactions are read-only. It reads from a read replica pool
|
|
65
|
+
if the runtime config provides one, unless `primary: true` is set.
|
|
65
66
|
|
|
66
|
-
`queryRow` and `rawQueryRow` return a row or `null
|
|
67
|
-
`exec` and `rawExec` return `{ rowsAffected: bigint }`,
|
|
68
|
-
rows before resolving. The bigint preserves
|
|
67
|
+
`queryRow` and `rawQueryRow` return a single row or `null`, and reject if more
|
|
68
|
+
than one row is returned. `exec` and `rawExec` return `{ rowsAffected: bigint }`,
|
|
69
|
+
draining any `RETURNING` rows before resolving. The `bigint` preserves
|
|
70
|
+
PostgreSQL's full affected-row count.
|
|
69
71
|
|
|
70
72
|
```typescript
|
|
71
73
|
await using conn = await db.write().acquire();
|
|
@@ -74,15 +76,17 @@ const result = await tx.exec`UPDATE orders SET paid = true WHERE id = ${1}`;
|
|
|
74
76
|
await tx.commit();
|
|
75
77
|
```
|
|
76
78
|
|
|
77
|
-
Transactions roll back on async disposal unless explicitly
|
|
78
|
-
scope
|
|
79
|
-
An acquired connection cannot be used or closed while its
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
`set_config(
|
|
79
|
+
Transactions roll back on async disposal unless explicitly committed or rolled
|
|
80
|
+
back; exiting a scope cleanly does not commit. Connections return to the pool
|
|
81
|
+
on async disposal. An acquired connection cannot be used or closed while its
|
|
82
|
+
transaction is active.
|
|
83
|
+
|
|
84
|
+
Session settings and roles (`SET`, `set_config`, `SET ROLE`) are reset before
|
|
85
|
+
the pool lends a connection again. However, Encore only tracks statements sent
|
|
86
|
+
directly in queries: a setting changed indirectly by a stored function or
|
|
87
|
+
procedure (such as `SELECT set_tenant($1)` calling `set_config(..., false)`) is
|
|
88
|
+
not detected and remains in effect for the next borrower. Scope per-request
|
|
89
|
+
settings to a transaction using `set_config(name, value, true)`:
|
|
86
90
|
|
|
87
91
|
```typescript
|
|
88
92
|
await using tx = await db.write().begin();
|
|
@@ -92,8 +96,9 @@ await tx.commit();
|
|
|
92
96
|
```
|
|
93
97
|
|
|
94
98
|
Streaming queries exclusively borrow their connection or transaction until
|
|
95
|
-
exhausted or closed. `for await` closes
|
|
96
|
-
when manually advancing an iterator, call `return()` before
|
|
99
|
+
exhausted or closed. `for await` closes the stream automatically if the loop
|
|
100
|
+
exits early; when manually advancing an iterator, call `return()` before
|
|
101
|
+
reusing its connection or transaction.
|
|
97
102
|
|
|
98
103
|
Run the SQL wrapper tests with `bun test storage/postgres/database.test.ts`.
|
|
99
104
|
The native integration test is enabled with `ENCORE_TS_POSTGRES_TEST_HOST=host:port`
|
|
@@ -104,9 +109,9 @@ if it is not staged beside the SDK.
|
|
|
104
109
|
## Pub/Sub payloads and ordering
|
|
105
110
|
|
|
106
111
|
Subscriptions start automatically when declared. JSON messages are decoded into
|
|
107
|
-
`Message<T>.data
|
|
108
|
-
exposes `id`, `attributes`, `deliveryAttempt`,
|
|
109
|
-
(`null` for messages without a key).
|
|
112
|
+
`Message<T>.data`, while `rawData` always contains the original bytes. The
|
|
113
|
+
message wrapper also exposes `id`, `attributes`, `deliveryAttempt`,
|
|
114
|
+
`publishTime`, and `orderingKey` (`null` for messages without a key).
|
|
110
115
|
|
|
111
116
|
```typescript
|
|
112
117
|
import {OrderedTopic, Subscription, Topic} from '@encore.dev/sdk/pubsub';
|
|
@@ -137,21 +142,21 @@ await files.publish(Buffer.from([0, 255]));
|
|
|
137
142
|
`Buffer`/`Uint8Array` bytes. Both topic constructors default to at-least-once
|
|
138
143
|
delivery; pass `{ deliveryGuarantee: "exactly-once" }` to request exactly-once.
|
|
139
144
|
`OrderedTopic.publish(payload, orderingKey, attributes?)` requires an explicit,
|
|
140
|
-
non-empty key, which is
|
|
141
|
-
attribute. Use `OrderedTopic.named<T>("name")`
|
|
142
|
-
including Python or Rust. A `Topic` is unordered;
|
|
143
|
-
ordered delivery.
|
|
144
|
-
|
|
145
|
-
TypeScript types do not validate incoming JSON. Supply
|
|
146
|
-
to validate or transform
|
|
147
|
-
`encoding: "raw"` for byte subscriptions, or combine it with a
|
|
148
|
-
for a custom format. Invalid JSON, decoder errors, and
|
|
149
|
-
the delivery so the runtime can apply its retry policy.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
145
|
+
non-empty ordering key, which is sent as the provider's native ordering key
|
|
146
|
+
rather than an attribute. Use `OrderedTopic.named<T>("name")` to reference a
|
|
147
|
+
topic declared elsewhere (including in Python or Rust). A `Topic` is unordered;
|
|
148
|
+
declare an `OrderedTopic` when you need ordered delivery.
|
|
149
|
+
|
|
150
|
+
TypeScript types do not validate incoming JSON at runtime. Supply
|
|
151
|
+
`decode: (data) => ...` to validate or transform parsed JSON into your message
|
|
152
|
+
type. Use `encoding: "raw"` for byte subscriptions, or combine it with a
|
|
153
|
+
`decode` callback for a custom format. Invalid JSON, decoder errors, and
|
|
154
|
+
handler failures reject the delivery so the runtime can apply its retry policy.
|
|
155
|
+
|
|
156
|
+
`message.data` is decoded JSON by default rather than raw bytes. Handlers that
|
|
157
|
+
parse JSON manually should use the decoded value directly or explicitly select
|
|
158
|
+
`encoding: "raw"`. When a consumer stops, it is no longer restarted on a timer:
|
|
159
|
+
failures are logged, and normal completion leaves the consumer stopped.
|
|
155
160
|
|
|
156
161
|
## Tracing
|
|
157
162
|
|
|
@@ -171,23 +176,26 @@ const items = await span(
|
|
|
171
176
|
);
|
|
172
177
|
```
|
|
173
178
|
|
|
174
|
-
`span(name, callback)`
|
|
175
|
-
an OpenTelemetry `Span`; the helper
|
|
176
|
-
Synchronous callbacks return or throw synchronously.
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
179
|
+
`span(name, callback)` creates a span without attributes. The callback receives
|
|
180
|
+
an OpenTelemetry `Span`; the helper manages the span's lifecycle, so do not
|
|
181
|
+
call `end()`. Synchronous callbacks return or throw synchronously.
|
|
182
|
+
`PromiseLike` results return a `Promise`, and the span ends once it settles.
|
|
183
|
+
Thrown errors and rejections record an exception and set the span status to
|
|
184
|
+
`ERROR`, rethrowing the original error. OpenTelemetry's `OK` status is final:
|
|
185
|
+
setting it prevents a later `ERROR` status. Successful callbacks leave the
|
|
186
|
+
status `UNSET` unless the callback sets it explicitly.
|
|
187
|
+
|
|
188
|
+
Use bounded span names and place order IDs or other high-cardinality values in
|
|
189
|
+
attributes. Nested spans, logs, metric exemplars, and service calls inherit the
|
|
190
|
+
active context across `await` boundaries and timers. Detached background work
|
|
191
|
+
must manage its own lifecycle.
|
|
192
|
+
|
|
193
|
+
Encore always uses its own cached tracer provider, independent of OpenTelemetry
|
|
194
|
+
globals. Importing or using tracing does not register a global provider,
|
|
195
|
+
context manager, propagator, meter, or logger. Native `span` works without any
|
|
196
|
+
OpenTelemetry setup. For OpenTelemetry interop, configure your application's
|
|
197
|
+
context manager through standard OpenTelemetry setup before instrumented work,
|
|
198
|
+
and pass Encore's tracer provider explicitly:
|
|
191
199
|
|
|
192
200
|
```typescript
|
|
193
201
|
import {span, tracerProvider} from '@encore.dev/sdk/tracing';
|
|
@@ -203,9 +211,9 @@ await tracer.startActiveSpan('order_request', async current => {
|
|
|
203
211
|
});
|
|
204
212
|
```
|
|
205
213
|
|
|
206
|
-
|
|
207
|
-
that
|
|
208
|
-
|
|
214
|
+
Your application may call `trace.setGlobalTracerProvider(tracerProvider())` for
|
|
215
|
+
libraries that rely on the global API; Encore never sets globals automatically.
|
|
216
|
+
`tracerProvider` is also exported from `@encore.dev/sdk`. See the paired
|
|
209
217
|
[tracing fixtures](../../../tests/ts/telemetry) for runnable examples.
|
|
210
218
|
|
|
211
219
|
### HTTP handlers
|
|
@@ -219,19 +227,20 @@ Bun.serve({fetch: instrumentHTTP(handleRequest)});
|
|
|
219
227
|
```
|
|
220
228
|
|
|
221
229
|
`instrumentHTTP` extracts W3C trace context and Encore Request Context, then
|
|
222
|
-
runs the handler
|
|
223
|
-
metrics and service calls inherit
|
|
224
|
-
preserved
|
|
225
|
-
|
|
226
|
-
Span names are `METHOD /template` when deployed policy supplies a route,
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
mark the span
|
|
230
|
-
The original
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
wrapper decodes them
|
|
230
|
+
runs the handler inside an Encore-owned `SERVER` span. Nested spans, logs,
|
|
231
|
+
metrics, and service calls inherit this context. Extra handler arguments and
|
|
232
|
+
`this` are preserved, and no OpenTelemetry globals are registered or replaced.
|
|
233
|
+
|
|
234
|
+
Span names are `METHOD /template` when a deployed policy supplies a route, or
|
|
235
|
+
`METHOD` with no `http.route` otherwise; unknown methods use `HTTP`. Recorded
|
|
236
|
+
URL paths, queries, and user agents come only from the deployed policy. Response
|
|
237
|
+
status codes are recorded, and 5xx responses or thrown errors mark the span as
|
|
238
|
+
`ERROR` (errors are rethrown). The original `Response` and its body are
|
|
239
|
+
untouched, so the span ends when the handler returns a `Response` rather than
|
|
240
|
+
when a streaming body finishes. Handlers must return a `Response`; WebSocket
|
|
241
|
+
upgrades require a runtime-specific adapter. Only accept Encore Request Context
|
|
242
|
+
headers from trusted Encore ingress — the wrapper decodes them without
|
|
243
|
+
authenticating them.
|
|
235
244
|
|
|
236
245
|
### Node HTTP handlers
|
|
237
246
|
|
|
@@ -247,20 +256,21 @@ createServer(
|
|
|
247
256
|
).listen(3000);
|
|
248
257
|
```
|
|
249
258
|
|
|
250
|
-
The Node adapter
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
response finishes does not end the span. Premature closes mark
|
|
259
|
-
The adapter records and rethrows handler failures;
|
|
260
|
-
responsible for error responses and handling rejected async
|
|
261
|
-
Failures before headers are sent
|
|
262
|
-
Synchronous return values are preserved; PromiseLike results
|
|
263
|
-
HTTP upgrade and CONNECT events require separate
|
|
259
|
+
The Node adapter wraps native `IncomingMessage`/`ServerResponse` listeners
|
|
260
|
+
without converting or buffering request or response bodies. It shares trace and
|
|
261
|
+
Request Context extraction with the Fetch wrapper and preserves `this`. During
|
|
262
|
+
response processing, request and response event callbacks run in the request's
|
|
263
|
+
context.
|
|
264
|
+
|
|
265
|
+
The span ends on response `finish`, premature `close`, response error, or a
|
|
266
|
+
thrown/rejected handler error. Returning from a handler before a streamed
|
|
267
|
+
response finishes does not end the span. Premature closes mark the span as
|
|
268
|
+
`ERROR`. The adapter records and rethrows handler failures; your application
|
|
269
|
+
remains responsible for writing error responses and handling rejected async
|
|
270
|
+
listeners. Failures occurring before headers are sent do not record an HTTP
|
|
271
|
+
response status. Synchronous return values are preserved; `PromiseLike` results
|
|
272
|
+
return a `Promise`. HTTP `upgrade` and `CONNECT` events require separate
|
|
273
|
+
instrumentation.
|
|
264
274
|
|
|
265
275
|
### Framework instrumentation
|
|
266
276
|
|
package/app_meta.ts
CHANGED
|
@@ -3,42 +3,43 @@ import * as runtime from './internal/runtime/mod';
|
|
|
3
3
|
/** Describes the running Encore application. */
|
|
4
4
|
export interface AppMeta {
|
|
5
5
|
/**
|
|
6
|
-
* The Encore application ID. If the application is not linked to the Encore
|
|
7
|
-
*
|
|
6
|
+
* The Encore application ID. If the application is not linked to the Encore
|
|
7
|
+
* platform, this is an empty string. To link the application, run
|
|
8
|
+
* `encore cloud link` in the root directory of your Encore app.
|
|
8
9
|
*/
|
|
9
10
|
appId: string;
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
|
-
* The Encore application slug — the human-readable identifier shown in the
|
|
13
|
-
* Cloud dashboard and used by the CLI. If the application is not
|
|
14
|
-
* Encore platform this
|
|
13
|
+
* The Encore application slug — the human-readable identifier shown in the
|
|
14
|
+
* Encore Cloud dashboard and used by the CLI. If the application is not
|
|
15
|
+
* linked to the Encore platform, this is an empty string.
|
|
15
16
|
*
|
|
16
|
-
* Distinct from `appId`: the
|
|
17
|
-
* be renamed. Locally
|
|
17
|
+
* Distinct from `appId`: the ID is opaque and stable, whereas the slug is
|
|
18
|
+
* human-readable and may be renamed. Locally, both have the same value.
|
|
18
19
|
*/
|
|
19
20
|
appSlug: string;
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
|
-
* The API gateways
|
|
23
|
-
* gateway name: those its code looks up the URL of, and the one it hosts.
|
|
23
|
+
* The API gateways visible to this service, keyed by gateway name.
|
|
24
24
|
*
|
|
25
|
-
*
|
|
26
|
-
* the API — look up the gateway you
|
|
27
|
-
*
|
|
28
|
-
* `@encore.dev/sdk/gateways`) and
|
|
29
|
-
*
|
|
25
|
+
* Because an application can declare multiple gateways, there is no single
|
|
26
|
+
* base URL for the API — look up the gateway you want by name. A service's
|
|
27
|
+
* processes (including its workers) receive only the gateways referenced by
|
|
28
|
+
* its code (`url("api")` from `@encore.dev/sdk/gateways`) and any gateway
|
|
29
|
+
* hosted by the service itself. When no gateways are configured (such as
|
|
30
|
+
* under `encore test`), this is an empty object.
|
|
30
31
|
*/
|
|
31
32
|
gateways: Record<string, GatewayMeta>;
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
|
-
* The frontends
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
35
|
+
* The frontends visible to this service, keyed by frontend name. Includes
|
|
36
|
+
* frontends referenced by this service's code (`url("web")` from
|
|
37
|
+
* `@encore.dev/sdk/frontends`) and any frontend hosted by the service itself.
|
|
38
|
+
* Frontends with no configured origins in this environment are omitted.
|
|
38
39
|
*/
|
|
39
40
|
frontends: Record<string, FrontendMeta>;
|
|
40
41
|
|
|
41
|
-
/** Information about the environment the
|
|
42
|
+
/** Information about the environment the application is running in. */
|
|
42
43
|
environment: EnvironmentMeta;
|
|
43
44
|
|
|
44
45
|
/** Information about the build. */
|
|
@@ -50,37 +51,37 @@ export interface AppMeta {
|
|
|
50
51
|
|
|
51
52
|
/** Describes an API gateway serving the application. */
|
|
52
53
|
export interface GatewayMeta {
|
|
53
|
-
/** The name
|
|
54
|
+
/** The gateway name as declared by the application. */
|
|
54
55
|
name: string;
|
|
55
56
|
|
|
56
57
|
/**
|
|
57
|
-
* The URL
|
|
58
|
-
*
|
|
59
|
-
*
|
|
58
|
+
* The primary URL at which this gateway is reached (the first entry in
|
|
59
|
+
* `origins`). Empty when no origins are configured for the gateway in this
|
|
60
|
+
* environment.
|
|
60
61
|
*/
|
|
61
62
|
url: string;
|
|
62
63
|
|
|
63
64
|
/**
|
|
64
|
-
*
|
|
65
|
-
* (`scheme://host[:port]`)
|
|
66
|
-
* be
|
|
67
|
-
*
|
|
65
|
+
* All origins at which the gateway is reached in this environment
|
|
66
|
+
* (`scheme://host[:port]`). The first entry is the primary `url`. Subsequent
|
|
67
|
+
* entries may be wildcard patterns (such as `https://*.example.com`) or `*`,
|
|
68
|
+
* which makes this gateway handle requests that no other origin matches.
|
|
68
69
|
*/
|
|
69
70
|
origins: string[];
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
/** Describes a frontend of the application
|
|
73
|
+
/** Describes a frontend of the application and where it is reached. */
|
|
73
74
|
export interface FrontendMeta {
|
|
74
|
-
/** The name
|
|
75
|
+
/** The frontend name (or the hosting service's name for a service-hosted frontend). */
|
|
75
76
|
name: string;
|
|
76
77
|
|
|
77
|
-
/** The URL the frontend is reached
|
|
78
|
+
/** The primary URL at which the frontend is reached (the first entry in `origins`). */
|
|
78
79
|
url: string;
|
|
79
80
|
|
|
80
81
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* `https://*.example.com`.
|
|
82
|
+
* All origins at which the frontend is reached in this environment. The first
|
|
83
|
+
* entry is the primary `url`; subsequent entries may be wildcard patterns
|
|
84
|
+
* such as `https://*.example.com`.
|
|
84
85
|
*/
|
|
85
86
|
origins: string[];
|
|
86
87
|
}
|
|
@@ -88,20 +89,20 @@ export interface FrontendMeta {
|
|
|
88
89
|
/** Describes the environment the Encore application is running in. */
|
|
89
90
|
export interface EnvironmentMeta {
|
|
90
91
|
/**
|
|
91
|
-
* The name of environment
|
|
92
|
-
* For local development
|
|
92
|
+
* The name of the environment this application is running in.
|
|
93
|
+
* For local development, this is `"local"`.
|
|
93
94
|
*/
|
|
94
95
|
name: string;
|
|
95
96
|
|
|
96
97
|
/**
|
|
97
|
-
* The type of environment
|
|
98
|
-
* For local development
|
|
98
|
+
* The type of environment this application is running in.
|
|
99
|
+
* For local development, this is `"development"`.
|
|
99
100
|
*/
|
|
100
101
|
type: EnvironmentType;
|
|
101
102
|
|
|
102
103
|
/**
|
|
103
|
-
* The cloud this is running
|
|
104
|
-
* For local development
|
|
104
|
+
* The cloud provider this application is running on.
|
|
105
|
+
* For local development, this is `"local"`.
|
|
105
106
|
*/
|
|
106
107
|
cloud: CloudProvider;
|
|
107
108
|
}
|
|
@@ -110,22 +111,22 @@ export interface EnvironmentMeta {
|
|
|
110
111
|
export type EnvironmentType =
|
|
111
112
|
// A production environment.
|
|
112
113
|
| 'production'
|
|
113
|
-
// A long-lived cloud-hosted
|
|
114
|
+
// A long-lived cloud-hosted non-production environment, or local development.
|
|
114
115
|
| 'development'
|
|
115
|
-
// A short-lived cloud-hosted
|
|
116
|
+
// A short-lived cloud-hosted non-production environment, such as a preview environment.
|
|
116
117
|
| 'ephemeral'
|
|
117
|
-
//
|
|
118
|
+
// An automated test environment.
|
|
118
119
|
| 'test';
|
|
119
120
|
|
|
120
|
-
/** Describes
|
|
121
|
+
/** Describes which cloud provider the application is running on. */
|
|
121
122
|
export type CloudProvider =
|
|
122
123
|
| 'aws' // Amazon Web Services
|
|
123
124
|
| 'gcp' // Google Cloud Platform
|
|
124
125
|
| 'azure' // Microsoft Azure
|
|
125
|
-
| 'encore' // Encore Cloud
|
|
126
|
+
| 'encore' // Encore Cloud
|
|
126
127
|
| 'local'; // Local development
|
|
127
128
|
|
|
128
|
-
/** Information about the build that
|
|
129
|
+
/** Information about the build that produced the running application. */
|
|
129
130
|
export interface BuildMeta {
|
|
130
131
|
/** The VCS revision the deployed application was built from. */
|
|
131
132
|
revision: string;
|
|
@@ -133,33 +134,34 @@ export interface BuildMeta {
|
|
|
133
134
|
|
|
134
135
|
/** Information about the deployment of the running application. */
|
|
135
136
|
export interface DeployMeta {
|
|
136
|
-
/** The unique
|
|
137
|
+
/** The unique deployment ID generated by the Encore platform. */
|
|
137
138
|
id: string;
|
|
138
139
|
|
|
139
|
-
/** The time the Encore
|
|
140
|
+
/** The time the Encore platform deployed this build to the environment. */
|
|
140
141
|
time: Date;
|
|
141
142
|
|
|
142
|
-
/** The services hosted by this deployment, keyed by
|
|
143
|
+
/** The services hosted by this deployment, keyed by service name. */
|
|
143
144
|
hostedServices: Record<string, HostedService>;
|
|
144
145
|
|
|
145
146
|
/**
|
|
146
|
-
* The
|
|
147
|
-
*
|
|
148
|
-
*
|
|
147
|
+
* The name of the worker this process is running, if any. A worker is a
|
|
148
|
+
* long-running process belonging to a service that does not serve HTTP
|
|
149
|
+
* requests, declared under `workers` in `encore.service.json`. Undefined for
|
|
150
|
+
* the service's main process.
|
|
149
151
|
*/
|
|
150
152
|
worker?: string;
|
|
151
153
|
}
|
|
152
154
|
|
|
153
155
|
export interface HostedService {
|
|
154
|
-
/** The name of the service */
|
|
156
|
+
/** The name of the service. */
|
|
155
157
|
name: string;
|
|
156
158
|
}
|
|
157
159
|
|
|
158
160
|
/**
|
|
159
161
|
* Returns metadata about the running Encore application.
|
|
160
162
|
*
|
|
161
|
-
* The metadata is cached and
|
|
162
|
-
*
|
|
163
|
+
* The metadata is cached and returns the same object on every call, so callers
|
|
164
|
+
* must not mutate it.
|
|
163
165
|
*/
|
|
164
166
|
export function appMeta(): AppMeta {
|
|
165
167
|
// Compute the metadata on first use.
|