@encore.dev/sdk 2.0.0-beta.8 → 2.0.0-beta.9
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 +54 -0
- package/app_meta.test.ts +25 -5
- package/app_meta.ts +43 -12
- package/config/config.test.ts +8 -12
- package/config/config.ts +16 -12
- package/config/secrets.ts +19 -10
- package/config/value.ts +13 -17
- package/cron/mod.test.ts +52 -0
- package/cron/mod.ts +9 -2
- package/dist/app_meta.d.ts +37 -12
- package/dist/app_meta.d.ts.map +1 -1
- package/dist/app_meta.js +1 -0
- package/dist/app_meta.js.map +1 -1
- package/dist/config/config.d.ts +16 -12
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +5 -2
- package/dist/config/config.js.map +1 -1
- package/dist/config/secrets.d.ts +19 -10
- package/dist/config/secrets.d.ts.map +1 -1
- package/dist/config/secrets.js +19 -10
- package/dist/config/secrets.js.map +1 -1
- package/dist/config/value.d.ts +7 -5
- package/dist/config/value.d.ts.map +1 -1
- package/dist/config/value.js +10 -7
- package/dist/config/value.js.map +1 -1
- package/dist/cron/mod.d.ts +5 -1
- package/dist/cron/mod.d.ts.map +1 -1
- package/dist/cron/mod.js +8 -1
- package/dist/cron/mod.js.map +1 -1
- package/dist/frontends/mod.d.ts +39 -0
- package/dist/frontends/mod.d.ts.map +1 -0
- package/dist/frontends/mod.js +47 -0
- package/dist/frontends/mod.js.map +1 -0
- package/dist/gateway/mod.d.ts +3 -2
- package/dist/gateway/mod.d.ts.map +1 -1
- package/dist/gateway/mod.js +3 -2
- package/dist/gateway/mod.js.map +1 -1
- package/dist/gateways/mod.d.ts +42 -0
- package/dist/gateways/mod.d.ts.map +1 -0
- package/dist/gateways/mod.js +55 -0
- package/dist/gateways/mod.js.map +1 -0
- package/dist/internal/fetch.d.ts +4 -0
- package/dist/internal/fetch.d.ts.map +1 -1
- package/dist/internal/fetch.js +12 -1
- package/dist/internal/fetch.js.map +1 -1
- package/dist/internal/otel/http.d.ts +11 -0
- package/dist/internal/otel/http.d.ts.map +1 -0
- package/dist/internal/otel/http.js +64 -0
- package/dist/internal/otel/http.js.map +1 -0
- package/dist/internal/otel/index.d.ts +1 -1
- package/dist/internal/otel/index.d.ts.map +1 -1
- package/dist/internal/otel/index.js +1 -1
- package/dist/internal/otel/index.js.map +1 -1
- package/dist/internal/otel/provider.d.ts +3 -0
- package/dist/internal/otel/provider.d.ts.map +1 -1
- package/dist/internal/otel/provider.js +3 -0
- package/dist/internal/otel/provider.js.map +1 -1
- package/dist/internal/otel/span.d.ts +11 -1
- package/dist/internal/otel/span.d.ts.map +1 -1
- package/dist/internal/otel/span.js +25 -2
- package/dist/internal/otel/span.js.map +1 -1
- package/dist/internal/reqfields.d.ts +26 -6
- package/dist/internal/reqfields.d.ts.map +1 -1
- package/dist/internal/reqfields.js +44 -7
- package/dist/internal/reqfields.js.map +1 -1
- package/dist/internal/runtime/napi/napi.cjs +36 -4
- package/dist/internal/runtime/napi/napi.d.cts +99 -4
- package/dist/internal/testing/carry.d.ts +49 -0
- package/dist/internal/testing/carry.d.ts.map +1 -0
- package/dist/internal/testing/carry.js +77 -0
- package/dist/internal/testing/carry.js.map +1 -0
- package/dist/internal/testing/scope.d.ts +34 -6
- package/dist/internal/testing/scope.d.ts.map +1 -1
- package/dist/internal/testing/scope.js +103 -5
- package/dist/internal/testing/scope.js.map +1 -1
- package/dist/internal/testing/steps.d.ts +55 -0
- package/dist/internal/testing/steps.d.ts.map +1 -0
- package/dist/internal/testing/steps.js +295 -0
- package/dist/internal/testing/steps.js.map +1 -0
- package/dist/internal/testing/telemetry.d.ts +305 -0
- package/dist/internal/testing/telemetry.d.ts.map +1 -0
- package/dist/internal/testing/telemetry.js +188 -0
- package/dist/internal/testing/telemetry.js.map +1 -0
- package/dist/mod.d.ts +1 -1
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js.map +1 -1
- package/dist/pubsub/mod.d.ts +1 -1
- package/dist/pubsub/mod.d.ts.map +1 -1
- package/dist/pubsub/subscription.d.ts +6 -5
- package/dist/pubsub/subscription.d.ts.map +1 -1
- package/dist/pubsub/subscription.js.map +1 -1
- package/dist/pubsub/topic.d.ts +14 -8
- package/dist/pubsub/topic.d.ts.map +1 -1
- package/dist/pubsub/topic.js +36 -22
- package/dist/pubsub/topic.js.map +1 -1
- package/dist/reqctx/mod.d.ts +1 -18
- package/dist/reqctx/mod.d.ts.map +1 -1
- package/dist/reqctx/mod.js +1 -17
- package/dist/reqctx/mod.js.map +1 -1
- package/dist/services/index.d.ts +2 -1
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +2 -1
- package/dist/services/index.js.map +1 -1
- package/dist/storage/objects/bucket.d.ts +2 -1
- package/dist/storage/objects/bucket.d.ts.map +1 -1
- package/dist/storage/objects/bucket.js +2 -1
- package/dist/storage/objects/bucket.js.map +1 -1
- package/dist/storage/postgres/database.d.ts +5 -1
- package/dist/storage/postgres/database.d.ts.map +1 -1
- package/dist/storage/postgres/database.js +7 -3
- package/dist/storage/postgres/database.js.map +1 -1
- package/dist/storage/redis/commands.d.ts +5 -5
- package/dist/storage/redis/commands.d.ts.map +1 -1
- package/dist/storage/redis/commands.js +5 -5
- package/dist/storage/redis/commands.js.map +1 -1
- package/dist/testing/mod.d.ts +28 -5
- package/dist/testing/mod.d.ts.map +1 -1
- package/dist/testing/mod.js +52 -8
- package/dist/testing/mod.js.map +1 -1
- package/dist/testing/playwright.d.ts +93 -0
- package/dist/testing/playwright.d.ts.map +1 -0
- package/dist/testing/playwright.js +164 -0
- package/dist/testing/playwright.js.map +1 -0
- package/dist/testing/puppeteer.d.ts +36 -0
- package/dist/testing/puppeteer.d.ts.map +1 -0
- package/dist/testing/puppeteer.js +70 -0
- package/dist/testing/puppeteer.js.map +1 -0
- package/dist/testing/system.d.ts +181 -0
- package/dist/testing/system.d.ts.map +1 -0
- package/dist/testing/system.js +255 -0
- package/dist/testing/system.js.map +1 -0
- package/dist/tracing/http.d.ts +11 -0
- package/dist/tracing/http.d.ts.map +1 -0
- package/dist/tracing/http.js +34 -0
- package/dist/tracing/http.js.map +1 -0
- package/dist/tracing/mod.d.ts +1 -0
- package/dist/tracing/mod.d.ts.map +1 -1
- package/dist/tracing/mod.js +1 -0
- package/dist/tracing/mod.js.map +1 -1
- package/dist/tracing/node.d.ts +10 -0
- package/dist/tracing/node.d.ts.map +1 -0
- package/dist/tracing/node.js +142 -0
- package/dist/tracing/node.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/frontends/mod.test.ts +51 -0
- package/frontends/mod.ts +50 -0
- package/gateway/mod.ts +3 -2
- package/gateways/mod.ts +60 -0
- package/internal/fetch.ts +12 -1
- package/internal/otel/http.ts +91 -0
- package/internal/otel/index.ts +1 -1
- package/internal/otel/provider.ts +3 -0
- package/internal/otel/span.ts +25 -2
- package/internal/reqfields.ts +43 -10
- package/internal/runtime/napi/napi.cjs +36 -4
- package/internal/runtime/napi/napi.d.cts +99 -4
- package/internal/testing/carry.test.ts +242 -0
- package/internal/testing/carry.ts +101 -0
- package/internal/testing/scope.ts +106 -7
- package/internal/testing/steps.test.ts +152 -0
- package/internal/testing/steps.ts +342 -0
- package/internal/testing/telemetry.test.ts +210 -0
- package/internal/testing/telemetry.ts +466 -0
- package/mod.ts +1 -0
- package/package.json +26 -1
- package/pubsub/mod.ts +6 -1
- package/pubsub/pubsub.test.ts +1 -0
- package/pubsub/subscription.ts +6 -5
- package/pubsub/topic.ts +45 -21
- package/reqctx/mod.ts +1 -18
- package/reqctx/reqctx.test.ts +23 -0
- package/scripts/postprocess-docs.test.ts +11 -1
- package/services/index.ts +2 -1
- package/storage/objects/bucket.ts +2 -1
- package/storage/postgres/database.ts +7 -3
- package/storage/redis/commands.ts +5 -5
- package/testing/mod.ts +63 -7
- package/testing/playwright.ts +247 -0
- package/testing/puppeteer.ts +101 -0
- package/testing/system.test.ts +108 -0
- package/testing/system.ts +373 -0
- package/tracing/http.ts +49 -0
- package/tracing/mod.ts +1 -0
- package/tracing/native.test.ts +101 -4
- package/tracing/node.ts +176 -0
- package/tracing/tracing.test.ts +660 -24
package/tracing/node.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import type {Context, TextMapGetter} from '@opentelemetry/api';
|
|
2
|
+
import {errorMonitor, type EventEmitter} from 'node:events';
|
|
3
|
+
import type {
|
|
4
|
+
IncomingHttpHeaders,
|
|
5
|
+
IncomingMessage,
|
|
6
|
+
Server,
|
|
7
|
+
ServerResponse,
|
|
8
|
+
} from 'node:http';
|
|
9
|
+
import {withContext} from '../internal/otel/context';
|
|
10
|
+
import {
|
|
11
|
+
recordHTTPConnectionClosed,
|
|
12
|
+
recordHTTPError,
|
|
13
|
+
recordHTTPStatus,
|
|
14
|
+
startHTTPSpan,
|
|
15
|
+
} from '../internal/otel/http';
|
|
16
|
+
|
|
17
|
+
const headersGetter: TextMapGetter<IncomingHttpHeaders> = {
|
|
18
|
+
keys: headers => Object.keys(headers),
|
|
19
|
+
get: (headers, key) => headers[key.toLowerCase()],
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Traces a native Node HTTP listener through response completion. Preserves
|
|
24
|
+
* the receiver, request and response without consuming bodies. Synchronous
|
|
25
|
+
* results stay synchronous; PromiseLike results become Promises.
|
|
26
|
+
* The application owns error handling and error responses.
|
|
27
|
+
*/
|
|
28
|
+
export function instrumentHTTP<This = Server, Result = void>(
|
|
29
|
+
handler: (
|
|
30
|
+
this: This,
|
|
31
|
+
request: IncomingMessage,
|
|
32
|
+
response: ServerResponse,
|
|
33
|
+
) => Result,
|
|
34
|
+
): (
|
|
35
|
+
this: This,
|
|
36
|
+
request: IncomingMessage,
|
|
37
|
+
response: ServerResponse,
|
|
38
|
+
) => Result extends PromiseLike<unknown> ? Promise<Awaited<Result>> : Result {
|
|
39
|
+
return function (this: This, request, response) {
|
|
40
|
+
const url = requestURL(request);
|
|
41
|
+
const {span, context} = startHTTPSpan(
|
|
42
|
+
request.headers,
|
|
43
|
+
headersGetter,
|
|
44
|
+
request.method || '',
|
|
45
|
+
url,
|
|
46
|
+
);
|
|
47
|
+
const restoreRequest = bindEmitter(request, context);
|
|
48
|
+
const restoreResponse = bindEmitter(response, context);
|
|
49
|
+
let ended = false;
|
|
50
|
+
const end = (record: () => void) => {
|
|
51
|
+
if (ended) return;
|
|
52
|
+
ended = true;
|
|
53
|
+
response.removeListener('finish', finish);
|
|
54
|
+
response.removeListener('close', close);
|
|
55
|
+
response.removeListener(errorMonitor, fail);
|
|
56
|
+
restoreRequest();
|
|
57
|
+
restoreResponse();
|
|
58
|
+
try {
|
|
59
|
+
if (response.headersSent) recordHTTPStatus(span, response.statusCode);
|
|
60
|
+
record();
|
|
61
|
+
} finally {
|
|
62
|
+
span.end();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const finish = () => end(() => recordHTTPStatus(span, response.statusCode));
|
|
66
|
+
const close = () => {
|
|
67
|
+
if (response.writableFinished) finish();
|
|
68
|
+
else end(() => recordHTTPConnectionClosed(span));
|
|
69
|
+
};
|
|
70
|
+
const fail = (error: unknown) => end(() => recordHTTPError(span, error));
|
|
71
|
+
response.once('finish', finish);
|
|
72
|
+
response.once('close', close);
|
|
73
|
+
response.once(errorMonitor, fail);
|
|
74
|
+
if (response.writableFinished) finish();
|
|
75
|
+
else if (response.destroyed) close();
|
|
76
|
+
|
|
77
|
+
return withContext(context, () => {
|
|
78
|
+
try {
|
|
79
|
+
const result = handler.call(this, request, response);
|
|
80
|
+
if (
|
|
81
|
+
result !== null &&
|
|
82
|
+
(typeof result === 'object' || typeof result === 'function')
|
|
83
|
+
) {
|
|
84
|
+
const then = (result as {then?: unknown}).then;
|
|
85
|
+
if (typeof then === 'function') {
|
|
86
|
+
return new Promise<unknown>((resolve, reject) => {
|
|
87
|
+
then.call(result, resolve, reject);
|
|
88
|
+
}).then(
|
|
89
|
+
value => value,
|
|
90
|
+
error => {
|
|
91
|
+
fail(error);
|
|
92
|
+
throw error;
|
|
93
|
+
},
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
} catch (error) {
|
|
99
|
+
fail(error);
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}) as Result extends PromiseLike<unknown>
|
|
103
|
+
? Promise<Awaited<Result>>
|
|
104
|
+
: Result;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function requestURL(request: IncomingMessage): URL {
|
|
109
|
+
const scheme =
|
|
110
|
+
'encrypted' in request.socket && request.socket.encrypted
|
|
111
|
+
? 'https'
|
|
112
|
+
: 'http';
|
|
113
|
+
let base: URL;
|
|
114
|
+
try {
|
|
115
|
+
base = new URL(`${scheme}://${request.headers.host || 'localhost'}`);
|
|
116
|
+
} catch {
|
|
117
|
+
base = new URL(`${scheme}://localhost`);
|
|
118
|
+
}
|
|
119
|
+
const target = request.url || '/';
|
|
120
|
+
try {
|
|
121
|
+
// An origin-form path starting with // is not a new authority.
|
|
122
|
+
return new URL(
|
|
123
|
+
target.startsWith('/') ? base.origin + target : target,
|
|
124
|
+
base,
|
|
125
|
+
);
|
|
126
|
+
} catch {
|
|
127
|
+
base.pathname = target.split('?')[0]!;
|
|
128
|
+
base.search = '';
|
|
129
|
+
base.hash = '';
|
|
130
|
+
return base;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
interface EmitterBinding {
|
|
135
|
+
active: boolean;
|
|
136
|
+
original: EventEmitter['emit'];
|
|
137
|
+
descriptor: PropertyDescriptor | undefined;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const emitterBindings = new WeakMap<EventEmitter['emit'], EmitterBinding>();
|
|
141
|
+
const dispatching = new WeakSet<EventEmitter>();
|
|
142
|
+
|
|
143
|
+
function bindEmitter(emitter: EventEmitter, context: Context): () => void {
|
|
144
|
+
const binding: EmitterBinding = {
|
|
145
|
+
active: true,
|
|
146
|
+
original: emitter.emit,
|
|
147
|
+
descriptor: Object.getOwnPropertyDescriptor(emitter, 'emit'),
|
|
148
|
+
};
|
|
149
|
+
const bound: typeof emitter.emit = function (this: EventEmitter, ...args) {
|
|
150
|
+
const emit = () => binding.original.apply(this, args);
|
|
151
|
+
if (!binding.active || dispatching.has(this)) return emit();
|
|
152
|
+
return withContext(context, () => {
|
|
153
|
+
dispatching.add(this);
|
|
154
|
+
try {
|
|
155
|
+
return emit();
|
|
156
|
+
} finally {
|
|
157
|
+
dispatching.delete(this);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
emitterBindings.set(bound, binding);
|
|
162
|
+
emitter.emit = bound;
|
|
163
|
+
return () => {
|
|
164
|
+
binding.active = false;
|
|
165
|
+
if (emitter.emit !== bound) return;
|
|
166
|
+
let previous = binding;
|
|
167
|
+
for (;;) {
|
|
168
|
+
const ancestor = emitterBindings.get(previous.original);
|
|
169
|
+
if (!ancestor || ancestor.active) break;
|
|
170
|
+
previous = ancestor;
|
|
171
|
+
}
|
|
172
|
+
if (previous.descriptor)
|
|
173
|
+
Object.defineProperty(emitter, 'emit', previous.descriptor);
|
|
174
|
+
else delete (emitter as Partial<EventEmitter>).emit;
|
|
175
|
+
};
|
|
176
|
+
}
|