@rasputin-ai/elysia 0.6.0 → 0.6.1
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/README.md +2 -214
- package/dist/index.js +1 -1
- package/dist/sdk-meta.d.ts +1 -1
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -1,217 +1,5 @@
|
|
|
1
1
|
# Official Rasputin AI SDK for Elysia
|
|
2
2
|
|
|
3
|
-
Report application errors to Rasputin.
|
|
3
|
+
Report application errors to Rasputin from Elysia services.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Initialize once and register the plugin early in your app:
|
|
8
|
-
|
|
9
|
-
```ts
|
|
10
|
-
import { Elysia } from 'elysia';
|
|
11
|
-
import { RasputinInit } from '@rasputin-ai/elysia';
|
|
12
|
-
|
|
13
|
-
const { client, plugin } = RasputinInit({
|
|
14
|
-
dsn: process.env.RASPUTIN_DSN!,
|
|
15
|
-
projectApiKey: process.env.RASPUTIN_PROJECT_API_KEY!,
|
|
16
|
-
release: process.env.RASPUTIN_RELEASE!,
|
|
17
|
-
environment: process.env.NODE_ENV ?? 'development',
|
|
18
|
-
enabled: ['staging', 'production'].includes(process.env.NODE_ENV ?? 'development'),
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
const app = new Elysia()
|
|
22
|
-
.use(plugin) // Register Rasputin before other plugins when possible.
|
|
23
|
-
.use(otherPlugins)
|
|
24
|
-
.listen(3000);
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
Route errors, uncaught exceptions, and unhandled rejections are reported automatically.
|
|
28
|
-
|
|
29
|
-
## Capture handled errors
|
|
30
|
-
|
|
31
|
-
```ts
|
|
32
|
-
try {
|
|
33
|
-
await processPayment();
|
|
34
|
-
} catch (error) {
|
|
35
|
-
client.captureException(error);
|
|
36
|
-
}
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Configuration
|
|
40
|
-
|
|
41
|
-
| Field | Required | Description |
|
|
42
|
-
| --- | --- | --- |
|
|
43
|
-
| `dsn` | yes | Public project DSN from Rasputin project settings. Safe for application runtime. |
|
|
44
|
-
| `projectApiKey` | yes | Secret project API key for deploy announcement and instrumentation manifest upload |
|
|
45
|
-
| `environment` | yes | Environment such as `production`, `staging`, or `preview` |
|
|
46
|
-
| `release` | yes | Git commit SHA for the deployed version |
|
|
47
|
-
| `enabled` | no | Enables or disables the SDK; defaults to `true` |
|
|
48
|
-
| `logSuccess` | no | Prints a configuration summary when setup succeeds; defaults to `true`. Failures always log. |
|
|
49
|
-
| `moduleUrl` | no | `import.meta.url` from the initialization file; helps normalize local stack paths |
|
|
50
|
-
| `sourceRoot` | no | Git repository folder for a single-package service, such as `apps/api` |
|
|
51
|
-
| `sourceRoots` | no | Package-name to Git-folder mappings for ambiguous monorepos |
|
|
52
|
-
| `repoRoot` | no | Local filesystem display root; it does not control instrumentation or Git identity |
|
|
53
|
-
|
|
54
|
-
Rasputin normally identifies source from the nearest `package.json` and verifies it against the exact release on the server. Filesystem paths such as `/container` are never used as source identity.
|
|
55
|
-
|
|
56
|
-
For deployment checks, call:
|
|
57
|
-
|
|
58
|
-
```ts
|
|
59
|
-
const verification = await client.verifyConfiguration();
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
`verified` means every instrumented source file maps uniquely to the configured Git release. If a monorepo is ambiguous, set `sourceRoot` or `sourceRoots` using repository-relative folders, never Docker paths.
|
|
63
|
-
|
|
64
|
-
Rasputin also prints a configuration summary after the instrumentation manifest is uploaded. Set `logSuccess: false` if you do not want that banner in production logs. Mapping failures still warn.
|
|
65
|
-
|
|
66
|
-
## Shutdown
|
|
67
|
-
|
|
68
|
-
Events are sent in the background. Flush before a short-lived process exits:
|
|
69
|
-
|
|
70
|
-
```ts
|
|
71
|
-
await client.flush();
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
Call `await client.close()` during graceful shutdown when the process stays alive afterward.
|
|
75
|
-
|
|
76
|
-
---
|
|
77
|
-
|
|
78
|
-
# Runtime recorder
|
|
79
|
-
|
|
80
|
-
Optionally attach the runtime state that led to an error — arguments, return values, and call history from the failing execution.
|
|
81
|
-
|
|
82
|
-
The Elysia plugin scopes each HTTP request as an execution automatically. For background jobs and other non-HTTP work, wrap them manually (see below).
|
|
83
|
-
|
|
84
|
-
## Automatic instrumentation
|
|
85
|
-
|
|
86
|
-
Rasputin wraps your functions so it can show what ran when an error happened.
|
|
87
|
-
|
|
88
|
-
**Compiled JavaScript (use this in production)**
|
|
89
|
-
|
|
90
|
-
Build as you already do, then run `rasputin-instrument` on the output. Start the process normally — no extra flags:
|
|
91
|
-
|
|
92
|
-
```json
|
|
93
|
-
{
|
|
94
|
-
"scripts": {
|
|
95
|
-
"build": "tsc && rasputin-instrument dist",
|
|
96
|
-
"start:node": "node dist/app.js",
|
|
97
|
-
"start:bun": "bun dist/app.js"
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
Have TypeScript write `.js.map` files next to the output so recorded functions still point at your `.ts` sources. The instrumenter writes `.rasputin/instrumentation-manifest.json` beside `dist`, and `RasputinInit` loads it automatically.
|
|
103
|
-
|
|
104
|
-
**Running TypeScript directly**
|
|
105
|
-
|
|
106
|
-
`rasputin-instrument` rewrites compiled `.js` files on disk. It does not run when you start TypeScript with Bun (`bun src/app.ts`, `bun run src/app.ts`, and similar). Use `--preload` so Bun wraps files as they load:
|
|
107
|
-
|
|
108
|
-
```json
|
|
109
|
-
{
|
|
110
|
-
"scripts": {
|
|
111
|
-
"start:bun": "bun --preload @rasputin-ai/elysia/instrument/bun src/app.ts"
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
On Node you can wrap compiled files as they load instead of instrumenting at build time:
|
|
117
|
-
|
|
118
|
-
```json
|
|
119
|
-
{
|
|
120
|
-
"scripts": {
|
|
121
|
-
"start:node": "node --import @rasputin-ai/elysia/instrument/node dist/app.js"
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
Use `--preload` / `--import` while you run TypeScript locally. In production, instrument at build time instead — wrapping files at startup is slower and uses more memory.
|
|
127
|
-
|
|
128
|
-
Runtime state is kept only while a request or job is running, and is attached when that work throws.
|
|
129
|
-
|
|
130
|
-
## Manual capture
|
|
131
|
-
|
|
132
|
-
For background jobs, scheduled tasks, or worker iterations, define an execution:
|
|
133
|
-
|
|
134
|
-
```ts
|
|
135
|
-
const scope = client.execution.createScope({
|
|
136
|
-
kind: 'job',
|
|
137
|
-
name: 'sync-invoices',
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
try {
|
|
141
|
-
return await scope.run(() => syncInvoices())
|
|
142
|
-
} catch (error) {
|
|
143
|
-
scope.associateError(error)
|
|
144
|
-
throw error
|
|
145
|
-
} finally {
|
|
146
|
-
scope.finish()
|
|
147
|
-
}
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
`scope.run()` executes the callback under this recording's async context and returns exactly what the callback returned. It does not wrap, replace, or observe Promises.
|
|
151
|
-
|
|
152
|
-
When automatic instrumentation is unavailable, mark individual functions explicitly:
|
|
153
|
-
|
|
154
|
-
```ts
|
|
155
|
-
const syncInvoices = client.execution.trace(
|
|
156
|
-
'src/jobs/sync-invoices.ts:syncInvoices',
|
|
157
|
-
async () => {
|
|
158
|
-
// ...
|
|
159
|
-
},
|
|
160
|
-
);
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
## Runtime support
|
|
164
|
-
|
|
165
|
-
| Environment | Support |
|
|
166
|
-
| --- | --- |
|
|
167
|
-
| TypeScript compiled to multiple JavaScript files | Use `rasputin-instrument dist` after `tsc`, with adjacent source maps |
|
|
168
|
-
| Elysia 1.4+ on Bun 1.3.x, running `.ts` or `.js` files directly | Use `--preload @rasputin-ai/elysia/instrument/bun` |
|
|
169
|
-
| Elysia 1.4+ on Node.js 22.15 or newer, unbundled ESM/CJS | Use `rasputin-instrument`, or `--import @rasputin-ai/elysia/instrument/node`; Node 22 and 24 are the supported LTS lines |
|
|
170
|
-
|
|
171
|
-
On Node.js 22, start the process with `--experimental-async-context-frame` (or set `NODE_OPTIONS`) so `AsyncLocalStorage` uses the faster implementation that Node.js 24 enables by default. Rasputin logs this once when the flag is missing; set `RASPUTIN_SUPPRESS_ASYNC_CONTEXT_FRAME_WARNING=1` to hide it.
|
|
172
|
-
| Single-file bundles (esbuild, tsup, webpack, Vite SSR, Next.js) | Automatic instrumentation is not supported |
|
|
173
|
-
| `tsx`, custom Node loader stacks, and Node's native TypeScript execution | Automatic instrumentation is not supported |
|
|
174
|
-
| Deno and edge runtimes | Not supported |
|
|
175
|
-
|
|
176
|
-
Tested on Bun 1.3.13, Node.js 24.19.0, and Elysia 1.4.28. Node.js 22.15.0 is the minimum for automatic instrumentation. Use `execution.createScope()` and `execution.trace()` when automatic instrumentation is not available.
|
|
177
|
-
|
|
178
|
-
## Recorder configuration
|
|
179
|
-
|
|
180
|
-
Defaults work for most apps. Customize to exclude noisy sources, redact fields, or retain less state:
|
|
181
|
-
|
|
182
|
-
| Field | Default | Description |
|
|
183
|
-
| --- | ---: | --- |
|
|
184
|
-
| `enabled` | `true` | Enables runtime-state capture |
|
|
185
|
-
| `maxEventsPerExecution` | `500` | Maximum events retained for one execution |
|
|
186
|
-
| `maxCapturedCallsPerFunction` | `3` | Detailed successful calls retained before similar calls are summarized |
|
|
187
|
-
| `maxActiveMemoryBytes` | `64 MiB` | Maximum recorder memory shared across active executions |
|
|
188
|
-
| `maxDepth` | `3` | Maximum captured value depth |
|
|
189
|
-
| `maxObjectKeys` | `30` | Maximum properties retained from one object |
|
|
190
|
-
| `maxArrayElements` | `20` | Maximum items retained from one array, map, or set |
|
|
191
|
-
| `maxStringLength` | `500` | Maximum characters retained from one string |
|
|
192
|
-
| `maxSerializedValueBytes` | `16 KiB` | Maximum retained size of one captured value |
|
|
193
|
-
| `runtimeStateTargetBytes` | `256 KiB` | Soft size goal for the snapshot sent with an error; extra reconstruction data is dropped first |
|
|
194
|
-
| `maxRuntimeStateBytes` | `512 KiB` | Hard size limit for that snapshot; values are dropped before call history |
|
|
195
|
-
| `redactKeys` | `[]` | Additional property names to redact (case- and separator-insensitive) |
|
|
196
|
-
| `excludeSources` | `[]` | Source globs or function-name patterns to exclude |
|
|
197
|
-
|
|
198
|
-
```ts
|
|
199
|
-
const { client, plugin } = RasputinInit({
|
|
200
|
-
// ...required options
|
|
201
|
-
executionRecorder: {
|
|
202
|
-
excludeSources: ['src/logger/**', 'packages/shared-logger/**'],
|
|
203
|
-
redactKeys: ['customerEmail'],
|
|
204
|
-
maxEventsPerExecution: 200,
|
|
205
|
-
},
|
|
206
|
-
});
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
Runtime state can include application data. Use `redactKeys` for sensitive fields.
|
|
210
|
-
|
|
211
|
-
## Diagnostics
|
|
212
|
-
|
|
213
|
-
```ts
|
|
214
|
-
const { recorder, transport } = client.getStats();
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
These counters describe what this process has recorded and sent since it started. They reset on restart. Compare two snapshots if you want activity over a window, rather than dividing lifetime totals by one request.
|
|
5
|
+
See the [Elysia documentation](https://rasputinai.dev/docs/elysia/installation).
|
package/dist/index.js
CHANGED
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.6.
|
|
3
|
+
"version": "0.6.1",
|
|
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.6.
|
|
39
|
-
"@rasputin-ai/node": "0.6.
|
|
38
|
+
"@rasputin-ai/core": "0.6.1",
|
|
39
|
+
"@rasputin-ai/node": "0.6.1"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"elysia": ">=1.4.0 <2"
|
|
@@ -46,7 +46,6 @@
|
|
|
46
46
|
"@rasputin-ai/node": "workspace:*",
|
|
47
47
|
"@types/bun": "1.3.14",
|
|
48
48
|
"@types/node": "22.13.10",
|
|
49
|
-
"esbuild": "0.25.12",
|
|
50
49
|
"elysia": "1.4.28",
|
|
51
50
|
"typescript": "5"
|
|
52
51
|
}
|