aissue 0.0.0-stage → 2.0.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 +390 -2
- package/dist/cjs/browser.d.ts +16 -0
- package/dist/cjs/browser.js +80 -0
- package/dist/cjs/core/breadcrumbs.d.ts +48 -0
- package/dist/cjs/core/breadcrumbs.js +313 -0
- package/dist/cjs/core/client.d.ts +54 -0
- package/dist/cjs/core/client.js +293 -0
- package/dist/cjs/core/env.d.ts +19 -0
- package/dist/cjs/core/env.js +71 -0
- package/dist/cjs/core/event.d.ts +35 -0
- package/dist/cjs/core/event.js +187 -0
- package/dist/cjs/core/hub.d.ts +20 -0
- package/dist/cjs/core/hub.js +21 -0
- package/dist/cjs/core/instrument-browser.d.ts +16 -0
- package/dist/cjs/core/instrument-browser.js +208 -0
- package/dist/cjs/core/instrument-node.d.ts +5 -0
- package/dist/cjs/core/instrument-node.js +250 -0
- package/dist/cjs/core/instrument.d.ts +12 -0
- package/dist/cjs/core/instrument.js +137 -0
- package/dist/cjs/core/privacy.d.ts +25 -0
- package/dist/cjs/core/privacy.js +269 -0
- package/dist/cjs/core/stack.d.ts +13 -0
- package/dist/cjs/core/stack.js +147 -0
- package/dist/cjs/core/transport.d.ts +31 -0
- package/dist/cjs/core/transport.js +154 -0
- package/dist/cjs/core/types.d.ts +149 -0
- package/dist/cjs/core/types.js +2 -0
- package/dist/cjs/core/version.d.ts +2 -0
- package/dist/cjs/core/version.js +6 -0
- package/dist/cjs/index.d.ts +27 -0
- package/dist/cjs/index.js +83 -0
- package/dist/cjs/nextjs/client.d.ts +10 -0
- package/dist/cjs/nextjs/client.js +99 -0
- package/dist/cjs/nextjs/index.d.ts +31 -0
- package/dist/cjs/nextjs/index.js +99 -0
- package/dist/cjs/node.d.ts +48 -0
- package/dist/cjs/node.js +223 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/react.d.ts +40 -0
- package/dist/cjs/react.js +90 -0
- package/dist/esm/browser.d.ts +16 -0
- package/dist/esm/browser.js +71 -0
- package/dist/esm/cli.d.ts +2 -0
- package/dist/esm/cli.js +386 -0
- package/dist/esm/core/breadcrumbs.d.ts +48 -0
- package/dist/esm/core/breadcrumbs.js +296 -0
- package/dist/esm/core/client.d.ts +54 -0
- package/dist/esm/core/client.js +285 -0
- package/dist/esm/core/env.d.ts +19 -0
- package/dist/esm/core/env.js +62 -0
- package/dist/esm/core/event.d.ts +35 -0
- package/dist/esm/core/event.js +179 -0
- package/dist/esm/core/hub.d.ts +20 -0
- package/dist/esm/core/hub.js +17 -0
- package/dist/esm/core/instrument-browser.d.ts +16 -0
- package/dist/esm/core/instrument-browser.js +203 -0
- package/dist/esm/core/instrument-node.d.ts +5 -0
- package/dist/esm/core/instrument-node.js +214 -0
- package/dist/esm/core/instrument.d.ts +12 -0
- package/dist/esm/core/instrument.js +132 -0
- package/dist/esm/core/privacy.d.ts +25 -0
- package/dist/esm/core/privacy.js +257 -0
- package/dist/esm/core/stack.d.ts +13 -0
- package/dist/esm/core/stack.js +140 -0
- package/dist/esm/core/transport.d.ts +31 -0
- package/dist/esm/core/transport.js +149 -0
- package/dist/esm/core/types.d.ts +149 -0
- package/dist/esm/core/types.js +1 -0
- package/dist/esm/core/version.d.ts +2 -0
- package/dist/esm/core/version.js +3 -0
- package/dist/esm/index.d.ts +27 -0
- package/dist/esm/index.js +72 -0
- package/dist/esm/nextjs/client.d.ts +10 -0
- package/dist/esm/nextjs/client.js +90 -0
- package/dist/esm/nextjs/index.d.ts +31 -0
- package/dist/esm/nextjs/index.js +88 -0
- package/dist/esm/node.d.ts +48 -0
- package/dist/esm/node.js +210 -0
- package/dist/esm/react.d.ts +40 -0
- package/dist/esm/react.js +47 -0
- package/package.json +141 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 AIssue Team
|
|
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,391 @@
|
|
|
1
|
-
#
|
|
1
|
+
# aissue
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The AIssue SDK for JavaScript. It sends errors from React, Next.js, Node/Express and plain browser apps to AIssue error monitoring.
|
|
4
|
+
|
|
5
|
+
- One package and zero runtime dependencies. It ships ESM, CommonJS and TypeScript types.
|
|
6
|
+
- Supports Node 18+, modern browsers, Next.js 14/15 and React 17–19.
|
|
7
|
+
- Private by default: no cookies, no `Authorization` header, no request bodies and no emails are sent (see [Privacy](#privacy-defaults)).
|
|
8
|
+
- Breadcrumbs (console, clicks, requests, navigation) show what led to each error, and the `aissue` CLI uploads source maps for minified bundles.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install aissue
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
You need two values from your AIssue domain page: the **API key** and your **AIssue host** (`baseUrl`, for example `https://aissue.example.com`). You can use the domain's **DSN** (`https://<api key>@<host>/<domain id>`) instead of both.
|
|
15
|
+
|
|
16
|
+
The SDK is **off when `NODE_ENV` is `development` or `test`**. Pass `enabled: true` to try it locally.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## React (Vite, Create React App)
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
// main.tsx
|
|
24
|
+
import { init, AIssueErrorBoundary } from 'aissue/react';
|
|
25
|
+
|
|
26
|
+
init({ apiKey: 'YOUR_API_KEY', baseUrl: 'https://aissue.example.com' });
|
|
27
|
+
|
|
28
|
+
createRoot(document.getElementById('root')!).render(
|
|
29
|
+
<AIssueErrorBoundary fallback={<p>Something went wrong.</p>}>
|
|
30
|
+
<App />
|
|
31
|
+
</AIssueErrorBoundary>,
|
|
32
|
+
);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`init` captures uncaught errors and unhandled promise rejections. `AIssueErrorBoundary` captures render errors, which React would otherwise swallow, and sends the component stack along with them. `fallback` can also be a function: `({ error, reset }) => <button onClick={reset}>Retry</button>`. To call your own code after a capture, use `onError={(error, { componentStack }) => …}`.
|
|
36
|
+
|
|
37
|
+
With Vite you can tie the settings to the build:
|
|
38
|
+
`init({ apiKey: import.meta.env.VITE_AISSUE_API_KEY, baseUrl: import.meta.env.VITE_AISSUE_BASE_URL, environment: import.meta.env.MODE, release: import.meta.env.VITE_COMMIT_SHA })`.
|
|
39
|
+
|
|
40
|
+
## Next.js (App Router, Next 15+)
|
|
41
|
+
|
|
42
|
+
**1. Environment variables** (`.env.local` or your host's settings):
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
AISSUE_API_KEY=YOUR_API_KEY
|
|
46
|
+
AISSUE_BASE_URL=https://aissue.example.com
|
|
47
|
+
NEXT_PUBLIC_AISSUE_API_KEY=YOUR_API_KEY
|
|
48
|
+
NEXT_PUBLIC_AISSUE_BASE_URL=https://aissue.example.com
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**2. `instrumentation.ts`** (project root, or `src/`). This handles server errors from Server Components, route handlers, server actions and middleware:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
export { register, onRequestError } from 'aissue/nextjs';
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**3. `instrumentation-client.ts`** (Next 15.3+). This handles browser errors:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { initClient } from 'aissue/nextjs/client';
|
|
61
|
+
|
|
62
|
+
initClient();
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**4. `app/global-error.tsx`**. This handles errors that reach the root error boundary:
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
'use client';
|
|
69
|
+
import { useEffect } from 'react';
|
|
70
|
+
import { captureException } from 'aissue';
|
|
71
|
+
|
|
72
|
+
export default function GlobalError({ error }: { error: Error & { digest?: string } }) {
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
// Errors with a digest come from the server and were already sent by onRequestError.
|
|
75
|
+
if (!error.digest) captureException(error);
|
|
76
|
+
}, [error]);
|
|
77
|
+
return (
|
|
78
|
+
<html>
|
|
79
|
+
<body>
|
|
80
|
+
<h2>Something went wrong.</h2>
|
|
81
|
+
</body>
|
|
82
|
+
</html>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
You can use the same `captureException` call in any `error.tsx`, or wrap client subtrees in `AIssueErrorBoundary` from `aissue/react`.
|
|
88
|
+
|
|
89
|
+
Notes:
|
|
90
|
+
|
|
91
|
+
- On the **server**, `register()` reads `AISSUE_API_KEY` and `AISSUE_BASE_URL` (or `AISSUE_DSN`), plus `AISSUE_ENVIRONMENT` and the release variables below. In the Node.js runtime it also captures uncaught exceptions and unhandled rejections. In the Edge runtime it only configures the SDK. To pass options, call it yourself:
|
|
92
|
+
`import { register as registerAIssue } from 'aissue/nextjs'; export function register() { registerAIssue({ beforeSend }); }`.
|
|
93
|
+
- `onRequestError` sends the path (without the query string), the method, allowlisted headers, `routePath`, `routeType` and the error `digest` (the id Next shows on production error pages). It skips 4xx errors and Next's `notFound()` / `redirect()`.
|
|
94
|
+
- In the **browser**, `initClient()` reads `NEXT_PUBLIC_AISSUE_API_KEY` and `NEXT_PUBLIC_AISSUE_BASE_URL` (or `NEXT_PUBLIC_AISSUE_DSN`). It takes the release from `NEXT_PUBLIC_AISSUE_RELEASE`, then `NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA`, and the environment from `NEXT_PUBLIC_AISSUE_ENVIRONMENT`, then `NEXT_PUBLIC_VERCEL_ENV`. You can pass any option to override these.
|
|
95
|
+
- **Next 15.0–15.2** has no `instrumentation-client.ts`. Use a client component in your root layout instead:
|
|
96
|
+
`'use client'; import { initClient } from 'aissue/nextjs/client'; initClient(); export function AIssueInit() { return null; }`.
|
|
97
|
+
|
|
98
|
+
### Next.js Pages Router
|
|
99
|
+
|
|
100
|
+
`instrumentation.ts` works the same way, and `onRequestError` also reports Pages Router errors. For the browser, use `instrumentation-client.ts` (15.3+), or call `initClient()` at the top of `pages/_app.tsx`. Wrap `<Component {...pageProps} />` in `AIssueErrorBoundary` to capture render errors.
|
|
101
|
+
|
|
102
|
+
### Next.js 14
|
|
103
|
+
|
|
104
|
+
Next 14 has no `onRequestError` hook.
|
|
105
|
+
|
|
106
|
+
1. Enable `experimental: { instrumentationHook: true }` in `next.config.js`.
|
|
107
|
+
2. Keep `export { register } from 'aissue/nextjs'` in `instrumentation.ts`. This captures uncaught exceptions and unhandled rejections in the Node.js runtime.
|
|
108
|
+
3. Errors that Next catches itself (rendering, route handlers, server actions) never reach those handlers. Capture them explicitly:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import { captureException, flush } from 'aissue/nextjs';
|
|
112
|
+
|
|
113
|
+
export async function GET(request: Request) {
|
|
114
|
+
try {
|
|
115
|
+
return await handle(request);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
captureException(error, { path: new URL(request.url).pathname, method: 'GET', headers: request.headers });
|
|
118
|
+
await flush(2000);
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
The browser setup (`initClient`, `global-error.tsx`) is the same as above.
|
|
125
|
+
|
|
126
|
+
## Node.js / Express
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
import express from 'express';
|
|
130
|
+
import { init, expressErrorHandler } from 'aissue/node';
|
|
131
|
+
|
|
132
|
+
init(); // reads AISSUE_API_KEY and AISSUE_BASE_URL (or pass { apiKey, baseUrl })
|
|
133
|
+
|
|
134
|
+
const app = express();
|
|
135
|
+
// ... your routes ...
|
|
136
|
+
app.use(expressErrorHandler()); // after the routes, before other error handlers
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
CommonJS works too: `const { init, expressErrorHandler } = require('aissue/node')`.
|
|
140
|
+
|
|
141
|
+
- `init()` captures **uncaught exceptions**. It sends the event (waiting at most 2 s), then the process crashes exactly as it would without AIssue: the error is printed and the exit code is 1. If your app has its own `uncaughtException` handler, AIssue only captures and leaves the decision to your handler. Pass `captureUncaughtExceptions: false` to opt out.
|
|
142
|
+
- `init()` captures **unhandled rejections** and keeps Node's `--unhandled-rejections` behaviour. In the default `throw` mode the process still crashes after the event is sent. In `warn` / `none` mode it keeps running. If your app has its own handler, AIssue only captures. Pass `captureUnhandledRejections: false` to opt out.
|
|
143
|
+
- `expressErrorHandler()` works with Express 4 and 5. It reports the status from `err.status` / `err.statusCode` (500 if neither is set), the path, method, filtered query and allowlisted headers, and then calls `next(err)`. It **skips 4xx errors**. Options: `shouldHandleError: (err, status) => boolean` and `getUserId: (req) => req.user?.id`.
|
|
144
|
+
- Anything else: `captureException(error, { path, method, headers, query, userId, extra })`.
|
|
145
|
+
- Short-lived scripts and serverless functions: `await flush()` before exiting.
|
|
146
|
+
- `init()` also records [breadcrumbs](#breadcrumbs) (console, `fetch`, `http`/`https` requests), kept separately for every incoming request.
|
|
147
|
+
|
|
148
|
+
## Plain browser (no framework)
|
|
149
|
+
|
|
150
|
+
```js
|
|
151
|
+
import { init } from 'aissue/browser';
|
|
152
|
+
|
|
153
|
+
init({ apiKey: 'YOUR_API_KEY', baseUrl: 'https://aissue.example.com' });
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
This captures `window` `error` events and `unhandledrejection` events, and records [breadcrumbs](#breadcrumbs) (console, clicks, `fetch`/XHR, navigation). Events go out with `fetch(…, { keepalive: true })`, with the key in the `?api_key=` query parameter and a `text/plain` body, so there is no CORS preflight. Browser events report `error_code: 0`, the page's `location.pathname` and only the `User-Agent` header.
|
|
157
|
+
|
|
158
|
+
By default the SDK ignores `ResizeObserver loop …` noise, cross-origin `Script error.` events, and errors whose frames all come from browser extensions.
|
|
159
|
+
|
|
160
|
+
**Your browser API key is public.** It is visible in your bundle, as it is with every client-side error monitor. It can only submit errors for your domain.
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## API
|
|
165
|
+
|
|
166
|
+
| Import | Exports |
|
|
167
|
+
|---|---|
|
|
168
|
+
| `aissue` | `init(options?)`, `captureException(error, context?)`, `setUser({ id })`, `flush(timeoutMs?)`, `addBreadcrumb(crumb)`, `clearBreadcrumbs()`, `SDK_VERSION`, types |
|
|
169
|
+
| `aissue/browser` | `init(options)` (also installs window handlers and breadcrumbs), plus the common functions |
|
|
170
|
+
| `aissue/react` | `AIssueErrorBoundary`, `init` (from `aissue/browser`), plus the common functions |
|
|
171
|
+
| `aissue/node` | `init(options?)` (also installs process handlers and breadcrumbs), `expressErrorHandler(options?)`, `runWithBreadcrumbs(fn)`, plus the common functions |
|
|
172
|
+
| `aissue/nextjs` | `register(options?)`, `onRequestError(error, request, context)`, `runWithBreadcrumbs(fn)`, plus the common functions |
|
|
173
|
+
| `aissue/nextjs/client` | `initClient(options?)`, plus the common functions |
|
|
174
|
+
|
|
175
|
+
The common functions, exported by every entry point: `captureException`, `setUser`, `flush`, `addBreadcrumb` and `clearBreadcrumbs`.
|
|
176
|
+
|
|
177
|
+
### Options
|
|
178
|
+
|
|
179
|
+
| Option | Default | |
|
|
180
|
+
|---|---|---|
|
|
181
|
+
| `apiKey` | `AISSUE_API_KEY` (server) | Domain API key. |
|
|
182
|
+
| `baseUrl` | `AISSUE_BASE_URL` (server) | Your AIssue host. |
|
|
183
|
+
| `dsn` | `AISSUE_DSN` (server) | Alternative to `apiKey` + `baseUrl`. |
|
|
184
|
+
| `release` | auto-detected (server) | See [Release detection](#release-detection). |
|
|
185
|
+
| `environment` | `AISSUE_ENVIRONMENT`, then `NODE_ENV` (server) | For example `production` or `staging`. |
|
|
186
|
+
| `enabled` | `false` when `NODE_ENV` is `development` or `test` | |
|
|
187
|
+
| `beforeSend(event)` | none | Return the event (modified or not) to send it, or `null` to drop it. |
|
|
188
|
+
| `ignoreErrors` | browser noise (browser only) | Strings match anywhere in the message, or in `Type: message`. RegExps are tested against both. |
|
|
189
|
+
| `maxEventsPerMinute` | `10` | Client-side cap per process or page. |
|
|
190
|
+
| `maxBreadcrumbs` | `50` | Breadcrumbs kept and sent with each event (at most 100). `0` turns breadcrumbs off. |
|
|
191
|
+
| `beforeBreadcrumb(crumb)` | none | Return the breadcrumb (modified or not) to keep it, or `null` to drop it. |
|
|
192
|
+
| `autoBreadcrumbs` | `true` | `false` turns automatic breadcrumbs off. An object turns off single sources: `{ console, clicks, fetch, xhr, navigation, http }`. |
|
|
193
|
+
| `debug` | `false` | Log what the SDK does. |
|
|
194
|
+
|
|
195
|
+
`captureException(error, context?)` accepts any thrown value. Non-`Error` values are wrapped into a synthetic `Error` with a safe message: objects are described by their keys, never their values. The optional `context` takes `{ errorCode, path, method, query, headers, userId, extra }`. Everything in it goes through the privacy filters, and `extra` is sent as `request_data.context`.
|
|
196
|
+
|
|
197
|
+
`setUser({ id })` attaches an **opaque id** to later events. Any other field is ignored. On servers the id is process-wide, so pass `userId` per call instead.
|
|
198
|
+
|
|
199
|
+
`flush(timeoutMs = 2000)` resolves `true` once in-flight events are sent, or `false` if the timeout passes first.
|
|
200
|
+
|
|
201
|
+
### beforeSend
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
init({
|
|
205
|
+
apiKey,
|
|
206
|
+
baseUrl,
|
|
207
|
+
beforeSend(event) {
|
|
208
|
+
if (event.exception.message.includes('AbortError')) return null; // drop
|
|
209
|
+
event.path = event.path?.replace(/\/users\/\d+/, '/users/:id'); // modify
|
|
210
|
+
return event;
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
`event` is exactly the JSON that will be sent ([ingestion protocol](../../docs/sdk/INGESTION_PROTOCOL.md)). If `beforeSend` throws, the event is dropped.
|
|
216
|
+
|
|
217
|
+
## Breadcrumbs
|
|
218
|
+
|
|
219
|
+
Breadcrumbs are the trail of events that led to an error: log lines, clicks, requests, page changes. The SDK keeps the last 50 (`maxBreadcrumbs`, at most 100) and sends a copy, oldest first, with every event.
|
|
220
|
+
|
|
221
|
+
Recorded automatically:
|
|
222
|
+
|
|
223
|
+
| Where | Source | Breadcrumb |
|
|
224
|
+
|---|---|---|
|
|
225
|
+
| Browser, Node | `console.log` / `info` / `warn` / `error` | `log`, category `console`, level from the method. The console still prints as before. |
|
|
226
|
+
| Browser | clicks | `ui`, category `ui.click`: a short selector such as `button#pay.btn.primary` and the element's text (at most 60 characters). Never the value of an input, textarea, select or editable element. |
|
|
227
|
+
| Browser, Node | `fetch` | `http`, category `fetch`: method, URL **without the query string**, status and duration. Requests to your AIssue host are skipped. |
|
|
228
|
+
| Browser | `XMLHttpRequest` | `http`, category `xhr`, same fields as `fetch`. |
|
|
229
|
+
| Browser | `history.pushState` / `replaceState` / `popstate` | `navigation`: `from` and `to` paths, without the query string. |
|
|
230
|
+
| Node | `http` / `https` client requests (`http.request`, `http.get`, and libraries built on them) | `http`, category `http`, same fields as `fetch`. |
|
|
231
|
+
|
|
232
|
+
Add your own:
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
import { addBreadcrumb } from 'aissue'; // or any entry point
|
|
236
|
+
|
|
237
|
+
addBreadcrumb({ category: 'cart', message: 'Applied coupon', level: 'info', data: { items: 3, total: 41.5 } });
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
A breadcrumb is `{ timestamp, type, category, level, message, data }`. `type` is `default`, `http`, `navigation`, `ui`, `log` or `query`. `level` is `debug`, `info`, `warning` or `error`. `message` is cut to 1000 characters, and `data` is a flat object of strings, numbers and booleans (at most 20 keys). Everything is optional. `clearBreadcrumbs()` empties the buffer.
|
|
241
|
+
|
|
242
|
+
**Privacy.** Breadcrumbs go through the same filters as the rest of the event. Values under sensitive-looking keys become `[Filtered]`. Emails (`[email]`), tokens (JWTs, `Bearer …`, API keys), `password=…`-style pairs and card numbers are redacted from messages and data. URLs never include query strings or credentials. To drop or edit breadcrumbs yourself, use `beforeBreadcrumb`:
|
|
243
|
+
|
|
244
|
+
```ts
|
|
245
|
+
init({
|
|
246
|
+
apiKey,
|
|
247
|
+
baseUrl,
|
|
248
|
+
beforeBreadcrumb(crumb) {
|
|
249
|
+
if (crumb.category === 'console' && crumb.level === 'info') return null; // drop console.log noise
|
|
250
|
+
if (crumb.category === 'fetch') crumb.data.url = String(crumb.data.url).replace(/\/users\/\d+/, '/users/:id');
|
|
251
|
+
return crumb;
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
**Per request in Node.** Every incoming `http` / `https` server request (Express, Next.js, Fastify, plain `http.createServer`) gets its own breadcrumb buffer through `AsyncLocalStorage`, so concurrent requests never mix their breadcrumbs. An error captured while handling a request carries only that request's breadcrumbs. Breadcrumbs recorded outside a request (startup, timers) go to a global buffer. For other units of work, such as queue jobs, wrap them: `runWithBreadcrumbs(() => handleJob(job))`.
|
|
257
|
+
|
|
258
|
+
The instrumentation is installed once by `init` from `aissue/browser`, `aissue/react`, `aissue/nextjs/client`, `aissue/node` or `register()` from `aissue/nextjs` (Node.js runtime). It is not installed while the SDK is disabled, and installed wrappers record nothing after a later `init({ enabled: false })`. They never throw into your app and keep the original behaviour. `init` from the plain `aissue` entry point installs nothing, but `addBreadcrumb` works there too. To turn automatic breadcrumbs off, pass `autoBreadcrumbs: false`, or `autoBreadcrumbs: { console: false }` for a single source.
|
|
259
|
+
|
|
260
|
+
## Privacy defaults
|
|
261
|
+
|
|
262
|
+
These match the Python SDK:
|
|
263
|
+
|
|
264
|
+
- **Headers**: only an allowlist is sent: `User-Agent`, `Content-Type`, `Content-Length`, `Accept`, `Accept-Language`, `Accept-Encoding`, `Host`, `Origin` and `Referer`. The query string and fragment are stripped from `Referer`. `Cookie`, `Authorization`, API-key headers and IP headers are **never** sent.
|
|
265
|
+
- **Query parameters** are sent as `{ key: [values] }`. Values under sensitive-looking keys are replaced with `[Filtered]`. This covers `password`, `token`, `secret`, `api_key`, `session`, `cookie`, `csrf`, `auth`, `credential`, `signature`, `credit_card`, `card_number`, `cvv`, `iban`, `ssn` and similar keys. The same filter applies to `extra` context.
|
|
266
|
+
- **No request bodies, no cookies and no user emails or names.** `user_id` is only ever an opaque id that you provide.
|
|
267
|
+
- Browser events carry only the path (no query) and the `User-Agent`.
|
|
268
|
+
- Breadcrumbs are filtered the same way: sensitive keys, emails, tokens and card numbers are redacted, and URLs lose their query string. Click breadcrumbs never contain input values.
|
|
269
|
+
- AIssue scrubs everything again on the server.
|
|
270
|
+
|
|
271
|
+
## Release detection
|
|
272
|
+
|
|
273
|
+
On servers, `release` is the first of these environment variables that is set: `AISSUE_RELEASE`, `VERCEL_GIT_COMMIT_SHA`, `NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA`, `RENDER_GIT_COMMIT`, `RAILWAY_GIT_COMMIT_SHA`, `HEROKU_SLUG_COMMIT`, `SOURCE_VERSION`, `CF_PAGES_COMMIT_SHA`, `GITHUB_SHA`, `COMMIT_SHA`, `GIT_SHA` and `GIT_COMMIT`. If the release is a **git commit SHA**, AIssue can read the exact deployed code from GitHub.
|
|
274
|
+
|
|
275
|
+
Browser bundles cannot read server environment variables. Pass `release` explicitly, or use `initClient()` on Next.js, which reads `NEXT_PUBLIC_AISSUE_RELEASE` / `NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA`.
|
|
276
|
+
|
|
277
|
+
## Reliability
|
|
278
|
+
|
|
279
|
+
- The SDK never throws into your app and never blocks the request that failed.
|
|
280
|
+
- Identical errors (same type, message and top frame) are sent once per 5 s. The same error object is never sent twice.
|
|
281
|
+
- At most `maxEventsPerMinute` events are sent per process or page. If the server answers `429`, sending pauses for `Retry-After`.
|
|
282
|
+
- Server-side sends time out after 5 s. Events are dropped, never queued. Payloads over 256 KB are trimmed (fewer frames, shorter traceback) or dropped.
|
|
283
|
+
|
|
284
|
+
## Stack traces
|
|
285
|
+
|
|
286
|
+
Frames are parsed from V8 (Node, Chrome, Edge) and Firefox/Safari stacks. They are sent oldest call first, with the frame where the error was thrown last, up to 50 frames. `node_modules`, `node:` internals and browser extensions are marked as not in-app. Browser frames keep the full script URL (without the query string) and the column, which is what source maps need.
|
|
287
|
+
|
|
288
|
+
## Source maps
|
|
289
|
+
|
|
290
|
+
Production bundles are minified, so browser stack traces point at the **built files** (for example `https://shop.example.com/assets/index-3f2a.js:1:20345`). Upload your source maps for each release and AIssue maps those frames back to your original files, lines and function names.
|
|
291
|
+
|
|
292
|
+
Two things must match:
|
|
293
|
+
|
|
294
|
+
1. **The release.** Events and source maps must use the same `release`. Use the git commit SHA for both.
|
|
295
|
+
2. **The URL.** Each map is stored under the URL path its minified file is served from. `~` means "any host", so `~/assets/index-3f2a.js` matches `https://shop.example.com/assets/index-3f2a.js`.
|
|
296
|
+
|
|
297
|
+
Build with source maps, then upload them with the `aissue` CLI (included in this package):
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
npx aissue sourcemaps upload dist --release $GITHUB_SHA --domain 123
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
You need the domain id (shown on your domain page and in its DSN) and an **account API token** (`aissue_pat_…`, created in your AIssue account settings), passed as `--token` or the `AISSUE_TOKEN` environment variable. Keep it secret: it is a CI secret, not the public browser API key.
|
|
304
|
+
|
|
305
|
+
```
|
|
306
|
+
Usage: aissue sourcemaps upload <dir> --release <release> --domain <domainId> [options]
|
|
307
|
+
|
|
308
|
+
Options:
|
|
309
|
+
--release <release> Release the maps belong to. Must equal the release the SDK sends.
|
|
310
|
+
Default: the first env var set of AISSUE_RELEASE, VERCEL_GIT_COMMIT_SHA, ...
|
|
311
|
+
(same list as the SDK, see Release detection).
|
|
312
|
+
--domain <domainId> AIssue domain id (default: AISSUE_DOMAIN).
|
|
313
|
+
--url-prefix <prefix> Prefix of the URL the minified files are served from (default "~/").
|
|
314
|
+
--host <url> AIssue host (default: AISSUE_HOST, then https://aissue.dev).
|
|
315
|
+
--token <token> Account API token, aissue_pat_... (default: AISSUE_TOKEN).
|
|
316
|
+
--dry-run Show what would be uploaded; upload and delete nothing.
|
|
317
|
+
--delete-after Delete each .map file after it was uploaded (so maps are not deployed).
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
The CLI finds every `*.map` file under `<dir>`, works out the minified file each one belongs to (`index-3f2a.js.map` belongs to `index-3f2a.js`, or to the file named in the map's own `file` field), and uploads it with `url = <url-prefix> + <path relative to dir>`. It prints a summary and exits with a non-zero code if any upload failed, so a CI step fails visibly. Maps of non-JavaScript files (CSS) are skipped. Run it with `--dry-run` first to check the URLs.
|
|
321
|
+
|
|
322
|
+
### Vite
|
|
323
|
+
|
|
324
|
+
```ts
|
|
325
|
+
// vite.config.ts
|
|
326
|
+
export default defineConfig({
|
|
327
|
+
build: { sourcemap: 'hidden' }, // emit .map files without the //# sourceMappingURL comment
|
|
328
|
+
});
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
```ts
|
|
332
|
+
// main.tsx: send the same release you upload
|
|
333
|
+
init({ apiKey, baseUrl, release: import.meta.env.VITE_COMMIT_SHA });
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
```bash
|
|
337
|
+
VITE_COMMIT_SHA=$GITHUB_SHA vite build
|
|
338
|
+
npx aissue sourcemaps upload dist --release $GITHUB_SHA --domain 123 --delete-after
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
Vite serves `dist/assets/index-3f2a.js` as `/assets/index-3f2a.js`, so the default `--url-prefix "~/"` is right. If you deploy under a sub-path (`base: '/app/'`), use `--url-prefix "~/app/"`.
|
|
342
|
+
|
|
343
|
+
### webpack (Create React App, custom setups)
|
|
344
|
+
|
|
345
|
+
```js
|
|
346
|
+
// webpack.config.js
|
|
347
|
+
module.exports = {
|
|
348
|
+
devtool: 'hidden-source-map',
|
|
349
|
+
output: { publicPath: '/static/js/' },
|
|
350
|
+
};
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
npx aissue sourcemaps upload build/static/js --url-prefix "~/static/js" --release $GITHUB_SHA --domain 123 --delete-after
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
`--url-prefix` plus the file's path relative to the uploaded directory must equal the path the browser loads the file from. With Create React App, set `GENERATE_SOURCEMAP=true` and upload `build` with the default prefix.
|
|
358
|
+
|
|
359
|
+
### Next.js
|
|
360
|
+
|
|
361
|
+
```js
|
|
362
|
+
// next.config.js
|
|
363
|
+
module.exports = { productionBrowserSourceMaps: true };
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
```bash
|
|
367
|
+
next build
|
|
368
|
+
npx aissue sourcemaps upload .next/static --url-prefix "~/_next/static" --release $GITHUB_SHA --domain 123 --delete-after
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
`initClient()` takes the release from `NEXT_PUBLIC_AISSUE_RELEASE` or, on Vercel, `NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA`. Set `NEXT_PUBLIC_AISSUE_RELEASE=$GITHUB_SHA` at build time elsewhere. Next.js server bundles (`.next/server/…`) are minified too. Plain Node/Express servers are not minified and need no source maps.
|
|
372
|
+
|
|
373
|
+
### Keeping maps private
|
|
374
|
+
|
|
375
|
+
`--delete-after` removes each map once it is uploaded, so the maps are not deployed with your site. Use it when the upload runs between the build and the deploy. With `sourcemap: 'hidden'` (Vite) or `hidden-source-map` (webpack), the bundles do not reference the maps at all. Otherwise browsers request the deleted `.map` file only when developer tools are open, which is a harmless 404.
|
|
376
|
+
|
|
377
|
+
### In CI (GitHub Actions)
|
|
378
|
+
|
|
379
|
+
```yaml
|
|
380
|
+
- run: npm run build
|
|
381
|
+
env:
|
|
382
|
+
VITE_COMMIT_SHA: ${{ github.sha }}
|
|
383
|
+
- run: npx aissue sourcemaps upload dist --release ${{ github.sha }} --domain 123 --delete-after
|
|
384
|
+
env:
|
|
385
|
+
AISSUE_TOKEN: ${{ secrets.AISSUE_TOKEN }}
|
|
386
|
+
- run: ./deploy.sh
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
## License
|
|
390
|
+
|
|
391
|
+
MIT
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AIssueOptions } from './core/types.js';
|
|
2
|
+
export { captureException, setUser, flush, addBreadcrumb, clearBreadcrumbs } from './index.js';
|
|
3
|
+
export type { AIssueEvent, AIssueOptions, AutoBreadcrumbsOptions, Breadcrumb, BreadcrumbInput, CaptureContext, StackFrame, User, } from './index.js';
|
|
4
|
+
/** Browser options: an API key and the AIssue host (or a DSN) are required. */
|
|
5
|
+
export type BrowserOptions = AIssueOptions & ({
|
|
6
|
+
apiKey: string;
|
|
7
|
+
baseUrl: string;
|
|
8
|
+
} | {
|
|
9
|
+
dsn: string;
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Configure the SDK in the browser, capture uncaught errors and unhandled rejections and record
|
|
13
|
+
* automatic breadcrumbs (see `autoBreadcrumbs`).
|
|
14
|
+
* Does nothing when called outside a browser (e.g. during server-side rendering).
|
|
15
|
+
*/
|
|
16
|
+
export declare function init(options: BrowserOptions): void;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clearBreadcrumbs = exports.addBreadcrumb = exports.flush = exports.setUser = exports.captureException = void 0;
|
|
4
|
+
exports.init = init;
|
|
5
|
+
/**
|
|
6
|
+
* aissue/browser: plain browser apps (and the base for aissue/react).
|
|
7
|
+
*
|
|
8
|
+
* import { init } from 'aissue/browser';
|
|
9
|
+
* init({ apiKey: '...', baseUrl: 'https://aissue.example.com' });
|
|
10
|
+
*
|
|
11
|
+
* Captures uncaught errors (window "error") and unhandled promise rejections automatically, and
|
|
12
|
+
* records breadcrumbs (console, clicks, fetch / XHR, navigation) that are sent with each event.
|
|
13
|
+
*/
|
|
14
|
+
const client_js_1 = require("./core/client.js");
|
|
15
|
+
const instrument_browser_js_1 = require("./core/instrument-browser.js");
|
|
16
|
+
const env_js_1 = require("./core/env.js");
|
|
17
|
+
const hub_js_1 = require("./core/hub.js");
|
|
18
|
+
var index_js_1 = require("./index.js");
|
|
19
|
+
Object.defineProperty(exports, "captureException", { enumerable: true, get: function () { return index_js_1.captureException; } });
|
|
20
|
+
Object.defineProperty(exports, "setUser", { enumerable: true, get: function () { return index_js_1.setUser; } });
|
|
21
|
+
Object.defineProperty(exports, "flush", { enumerable: true, get: function () { return index_js_1.flush; } });
|
|
22
|
+
Object.defineProperty(exports, "addBreadcrumb", { enumerable: true, get: function () { return index_js_1.addBreadcrumb; } });
|
|
23
|
+
Object.defineProperty(exports, "clearBreadcrumbs", { enumerable: true, get: function () { return index_js_1.clearBreadcrumbs; } });
|
|
24
|
+
function onWindowError(event) {
|
|
25
|
+
if (event.error !== undefined && event.error !== null) {
|
|
26
|
+
(0, client_js_1.captureWithExtras)(event.error);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// No error object (e.g. cross-origin "Script error."): rebuild what we can from the event.
|
|
30
|
+
if (typeof event.message !== 'string' || !event.message)
|
|
31
|
+
return;
|
|
32
|
+
const filename = typeof event.filename === 'string' ? event.filename : '';
|
|
33
|
+
const location = filename ? `\n at ${filename}:${Number(event.lineno) || 0}:${Number(event.colno) || 0}` : '';
|
|
34
|
+
(0, client_js_1.captureWithExtras)({ name: 'Error', message: event.message, stack: `Error: ${event.message}${location}` });
|
|
35
|
+
}
|
|
36
|
+
function installGlobalHandlers() {
|
|
37
|
+
const hub = (0, hub_js_1.getHub)();
|
|
38
|
+
if (hub.installed.browser)
|
|
39
|
+
return;
|
|
40
|
+
const w = globalThis
|
|
41
|
+
.window;
|
|
42
|
+
if (!w || typeof w.addEventListener !== 'function')
|
|
43
|
+
return;
|
|
44
|
+
hub.installed.browser = true;
|
|
45
|
+
w.addEventListener('error', (event) => {
|
|
46
|
+
try {
|
|
47
|
+
onWindowError(event);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// never throw into the host app
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
w.addEventListener('unhandledrejection', (event) => {
|
|
54
|
+
try {
|
|
55
|
+
(0, client_js_1.captureWithExtras)(event ? event.reason : undefined);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// never throw into the host app
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Configure the SDK in the browser, capture uncaught errors and unhandled rejections and record
|
|
64
|
+
* automatic breadcrumbs (see `autoBreadcrumbs`).
|
|
65
|
+
* Does nothing when called outside a browser (e.g. during server-side rendering).
|
|
66
|
+
*/
|
|
67
|
+
function init(options) {
|
|
68
|
+
try {
|
|
69
|
+
if (!(0, env_js_1.isBrowser)())
|
|
70
|
+
return;
|
|
71
|
+
const client = (0, client_js_1.setupClient)(options, { runtime: 'browser', platform: 'browser' });
|
|
72
|
+
installGlobalHandlers();
|
|
73
|
+
if (client?.enabled && client.config.maxBreadcrumbs > 0 && client.config.autoBreadcrumbs !== false) {
|
|
74
|
+
(0, instrument_browser_js_1.instrumentBrowser)();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// never throw into the host app
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Breadcrumb, BreadcrumbInput, BreadcrumbLevel } from './types.js';
|
|
2
|
+
export declare const DEFAULT_MAX_BREADCRUMBS = 50;
|
|
3
|
+
/** Protocol limit: at most 100 breadcrumbs per event. */
|
|
4
|
+
export declare const MAX_BREADCRUMBS = 100;
|
|
5
|
+
export declare const MAX_BREADCRUMB_MESSAGE = 1000;
|
|
6
|
+
/** Which automatic breadcrumb sources are on (all by default). */
|
|
7
|
+
export type AutoBreadcrumbKind = 'console' | 'clicks' | 'fetch' | 'xhr' | 'navigation' | 'http';
|
|
8
|
+
/** Where the current breadcrumbs live: per request (Node AsyncLocalStorage) or the global buffer. */
|
|
9
|
+
export interface BreadcrumbStorage {
|
|
10
|
+
getStore(): Breadcrumb[] | undefined;
|
|
11
|
+
run<T>(store: Breadcrumb[], fn: () => T): T;
|
|
12
|
+
}
|
|
13
|
+
/** Cut to `max` characters, ellipsis included. */
|
|
14
|
+
export declare function clip(value: string, max: number): string;
|
|
15
|
+
/** Short, safe text for any value (used for console arguments and nested data values). */
|
|
16
|
+
export declare function describeValue(value: unknown, max?: number): string;
|
|
17
|
+
/**
|
|
18
|
+
* Turn user or instrumentation input into a protocol breadcrumb: valid type / level, ISO timestamp,
|
|
19
|
+
* message <= 1000 chars, flat data (<= 20 keys). Sensitive keys and secrets / emails in strings are filtered.
|
|
20
|
+
*/
|
|
21
|
+
export declare function normalizeBreadcrumb(input: BreadcrumbInput | null | undefined): Breadcrumb | null;
|
|
22
|
+
/** The buffer breadcrumbs go to right now: the current request's (Node) or the global one. */
|
|
23
|
+
export declare function currentBuffer(): Breadcrumb[];
|
|
24
|
+
/** True when a client is enabled and keeps breadcrumbs (optionally: and this automatic source is on). */
|
|
25
|
+
export declare function breadcrumbsActive(kind?: AutoBreadcrumbKind): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Store a breadcrumb in `buffer` (default: the current one). Runs beforeBreadcrumb.
|
|
28
|
+
* Never throws; ignored when the SDK is disabled or while another breadcrumb is being recorded
|
|
29
|
+
* (so a console.log inside beforeBreadcrumb cannot loop).
|
|
30
|
+
*/
|
|
31
|
+
export declare function recordBreadcrumb(input: BreadcrumbInput, buffer?: Breadcrumb[]): void;
|
|
32
|
+
/** Copy of the current breadcrumbs (oldest first) for an event. */
|
|
33
|
+
export declare function snapshotBreadcrumbs(): Breadcrumb[];
|
|
34
|
+
/** Empty the current buffer (the current request's in Node, otherwise the global one). */
|
|
35
|
+
export declare function clearCurrentBreadcrumbs(): void;
|
|
36
|
+
/** Run `fn` with its own, empty breadcrumb buffer (Node AsyncLocalStorage); plain call elsewhere. */
|
|
37
|
+
export declare function runWithBreadcrumbScope<T>(fn: () => T): T;
|
|
38
|
+
export declare function isWrapped(fn: unknown): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Mark `wrapper` as ours and copy the original's own properties (e.g. Next.js' `__nextPatched` on fetch)
|
|
41
|
+
* so code that inspects the function keeps working.
|
|
42
|
+
*/
|
|
43
|
+
export declare function markWrapped<T extends Function>(wrapper: T, original: Function): T;
|
|
44
|
+
/** Replace obj[name] with makeWrapper(original) unless it is already our wrapper. Never throws. */
|
|
45
|
+
export declare function wrapMethod(obj: unknown, name: string, makeWrapper: (original: Function) => Function): boolean;
|
|
46
|
+
/** True for URLs that point at the AIssue host itself (the SDK's own requests). */
|
|
47
|
+
export declare function isAIssueUrl(url: string): boolean;
|
|
48
|
+
export declare function levelForStatus(status: number | undefined): BreadcrumbLevel;
|