@reqray/fastify 0.1.0 → 0.1.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 +69 -5
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,12 +1,76 @@
|
|
|
1
1
|
# @reqray/fastify
|
|
2
2
|
|
|
3
|
-
Fastify
|
|
3
|
+
Reqray for Fastify: every request as a waterfall — SQL, outgoing HTTP, cache,
|
|
4
|
+
bodies after masking — and N+1 queries pointed at the file and the line.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
Node.js. It instruments HTTP, SQL, outgoing calls and cache on its own, shows
|
|
7
|
-
every request as a waterfall, and finds N+1 down to the file and the line.
|
|
6
|
+

|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
## Use
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @reqray/fastify @reqray/register
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
import Fastify from 'fastify';
|
|
16
|
+
import { reqray } from '@reqray/fastify';
|
|
17
|
+
|
|
18
|
+
const app = Fastify();
|
|
19
|
+
await app.register(reqray);
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
node --import @reqray/register app.js
|
|
24
|
+
# open http://localhost:3000/_reqray/
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`--import @reqray/register` is what instruments the database driver, the cache
|
|
28
|
+
client and `fetch`; without it the plugin records requests and nothing inside
|
|
29
|
+
them, and says so at startup.
|
|
30
|
+
|
|
31
|
+
Fastify 5. Node 20 or newer.
|
|
32
|
+
|
|
33
|
+
## Options
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
await app.register(reqray, {
|
|
37
|
+
panel: { gate: ({ headers }) => headers['x-admin'] === process.env.ADMIN_KEY },
|
|
38
|
+
redact: { headers: ['x-api-key'] },
|
|
39
|
+
detect: { nPlusOne: { threshold: 10 } },
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
| Option | Default | What it does |
|
|
44
|
+
|---|---|---|
|
|
45
|
+
| `enabled` | `NODE_ENV !== 'production'` | Off means off: nothing is recorded and nothing is mounted |
|
|
46
|
+
| `mode` | from `NODE_ENV` | `'development'` keeps every request; `'production'` samples |
|
|
47
|
+
| `panel` | `{ path: '/_reqray' }` | `false` to not mount it; `{ gate }` decides who gets in |
|
|
48
|
+
| `transport` | memory, last 500 requests | Where records go — see `@reqray/store-sqlite`, `@reqray/transport-http`, `@reqray/transport-file` |
|
|
49
|
+
| `redact` | see below | `{ headers: [...], body: [...] }` extend the masked names |
|
|
50
|
+
| `detect` | all on | `{ nPlusOne: { threshold: 10 }, slowBudget: false }` |
|
|
51
|
+
| `sampling` | 100% locally, 1% in production | `{ rate, slowMs, alwaysOnError, alwaysOnFinding }` |
|
|
52
|
+
| `replay`, `explain`, `blame` | local development only | Opt-in anywhere else |
|
|
53
|
+
| `collectSqlValues` | `false` | SQL parameter values are never recorded unless you ask |
|
|
54
|
+
|
|
55
|
+
Masked before anything is stored: `authorization`, `cookie`, `set-cookie` in
|
|
56
|
+
headers; `password`, `token`, `secret`, `cardNumber`, `cvv`, `apiKey`,
|
|
57
|
+
`signature` in bodies and query strings.
|
|
58
|
+
|
|
59
|
+
Outside local development the panel does not mount without an explicit gate —
|
|
60
|
+
the application fails at startup with an explanation rather than opening
|
|
61
|
+
access. `panel: { gate: 'open' }` if open is what you mean, or a function:
|
|
62
|
+
`gate: ({ headers, ip }) => headers['x-admin'] === process.env.ADMIN_KEY`.
|
|
63
|
+
|
|
64
|
+
## Exceptions
|
|
65
|
+
|
|
66
|
+
An exception thrown by a handler lands in the request's record through
|
|
67
|
+
Fastify's `onError` hook. A framework on top of Fastify that catches
|
|
68
|
+
exceptions first can hand them over with `recordFailure(request, error)`.
|
|
69
|
+
|
|
70
|
+
## More
|
|
71
|
+
|
|
72
|
+
Everything else — the detectors, security defaults, measured overhead and a
|
|
73
|
+
demo that runs with one command — is in the
|
|
10
74
|
[main README](https://github.com/reqray/reqray#readme).
|
|
11
75
|
|
|
12
76
|
## License
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reqray/fastify",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Fastify
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Reqray for Fastify: every request as a waterfall with its SQL, cache and outgoing calls, and N+1 queries found down to the line.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"nodejs",
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"fastify-plugin": "^6.0.0",
|
|
52
|
-
"@reqray/core": "^0.1.
|
|
53
|
-
"@reqray/
|
|
54
|
-
"@reqray/
|
|
52
|
+
"@reqray/core": "^0.1.1",
|
|
53
|
+
"@reqray/dashboard": "^0.1.1",
|
|
54
|
+
"@reqray/store-memory": "^0.1.1"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"fastify": "^5"
|