@rasputin-ai/elysia 0.10.2 → 0.11.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 +50 -29
- package/dist/rasputin-init.d.ts +3 -2
- 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
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
scheduleAnnounceDeploy
|
|
9
9
|
} from "@rasputin-ai/core";
|
|
10
10
|
import {
|
|
11
|
+
bindAdaptiveRecorder,
|
|
11
12
|
createExecutionRecorder,
|
|
12
13
|
installAutomaticExecutionRuntime,
|
|
13
14
|
installGlobalHandlers,
|
|
@@ -17,7 +18,7 @@ import { Elysia } from "elysia";
|
|
|
17
18
|
|
|
18
19
|
// src/sdk-meta.ts
|
|
19
20
|
var SDK_NAME = "@rasputin-ai/elysia";
|
|
20
|
-
var SDK_VERSION = "0.
|
|
21
|
+
var SDK_VERSION = "0.11.0";
|
|
21
22
|
|
|
22
23
|
// src/rasputin-init.ts
|
|
23
24
|
var publicExecution = (runtime) => ({
|
|
@@ -33,7 +34,7 @@ var publicExecution = (runtime) => ({
|
|
|
33
34
|
getStats: runtime.getStats
|
|
34
35
|
});
|
|
35
36
|
var withExecution = (client, runtime, installRuntime, manifest, uninstallHandlers = () => {
|
|
36
|
-
}) => {
|
|
37
|
+
}, policy) => {
|
|
37
38
|
const uninstallRuntime = installRuntime ? installAutomaticExecutionRuntime(runtime) : () => {
|
|
38
39
|
};
|
|
39
40
|
const manifestUpload = scheduleInstrumentationManifestUpload({
|
|
@@ -56,9 +57,11 @@ var withExecution = (client, runtime, installRuntime, manifest, uninstallHandler
|
|
|
56
57
|
const startedAt = Date.now();
|
|
57
58
|
await client.flush(timeoutMs);
|
|
58
59
|
if (timeoutMs === void 0) {
|
|
60
|
+
await policy?.flush();
|
|
59
61
|
await manifestUpload.wait();
|
|
60
62
|
return;
|
|
61
63
|
}
|
|
64
|
+
await policy?.flush(Math.max(0, timeoutMs - (Date.now() - startedAt)));
|
|
62
65
|
await manifestUpload.wait(Math.max(0, timeoutMs - (Date.now() - startedAt)));
|
|
63
66
|
},
|
|
64
67
|
close: async () => {
|
|
@@ -66,6 +69,7 @@ var withExecution = (client, runtime, installRuntime, manifest, uninstallHandler
|
|
|
66
69
|
uninstallRuntime();
|
|
67
70
|
manifestUpload.disconnect();
|
|
68
71
|
const startedAt = Date.now();
|
|
72
|
+
await policy?.close();
|
|
69
73
|
await client.close();
|
|
70
74
|
await manifestUpload.wait(Math.max(0, 2e3 - (Date.now() - startedAt)));
|
|
71
75
|
}
|
|
@@ -102,10 +106,17 @@ var observeExecutionError = (scope, error) => {
|
|
|
102
106
|
return void 0;
|
|
103
107
|
}
|
|
104
108
|
};
|
|
105
|
-
var
|
|
109
|
+
var mergeRequestMetadata = (scope, request) => {
|
|
110
|
+
if (!scope) return;
|
|
111
|
+
try {
|
|
112
|
+
scope.mergeMetadata({ request });
|
|
113
|
+
} catch {
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
var buildPlugin = (client, runtime, recorderEnabled) => {
|
|
106
117
|
const executionBoundary = ((handler, initialRequest) => {
|
|
107
118
|
return (request) => {
|
|
108
|
-
const scope =
|
|
119
|
+
const scope = runtime.createScope({
|
|
109
120
|
kind: "http",
|
|
110
121
|
request: { method: request.method || initialRequest.method }
|
|
111
122
|
});
|
|
@@ -115,34 +126,31 @@ var buildPlugin = (client, execution, recorderEnabled) => {
|
|
|
115
126
|
} catch {
|
|
116
127
|
}
|
|
117
128
|
return scope.run(() => {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
(value
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
finishExecution(scope);
|
|
129
|
-
}
|
|
130
|
-
);
|
|
131
|
-
return response;
|
|
132
|
-
}
|
|
133
|
-
finishExecution(scope, { request: { status: response.status } });
|
|
129
|
+
const response = handler(request);
|
|
130
|
+
if (isNativeResponsePromise(response)) {
|
|
131
|
+
Promise.prototype.then.call(
|
|
132
|
+
response,
|
|
133
|
+
(value) => {
|
|
134
|
+
finishExecution(scope, { request: { status: value.status } });
|
|
135
|
+
},
|
|
136
|
+
(_error) => {
|
|
137
|
+
}
|
|
138
|
+
);
|
|
134
139
|
return response;
|
|
135
|
-
} catch (error) {
|
|
136
|
-
observeExecutionError(scope, error);
|
|
137
|
-
finishExecution(scope);
|
|
138
|
-
throw error;
|
|
139
140
|
}
|
|
141
|
+
finishExecution(scope, { request: { status: response.status } });
|
|
142
|
+
return response;
|
|
140
143
|
});
|
|
141
144
|
};
|
|
142
145
|
});
|
|
143
146
|
const plugin = new Elysia({ name: "rasputin" }).decorate("rasputin", client);
|
|
144
147
|
if (recorderEnabled) plugin.wrap(executionBoundary);
|
|
145
|
-
return plugin.
|
|
148
|
+
return plugin.onBeforeHandle({ as: "global" }, ({ request, route }) => {
|
|
149
|
+
mergeRequestMetadata(requestScopes.get(request), {
|
|
150
|
+
method: request.method,
|
|
151
|
+
route: route || void 0
|
|
152
|
+
});
|
|
153
|
+
}).onError({ as: "global" }, ({ error, request, set, route }) => {
|
|
146
154
|
const requestContext = {
|
|
147
155
|
method: request.method,
|
|
148
156
|
route: route || void 0,
|
|
@@ -150,7 +158,9 @@ var buildPlugin = (client, execution, recorderEnabled) => {
|
|
|
150
158
|
};
|
|
151
159
|
try {
|
|
152
160
|
const scope = requestScopes.get(request);
|
|
161
|
+
mergeRequestMetadata(scope, requestContext);
|
|
153
162
|
const observation = scope ? observeExecutionError(scope, error) : void 0;
|
|
163
|
+
if (scope) finishExecution(scope, { request: requestContext });
|
|
154
164
|
client.captureException(error, {
|
|
155
165
|
request: requestContext,
|
|
156
166
|
...observation ? { observation } : {}
|
|
@@ -170,9 +180,19 @@ function RasputinInit(options, hooks = {}) {
|
|
|
170
180
|
} = hooks;
|
|
171
181
|
const enabled = isClientEnabled(options);
|
|
172
182
|
const recorderEnabled = enabled && options.executionRecorder?.enabled !== false;
|
|
173
|
-
const runtime =
|
|
174
|
-
|
|
175
|
-
|
|
183
|
+
const { runtime, policy } = bindAdaptiveRecorder({
|
|
184
|
+
executionRecorder: options.executionRecorder,
|
|
185
|
+
recorderEnabled,
|
|
186
|
+
dsn: options.dsn,
|
|
187
|
+
projectApiKey: options.projectApiKey,
|
|
188
|
+
apiUrl: options.apiUrl,
|
|
189
|
+
release: options.release,
|
|
190
|
+
environment: options.environment,
|
|
191
|
+
fetch,
|
|
192
|
+
enabled: options.enabled,
|
|
193
|
+
sdkName: SDK_NAME,
|
|
194
|
+
sdkVersion: SDK_VERSION,
|
|
195
|
+
scrubPII: options.scrubPII
|
|
176
196
|
});
|
|
177
197
|
const client = createClient(options, {
|
|
178
198
|
fetch,
|
|
@@ -199,7 +219,8 @@ function RasputinInit(options, hooks = {}) {
|
|
|
199
219
|
sourceRoots: options.sourceRoots,
|
|
200
220
|
logSuccess: options.logSuccess
|
|
201
221
|
},
|
|
202
|
-
() => uninstallHandlers()
|
|
222
|
+
() => uninstallHandlers(),
|
|
223
|
+
policy
|
|
203
224
|
);
|
|
204
225
|
if (enabled && installProcessHandlers) {
|
|
205
226
|
uninstallHandlers = installGlobalHandlers(wrappedClient);
|
package/dist/rasputin-init.d.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* the framework-neutral Node recorder.
|
|
6
6
|
*/
|
|
7
7
|
import { type RasputinOptions } from '@rasputin-ai/core';
|
|
8
|
-
import type { ExecutionRecorderOptions,
|
|
8
|
+
import type { ExecutionRecorderOptions, RasputinNodeClient } from '@rasputin-ai/node';
|
|
9
|
+
import { type ExecutionRuntime } from '@rasputin-ai/node/internal';
|
|
9
10
|
import { Elysia } from 'elysia';
|
|
10
11
|
/** Elysia plugin returned by `RasputinInit`. Register it with `.use(plugin)`. */
|
|
11
12
|
export type RasputinElysiaPlugin = ReturnType<typeof buildPlugin>;
|
|
@@ -34,7 +35,7 @@ export type RasputinElysiaOptions = RasputinOptions & {
|
|
|
34
35
|
*/
|
|
35
36
|
installTransportSignalHandlers?: boolean;
|
|
36
37
|
};
|
|
37
|
-
declare const buildPlugin: (client: RasputinNodeClient,
|
|
38
|
+
declare const buildPlugin: (client: RasputinNodeClient, runtime: ExecutionRuntime, recorderEnabled: boolean) => Elysia<"", {
|
|
38
39
|
decorator: {
|
|
39
40
|
rasputin: RasputinNodeClient;
|
|
40
41
|
};
|
|
@@ -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,EAGpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACX,wBAAwB,EAExB,
|
|
1
|
+
{"version":3,"file":"rasputin-init.d.ts","sourceRoot":"","sources":["../src/rasputin-init.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAON,KAAK,eAAe,EAGpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACX,wBAAwB,EAExB,kBAAkB,EAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAIN,KAAK,gBAAgB,EAKrB,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;CACzC,CAAC;AAuIF,QAAA,MAAM,WAAW,GAChB,QAAQ,kBAAkB,EAC1B,SAAS,gBAAgB,EACzB,iBAAiB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmExB,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;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.11.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": "0.11.0",
|
|
39
|
+
"@rasputin-ai/node": "0.11.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"elysia": ">=1.4.0 <2"
|