@rasputin-ai/elysia 0.15.1 → 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 CHANGED
@@ -1,95 +1,16 @@
1
1
  // src/rasputin-init.ts
2
2
  import {
3
- copyRedactKeys,
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.15.1";
9
+ var SDK_VERSION = "1.0.0";
28
10
 
29
11
  // src/rasputin-init.ts
30
- var publicExecution = (runtime) => ({
31
- createScope: (metadata) => {
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.onBeforeHandle({ as: "global" }, ({ request, route }) => {
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,126 +116,25 @@ var buildPlugin = (client, runtime, wrapRequests) => {
184
116
  });
185
117
  };
186
118
  function RasputinInit(options, hooks = {}) {
187
- try {
188
- const {
189
- installGlobalHandlers: installProcessHandlers = options.installGlobalHandlers !== false,
190
- fetch,
191
- announceDeploy,
192
- installTransportSignalHandlers = options.installTransportSignalHandlers
193
- } = hooks;
194
- const enabled = isClientEnabled(options);
195
- const activation = resolveClientActivation({
196
- enabled: options.enabled,
197
- dsn: options.dsn,
198
- projectApiKey: options.projectApiKey,
199
- apiUrl: options.apiUrl,
200
- release: options.release,
201
- environment: options.environment
202
- });
203
- const recorderEnabled = enabled && options.executionRecorder?.enabled !== false;
204
- const durationSampling = options.dynamicDurationSampling === true;
205
- const metrics = activation.enabled ? bindFunctionMetrics({
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
- scrubPII: options.scrubPII,
238
- functionMetrics: metrics?.collector,
239
- executionMetrics: executionMetrics?.collector,
240
- durationSampler
241
- });
242
- const client = createClient(options, {
243
- fetch,
244
- announceDeploy: false,
245
- installTransportSignalHandlers,
246
- sdkVersion: SDK_VERSION,
247
- sdkName: SDK_NAME,
248
- redactKeys: copyRedactKeys(options.executionRecorder?.redactKeys),
249
- resolveObservation: (observation) => runtime.getErrorState(observation)
250
- });
251
- let uninstallHandlers = () => {
252
- };
253
- const { client: wrappedClient, startManifestUpload } = withExecution(
254
- client,
255
- runtime,
256
- observeExecutions,
257
- {
258
- projectApiKey: options.projectApiKey,
259
- release: options.release,
260
- apiUrl: options.apiUrl,
261
- fetch,
262
- enabled,
263
- sourceRoot: options.sourceRoot,
264
- sourceRoots: options.sourceRoots,
265
- logSuccess: options.logSuccess
266
- },
267
- () => uninstallHandlers(),
268
- policy,
269
- metrics,
270
- executionMetrics
271
- );
272
- if (enabled && installProcessHandlers) {
273
- uninstallHandlers = installGlobalHandlers(wrappedClient);
274
- }
275
- const plugin = buildPlugin(wrappedClient, runtime, observeExecutions).onStart(() => {
276
- startManifestUpload();
277
- if (!enabled || announceDeploy === false) return;
278
- const parsed = parseDsn(options.dsn);
279
- const apiUrl = typeof options.apiUrl === "string" && options.apiUrl.trim() ? options.apiUrl.trim() : parsed?.apiUrl;
280
- if (!apiUrl) return;
281
- scheduleAnnounceDeploy({
282
- deployUrl: resolveEndpointUrls(apiUrl).deployUrl,
283
- projectApiKey: options.projectApiKey,
284
- environment: options.environment,
285
- release: options.release,
286
- fetch
287
- });
288
- });
289
- return {
290
- client: wrappedClient,
291
- plugin
292
- };
293
- } catch {
294
- const client = createClient({ ...options, enabled: false });
295
- const runtime = createExecutionRecorder({ enabled: false });
296
- const { client: wrappedClient } = withExecution(client, runtime, false, {
297
- projectApiKey: options.projectApiKey,
298
- release: options.release,
299
- apiUrl: options.apiUrl,
300
- enabled: false,
301
- sourceRoot: options.sourceRoot,
302
- sourceRoots: options.sourceRoots,
303
- logSuccess: options.logSuccess
304
- });
305
- return { client: wrappedClient, plugin: buildPlugin(wrappedClient, runtime, false) };
306
- }
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 };
307
138
  }
308
139
  export {
309
140
  RasputinInit
@@ -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 { type RasputinOptions } from '@rasputin-ai/core';
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 = RasputinOptions & {
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,EAON,KAAK,eAAe,EAIpB,MAAM,mBAAmB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AM,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"}
@@ -1,4 +1,4 @@
1
1
  /** Generated by scripts/generate-sdk-meta.ts — do not edit. */
2
2
  export declare const SDK_NAME = "@rasputin-ai/elysia";
3
- export declare const SDK_VERSION = "0.15.1";
3
+ export declare const SDK_VERSION = "1.0.0";
4
4
  //# sourceMappingURL=sdk-meta.d.ts.map
@@ -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,WAAW,CAAC"}
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.15.1",
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.15.1",
39
- "@rasputin-ai/node": "0.15.1"
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.3.14",
47
+ "@types/bun": "1.4.5",
48
48
  "@types/node": "22.13.10",
49
49
  "elysia": "1.4.28",
50
50
  "typescript": "5"