peekinside 0.0.0-stage → 1.2.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/LICENSE +21 -0
- package/README.md +45 -2
- package/bin/peekinside.js +8 -0
- package/index.d.ts +389 -0
- package/index.js +3 -0
- package/package.json +77 -4
- package/src/PeekInside.js +731 -0
- package/src/capture/body-capture.js +86 -0
- package/src/capture/body-decoder.js +188 -0
- package/src/capture/exchange-recorder.js +263 -0
- package/src/capture/http-message.js +138 -0
- package/src/capture/ignored-paths.js +49 -0
- package/src/capture/request-body-tap.js +40 -0
- package/src/capture/response-tap.js +83 -0
- package/src/cli.js +254 -0
- package/src/config.js +183 -0
- package/src/crypto.js +189 -0
- package/src/deployment.js +183 -0
- package/src/exceptions/exception-builder.js +339 -0
- package/src/exceptions/exception-capture.js +407 -0
- package/src/exceptions/exception-record.js +118 -0
- package/src/exceptions/fingerprint.js +60 -0
- package/src/exceptions/frame-classifier.js +114 -0
- package/src/exceptions/limits.js +95 -0
- package/src/exceptions/process-monitor.js +192 -0
- package/src/exceptions/rate-limiter.js +50 -0
- package/src/exceptions/request-context.js +337 -0
- package/src/exceptions/safe-json.js +186 -0
- package/src/exceptions/source-context.js +144 -0
- package/src/exceptions/source-maps.js +313 -0
- package/src/exceptions/stack-parser.js +179 -0
- package/src/hub/brand/peekinside-span-core-mark-dark.svg +7 -0
- package/src/hub/brand/peekinside-span-core-mark-light.svg +7 -0
- package/src/hub/client.js +184 -0
- package/src/hub/entry.js +4 -0
- package/src/hub/exception-state.js +97 -0
- package/src/hub/ingest-payload.js +362 -0
- package/src/hub/process.js +175 -0
- package/src/hub/project-log.js +559 -0
- package/src/hub/segment-log.js +282 -0
- package/src/hub/server.js +561 -0
- package/src/hub/spool-ingester.js +110 -0
- package/src/hub/store.js +404 -0
- package/src/instrumentation/console.js +83 -0
- package/src/instrumentation/http.js +146 -0
- package/src/instrumentation/index.js +234 -0
- package/src/instrumentation/jobs.js +186 -0
- package/src/instrumentation/loggers.js +135 -0
- package/src/instrumentation/mongodb.js +221 -0
- package/src/instrumentation/mysql2.js +161 -0
- package/src/instrumentation/operation.js +70 -0
- package/src/instrumentation/patch.js +72 -0
- package/src/instrumentation/pg.js +218 -0
- package/src/instrumentation/prisma.js +181 -0
- package/src/integrations/express-errors.js +135 -0
- package/src/integrations/express.js +57 -0
- package/src/integrations/fastify.js +72 -0
- package/src/integrations/framework-adapter.js +53 -0
- package/src/integrations/http-server.js +32 -0
- package/src/integrations/koa.js +72 -0
- package/src/integrations/server-binder.js +120 -0
- package/src/jobs/job-context.js +40 -0
- package/src/jobs/job-run-record.js +104 -0
- package/src/jobs/job-runner.js +173 -0
- package/src/logs/log-capture.js +143 -0
- package/src/logs/log-record.js +74 -0
- package/src/project.js +76 -0
- package/src/record.js +181 -0
- package/src/release.js +157 -0
- package/src/runtime/loop-monitor.js +162 -0
- package/src/runtime/sampler.js +93 -0
- package/src/spool.js +195 -0
- package/src/timeline/caller.js +129 -0
- package/src/timeline/execution-hash.js +110 -0
- package/src/timeline/lru.js +50 -0
- package/src/timeline/masking.js +266 -0
- package/src/timeline/shape.js +77 -0
- package/src/timeline/sql.js +396 -0
- package/src/timeline/timeline.js +642 -0
- package/src/transport/batch.js +324 -0
- package/src/transport/cloud.js +363 -0
- package/src/transport/local.js +354 -0
- package/src/user.js +83 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 Steycode
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
-
#
|
|
1
|
+
# PeekInside
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Debug Node.js from the inside: every error with the request that set it off, the queries and calls it made, what it logged and your code around the line that threw. A free dashboard on your computer while you develop, and encrypted monitoring for your servers.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/peekinside)
|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install peekinside
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
import express from 'express';
|
|
17
|
+
import PeekInside from 'peekinside';
|
|
18
|
+
|
|
19
|
+
const app = express();
|
|
20
|
+
PeekInside.attach(app);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Start your app, and PeekInside prints the link to its dashboard. It works with Express, Koa, Fastify and the native http module.
|
|
24
|
+
|
|
25
|
+
Check the setup before anything breaks on its own: `npx peekinside test` sends a test error from your project.
|
|
26
|
+
|
|
27
|
+
Also recorded: background jobs (node-cron, cron, BullMQ, or `PeekInside.job()`, with an email when a scheduled job misses its run), log lines from the console, pino and winston, event-loop blocks and memory, the deploy each error came from, the user it happened to (`PeekInside.setUser()`), and TypeScript lines through your source maps.
|
|
28
|
+
|
|
29
|
+
## Documentation
|
|
30
|
+
|
|
31
|
+
Everything else is in the docs: **[peekinside.dev/docs](https://peekinside.dev/docs)**
|
|
32
|
+
|
|
33
|
+
- [Quick start](https://peekinside.dev/docs/quick-start)
|
|
34
|
+
- [Local dashboard](https://peekinside.dev/docs/local-dashboard)
|
|
35
|
+
- [PeekInside Cloud](https://peekinside.dev/docs/cloud)
|
|
36
|
+
- [Exceptions](https://peekinside.dev/docs/exceptions)
|
|
37
|
+
- [Timeline and queries](https://peekinside.dev/docs/timeline)
|
|
38
|
+
- [Logs](https://peekinside.dev/docs/logs)
|
|
39
|
+
- [Jobs and schedules](https://peekinside.dev/docs/jobs)
|
|
40
|
+
- [Runtime](https://peekinside.dev/docs/runtime)
|
|
41
|
+
- [Configuration](https://peekinside.dev/docs/configuration)
|
|
42
|
+
- [API](https://peekinside.dev/docs/api)
|
|
43
|
+
|
|
44
|
+
## License
|
|
45
|
+
|
|
46
|
+
MIT
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for PeekInside: records every request and response your Node.js app handles,
|
|
3
|
+
* and the exceptions that happen while handling them. In development they go to the free local
|
|
4
|
+
* dashboard; with an API key they are encrypted and sent to PeekInside Cloud.
|
|
5
|
+
*
|
|
6
|
+
* The signatures are structural, so Express, Connect, Koa, Fastify and node:http objects fit
|
|
7
|
+
* without PeekInside depending on any of those packages.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { IncomingMessage, Server, ServerResponse } from "node:http";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A path that is never recorded: a prefix such as `"/health"`, a regular expression, or a
|
|
14
|
+
* function that receives the pathname and returns `true` to skip it.
|
|
15
|
+
*/
|
|
16
|
+
export type IgnorePath = string | RegExp | ((pathname: string) => boolean);
|
|
17
|
+
|
|
18
|
+
export interface PeekInsideOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Maximum bytes captured per request or response body. Longer bodies are truncated and
|
|
21
|
+
* marked as such in the dashboard.
|
|
22
|
+
* @default 65536
|
|
23
|
+
*/
|
|
24
|
+
maxBodySize?: number;
|
|
25
|
+
|
|
26
|
+
/** Paths that are never recorded. */
|
|
27
|
+
ignorePaths?: IgnorePath | IgnorePath[];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Name of this app in the local dashboard.
|
|
31
|
+
* @default process.env.PEEKINSIDE_PROJECT, then the name in package.json
|
|
32
|
+
*/
|
|
33
|
+
project?: string;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Turns the free local dashboard on or off. By default it is on, except when NODE_ENV is
|
|
37
|
+
* "production" or "test", or in CI. Requests that reach the app as a deployed server are
|
|
38
|
+
* never recorded locally either way: servers need PeekInside Cloud.
|
|
39
|
+
*/
|
|
40
|
+
local?: boolean;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* PeekInside Cloud API key. When set, requests are encrypted and sent to
|
|
44
|
+
* PeekInside Cloud instead of the local dashboard.
|
|
45
|
+
* @default process.env.PEEKINSIDE_API_KEY
|
|
46
|
+
*/
|
|
47
|
+
apiKey?: string;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Environment label shown with each request, such as `"staging"`.
|
|
51
|
+
* @default process.env.PEEKINSIDE_ENV, then process.env.NODE_ENV
|
|
52
|
+
*/
|
|
53
|
+
environment?: string;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The deploy that is running, such as `"v2.4.0"` or a commit hash. Stored with every request
|
|
57
|
+
* and exception, so the dashboard shows the deploy an issue first happened in.
|
|
58
|
+
* @default process.env.PEEKINSIDE_RELEASE, then the commit your host deployed (Vercel, Render,
|
|
59
|
+
* Railway, Heroku, Netlify, Fly.io...), then the commit checked out in the project folder
|
|
60
|
+
*/
|
|
61
|
+
release?: string;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The project's folder: its name, git commit and source files are read from there.
|
|
65
|
+
* @default the folder of the package.json nearest to the app's entry file
|
|
66
|
+
*/
|
|
67
|
+
projectRoot?: string;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Records exceptions automatically: errors that reach Express, Koa or Fastify error handling,
|
|
71
|
+
* uncaught exceptions and unhandled rejections. `report()` works either way.
|
|
72
|
+
* @default true
|
|
73
|
+
*/
|
|
74
|
+
captureExceptions?: boolean;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Includes the source lines around your own code's stack frames in exception records.
|
|
78
|
+
* @default true
|
|
79
|
+
*/
|
|
80
|
+
sourceContext?: boolean;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Maps stack frames of compiled code (TypeScript output, bundles) back to your source files,
|
|
84
|
+
* with the source maps your build writes (a `.map` file, or inline). Frames keep where they ran
|
|
85
|
+
* in `generated`.
|
|
86
|
+
* @default true
|
|
87
|
+
*/
|
|
88
|
+
sourceMaps?: boolean;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Records a timeline for each request: its database queries, outgoing HTTP calls, console
|
|
92
|
+
* lines and exceptions, with counters (queries, slow queries, N+1 statements...) for the
|
|
93
|
+
* request list. `false` turns the whole timeline off.
|
|
94
|
+
* @default true
|
|
95
|
+
*/
|
|
96
|
+
timeline?: boolean;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Records database queries: pg, mysql2, MongoDB (and Mongoose), Prisma. ORMs and query
|
|
100
|
+
* builders running on them (Knex, Sequelize, TypeORM, Drizzle, Kysely) are covered too.
|
|
101
|
+
* @default true
|
|
102
|
+
*/
|
|
103
|
+
captureQueries?: boolean;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Records outgoing HTTP calls: node:http/https requests (and clients built on them) and fetch.
|
|
107
|
+
* @default true
|
|
108
|
+
*/
|
|
109
|
+
captureOutgoing?: boolean;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Records log lines from the console, pino and winston: on the timeline of the request (or job
|
|
113
|
+
* run) they are written in, and on the Logs page, from anywhere in the app.
|
|
114
|
+
* @default true
|
|
115
|
+
*/
|
|
116
|
+
captureLogs?: boolean;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The lowest level the Logs page records. Request timelines keep every level.
|
|
120
|
+
* @default "info"
|
|
121
|
+
*/
|
|
122
|
+
logLevel?: "debug" | "info" | "warn" | "error";
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Records runs of node-cron, cron and BullMQ jobs automatically (see `job()` for other jobs).
|
|
126
|
+
* @default true
|
|
127
|
+
*/
|
|
128
|
+
captureJobs?: boolean;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Keeps the values sent with queries, masked (passwords, tokens and secret-looking values
|
|
132
|
+
* never leave the process).
|
|
133
|
+
* @default true
|
|
134
|
+
*/
|
|
135
|
+
queryParams?: boolean;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Queries that take this many milliseconds or longer are flagged as slow.
|
|
139
|
+
* @default 100
|
|
140
|
+
*/
|
|
141
|
+
slowQueryMs?: number;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* A statement run this many times in one request is flagged as an N+1.
|
|
145
|
+
* @default 5
|
|
146
|
+
*/
|
|
147
|
+
nPlusOneThreshold?: number;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Event-loop blocks this long or longer (synchronous work: a large JSON.parse, a slow regular
|
|
151
|
+
* expression, a sync file read) are recorded on the timelines of the requests that waited for
|
|
152
|
+
* them. `false` turns detection off.
|
|
153
|
+
* @default 100
|
|
154
|
+
*/
|
|
155
|
+
loopBlockMs?: number | false;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Samples the process's memory, CPU and event-loop delay for the Runtime page: every 10 seconds
|
|
159
|
+
* for the local dashboard, every minute for PeekInside Cloud.
|
|
160
|
+
* @default true
|
|
161
|
+
*/
|
|
162
|
+
runtime?: boolean;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Options of `job()`. */
|
|
166
|
+
export interface JobOptions {
|
|
167
|
+
/**
|
|
168
|
+
* The job's cron expression (`"0 * * * *"`), when it runs on one: the Jobs page then shows when
|
|
169
|
+
* it misses a run, and PeekInside Cloud can email you.
|
|
170
|
+
*/
|
|
171
|
+
schedule?: string;
|
|
172
|
+
/** The schedule's time zone, such as `"Europe/Paris"`. */
|
|
173
|
+
timezone?: string;
|
|
174
|
+
/** The queue it came from. */
|
|
175
|
+
queue?: string;
|
|
176
|
+
/** @default 1 */
|
|
177
|
+
attempt?: number;
|
|
178
|
+
/** The job's input, shown with the run (the first 8 KB). */
|
|
179
|
+
data?: unknown;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Options of `report()`. */
|
|
183
|
+
export interface ReportOptions {
|
|
184
|
+
/**
|
|
185
|
+
* The request the error relates to. By default, the request being handled when `report()` is
|
|
186
|
+
* called, if any.
|
|
187
|
+
*/
|
|
188
|
+
request?: IncomingMessage;
|
|
189
|
+
|
|
190
|
+
/** Up to 32 short labels shown with the exception, such as `{ provider: "stripe" }`. */
|
|
191
|
+
tags?: Record<string, string>;
|
|
192
|
+
|
|
193
|
+
/** Any JSON-safe data shown with the exception. Past 16 KB, only a preview is kept. */
|
|
194
|
+
extra?: unknown;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Whether your app handled the error.
|
|
198
|
+
* @default true
|
|
199
|
+
*/
|
|
200
|
+
handled?: boolean;
|
|
201
|
+
|
|
202
|
+
/** Who it happened to. By default, the user set for the current request (see `setUser`). */
|
|
203
|
+
user?: PeekInsideUser | string | number | null;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Who a request or an exception was for. Encrypted with the rest in PeekInside Cloud. */
|
|
207
|
+
export interface PeekInsideUser {
|
|
208
|
+
id?: string | number;
|
|
209
|
+
email?: string;
|
|
210
|
+
name?: string;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** Options that can still change after the instance is created (see `attachTo`). */
|
|
214
|
+
export type CaptureOptions = Pick<PeekInsideOptions, "maxBodySize" | "ignorePaths">;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* What `PeekInside.attach()` understands: an Express or Connect app, a Koa app, a Fastify
|
|
218
|
+
* instance, or a node:http (or https) server.
|
|
219
|
+
*/
|
|
220
|
+
export type AttachTarget = Server | { use(...args: any[]): unknown } | { addHook(...args: any[]): unknown };
|
|
221
|
+
|
|
222
|
+
/** Express and Connect style middleware. */
|
|
223
|
+
export type NodeMiddleware = (req: IncomingMessage, res: ServerResponse, next: (error?: unknown) => void) => void;
|
|
224
|
+
|
|
225
|
+
/** Koa style middleware. */
|
|
226
|
+
export type KoaMiddleware = (
|
|
227
|
+
context: { req: IncomingMessage; res: ServerResponse },
|
|
228
|
+
next: () => Promise<unknown>,
|
|
229
|
+
) => Promise<void>;
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Records every request and response an app handles.
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* import PeekInside from "peekinside";
|
|
236
|
+
*
|
|
237
|
+
* PeekInside.attach(app); // Express, Koa, Fastify or an http.Server
|
|
238
|
+
*/
|
|
239
|
+
declare class PeekInside {
|
|
240
|
+
/**
|
|
241
|
+
* Creates an instance without attaching it. Use the middleware methods to record traffic,
|
|
242
|
+
* or `PeekInside.attach()` to do both in one line.
|
|
243
|
+
*/
|
|
244
|
+
constructor(options?: PeekInsideOptions);
|
|
245
|
+
|
|
246
|
+
/** The effective configuration. */
|
|
247
|
+
readonly options: PeekInsideOptions & Required<CaptureOptions>;
|
|
248
|
+
|
|
249
|
+
/** Whether new requests are recorded (see `setEnabled`). */
|
|
250
|
+
readonly isEnabled: boolean;
|
|
251
|
+
|
|
252
|
+
/** The deploy that is running (see the `release` option), or `null` when none was found. */
|
|
253
|
+
readonly release: string | null;
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* One-line setup: records every request the app handles.
|
|
257
|
+
*
|
|
258
|
+
* @param app - Express or Connect app, Koa app, Fastify instance, or http.Server
|
|
259
|
+
*/
|
|
260
|
+
static attach(app: AttachTarget, options?: PeekInsideOptions): PeekInside;
|
|
261
|
+
|
|
262
|
+
/** Attaches this instance to an app; see `PeekInside.attach`. */
|
|
263
|
+
attachTo(app: AttachTarget, options?: CaptureOptions): this;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Records an error, linked to the request being handled (or `options.request`).
|
|
267
|
+
*
|
|
268
|
+
* @param error - An Error, or any thrown value
|
|
269
|
+
* @returns The exception's id, or `null` when nothing was recorded (recording is off or paused,
|
|
270
|
+
* the request isn't recorded, or too many exceptions were recorded this second)
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* try {
|
|
274
|
+
* await chargeCard(order);
|
|
275
|
+
* } catch (error) {
|
|
276
|
+
* peekInside.report(error, { tags: { provider: "stripe" } });
|
|
277
|
+
* }
|
|
278
|
+
*/
|
|
279
|
+
report(error: unknown, options?: ReportOptions): string | null;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Records an error with the instance that tracks the current request, or else the most
|
|
283
|
+
* recently created instance that records. See `report()`.
|
|
284
|
+
*/
|
|
285
|
+
static report(error: unknown, options?: ReportOptions): string | null;
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Runs `fn` and records how long it took on the request's timeline. Async functions are
|
|
289
|
+
* measured until their promise settles. Outside a request, just runs `fn`.
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* const pdf = await peekInside.measure("render invoice", () => renderPdf(order));
|
|
293
|
+
*/
|
|
294
|
+
measure<T>(name: string, fn: () => T): T;
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* `measure()` with the instance that tracks the current request, or else the most recently
|
|
298
|
+
* created instance that records. Without one, just runs `fn`.
|
|
299
|
+
*/
|
|
300
|
+
static measure<T>(name: string, fn: () => T): T;
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* The id of the request the calling code runs for, as the dashboard knows it: put it in your
|
|
304
|
+
* own logs to find the request from a log line. `null` outside a recorded request.
|
|
305
|
+
*/
|
|
306
|
+
static requestId(): string | null;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Tells PeekInside who the current request is for: the request and every exception it runs into
|
|
310
|
+
* carry the user, so the dashboard counts the users an issue affects and lists everything one
|
|
311
|
+
* customer ran into. Call it once the user is known, such as in your authentication middleware.
|
|
312
|
+
*
|
|
313
|
+
* @param user - The user, or just their id; `null` forgets it
|
|
314
|
+
* @returns Whether a request was running to attach it to
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* app.use((req, res, next) => {
|
|
318
|
+
* if (req.user) PeekInside.setUser({ id: req.user.id, email: req.user.email });
|
|
319
|
+
* next();
|
|
320
|
+
* });
|
|
321
|
+
*/
|
|
322
|
+
static setUser(user: PeekInsideUser | string | number | null): boolean;
|
|
323
|
+
|
|
324
|
+
/** Same as `PeekInside.setUser()`: the user belongs to the request running now. */
|
|
325
|
+
setUser(user: PeekInsideUser | string | number | null): boolean;
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Runs a background job as a recorded job run: the Jobs page lists it with how long it took and
|
|
329
|
+
* how it ended, and its queries, calls, log lines and exceptions link to it. A job that throws or
|
|
330
|
+
* rejects is recorded as failed, and its error as an exception. `fn` runs exactly as without
|
|
331
|
+
* PeekInside, and its result (or error) is returned (or thrown) unchanged.
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* cron.schedule("0 * * * *", () =>
|
|
335
|
+
* peekInside.job("send-invoices", sendInvoices, { schedule: "0 * * * *" }));
|
|
336
|
+
*/
|
|
337
|
+
job<T>(name: string, fn: () => T, options?: JobOptions): T;
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* `job()` with the instance that tracks the current request, or else the most recently created
|
|
341
|
+
* instance that records. Without one, just runs `fn`.
|
|
342
|
+
*/
|
|
343
|
+
static job<T>(name: string, fn: () => T, options?: JobOptions): T;
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Instruments database modules that automatic patching can't reach (bundled apps, a monorepo
|
|
347
|
+
* package with its own copy): pg, mysql2, mysql2/promise, mongodb, mongoose, a PrismaClient
|
|
348
|
+
* class or instance, or the @prisma/client module. Other values are ignored.
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* import pg from "pg";
|
|
352
|
+
* peekInside.instrument(pg);
|
|
353
|
+
*/
|
|
354
|
+
instrument(...modules: unknown[]): this;
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Records one request/response pair, for frameworks without a ready-made integration.
|
|
358
|
+
* Request bodies are captured as the app reads them, so call it before reading the body.
|
|
359
|
+
*
|
|
360
|
+
* @param next - Called once tracking is set up (middleware style); its result is returned
|
|
361
|
+
*/
|
|
362
|
+
intercept(req: IncomingMessage, res: ServerResponse, next?: () => unknown): unknown;
|
|
363
|
+
|
|
364
|
+
/** Pauses (`false`) or resumes (`true`) recording. */
|
|
365
|
+
setEnabled(enabled: boolean): void;
|
|
366
|
+
|
|
367
|
+
/** Express and Connect middleware that records requests. */
|
|
368
|
+
expressMiddleware(): NodeMiddleware;
|
|
369
|
+
|
|
370
|
+
/** Koa middleware that records requests. */
|
|
371
|
+
koaMiddleware(): KoaMiddleware;
|
|
372
|
+
|
|
373
|
+
/** Registers a Fastify `onRequest` hook that records requests. */
|
|
374
|
+
fastifyHook(fastify: { addHook(...args: any[]): unknown; server?: Server }): void;
|
|
375
|
+
|
|
376
|
+
/** Records every request a node:http (or https) server handles. Returns the same server. */
|
|
377
|
+
wrapHttpServer<T extends Server>(server: T): T;
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Sends everything still queued. Call it before a short-lived process (script, serverless
|
|
381
|
+
* function, test) exits.
|
|
382
|
+
*/
|
|
383
|
+
flush(): Promise<void>;
|
|
384
|
+
|
|
385
|
+
/** Stops recording and sending. */
|
|
386
|
+
stop(): void;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export default PeekInside;
|
package/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "peekinside",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.2.1",
|
|
4
|
+
"description": "Debug Node.js from the inside: errors with the requests, queries, logs and jobs behind them. A free local dashboard, and encrypted monitoring for production",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "./index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./index.d.ts",
|
|
10
|
+
"default": "./index.js"
|
|
11
|
+
},
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"peekinside": "bin/peekinside.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"index.js",
|
|
19
|
+
"index.d.ts",
|
|
20
|
+
"src/",
|
|
21
|
+
"bin/",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"demo": "node examples/demo.js",
|
|
28
|
+
"test": "node --test",
|
|
29
|
+
"test:types": "tsc -p test-d && tsc -p test-d/tsconfig.bundler.json && tsc -p test-d/tsconfig.cjs.json",
|
|
30
|
+
"prepublishOnly": "npm test && npm run test:types"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"peekinside",
|
|
34
|
+
"http",
|
|
35
|
+
"inspector",
|
|
36
|
+
"debugging",
|
|
37
|
+
"monitoring",
|
|
38
|
+
"observability",
|
|
39
|
+
"express",
|
|
40
|
+
"koa",
|
|
41
|
+
"fastify",
|
|
42
|
+
"middleware",
|
|
43
|
+
"nodejs"
|
|
44
|
+
],
|
|
45
|
+
"author": "Jesbin",
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=18"
|
|
49
|
+
},
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "git+https://github.com/thejesbin/peekinside.git"
|
|
53
|
+
},
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/thejesbin/peekinside/issues",
|
|
56
|
+
"email": "support@peekinside.dev"
|
|
57
|
+
},
|
|
58
|
+
"homepage": "https://peekinside.dev",
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/express": "4.17.25",
|
|
61
|
+
"@types/koa": "2.15.0",
|
|
62
|
+
"@types/node": "24.10.1",
|
|
63
|
+
"bullmq": "6.3.14",
|
|
64
|
+
"cron": "4.4.0",
|
|
65
|
+
"express": "4.22.3",
|
|
66
|
+
"express5": "npm:express@5.1.0",
|
|
67
|
+
"fastify": "5.12.5",
|
|
68
|
+
"koa": "2.16.4",
|
|
69
|
+
"mongodb": "6.21.0",
|
|
70
|
+
"mongodb-memory-server-core": "11.3.0",
|
|
71
|
+
"mongoose": "8.24.5",
|
|
72
|
+
"mysql2": "3.24.5",
|
|
73
|
+
"node-cron": "4.6.0",
|
|
74
|
+
"pg": "8.23.1",
|
|
75
|
+
"pino": "10.4.0",
|
|
76
|
+
"typescript": "5.9.3",
|
|
77
|
+
"winston": "3.19.0"
|
|
78
|
+
}
|
|
79
|
+
}
|