@rasputin-ai/elysia 0.6.1 → 0.7.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 +98 -64
- package/dist/rasputin-init.d.ts.map +1 -1
- package/dist/sdk-meta.d.ts +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
// src/rasputin-init.ts
|
|
2
2
|
import {
|
|
3
3
|
createClient,
|
|
4
|
-
isClientEnabled
|
|
4
|
+
isClientEnabled,
|
|
5
|
+
parseDsn,
|
|
6
|
+
resolveEndpointUrls,
|
|
7
|
+
scheduleAnnounceDeploy
|
|
5
8
|
} from "@rasputin-ai/core";
|
|
6
9
|
import {
|
|
7
10
|
createExecutionRecorder,
|
|
@@ -13,7 +16,7 @@ import { Elysia } from "elysia";
|
|
|
13
16
|
|
|
14
17
|
// src/sdk-meta.ts
|
|
15
18
|
var SDK_NAME = "@rasputin-ai/elysia";
|
|
16
|
-
var SDK_VERSION = "0.
|
|
19
|
+
var SDK_VERSION = "0.7.0";
|
|
17
20
|
|
|
18
21
|
// src/rasputin-init.ts
|
|
19
22
|
var publicExecution = (runtime) => ({
|
|
@@ -21,7 +24,7 @@ var publicExecution = (runtime) => ({
|
|
|
21
24
|
const scope = runtime.createScope(metadata);
|
|
22
25
|
return {
|
|
23
26
|
run: scope.run,
|
|
24
|
-
|
|
27
|
+
observeError: scope.observeError,
|
|
25
28
|
finish: scope.finish
|
|
26
29
|
};
|
|
27
30
|
},
|
|
@@ -32,35 +35,41 @@ var withExecution = (client, runtime, installRuntime, manifest, uninstallHandler
|
|
|
32
35
|
}) => {
|
|
33
36
|
const uninstallRuntime = installRuntime ? installAutomaticExecutionRuntime(runtime) : () => {
|
|
34
37
|
};
|
|
35
|
-
const manifestUpload = scheduleInstrumentationManifestUpload(
|
|
38
|
+
const manifestUpload = scheduleInstrumentationManifestUpload({
|
|
39
|
+
...manifest,
|
|
40
|
+
deferStart: true
|
|
41
|
+
});
|
|
36
42
|
const execution = publicExecution(runtime);
|
|
37
43
|
return {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
44
|
+
client: {
|
|
45
|
+
...client,
|
|
46
|
+
execution,
|
|
47
|
+
getStats: () => ({ ...client.getStats(), recorder: execution.getStats() }),
|
|
48
|
+
verifyConfiguration: manifestUpload.verify,
|
|
49
|
+
captureException: (error, context) => {
|
|
50
|
+
const result = client.captureException(error, context);
|
|
51
|
+
manifestUpload.flushSoon();
|
|
52
|
+
return result;
|
|
53
|
+
},
|
|
54
|
+
flush: async (timeoutMs) => {
|
|
55
|
+
const startedAt = Date.now();
|
|
56
|
+
await client.flush(timeoutMs);
|
|
57
|
+
if (timeoutMs === void 0) {
|
|
58
|
+
await manifestUpload.wait();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
await manifestUpload.wait(Math.max(0, timeoutMs - (Date.now() - startedAt)));
|
|
62
|
+
},
|
|
63
|
+
close: async () => {
|
|
64
|
+
uninstallHandlers();
|
|
65
|
+
uninstallRuntime();
|
|
66
|
+
manifestUpload.disconnect();
|
|
67
|
+
const startedAt = Date.now();
|
|
68
|
+
await client.close();
|
|
69
|
+
await manifestUpload.wait(Math.max(0, 2e3 - (Date.now() - startedAt)));
|
|
53
70
|
}
|
|
54
|
-
await manifestUpload.wait(Math.max(0, timeoutMs - (Date.now() - startedAt)));
|
|
55
71
|
},
|
|
56
|
-
|
|
57
|
-
uninstallHandlers();
|
|
58
|
-
uninstallRuntime();
|
|
59
|
-
manifestUpload.disconnect();
|
|
60
|
-
const startedAt = Date.now();
|
|
61
|
-
await client.close();
|
|
62
|
-
await manifestUpload.wait(Math.max(0, 2e3 - (Date.now() - startedAt)));
|
|
63
|
-
}
|
|
72
|
+
startManifestUpload: manifestUpload.start
|
|
64
73
|
};
|
|
65
74
|
};
|
|
66
75
|
var toStatus = (status) => {
|
|
@@ -84,42 +93,51 @@ var finishExecution = (scope, metadata) => {
|
|
|
84
93
|
} catch {
|
|
85
94
|
}
|
|
86
95
|
};
|
|
87
|
-
var
|
|
96
|
+
var requestScopes = /* @__PURE__ */ new WeakMap();
|
|
97
|
+
var observeExecutionError = (scope, error) => {
|
|
88
98
|
try {
|
|
89
|
-
scope.
|
|
99
|
+
return scope.observeError(error);
|
|
90
100
|
} catch {
|
|
101
|
+
return void 0;
|
|
91
102
|
}
|
|
92
103
|
};
|
|
93
104
|
var buildPlugin = (client, execution, recorderEnabled) => {
|
|
94
105
|
const executionBoundary = ((handler, initialRequest) => {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
106
|
+
return (request) => {
|
|
107
|
+
const scope = execution.createScope({
|
|
108
|
+
kind: "http",
|
|
109
|
+
request: { method: request.method || initialRequest.method }
|
|
110
|
+
});
|
|
100
111
|
try {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
112
|
+
requestScopes.set(request, scope);
|
|
113
|
+
requestScopes.set(initialRequest, scope);
|
|
114
|
+
} catch {
|
|
115
|
+
}
|
|
116
|
+
return scope.run(() => {
|
|
117
|
+
try {
|
|
118
|
+
const response = handler(request);
|
|
119
|
+
if (isNativeResponsePromise(response)) {
|
|
120
|
+
Promise.prototype.then.call(
|
|
121
|
+
response,
|
|
122
|
+
(value) => {
|
|
123
|
+
finishExecution(scope, { request: { status: value.status } });
|
|
124
|
+
},
|
|
125
|
+
(error) => {
|
|
126
|
+
observeExecutionError(scope, error);
|
|
127
|
+
finishExecution(scope);
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
return response;
|
|
131
|
+
}
|
|
132
|
+
finishExecution(scope, { request: { status: response.status } });
|
|
113
133
|
return response;
|
|
134
|
+
} catch (error) {
|
|
135
|
+
observeExecutionError(scope, error);
|
|
136
|
+
finishExecution(scope);
|
|
137
|
+
throw error;
|
|
114
138
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
} catch (error) {
|
|
118
|
-
rememberExecutionError(scope, error);
|
|
119
|
-
finishExecution(scope);
|
|
120
|
-
throw error;
|
|
121
|
-
}
|
|
122
|
-
});
|
|
139
|
+
});
|
|
140
|
+
};
|
|
123
141
|
});
|
|
124
142
|
const plugin = new Elysia({ name: "rasputin" }).decorate("rasputin", client);
|
|
125
143
|
if (recorderEnabled) plugin.wrap(executionBoundary);
|
|
@@ -130,7 +148,12 @@ var buildPlugin = (client, execution, recorderEnabled) => {
|
|
|
130
148
|
status: toStatus(set.status)
|
|
131
149
|
};
|
|
132
150
|
try {
|
|
133
|
-
|
|
151
|
+
const scope = requestScopes.get(request);
|
|
152
|
+
const observation = scope ? observeExecutionError(scope, error) : void 0;
|
|
153
|
+
client.captureException(error, {
|
|
154
|
+
request: requestContext,
|
|
155
|
+
...observation ? { observation } : {}
|
|
156
|
+
});
|
|
134
157
|
} catch {
|
|
135
158
|
}
|
|
136
159
|
return;
|
|
@@ -152,18 +175,15 @@ function RasputinInit(options, hooks = {}) {
|
|
|
152
175
|
});
|
|
153
176
|
const client = createClient(options, {
|
|
154
177
|
fetch,
|
|
155
|
-
announceDeploy,
|
|
178
|
+
announceDeploy: false,
|
|
156
179
|
installTransportSignalHandlers,
|
|
157
180
|
sdkVersion: SDK_VERSION,
|
|
158
181
|
sdkName: SDK_NAME,
|
|
159
|
-
|
|
160
|
-
error,
|
|
161
|
-
context?.request ? { kind: "http", request: context.request } : void 0
|
|
162
|
-
)
|
|
182
|
+
resolveObservation: (observation) => runtime.getErrorState(observation)
|
|
163
183
|
});
|
|
164
184
|
let uninstallHandlers = () => {
|
|
165
185
|
};
|
|
166
|
-
const wrappedClient = withExecution(
|
|
186
|
+
const { client: wrappedClient, startManifestUpload } = withExecution(
|
|
167
187
|
client,
|
|
168
188
|
runtime,
|
|
169
189
|
recorderEnabled,
|
|
@@ -182,14 +202,28 @@ function RasputinInit(options, hooks = {}) {
|
|
|
182
202
|
if (enabled && installProcessHandlers) {
|
|
183
203
|
uninstallHandlers = installGlobalHandlers(wrappedClient);
|
|
184
204
|
}
|
|
205
|
+
const plugin = buildPlugin(wrappedClient, runtime, recorderEnabled).onStart(() => {
|
|
206
|
+
startManifestUpload();
|
|
207
|
+
if (!enabled || announceDeploy === false) return;
|
|
208
|
+
const parsed = parseDsn(options.dsn);
|
|
209
|
+
const apiUrl = typeof options.apiUrl === "string" && options.apiUrl.trim() ? options.apiUrl.trim() : parsed?.apiUrl;
|
|
210
|
+
if (!apiUrl) return;
|
|
211
|
+
scheduleAnnounceDeploy({
|
|
212
|
+
deployUrl: resolveEndpointUrls(apiUrl).deployUrl,
|
|
213
|
+
projectApiKey: options.projectApiKey,
|
|
214
|
+
environment: options.environment,
|
|
215
|
+
release: options.release,
|
|
216
|
+
fetch
|
|
217
|
+
});
|
|
218
|
+
});
|
|
185
219
|
return {
|
|
186
220
|
client: wrappedClient,
|
|
187
|
-
plugin
|
|
221
|
+
plugin
|
|
188
222
|
};
|
|
189
223
|
} catch {
|
|
190
224
|
const client = createClient({ ...options, enabled: false });
|
|
191
225
|
const runtime = createExecutionRecorder({ enabled: false });
|
|
192
|
-
const wrappedClient = withExecution(client, runtime, false, {
|
|
226
|
+
const { client: wrappedClient } = withExecution(client, runtime, false, {
|
|
193
227
|
projectApiKey: options.projectApiKey,
|
|
194
228
|
release: options.release,
|
|
195
229
|
apiUrl: options.apiUrl,
|
|
@@ -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,EAMN,KAAK,eAAe,EAGpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACX,wBAAwB,EAExB,iBAAiB,EACjB,kBAAkB,EAClB,MAAM,mBAAmB,CAAC;AAQ3B,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;AAuHF,QAAA,MAAM,WAAW,GAChB,QAAQ,kBAAkB,EAC1B,WAAW,IAAI,CAAC,iBAAiB,EAAE,aAAa,CAAC,EACjD,iBAAiB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiExB,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.7.0",
|
|
4
4
|
"description": "Official Rasputin AI SDK for Elysia.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "bun
|
|
28
|
-
"prepublishOnly": "npm run build && bun
|
|
27
|
+
"build": "bun ../../scripts/build-package.ts .",
|
|
28
|
+
"prepublishOnly": "npm run build && bun ../../scripts/check-lockstep-versions.ts",
|
|
29
29
|
"pack:check": "npm run build && npm pack --dry-run",
|
|
30
|
-
"typecheck": "bun
|
|
30
|
+
"typecheck": "bun ../../scripts/generate-sdk-meta.ts . && bunx tsc --noEmit",
|
|
31
31
|
"lint": "biome check .",
|
|
32
32
|
"test": "bun test"
|
|
33
33
|
},
|
|
@@ -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.7.0",
|
|
39
|
+
"@rasputin-ai/node": "0.7.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"elysia": ">=1.4.0 <2"
|