@rasputin-ai/elysia 0.16.0 → 1.0.0
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 +36 -204
- package/dist/rasputin-init.d.ts +2 -35
- package/dist/rasputin-init.d.ts.map +1 -1
- package/dist/sdk-meta.d.ts +1 -1
- package/dist/sdk-meta.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,95 +1,16 @@
|
|
|
1
1
|
// src/rasputin-init.ts
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
createClient,
|
|
5
|
-
isClientEnabled,
|
|
6
|
-
parseDsn,
|
|
7
|
-
resolveClientActivation,
|
|
8
|
-
resolveEndpointUrls,
|
|
9
|
-
scheduleAnnounceDeploy
|
|
10
|
-
} from "@rasputin-ai/core";
|
|
11
|
-
import {
|
|
12
|
-
bindAdaptiveRecorder,
|
|
13
|
-
bindExecutionMetrics,
|
|
14
|
-
bindFunctionMetrics,
|
|
15
|
-
createDynamicDurationSampleBuckets,
|
|
16
|
-
createExecutionRecorder,
|
|
17
|
-
installAutomaticExecutionRuntime,
|
|
18
|
-
installGlobalHandlers,
|
|
19
|
-
releaseExecutionMetricsBindings,
|
|
20
|
-
releaseFunctionMetricsBindings,
|
|
21
|
-
scheduleInstrumentationManifestUpload
|
|
3
|
+
createRasputinRuntime
|
|
22
4
|
} from "@rasputin-ai/node/internal";
|
|
23
5
|
import { Elysia } from "elysia";
|
|
24
6
|
|
|
25
7
|
// src/sdk-meta.ts
|
|
26
8
|
var SDK_NAME = "@rasputin-ai/elysia";
|
|
27
|
-
var SDK_VERSION = "0.
|
|
9
|
+
var SDK_VERSION = "1.0.0";
|
|
28
10
|
|
|
29
11
|
// src/rasputin-init.ts
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
const scope = runtime.createScope(metadata);
|
|
33
|
-
return {
|
|
34
|
-
run: scope.run,
|
|
35
|
-
observeError: scope.observeError,
|
|
36
|
-
finish: scope.finish
|
|
37
|
-
};
|
|
38
|
-
},
|
|
39
|
-
trace: runtime.trace,
|
|
40
|
-
getStats: runtime.getStats
|
|
41
|
-
});
|
|
42
|
-
var withExecution = (client, runtime, installRuntime, manifest, uninstallHandlers = () => {
|
|
43
|
-
}, policy, metrics, executionMetrics) => {
|
|
44
|
-
const uninstallRuntime = installRuntime ? installAutomaticExecutionRuntime(runtime) : () => {
|
|
45
|
-
};
|
|
46
|
-
const manifestUpload = scheduleInstrumentationManifestUpload({
|
|
47
|
-
...manifest,
|
|
48
|
-
deferStart: true
|
|
49
|
-
});
|
|
50
|
-
const execution = publicExecution(runtime);
|
|
51
|
-
return {
|
|
52
|
-
client: {
|
|
53
|
-
...client,
|
|
54
|
-
execution,
|
|
55
|
-
getStats: () => ({ ...client.getStats(), recorder: execution.getStats() }),
|
|
56
|
-
verifyConfiguration: manifestUpload.verify,
|
|
57
|
-
captureException: (error, context) => {
|
|
58
|
-
const result = client.captureException(error, context);
|
|
59
|
-
manifestUpload.flushSoon();
|
|
60
|
-
return result;
|
|
61
|
-
},
|
|
62
|
-
flush: async (timeoutMs) => {
|
|
63
|
-
const startedAt = Date.now();
|
|
64
|
-
await client.flush(timeoutMs);
|
|
65
|
-
if (timeoutMs === void 0) {
|
|
66
|
-
await policy?.flush();
|
|
67
|
-
await metrics?.exporter.flush();
|
|
68
|
-
await executionMetrics?.exporter.flush();
|
|
69
|
-
await manifestUpload.wait();
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
await policy?.flush(Math.max(0, timeoutMs - (Date.now() - startedAt)));
|
|
73
|
-
await metrics?.exporter.flush(Math.max(0, timeoutMs - (Date.now() - startedAt)));
|
|
74
|
-
await executionMetrics?.exporter.flush(Math.max(0, timeoutMs - (Date.now() - startedAt)));
|
|
75
|
-
await manifestUpload.wait(Math.max(0, timeoutMs - (Date.now() - startedAt)));
|
|
76
|
-
},
|
|
77
|
-
close: async () => {
|
|
78
|
-
uninstallHandlers();
|
|
79
|
-
uninstallRuntime();
|
|
80
|
-
runtime.close();
|
|
81
|
-
manifestUpload.disconnect();
|
|
82
|
-
const startedAt = Date.now();
|
|
83
|
-
await policy?.close();
|
|
84
|
-
await releaseFunctionMetricsBindings(metrics);
|
|
85
|
-
await releaseExecutionMetricsBindings(executionMetrics);
|
|
86
|
-
await client.close();
|
|
87
|
-
await manifestUpload.wait(Math.max(0, 2e3 - (Date.now() - startedAt)));
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
startManifestUpload: manifestUpload.start
|
|
91
|
-
};
|
|
92
|
-
};
|
|
12
|
+
var CONTEXT_BODY = "body";
|
|
13
|
+
var requestScopes = /* @__PURE__ */ new WeakMap();
|
|
93
14
|
var toStatus = (status) => {
|
|
94
15
|
if (typeof status === "number" && Number.isFinite(status)) return status;
|
|
95
16
|
if (typeof status === "string") {
|
|
@@ -111,7 +32,6 @@ var finishExecution = (scope, metadata) => {
|
|
|
111
32
|
} catch {
|
|
112
33
|
}
|
|
113
34
|
};
|
|
114
|
-
var requestScopes = /* @__PURE__ */ new WeakMap();
|
|
115
35
|
var observeExecutionError = (scope, error) => {
|
|
116
36
|
try {
|
|
117
37
|
return scope.observeError(error);
|
|
@@ -126,6 +46,13 @@ var mergeRequestMetadata = (scope, request) => {
|
|
|
126
46
|
} catch {
|
|
127
47
|
}
|
|
128
48
|
};
|
|
49
|
+
var captureParsedRequestBody = (scope, parsed) => {
|
|
50
|
+
if (!scope || parsed === void 0) return;
|
|
51
|
+
try {
|
|
52
|
+
scope.captureInput(parsed);
|
|
53
|
+
} catch {
|
|
54
|
+
}
|
|
55
|
+
};
|
|
129
56
|
var buildPlugin = (client, runtime, wrapRequests) => {
|
|
130
57
|
const executionBoundary = ((handler, initialRequest) => {
|
|
131
58
|
return (request) => {
|
|
@@ -158,7 +85,12 @@ var buildPlugin = (client, runtime, wrapRequests) => {
|
|
|
158
85
|
});
|
|
159
86
|
const plugin = new Elysia({ name: "rasputin" }).decorate("rasputin", client);
|
|
160
87
|
if (wrapRequests) plugin.wrap(executionBoundary);
|
|
161
|
-
return plugin.
|
|
88
|
+
return plugin.onTransform({ as: "global" }, (context) => {
|
|
89
|
+
const request = context.request;
|
|
90
|
+
const scope = requestScopes.get(request);
|
|
91
|
+
const parsed = context[CONTEXT_BODY];
|
|
92
|
+
captureParsedRequestBody(scope, parsed);
|
|
93
|
+
}).onBeforeHandle({ as: "global" }, ({ request, route }) => {
|
|
162
94
|
mergeRequestMetadata(requestScopes.get(request), {
|
|
163
95
|
method: request.method,
|
|
164
96
|
route: route || void 0
|
|
@@ -184,125 +116,25 @@ var buildPlugin = (client, runtime, wrapRequests) => {
|
|
|
184
116
|
});
|
|
185
117
|
};
|
|
186
118
|
function RasputinInit(options, hooks = {}) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
clientEnabled: true,
|
|
207
|
-
environment: activation.environment,
|
|
208
|
-
release: activation.release,
|
|
209
|
-
ingestToken: activation.ingestToken,
|
|
210
|
-
apiUrl: activation.apiUrl,
|
|
211
|
-
fetch,
|
|
212
|
-
sampledMeasurementFormat: durationSampling
|
|
213
|
-
}) : void 0;
|
|
214
|
-
const executionMetrics = activation.enabled ? bindExecutionMetrics({
|
|
215
|
-
clientEnabled: true,
|
|
216
|
-
environment: activation.environment,
|
|
217
|
-
release: activation.release,
|
|
218
|
-
ingestToken: activation.ingestToken,
|
|
219
|
-
apiUrl: activation.apiUrl,
|
|
220
|
-
fetch,
|
|
221
|
-
sampledMeasurementFormat: durationSampling
|
|
222
|
-
}) : void 0;
|
|
223
|
-
const observeExecutions = recorderEnabled || Boolean(metrics) || Boolean(executionMetrics);
|
|
224
|
-
const durationSampler = durationSampling && observeExecutions ? createDynamicDurationSampleBuckets({ nowMs: () => Date.now() }) : void 0;
|
|
225
|
-
const { runtime, policy } = bindAdaptiveRecorder({
|
|
226
|
-
executionRecorder: options.executionRecorder,
|
|
227
|
-
recorderEnabled,
|
|
228
|
-
dsn: options.dsn,
|
|
229
|
-
projectApiKey: options.projectApiKey,
|
|
230
|
-
apiUrl: options.apiUrl,
|
|
231
|
-
release: options.release,
|
|
232
|
-
environment: options.environment,
|
|
233
|
-
fetch,
|
|
234
|
-
enabled: options.enabled,
|
|
235
|
-
sdkName: SDK_NAME,
|
|
236
|
-
sdkVersion: SDK_VERSION,
|
|
237
|
-
functionMetrics: metrics?.collector,
|
|
238
|
-
executionMetrics: executionMetrics?.collector,
|
|
239
|
-
durationSampler
|
|
240
|
-
});
|
|
241
|
-
const client = createClient(options, {
|
|
242
|
-
fetch,
|
|
243
|
-
announceDeploy: false,
|
|
244
|
-
installTransportSignalHandlers,
|
|
245
|
-
sdkVersion: SDK_VERSION,
|
|
246
|
-
sdkName: SDK_NAME,
|
|
247
|
-
redactKeys: copyRedactKeys(options.executionRecorder?.redactKeys),
|
|
248
|
-
resolveObservation: (observation) => runtime.getErrorState(observation)
|
|
249
|
-
});
|
|
250
|
-
let uninstallHandlers = () => {
|
|
251
|
-
};
|
|
252
|
-
const { client: wrappedClient, startManifestUpload } = withExecution(
|
|
253
|
-
client,
|
|
254
|
-
runtime,
|
|
255
|
-
observeExecutions,
|
|
256
|
-
{
|
|
257
|
-
projectApiKey: options.projectApiKey,
|
|
258
|
-
release: options.release,
|
|
259
|
-
apiUrl: options.apiUrl,
|
|
260
|
-
fetch,
|
|
261
|
-
enabled,
|
|
262
|
-
sourceRoot: options.sourceRoot,
|
|
263
|
-
sourceRoots: options.sourceRoots,
|
|
264
|
-
logSuccess: options.logSuccess
|
|
265
|
-
},
|
|
266
|
-
() => uninstallHandlers(),
|
|
267
|
-
policy,
|
|
268
|
-
metrics,
|
|
269
|
-
executionMetrics
|
|
270
|
-
);
|
|
271
|
-
if (enabled && installProcessHandlers) {
|
|
272
|
-
uninstallHandlers = installGlobalHandlers(wrappedClient);
|
|
273
|
-
}
|
|
274
|
-
const plugin = buildPlugin(wrappedClient, runtime, observeExecutions).onStart(() => {
|
|
275
|
-
startManifestUpload();
|
|
276
|
-
if (!enabled || announceDeploy === false) return;
|
|
277
|
-
const parsed = parseDsn(options.dsn);
|
|
278
|
-
const apiUrl = typeof options.apiUrl === "string" && options.apiUrl.trim() ? options.apiUrl.trim() : parsed?.apiUrl;
|
|
279
|
-
if (!apiUrl) return;
|
|
280
|
-
scheduleAnnounceDeploy({
|
|
281
|
-
deployUrl: resolveEndpointUrls(apiUrl).deployUrl,
|
|
282
|
-
projectApiKey: options.projectApiKey,
|
|
283
|
-
environment: options.environment,
|
|
284
|
-
release: options.release,
|
|
285
|
-
fetch
|
|
286
|
-
});
|
|
287
|
-
});
|
|
288
|
-
return {
|
|
289
|
-
client: wrappedClient,
|
|
290
|
-
plugin
|
|
291
|
-
};
|
|
292
|
-
} catch {
|
|
293
|
-
const client = createClient({ ...options, enabled: false });
|
|
294
|
-
const runtime = createExecutionRecorder({ enabled: false });
|
|
295
|
-
const { client: wrappedClient } = withExecution(client, runtime, false, {
|
|
296
|
-
projectApiKey: options.projectApiKey,
|
|
297
|
-
release: options.release,
|
|
298
|
-
apiUrl: options.apiUrl,
|
|
299
|
-
enabled: false,
|
|
300
|
-
sourceRoot: options.sourceRoot,
|
|
301
|
-
sourceRoots: options.sourceRoots,
|
|
302
|
-
logSuccess: options.logSuccess
|
|
303
|
-
});
|
|
304
|
-
return { client: wrappedClient, plugin: buildPlugin(wrappedClient, runtime, false) };
|
|
305
|
-
}
|
|
119
|
+
const {
|
|
120
|
+
installGlobalHandlers: installProcessHandlers = options.installGlobalHandlers,
|
|
121
|
+
fetch,
|
|
122
|
+
announceDeploy,
|
|
123
|
+
installTransportSignalHandlers = options.installTransportSignalHandlers
|
|
124
|
+
} = hooks;
|
|
125
|
+
const { client, runtime, observeExecutions, startStartupWork } = createRasputinRuntime(options, {
|
|
126
|
+
sdkName: SDK_NAME,
|
|
127
|
+
sdkVersion: SDK_VERSION,
|
|
128
|
+
fetch,
|
|
129
|
+
installGlobalHandlers: installProcessHandlers,
|
|
130
|
+
installTransportSignalHandlers,
|
|
131
|
+
announceDeploy,
|
|
132
|
+
deferStartupWork: true
|
|
133
|
+
});
|
|
134
|
+
const plugin = buildPlugin(client, runtime, observeExecutions).onStart(() => {
|
|
135
|
+
startStartupWork();
|
|
136
|
+
});
|
|
137
|
+
return { client, plugin };
|
|
306
138
|
}
|
|
307
139
|
export {
|
|
308
140
|
RasputinInit
|
package/dist/rasputin-init.d.ts
CHANGED
|
@@ -4,8 +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 {
|
|
8
|
-
import type { ExecutionRecorderOptions, RasputinNodeClient } from '@rasputin-ai/node';
|
|
7
|
+
import type { RasputinNodeClient, RasputinNodeOptions } from '@rasputin-ai/node';
|
|
9
8
|
import { type ExecutionRuntime } from '@rasputin-ai/node/internal';
|
|
10
9
|
import { Elysia } from 'elysia';
|
|
11
10
|
/** Elysia plugin returned by `RasputinInit`. Register it with `.use(plugin)`. */
|
|
@@ -16,39 +15,7 @@ export type RasputinElysia = {
|
|
|
16
15
|
/** Register early with `.use(plugin)` so each HTTP request is recorded. */
|
|
17
16
|
plugin: RasputinElysiaPlugin;
|
|
18
17
|
};
|
|
19
|
-
export type RasputinElysiaOptions =
|
|
20
|
-
/**
|
|
21
|
-
* Limits and redaction for the runtime recorder. Recording is on unless you
|
|
22
|
-
* set `enabled: false`. Successful requests and jobs are not kept.
|
|
23
|
-
*/
|
|
24
|
-
executionRecorder?: ExecutionRecorderOptions;
|
|
25
|
-
/**
|
|
26
|
-
* Observe `uncaughtException` / nonfatal `unhandledRejection`. Default true.
|
|
27
|
-
* Rasputin does not become the host crash/recovery owner: it exits only when
|
|
28
|
-
* it is the sole `uncaughtException` listener. Set false when the host owns
|
|
29
|
-
* process diagnostics.
|
|
30
|
-
*/
|
|
31
|
-
installGlobalHandlers?: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Install SIGINT / SIGTERM / beforeExit flush hooks. Default true.
|
|
34
|
-
* Set false when the host owns process shutdown.
|
|
35
|
-
*/
|
|
36
|
-
installTransportSignalHandlers?: boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Measure durations on a progressive schedule shared by function metrics,
|
|
39
|
-
* execution metrics, and lightweight execution recording. Default false
|
|
40
|
-
* times every eligible call and execution. True counts every call,
|
|
41
|
-
* execution, and failure, and times a subset. Function durations are
|
|
42
|
-
* keyed by function, direct caller, and execution type. Execution
|
|
43
|
-
* durations use a separate counter per execution type so they cannot
|
|
44
|
-
* move function sampling. Counters reset hourly. After 5,000 samples
|
|
45
|
-
* the tail rate still samples. Selected sessions, activations, and full
|
|
46
|
-
* capture still record every duration; metric duration statistics follow
|
|
47
|
-
* this schedule so incident traffic does not bias aggregates. Invalid
|
|
48
|
-
* values are treated as false.
|
|
49
|
-
*/
|
|
50
|
-
dynamicDurationSampling?: boolean;
|
|
51
|
-
};
|
|
18
|
+
export type RasputinElysiaOptions = RasputinNodeOptions;
|
|
52
19
|
declare const buildPlugin: (client: RasputinNodeClient, runtime: ExecutionRuntime, wrapRequests: boolean) => Elysia<"", {
|
|
53
20
|
decorator: {
|
|
54
21
|
rasputin: RasputinNodeClient;
|
|
@@ -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,KAAK,EAAqB,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACpG,OAAO,EAEN,KAAK,gBAAgB,EAErB,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,mBAAmB,CAAC;AA0ExD,QAAA,MAAM,WAAW,GAChB,QAAQ,kBAAkB,EAC1B,SAAS,gBAAgB,EACzB,cAAc,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6ErB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,qBAAqB,GAAG,cAAc,CAAC"}
|
package/dist/sdk-meta.d.ts
CHANGED
package/dist/sdk-meta.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk-meta.d.ts","sourceRoot":"","sources":["../src/sdk-meta.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,eAAO,MAAM,QAAQ,wBAAwB,CAAC;AAC9C,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"sdk-meta.d.ts","sourceRoot":"","sources":["../src/sdk-meta.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,eAAO,MAAM,QAAQ,wBAAwB,CAAC;AAC9C,eAAO,MAAM,WAAW,UAAU,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rasputin-ai/elysia",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
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": "1.0.0",
|
|
39
|
+
"@rasputin-ai/node": "1.0.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"elysia": ">=1.4.0 <2"
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@rasputin-ai/core": "workspace:*",
|
|
46
46
|
"@rasputin-ai/node": "workspace:*",
|
|
47
|
-
"@types/bun": "1.
|
|
47
|
+
"@types/bun": "1.4.5",
|
|
48
48
|
"@types/node": "22.13.10",
|
|
49
49
|
"elysia": "1.4.28",
|
|
50
50
|
"typescript": "5"
|