api-tracer-kit 1.0.0 → 1.1.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/CHANGELOG.md +17 -0
- package/README.md +77 -342
- package/cli/bin/api-tracer.mjs +93 -2
- package/cli/setup.mjs +182 -0
- package/cli/test.mjs +97 -0
- package/cli/web/app.css +1 -2
- package/dist/axios.cjs +8 -0
- package/dist/axios.cjs.map +1 -1
- package/dist/axios.js +8 -0
- package/dist/axios.js.map +1 -1
- package/dist/index.cjs +8 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +8 -0
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +8 -0
- package/dist/react.js.map +1 -1
- package/dist/ui.cjs +8 -0
- package/dist/ui.cjs.map +1 -1
- package/dist/ui.js +8 -0
- package/dist/ui.js.map +1 -1
- package/docs/architecture.md +136 -0
- package/docs/configuration.md +275 -0
- package/docs/console.md +428 -0
- package/docs/frameworks.md +192 -0
- package/docs/getting-started.md +120 -0
- package/docs/security.md +143 -0
- package/docs/tracer.md +330 -0
- package/docs/troubleshooting.md +194 -0
- package/package.json +2 -1
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# Troubleshooting
|
|
2
|
+
|
|
3
|
+
## Nothing is being recorded
|
|
4
|
+
|
|
5
|
+
Work down this list in order. Each step tells you which link in the chain is
|
|
6
|
+
broken, so you never have to guess.
|
|
7
|
+
|
|
8
|
+
### 1. Is the tracer running at all?
|
|
9
|
+
|
|
10
|
+
Open your app and look at the **browser** console. With `debug: true` or a log
|
|
11
|
+
of your own you should see the tracer start. If you see nothing, `init()` never
|
|
12
|
+
ran — the package is installed but nothing imported it.
|
|
13
|
+
|
|
14
|
+
**Installing a package does not run it.** Something must import the module that
|
|
15
|
+
calls `init()`, and that module must be reachable from your entry point:
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
// src/index.js
|
|
19
|
+
import './services/apiRecorder';
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Check the module is actually in the bundle:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
curl -s http://localhost:3000/static/js/bundle.js | grep -c 'api-tracer-kit'
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Zero means it is not being compiled in.
|
|
29
|
+
|
|
30
|
+
### 2. Is it configured the way you think?
|
|
31
|
+
|
|
32
|
+
Inspect the live tracer from the browser console:
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
const t = globalThis[Symbol.for('api-tracer-kit.registry')].tracer;
|
|
36
|
+
({ active: t.isActive, patches: t.uninstallers.length, excludes: t.options.exclude.map(String) });
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
| What you see | What it means |
|
|
40
|
+
| --- | --- |
|
|
41
|
+
| `active: false` | `init()` never ran |
|
|
42
|
+
| `excludes: []` when you passed `reportTo` | **your options were ignored — see below** |
|
|
43
|
+
| `patches: 3` when you passed `transports: []` | same cause |
|
|
44
|
+
|
|
45
|
+
**The most common cause of a tracer that runs but reports nothing is a second
|
|
46
|
+
`init()`.** It is idempotent — a second call keeps the first one's configuration
|
|
47
|
+
so it cannot install a second set of interceptors and double-count every
|
|
48
|
+
request. Since 1.0.1 it warns:
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
[api-tracer] init() was called again on a tracer that is already running, so these
|
|
52
|
+
options were ignored: reportTo, transports, envelope.
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Find every call and keep exactly one:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
grep -rn 'apiTracer.init\|initApiTracer' src/
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 3. Is your app actually making API calls?
|
|
62
|
+
|
|
63
|
+
An app sitting on a login screen may make none. Check the Network tab, or:
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
globalThis[Symbol.for('api-tracer-kit.registry')].tracer.getTraces().length;
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Traces above zero means the tracer works and the problem is downstream — go to
|
|
70
|
+
step 5. Zero traces with calls visible in the Network tab means the transport
|
|
71
|
+
carrying them is not patched — step 4.
|
|
72
|
+
|
|
73
|
+
### 4. Is the right transport patched?
|
|
74
|
+
|
|
75
|
+
`transports: []` patches **nothing globally**. That is correct when you only
|
|
76
|
+
want axios, but it means plain `fetch` and `XMLHttpRequest` calls are invisible.
|
|
77
|
+
|
|
78
|
+
axios instances need `useAxios()`; there is no global to patch. And it must
|
|
79
|
+
cover the instance your code actually uses — `useAxios(axios)` covers the
|
|
80
|
+
default export and everything `axios.create()` makes **after** that call, so
|
|
81
|
+
`init()` has to run before your API layer creates its instances.
|
|
82
|
+
|
|
83
|
+
### 5. Are traces reaching the console?
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
curl -s http://127.0.0.1:4400/api/live | python3 -c 'import json,sys; print(json.load(sys.stdin)["count"])'
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Still zero with traces in memory? The reporter is failing. It fails **silently
|
|
90
|
+
by design** — a console that is not running must never affect your app — so look
|
|
91
|
+
at the Network tab for the POST to `/api/record`.
|
|
92
|
+
|
|
93
|
+
| | |
|
|
94
|
+
| --- | --- |
|
|
95
|
+
| No request at all | `reportTo` is not set. Back to step 2. |
|
|
96
|
+
| `404` | Path mismatch. If `reportTo` is `/api-console`, the console must run with `BASE_PATH=/api-console`. |
|
|
97
|
+
| CORS error | Add your app's origin to `ALLOWED_ORIGINS`. Localhost always works. |
|
|
98
|
+
| `ERR_CONNECTION_REFUSED` | The console is not running, or is on a different port. |
|
|
99
|
+
| Blocked, mixed content | An HTTPS app cannot post to an `http://` console. Serve the console over TLS or under a path on the app's own origin. |
|
|
100
|
+
|
|
101
|
+
### 6. Are you looking at the right app?
|
|
102
|
+
|
|
103
|
+
If port 3000 was taken, CRA silently starts on 3001 — and you may be browsing a
|
|
104
|
+
different project entirely:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
lsof -nP -iTCP:3000 -sTCP:LISTEN
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## The scan finds no endpoints
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
npx api-tracer init
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
It prints what each preset found:
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
service-object 325
|
|
120
|
+
fetch-direct 1
|
|
121
|
+
axios-direct 0
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
All zero means no preset reads your codebase. Check `sources` covers where your
|
|
125
|
+
API layer lives, then either force one with `--preset`, or write a `parse`
|
|
126
|
+
function — see [Configuration](./configuration.md#your-own-scanner).
|
|
127
|
+
|
|
128
|
+
Live recording works without a catalog: every call is adopted as an endpoint of
|
|
129
|
+
its own.
|
|
130
|
+
|
|
131
|
+
## Endpoints list, but nothing is captured
|
|
132
|
+
|
|
133
|
+
Those are independent. The list comes from the console reading your source; the
|
|
134
|
+
captures come from your app posting traffic. A working list tells you nothing
|
|
135
|
+
about the tracer. Go to step 1 above.
|
|
136
|
+
|
|
137
|
+
## `Module not found: ... falls outside of the project src/ directory`
|
|
138
|
+
|
|
139
|
+
CRA's `ModuleScopePlugin`. You imported by relative path. Import by package
|
|
140
|
+
name; see [Frameworks → CRA](./frameworks.md#create-react-app).
|
|
141
|
+
|
|
142
|
+
## `Package "api-tracer-kit" refers to a non-existing file`
|
|
143
|
+
|
|
144
|
+
Yarn 1 resolving a relative `file:` path wrongly. Use a packed tarball, or a
|
|
145
|
+
published version. See [Frameworks → CRA](./frameworks.md#create-react-app).
|
|
146
|
+
|
|
147
|
+
## A second React, or "invalid hook call"
|
|
148
|
+
|
|
149
|
+
`yarn add file:<directory>` copies the whole directory, **including its own
|
|
150
|
+
`node_modules`** — React among them. Two Reacts in one build breaks hooks. A
|
|
151
|
+
registry install or a packed tarball ships only what `files` allows.
|
|
152
|
+
|
|
153
|
+
## Every call is recorded twice
|
|
154
|
+
|
|
155
|
+
Two `init()` calls on separate instances, or a second copy of the package in the
|
|
156
|
+
build. The shared tracer is held in a global registry so entry points agree; a
|
|
157
|
+
duplicate usually means two different versions are installed.
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
npm ls api-tracer-kit
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
axios calls are **not** a cause: a call seen by both the axios and XHR adapters
|
|
164
|
+
is recorded once.
|
|
165
|
+
|
|
166
|
+
## Response bodies are missing
|
|
167
|
+
|
|
168
|
+
Check `response.bodyOmitted`:
|
|
169
|
+
|
|
170
|
+
| | |
|
|
171
|
+
| --- | --- |
|
|
172
|
+
| `too-large` | over `maxBodyBytes` (default 200 kB). Raise it if you need them. |
|
|
173
|
+
| `stream` | `text/event-stream`. Never buffered, deliberately. |
|
|
174
|
+
| `binary` | a non-textual content type. Described, not read. |
|
|
175
|
+
| `unreadable` | the body could not be cloned or parsed. |
|
|
176
|
+
|
|
177
|
+
## A response body is `<redacted>`
|
|
178
|
+
|
|
179
|
+
A field whose **name** matched `redactFields`, or a header matching
|
|
180
|
+
`redactHeaders`. That is working as intended. Narrow the pattern if it is too
|
|
181
|
+
eager — but see [Security](./security.md) first.
|
|
182
|
+
|
|
183
|
+
## The app broke after adding the tracer
|
|
184
|
+
|
|
185
|
+
It should not have; that is the package's first design constraint. Confirm by
|
|
186
|
+
removing it:
|
|
187
|
+
|
|
188
|
+
```js
|
|
189
|
+
apiTracer.destroy();
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
That restores every patched global and axios adapter. If the problem survives
|
|
193
|
+
`destroy()`, it is not the tracer. If it does not, please open an issue with the
|
|
194
|
+
transport and the call shape.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "api-tracer-kit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Trace every API call an app makes, and map, exercise and monitor the endpoints it has.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"files": [
|
|
51
51
|
"dist",
|
|
52
52
|
"cli",
|
|
53
|
+
"docs",
|
|
53
54
|
"README.md",
|
|
54
55
|
"LICENSE",
|
|
55
56
|
"CHANGELOG.md"
|