@rasputin-ai/elysia 0.13.1 → 0.14.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
@@ -10,10 +10,13 @@ import {
10
10
  } from "@rasputin-ai/core";
11
11
  import {
12
12
  bindAdaptiveRecorder,
13
+ bindExecutionMetrics,
13
14
  bindFunctionMetrics,
15
+ createDynamicDurationSampleBuckets,
14
16
  createExecutionRecorder,
15
17
  installAutomaticExecutionRuntime,
16
18
  installGlobalHandlers,
19
+ releaseExecutionMetricsBindings,
17
20
  releaseFunctionMetricsBindings,
18
21
  scheduleInstrumentationManifestUpload
19
22
  } from "@rasputin-ai/node/internal";
@@ -21,7 +24,7 @@ import { Elysia } from "elysia";
21
24
 
22
25
  // src/sdk-meta.ts
23
26
  var SDK_NAME = "@rasputin-ai/elysia";
24
- var SDK_VERSION = "0.13.1";
27
+ var SDK_VERSION = "0.14.0";
25
28
 
26
29
  // src/rasputin-init.ts
27
30
  var publicExecution = (runtime) => ({
@@ -37,7 +40,7 @@ var publicExecution = (runtime) => ({
37
40
  getStats: runtime.getStats
38
41
  });
39
42
  var withExecution = (client, runtime, installRuntime, manifest, uninstallHandlers = () => {
40
- }, policy, metrics) => {
43
+ }, policy, metrics, executionMetrics) => {
41
44
  const uninstallRuntime = installRuntime ? installAutomaticExecutionRuntime(runtime) : () => {
42
45
  };
43
46
  const manifestUpload = scheduleInstrumentationManifestUpload({
@@ -62,11 +65,13 @@ var withExecution = (client, runtime, installRuntime, manifest, uninstallHandler
62
65
  if (timeoutMs === void 0) {
63
66
  await policy?.flush();
64
67
  await metrics?.exporter.flush();
68
+ await executionMetrics?.exporter.flush();
65
69
  await manifestUpload.wait();
66
70
  return;
67
71
  }
68
72
  await policy?.flush(Math.max(0, timeoutMs - (Date.now() - startedAt)));
69
73
  await metrics?.exporter.flush(Math.max(0, timeoutMs - (Date.now() - startedAt)));
74
+ await executionMetrics?.exporter.flush(Math.max(0, timeoutMs - (Date.now() - startedAt)));
70
75
  await manifestUpload.wait(Math.max(0, timeoutMs - (Date.now() - startedAt)));
71
76
  },
72
77
  close: async () => {
@@ -77,6 +82,7 @@ var withExecution = (client, runtime, installRuntime, manifest, uninstallHandler
77
82
  const startedAt = Date.now();
78
83
  await policy?.close();
79
84
  await releaseFunctionMetricsBindings(metrics);
85
+ await releaseExecutionMetricsBindings(executionMetrics);
80
86
  await client.close();
81
87
  await manifestUpload.wait(Math.max(0, 2e3 - (Date.now() - startedAt)));
82
88
  }
@@ -195,6 +201,7 @@ function RasputinInit(options, hooks = {}) {
195
201
  environment: options.environment
196
202
  });
197
203
  const recorderEnabled = enabled && options.executionRecorder?.enabled !== false;
204
+ const durationSampling = options.dynamicDurationSampling === true;
198
205
  const metrics = activation.enabled ? bindFunctionMetrics({
199
206
  options: options.functionMetrics,
200
207
  clientEnabled: true,
@@ -202,8 +209,20 @@ function RasputinInit(options, hooks = {}) {
202
209
  release: activation.release,
203
210
  ingestToken: activation.ingestToken,
204
211
  apiUrl: activation.apiUrl,
205
- fetch
212
+ fetch,
213
+ sampledMeasurementFormat: durationSampling
214
+ }) : void 0;
215
+ const executionMetrics = activation.enabled ? bindExecutionMetrics({
216
+ options: options.executionMetrics,
217
+ clientEnabled: true,
218
+ environment: activation.environment,
219
+ release: activation.release,
220
+ ingestToken: activation.ingestToken,
221
+ apiUrl: activation.apiUrl,
222
+ fetch,
223
+ sampledMeasurementFormat: durationSampling
206
224
  }) : void 0;
225
+ const durationSampler = durationSampling && (recorderEnabled || Boolean(metrics) || Boolean(executionMetrics)) ? createDynamicDurationSampleBuckets({ nowMs: () => Date.now() }) : void 0;
207
226
  const { runtime, policy } = bindAdaptiveRecorder({
208
227
  executionRecorder: options.executionRecorder,
209
228
  recorderEnabled,
@@ -217,7 +236,9 @@ function RasputinInit(options, hooks = {}) {
217
236
  sdkName: SDK_NAME,
218
237
  sdkVersion: SDK_VERSION,
219
238
  scrubPII: options.scrubPII,
220
- functionMetrics: metrics?.collector
239
+ functionMetrics: metrics?.collector,
240
+ executionMetrics: executionMetrics?.collector,
241
+ durationSampler
221
242
  });
222
243
  const client = createClient(options, {
223
244
  fetch,
@@ -246,7 +267,8 @@ function RasputinInit(options, hooks = {}) {
246
267
  },
247
268
  () => uninstallHandlers(),
248
269
  policy,
249
- metrics
270
+ metrics,
271
+ executionMetrics
250
272
  );
251
273
  if (enabled && installProcessHandlers) {
252
274
  uninstallHandlers = installGlobalHandlers(wrappedClient);
@@ -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 FunctionMetricsOptions, type RasputinOptions } from '@rasputin-ai/core';
7
+ import { type ExecutionMetricsOptions, 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,11 +34,31 @@ export type RasputinElysiaOptions = RasputinOptions & {
34
34
  * Set false when the host owns process shutdown.
35
35
  */
36
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;
37
51
  /**
38
52
  * Opt-in function-level aggregate metrics. Off unless `enabled` is `true`.
39
53
  * Independent of `executionRecorder`.
40
54
  */
41
55
  functionMetrics?: FunctionMetricsOptions;
56
+ /**
57
+ * Execution-level counts, failures, and duration histograms. On with a
58
+ * valid client. Set `enabled: false` to turn them off. Independent of
59
+ * `executionRecorder` and `functionMetrics`.
60
+ */
61
+ executionMetrics?: ExecutionMetricsOptions;
42
62
  };
43
63
  declare const buildPlugin: (client: RasputinNodeClient, runtime: ExecutionRuntime, wrapRequests: boolean) => Elysia<"", {
44
64
  decorator: {
@@ -1 +1 @@
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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F;;;;;;;;;;;;;;;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.13.1";
3
+ export declare const SDK_VERSION = "0.14.0";
4
4
  //# sourceMappingURL=sdk-meta.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rasputin-ai/elysia",
3
- "version": "0.13.1",
3
+ "version": "0.14.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.13.1",
39
- "@rasputin-ai/node": "0.13.1"
38
+ "@rasputin-ai/core": "0.14.0",
39
+ "@rasputin-ai/node": "0.14.0"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "elysia": ">=1.4.0 <2"