@rasputin-ai/elysia 0.12.1 → 0.13.1
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/dist/index.js +48 -21
- package/dist/rasputin-init.d.ts +8 -4
- package/dist/rasputin-init.d.ts.map +1 -1
- package/dist/sdk-meta.d.ts +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -4,21 +4,24 @@ import {
|
|
|
4
4
|
createClient,
|
|
5
5
|
isClientEnabled,
|
|
6
6
|
parseDsn,
|
|
7
|
+
resolveClientActivation,
|
|
7
8
|
resolveEndpointUrls,
|
|
8
9
|
scheduleAnnounceDeploy
|
|
9
10
|
} from "@rasputin-ai/core";
|
|
10
11
|
import {
|
|
11
12
|
bindAdaptiveRecorder,
|
|
13
|
+
bindFunctionMetrics,
|
|
12
14
|
createExecutionRecorder,
|
|
13
15
|
installAutomaticExecutionRuntime,
|
|
14
16
|
installGlobalHandlers,
|
|
17
|
+
releaseFunctionMetricsBindings,
|
|
15
18
|
scheduleInstrumentationManifestUpload
|
|
16
19
|
} from "@rasputin-ai/node/internal";
|
|
17
20
|
import { Elysia } from "elysia";
|
|
18
21
|
|
|
19
22
|
// src/sdk-meta.ts
|
|
20
23
|
var SDK_NAME = "@rasputin-ai/elysia";
|
|
21
|
-
var SDK_VERSION = "0.
|
|
24
|
+
var SDK_VERSION = "0.13.1";
|
|
22
25
|
|
|
23
26
|
// src/rasputin-init.ts
|
|
24
27
|
var publicExecution = (runtime) => ({
|
|
@@ -34,7 +37,7 @@ var publicExecution = (runtime) => ({
|
|
|
34
37
|
getStats: runtime.getStats
|
|
35
38
|
});
|
|
36
39
|
var withExecution = (client, runtime, installRuntime, manifest, uninstallHandlers = () => {
|
|
37
|
-
}, policy) => {
|
|
40
|
+
}, policy, metrics) => {
|
|
38
41
|
const uninstallRuntime = installRuntime ? installAutomaticExecutionRuntime(runtime) : () => {
|
|
39
42
|
};
|
|
40
43
|
const manifestUpload = scheduleInstrumentationManifestUpload({
|
|
@@ -58,10 +61,12 @@ var withExecution = (client, runtime, installRuntime, manifest, uninstallHandler
|
|
|
58
61
|
await client.flush(timeoutMs);
|
|
59
62
|
if (timeoutMs === void 0) {
|
|
60
63
|
await policy?.flush();
|
|
64
|
+
await metrics?.exporter.flush();
|
|
61
65
|
await manifestUpload.wait();
|
|
62
66
|
return;
|
|
63
67
|
}
|
|
64
68
|
await policy?.flush(Math.max(0, timeoutMs - (Date.now() - startedAt)));
|
|
69
|
+
await metrics?.exporter.flush(Math.max(0, timeoutMs - (Date.now() - startedAt)));
|
|
65
70
|
await manifestUpload.wait(Math.max(0, timeoutMs - (Date.now() - startedAt)));
|
|
66
71
|
},
|
|
67
72
|
close: async () => {
|
|
@@ -71,6 +76,7 @@ var withExecution = (client, runtime, installRuntime, manifest, uninstallHandler
|
|
|
71
76
|
manifestUpload.disconnect();
|
|
72
77
|
const startedAt = Date.now();
|
|
73
78
|
await policy?.close();
|
|
79
|
+
await releaseFunctionMetricsBindings(metrics);
|
|
74
80
|
await client.close();
|
|
75
81
|
await manifestUpload.wait(Math.max(0, 2e3 - (Date.now() - startedAt)));
|
|
76
82
|
}
|
|
@@ -114,7 +120,7 @@ var mergeRequestMetadata = (scope, request) => {
|
|
|
114
120
|
} catch {
|
|
115
121
|
}
|
|
116
122
|
};
|
|
117
|
-
var buildPlugin = (client, runtime,
|
|
123
|
+
var buildPlugin = (client, runtime, wrapRequests) => {
|
|
118
124
|
const executionBoundary = ((handler, initialRequest) => {
|
|
119
125
|
return (request) => {
|
|
120
126
|
const scope = runtime.createScope({
|
|
@@ -145,7 +151,7 @@ var buildPlugin = (client, runtime, recorderEnabled) => {
|
|
|
145
151
|
};
|
|
146
152
|
});
|
|
147
153
|
const plugin = new Elysia({ name: "rasputin" }).decorate("rasputin", client);
|
|
148
|
-
if (
|
|
154
|
+
if (wrapRequests) plugin.wrap(executionBoundary);
|
|
149
155
|
return plugin.onBeforeHandle({ as: "global" }, ({ request, route }) => {
|
|
150
156
|
mergeRequestMetadata(requestScopes.get(request), {
|
|
151
157
|
method: request.method,
|
|
@@ -180,7 +186,24 @@ function RasputinInit(options, hooks = {}) {
|
|
|
180
186
|
installTransportSignalHandlers = options.installTransportSignalHandlers
|
|
181
187
|
} = hooks;
|
|
182
188
|
const enabled = isClientEnabled(options);
|
|
189
|
+
const activation = resolveClientActivation({
|
|
190
|
+
enabled: options.enabled,
|
|
191
|
+
dsn: options.dsn,
|
|
192
|
+
projectApiKey: options.projectApiKey,
|
|
193
|
+
apiUrl: options.apiUrl,
|
|
194
|
+
release: options.release,
|
|
195
|
+
environment: options.environment
|
|
196
|
+
});
|
|
183
197
|
const recorderEnabled = enabled && options.executionRecorder?.enabled !== false;
|
|
198
|
+
const metrics = activation.enabled ? bindFunctionMetrics({
|
|
199
|
+
options: options.functionMetrics,
|
|
200
|
+
clientEnabled: true,
|
|
201
|
+
environment: activation.environment,
|
|
202
|
+
release: activation.release,
|
|
203
|
+
ingestToken: activation.ingestToken,
|
|
204
|
+
apiUrl: activation.apiUrl,
|
|
205
|
+
fetch
|
|
206
|
+
}) : void 0;
|
|
184
207
|
const { runtime, policy } = bindAdaptiveRecorder({
|
|
185
208
|
executionRecorder: options.executionRecorder,
|
|
186
209
|
recorderEnabled,
|
|
@@ -193,7 +216,8 @@ function RasputinInit(options, hooks = {}) {
|
|
|
193
216
|
enabled: options.enabled,
|
|
194
217
|
sdkName: SDK_NAME,
|
|
195
218
|
sdkVersion: SDK_VERSION,
|
|
196
|
-
scrubPII: options.scrubPII
|
|
219
|
+
scrubPII: options.scrubPII,
|
|
220
|
+
functionMetrics: metrics?.collector
|
|
197
221
|
});
|
|
198
222
|
const client = createClient(options, {
|
|
199
223
|
fetch,
|
|
@@ -209,7 +233,7 @@ function RasputinInit(options, hooks = {}) {
|
|
|
209
233
|
const { client: wrappedClient, startManifestUpload } = withExecution(
|
|
210
234
|
client,
|
|
211
235
|
runtime,
|
|
212
|
-
recorderEnabled,
|
|
236
|
+
recorderEnabled || Boolean(metrics),
|
|
213
237
|
{
|
|
214
238
|
projectApiKey: options.projectApiKey,
|
|
215
239
|
release: options.release,
|
|
@@ -221,25 +245,28 @@ function RasputinInit(options, hooks = {}) {
|
|
|
221
245
|
logSuccess: options.logSuccess
|
|
222
246
|
},
|
|
223
247
|
() => uninstallHandlers(),
|
|
224
|
-
policy
|
|
248
|
+
policy,
|
|
249
|
+
metrics
|
|
225
250
|
);
|
|
226
251
|
if (enabled && installProcessHandlers) {
|
|
227
252
|
uninstallHandlers = installGlobalHandlers(wrappedClient);
|
|
228
253
|
}
|
|
229
|
-
const plugin = buildPlugin(wrappedClient, runtime, recorderEnabled).onStart(
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
254
|
+
const plugin = buildPlugin(wrappedClient, runtime, recorderEnabled || Boolean(metrics)).onStart(
|
|
255
|
+
() => {
|
|
256
|
+
startManifestUpload();
|
|
257
|
+
if (!enabled || announceDeploy === false) return;
|
|
258
|
+
const parsed = parseDsn(options.dsn);
|
|
259
|
+
const apiUrl = typeof options.apiUrl === "string" && options.apiUrl.trim() ? options.apiUrl.trim() : parsed?.apiUrl;
|
|
260
|
+
if (!apiUrl) return;
|
|
261
|
+
scheduleAnnounceDeploy({
|
|
262
|
+
deployUrl: resolveEndpointUrls(apiUrl).deployUrl,
|
|
263
|
+
projectApiKey: options.projectApiKey,
|
|
264
|
+
environment: options.environment,
|
|
265
|
+
release: options.release,
|
|
266
|
+
fetch
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
);
|
|
243
270
|
return {
|
|
244
271
|
client: wrappedClient,
|
|
245
272
|
plugin
|
package/dist/rasputin-init.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* intentionally limited to lifecycle wiring; recording, serialization, and safety policy stay in
|
|
5
5
|
* the framework-neutral Node recorder.
|
|
6
6
|
*/
|
|
7
|
-
import { type RasputinOptions } from '@rasputin-ai/core';
|
|
7
|
+
import { type FunctionMetricsOptions, type RasputinOptions } from '@rasputin-ai/core';
|
|
8
8
|
import type { ExecutionRecorderOptions, RasputinNodeClient } from '@rasputin-ai/node';
|
|
9
9
|
import { type ExecutionRuntime } from '@rasputin-ai/node/internal';
|
|
10
10
|
import { Elysia } from 'elysia';
|
|
@@ -34,8 +34,13 @@ export type RasputinElysiaOptions = RasputinOptions & {
|
|
|
34
34
|
* Set false when the host owns process shutdown.
|
|
35
35
|
*/
|
|
36
36
|
installTransportSignalHandlers?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Opt-in function-level aggregate metrics. Off unless `enabled` is `true`.
|
|
39
|
+
* Independent of `executionRecorder`.
|
|
40
|
+
*/
|
|
41
|
+
functionMetrics?: FunctionMetricsOptions;
|
|
37
42
|
};
|
|
38
|
-
declare const buildPlugin: (client: RasputinNodeClient, runtime: ExecutionRuntime,
|
|
43
|
+
declare const buildPlugin: (client: RasputinNodeClient, runtime: ExecutionRuntime, wrapRequests: boolean) => Elysia<"", {
|
|
39
44
|
decorator: {
|
|
40
45
|
rasputin: RasputinNodeClient;
|
|
41
46
|
};
|
|
@@ -73,8 +78,7 @@ declare const buildPlugin: (client: RasputinNodeClient, runtime: ExecutionRuntim
|
|
|
73
78
|
* dsn: process.env.RASPUTIN_DSN!,
|
|
74
79
|
* projectApiKey: process.env.RASPUTIN_PROJECT_API_KEY!,
|
|
75
80
|
* release: process.env.RASPUTIN_RELEASE!,
|
|
76
|
-
* environment:
|
|
77
|
-
* enabled: ['staging', 'production'].includes(process.env.NODE_ENV ?? 'development'),
|
|
81
|
+
* environment: 'production',
|
|
78
82
|
* });
|
|
79
83
|
* app.use(plugin); // Chain this plugin as early as possible with .use(), before any other plugins or middleware.
|
|
80
84
|
* client.captureException(err); // manual capture
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rasputin-init.d.ts","sourceRoot":"","sources":["../src/rasputin-init.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"rasputin-init.d.ts","sourceRoot":"","sources":["../src/rasputin-init.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAIN,KAAK,sBAAsB,EAI3B,KAAK,eAAe,EAIpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACX,wBAAwB,EAExB,kBAAkB,EAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAKN,KAAK,gBAAgB,EAOrB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,iFAAiF;AACjF,MAAM,MAAM,oBAAoB,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAElE,MAAM,MAAM,cAAc,GAAG;IAC5B,8EAA8E;IAC9E,MAAM,EAAE,kBAAkB,CAAC;IAC3B,2EAA2E;IAC3E,MAAM,EAAE,oBAAoB,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,eAAe,GAAG;IACrD;;;OAGG;IACH,iBAAiB,CAAC,EAAE,wBAAwB,CAAC;IAC7C;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;OAGG;IACH,8BAA8B,CAAC,EAAE,OAAO,CAAC;IACzC;;;OAGG;IACH,eAAe,CAAC,EAAE,sBAAsB,CAAC;CACzC,CAAC;AA4IF,QAAA,MAAM,WAAW,GAChB,QAAQ,kBAAkB,EAC1B,SAAS,gBAAgB,EACzB,cAAc,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmErB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,qBAAqB,GAAG,cAAc,CAAC"}
|
package/dist/sdk-meta.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rasputin-ai/elysia",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"description": "Official Rasputin AI SDK for Elysia.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@rasputin-ai/core": "0.
|
|
39
|
-
"@rasputin-ai/node": "0.
|
|
38
|
+
"@rasputin-ai/core": "0.13.1",
|
|
39
|
+
"@rasputin-ai/node": "0.13.1"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"elysia": ">=1.4.0 <2"
|