aissue 0.0.0-stage → 2.0.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/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
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/** Runtime that produced the event (see the ingestion protocol). */
|
|
2
|
+
export type Platform = 'node' | 'browser' | 'javascript';
|
|
3
|
+
/** One stack frame. Frames are ordered oldest call first, innermost (where it failed) last. */
|
|
4
|
+
export interface StackFrame {
|
|
5
|
+
filename: string;
|
|
6
|
+
function: string;
|
|
7
|
+
lineno?: number;
|
|
8
|
+
colno?: number;
|
|
9
|
+
/** false for library code (node_modules), runtime internals and browser extensions. */
|
|
10
|
+
in_app: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** The JSON body sent to `POST {baseUrl}/api/errors/` (ingestion protocol v1). */
|
|
13
|
+
export interface AIssueEvent {
|
|
14
|
+
/** HTTP status the error produced. Browser-side errors send 0. */
|
|
15
|
+
error_code: number;
|
|
16
|
+
/** Request path without the query string. */
|
|
17
|
+
path?: string;
|
|
18
|
+
method?: string;
|
|
19
|
+
/** Raw stack text. */
|
|
20
|
+
traceback: string;
|
|
21
|
+
exception: {
|
|
22
|
+
type: string;
|
|
23
|
+
message: string;
|
|
24
|
+
};
|
|
25
|
+
frames: StackFrame[];
|
|
26
|
+
release?: string;
|
|
27
|
+
environment?: string;
|
|
28
|
+
platform: Platform;
|
|
29
|
+
sdk: {
|
|
30
|
+
name: string;
|
|
31
|
+
version: string;
|
|
32
|
+
};
|
|
33
|
+
/** Opaque identifier only, never an email or a name. */
|
|
34
|
+
user_id?: string;
|
|
35
|
+
request_data?: {
|
|
36
|
+
/** Query parameters. Values under sensitive-looking keys are replaced with "[Filtered]". */
|
|
37
|
+
GET?: Record<string, string[]>;
|
|
38
|
+
/** Extra context (e.g. Next.js routePath, React componentStack). Sensitive keys are filtered. */
|
|
39
|
+
context?: Record<string, unknown>;
|
|
40
|
+
};
|
|
41
|
+
/** Allowlisted request headers only. Never Cookie or Authorization. */
|
|
42
|
+
headers?: Record<string, string>;
|
|
43
|
+
/** What happened before the error, oldest first (at most 100). */
|
|
44
|
+
breadcrumbs?: Breadcrumb[];
|
|
45
|
+
}
|
|
46
|
+
export type BreadcrumbType = 'default' | 'http' | 'navigation' | 'ui' | 'log' | 'query';
|
|
47
|
+
export type BreadcrumbLevel = 'debug' | 'info' | 'warning' | 'error';
|
|
48
|
+
/** One breadcrumb as sent in an event (ingestion protocol `breadcrumbs`). */
|
|
49
|
+
export interface Breadcrumb {
|
|
50
|
+
/** ISO-8601 UTC, e.g. "2026-01-31T12:00:00.000Z". */
|
|
51
|
+
timestamp: string;
|
|
52
|
+
type: BreadcrumbType;
|
|
53
|
+
category: string;
|
|
54
|
+
level: BreadcrumbLevel;
|
|
55
|
+
/** At most 1000 characters. */
|
|
56
|
+
message: string;
|
|
57
|
+
/** Flat: string / number / boolean values only, at most 20 keys. */
|
|
58
|
+
data: Record<string, string | number | boolean>;
|
|
59
|
+
}
|
|
60
|
+
/** What addBreadcrumb accepts. Everything is optional, validated and filtered with the privacy rules. */
|
|
61
|
+
export interface BreadcrumbInput {
|
|
62
|
+
/** Date, ms (or s) since the epoch, or an ISO string. Default: now. */
|
|
63
|
+
timestamp?: string | number | Date;
|
|
64
|
+
/** 'default' | 'http' | 'navigation' | 'ui' | 'log' | 'query'. Default 'default'. */
|
|
65
|
+
type?: BreadcrumbType | string;
|
|
66
|
+
/** e.g. "auth", "cart". Default "manual" (or the type). */
|
|
67
|
+
category?: string;
|
|
68
|
+
/** 'debug' | 'info' | 'warning' | 'error' ('warn' is accepted). Default 'info'. */
|
|
69
|
+
level?: BreadcrumbLevel | string;
|
|
70
|
+
message?: string;
|
|
71
|
+
/** Flat object of strings / numbers / booleans (other values are stringified), at most 20 keys. */
|
|
72
|
+
data?: Record<string, unknown>;
|
|
73
|
+
}
|
|
74
|
+
/** Turn individual automatic breadcrumb sources off (all are on by default). */
|
|
75
|
+
export interface AutoBreadcrumbsOptions {
|
|
76
|
+
/** console.log / info / warn / error. */
|
|
77
|
+
console?: boolean;
|
|
78
|
+
/** Browser: clicks (element selector and short text, never input values). */
|
|
79
|
+
clicks?: boolean;
|
|
80
|
+
/** Outgoing fetch requests (browser and Node). */
|
|
81
|
+
fetch?: boolean;
|
|
82
|
+
/** Browser: XMLHttpRequest. */
|
|
83
|
+
xhr?: boolean;
|
|
84
|
+
/** Browser: history.pushState / replaceState / popstate. */
|
|
85
|
+
navigation?: boolean;
|
|
86
|
+
/** Node: outgoing http / https requests. */
|
|
87
|
+
http?: boolean;
|
|
88
|
+
}
|
|
89
|
+
export interface AIssueOptions {
|
|
90
|
+
/** Domain API key. Server-side falls back to the AISSUE_API_KEY env var. */
|
|
91
|
+
apiKey?: string;
|
|
92
|
+
/** Your AIssue host, e.g. "https://aissue.example.com". Server-side falls back to AISSUE_BASE_URL. */
|
|
93
|
+
baseUrl?: string;
|
|
94
|
+
/**
|
|
95
|
+
* Alternative to apiKey + baseUrl: "https://<api key>@<aissue host>/<domain id>"
|
|
96
|
+
* (the DSN shown on the domain page). Server-side falls back to AISSUE_DSN.
|
|
97
|
+
*/
|
|
98
|
+
dsn?: string;
|
|
99
|
+
/** Deployed version, ideally a git commit SHA. Server-side it is detected from common platform env vars. */
|
|
100
|
+
release?: string;
|
|
101
|
+
/** e.g. "production" or "staging". Server-side falls back to AISSUE_ENVIRONMENT, then NODE_ENV. */
|
|
102
|
+
environment?: string;
|
|
103
|
+
/** Defaults to false when NODE_ENV is "development" or "test", true otherwise. */
|
|
104
|
+
enabled?: boolean;
|
|
105
|
+
/** Inspect, modify or drop (return null) every event before it is sent. */
|
|
106
|
+
beforeSend?: (event: AIssueEvent) => AIssueEvent | null | undefined;
|
|
107
|
+
/** Errors whose message (or "Type: message") contains a string, or matches a RegExp, are not sent. */
|
|
108
|
+
ignoreErrors?: Array<string | RegExp>;
|
|
109
|
+
/** Client-side cap on events sent per minute by this process / page. Default 10. */
|
|
110
|
+
maxEventsPerMinute?: number;
|
|
111
|
+
/** Log what the SDK does to the console. */
|
|
112
|
+
debug?: boolean;
|
|
113
|
+
/** Breadcrumbs kept (and sent with each event). Default 50, at most 100; 0 disables breadcrumbs. */
|
|
114
|
+
maxBreadcrumbs?: number;
|
|
115
|
+
/** Inspect, modify or drop (return null) every breadcrumb before it is stored. */
|
|
116
|
+
beforeBreadcrumb?: (breadcrumb: Breadcrumb) => Breadcrumb | BreadcrumbInput | null | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Automatic breadcrumbs installed by aissue/browser and aissue/node. `false` turns them all off
|
|
119
|
+
* (addBreadcrumb still works); an object turns off individual sources.
|
|
120
|
+
*/
|
|
121
|
+
autoBreadcrumbs?: boolean | AutoBreadcrumbsOptions;
|
|
122
|
+
}
|
|
123
|
+
/** Anything that looks like request headers: a plain object, a Headers instance, or [name, value] pairs. */
|
|
124
|
+
export type HeadersInput = Record<string, string | string[] | number | undefined | null> | {
|
|
125
|
+
forEach(callback: (value: string, name: string) => void): void;
|
|
126
|
+
} | Array<[string, string]>;
|
|
127
|
+
/** Query parameters as a raw query string, URLSearchParams, or an object. */
|
|
128
|
+
export type QueryInput = string | {
|
|
129
|
+
forEach(callback: (value: string, name: string) => void): void;
|
|
130
|
+
} | Record<string, unknown>;
|
|
131
|
+
/** Optional details for captureException. Everything is filtered with the same privacy rules. */
|
|
132
|
+
export interface CaptureContext {
|
|
133
|
+
/** HTTP status the error produced (default 500 on servers, 0 in browsers). */
|
|
134
|
+
errorCode?: number;
|
|
135
|
+
/** Request path. A query string or fragment is stripped (the query is used as `query` if none is given). */
|
|
136
|
+
path?: string;
|
|
137
|
+
method?: string;
|
|
138
|
+
query?: QueryInput;
|
|
139
|
+
/** Only allowlisted headers are kept (User-Agent, Content-Type, Accept, Host, Origin, Referer, ...). */
|
|
140
|
+
headers?: HeadersInput;
|
|
141
|
+
/** Opaque user id for this event (overrides setUser). Never pass an email. */
|
|
142
|
+
userId?: string | number;
|
|
143
|
+
/** Extra context, sent as request_data.context. Sensitive-looking keys are filtered. */
|
|
144
|
+
extra?: Record<string, unknown>;
|
|
145
|
+
}
|
|
146
|
+
export interface User {
|
|
147
|
+
/** Opaque identifier only, never an email or a name. */
|
|
148
|
+
id: string | number;
|
|
149
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AIssueOptions, BreadcrumbInput, CaptureContext, User } from './core/types.js';
|
|
2
|
+
export type { AIssueEvent, AIssueOptions, AutoBreadcrumbsOptions, Breadcrumb, BreadcrumbInput, BreadcrumbLevel, BreadcrumbType, CaptureContext, HeadersInput, Platform, QueryInput, StackFrame, User, } from './core/types.js';
|
|
3
|
+
export { SDK_NAME, SDK_VERSION } from './core/version.js';
|
|
4
|
+
/**
|
|
5
|
+
* Configure the SDK. Server-side, omitted options are read from AISSUE_API_KEY, AISSUE_BASE_URL
|
|
6
|
+
* (or AISSUE_DSN), AISSUE_ENVIRONMENT and the release env vars. Calling init again replaces the config.
|
|
7
|
+
* Installs no global handlers: use aissue/browser or aissue/node for that.
|
|
8
|
+
*/
|
|
9
|
+
export declare function init(options?: AIssueOptions): void;
|
|
10
|
+
/** Send an error (or any thrown value) to AIssue. Never throws; does nothing before init(). */
|
|
11
|
+
export declare function captureException(error: unknown, context?: CaptureContext): void;
|
|
12
|
+
/**
|
|
13
|
+
* Attach an opaque user id to subsequent events (null clears it). Only the id is used: never pass
|
|
14
|
+
* an email or a name. On servers this is process-wide; prefer captureException(err, { userId }).
|
|
15
|
+
*/
|
|
16
|
+
export declare function setUser(user: User | null | undefined): void;
|
|
17
|
+
/** Wait for in-flight events. Resolves true when all were sent, false if `timeoutMs` (default 2000) passed. */
|
|
18
|
+
export declare function flush(timeoutMs?: number): Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Record something that happened (oldest breadcrumbs are dropped beyond `maxBreadcrumbs`). The
|
|
21
|
+
* breadcrumbs are sent with the next events. Message and data go through the privacy filters.
|
|
22
|
+
* Does nothing before init() or while the SDK is disabled. In Node, breadcrumbs added while handling
|
|
23
|
+
* an http request belong to that request only.
|
|
24
|
+
*/
|
|
25
|
+
export declare function addBreadcrumb(breadcrumb: BreadcrumbInput): void;
|
|
26
|
+
/** Forget the current breadcrumbs (in Node, inside a request: that request's breadcrumbs). */
|
|
27
|
+
export declare function clearBreadcrumbs(): void;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SDK_VERSION = exports.SDK_NAME = void 0;
|
|
4
|
+
exports.init = init;
|
|
5
|
+
exports.captureException = captureException;
|
|
6
|
+
exports.setUser = setUser;
|
|
7
|
+
exports.flush = flush;
|
|
8
|
+
exports.addBreadcrumb = addBreadcrumb;
|
|
9
|
+
exports.clearBreadcrumbs = clearBreadcrumbs;
|
|
10
|
+
/**
|
|
11
|
+
* aissue: isomorphic core. Works in Node, browsers and edge runtimes.
|
|
12
|
+
*
|
|
13
|
+
* import { init, captureException } from 'aissue';
|
|
14
|
+
* init({ apiKey: '...', baseUrl: 'https://aissue.example.com' });
|
|
15
|
+
* captureException(error);
|
|
16
|
+
*
|
|
17
|
+
* Framework entry points add automatic capture: aissue/browser, aissue/react,
|
|
18
|
+
* aissue/node (incl. Express), aissue/nextjs and aissue/nextjs/client.
|
|
19
|
+
*/
|
|
20
|
+
const breadcrumbs_js_1 = require("./core/breadcrumbs.js");
|
|
21
|
+
const client_js_1 = require("./core/client.js");
|
|
22
|
+
const hub_js_1 = require("./core/hub.js");
|
|
23
|
+
var version_js_1 = require("./core/version.js");
|
|
24
|
+
Object.defineProperty(exports, "SDK_NAME", { enumerable: true, get: function () { return version_js_1.SDK_NAME; } });
|
|
25
|
+
Object.defineProperty(exports, "SDK_VERSION", { enumerable: true, get: function () { return version_js_1.SDK_VERSION; } });
|
|
26
|
+
/**
|
|
27
|
+
* Configure the SDK. Server-side, omitted options are read from AISSUE_API_KEY, AISSUE_BASE_URL
|
|
28
|
+
* (or AISSUE_DSN), AISSUE_ENVIRONMENT and the release env vars. Calling init again replaces the config.
|
|
29
|
+
* Installs no global handlers: use aissue/browser or aissue/node for that.
|
|
30
|
+
*/
|
|
31
|
+
function init(options) {
|
|
32
|
+
(0, client_js_1.setupClient)(options);
|
|
33
|
+
}
|
|
34
|
+
/** Send an error (or any thrown value) to AIssue. Never throws; does nothing before init(). */
|
|
35
|
+
function captureException(error, context) {
|
|
36
|
+
try {
|
|
37
|
+
(0, hub_js_1.getHub)().client?.capture(error, context);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// never throw into the host app
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Attach an opaque user id to subsequent events (null clears it). Only the id is used: never pass
|
|
45
|
+
* an email or a name. On servers this is process-wide; prefer captureException(err, { userId }).
|
|
46
|
+
*/
|
|
47
|
+
function setUser(user) {
|
|
48
|
+
try {
|
|
49
|
+
const id = user && user.id !== undefined && user.id !== null ? String(user.id) : undefined;
|
|
50
|
+
(0, hub_js_1.getHub)().userId = id || undefined;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// ignore
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Wait for in-flight events. Resolves true when all were sent, false if `timeoutMs` (default 2000) passed. */
|
|
57
|
+
function flush(timeoutMs = 2000) {
|
|
58
|
+
try {
|
|
59
|
+
const client = (0, hub_js_1.getHub)().client;
|
|
60
|
+
return client ? client.flush(timeoutMs) : Promise.resolve(true);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return Promise.resolve(false);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Record something that happened (oldest breadcrumbs are dropped beyond `maxBreadcrumbs`). The
|
|
68
|
+
* breadcrumbs are sent with the next events. Message and data go through the privacy filters.
|
|
69
|
+
* Does nothing before init() or while the SDK is disabled. In Node, breadcrumbs added while handling
|
|
70
|
+
* an http request belong to that request only.
|
|
71
|
+
*/
|
|
72
|
+
function addBreadcrumb(breadcrumb) {
|
|
73
|
+
try {
|
|
74
|
+
(0, breadcrumbs_js_1.recordBreadcrumb)(breadcrumb);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// never throw into the host app
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** Forget the current breadcrumbs (in Node, inside a request: that request's breadcrumbs). */
|
|
81
|
+
function clearBreadcrumbs() {
|
|
82
|
+
(0, breadcrumbs_js_1.clearCurrentBreadcrumbs)();
|
|
83
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
/**
|
|
5
|
+
* Configure the browser SDK for a Next.js app and capture uncaught errors / unhandled rejections.
|
|
6
|
+
* Omitted options come from NEXT_PUBLIC_AISSUE_API_KEY, NEXT_PUBLIC_AISSUE_BASE_URL (or
|
|
7
|
+
* NEXT_PUBLIC_AISSUE_DSN), NEXT_PUBLIC_AISSUE_RELEASE / NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA and
|
|
8
|
+
* NEXT_PUBLIC_AISSUE_ENVIRONMENT / NEXT_PUBLIC_VERCEL_ENV. Does nothing on the server.
|
|
9
|
+
*/
|
|
10
|
+
export declare function initClient(options?: AIssueOptions): void;
|
|
@@ -0,0 +1,99 @@
|
|
|
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.initClient = initClient;
|
|
5
|
+
/**
|
|
6
|
+
* aissue/nextjs/client: browser side of Next.js. In instrumentation-client.ts (Next 15.3+):
|
|
7
|
+
*
|
|
8
|
+
* import { initClient } from 'aissue/nextjs/client';
|
|
9
|
+
* initClient();
|
|
10
|
+
*
|
|
11
|
+
* Reads NEXT_PUBLIC_AISSUE_API_KEY and NEXT_PUBLIC_AISSUE_BASE_URL (or NEXT_PUBLIC_AISSUE_DSN).
|
|
12
|
+
*/
|
|
13
|
+
const browser_js_1 = require("../browser.js");
|
|
14
|
+
var index_js_1 = require("../index.js");
|
|
15
|
+
Object.defineProperty(exports, "captureException", { enumerable: true, get: function () { return index_js_1.captureException; } });
|
|
16
|
+
Object.defineProperty(exports, "setUser", { enumerable: true, get: function () { return index_js_1.setUser; } });
|
|
17
|
+
Object.defineProperty(exports, "flush", { enumerable: true, get: function () { return index_js_1.flush; } });
|
|
18
|
+
Object.defineProperty(exports, "addBreadcrumb", { enumerable: true, get: function () { return index_js_1.addBreadcrumb; } });
|
|
19
|
+
Object.defineProperty(exports, "clearBreadcrumbs", { enumerable: true, get: function () { return index_js_1.clearBreadcrumbs; } });
|
|
20
|
+
// Each variable is referenced literally: Next.js only inlines `process.env.NEXT_PUBLIC_*`
|
|
21
|
+
// when the full expression appears in the source.
|
|
22
|
+
function publicApiKey() {
|
|
23
|
+
try {
|
|
24
|
+
return process.env.NEXT_PUBLIC_AISSUE_API_KEY || undefined;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function publicBaseUrl() {
|
|
31
|
+
try {
|
|
32
|
+
return process.env.NEXT_PUBLIC_AISSUE_BASE_URL || undefined;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function publicDsn() {
|
|
39
|
+
try {
|
|
40
|
+
return process.env.NEXT_PUBLIC_AISSUE_DSN || undefined;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function publicRelease() {
|
|
47
|
+
try {
|
|
48
|
+
const explicit = process.env.NEXT_PUBLIC_AISSUE_RELEASE;
|
|
49
|
+
if (explicit)
|
|
50
|
+
return explicit;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// ignore
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
return process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA || undefined;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function publicEnvironment() {
|
|
63
|
+
try {
|
|
64
|
+
const explicit = process.env.NEXT_PUBLIC_AISSUE_ENVIRONMENT;
|
|
65
|
+
if (explicit)
|
|
66
|
+
return explicit;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// ignore
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
return process.env.NEXT_PUBLIC_VERCEL_ENV || undefined;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Configure the browser SDK for a Next.js app and capture uncaught errors / unhandled rejections.
|
|
80
|
+
* Omitted options come from NEXT_PUBLIC_AISSUE_API_KEY, NEXT_PUBLIC_AISSUE_BASE_URL (or
|
|
81
|
+
* NEXT_PUBLIC_AISSUE_DSN), NEXT_PUBLIC_AISSUE_RELEASE / NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA and
|
|
82
|
+
* NEXT_PUBLIC_AISSUE_ENVIRONMENT / NEXT_PUBLIC_VERCEL_ENV. Does nothing on the server.
|
|
83
|
+
*/
|
|
84
|
+
function initClient(options = {}) {
|
|
85
|
+
try {
|
|
86
|
+
const dsn = options.dsn || publicDsn();
|
|
87
|
+
(0, browser_js_1.init)({
|
|
88
|
+
...options,
|
|
89
|
+
apiKey: options.apiKey || publicApiKey() || '',
|
|
90
|
+
baseUrl: options.baseUrl || publicBaseUrl() || '',
|
|
91
|
+
dsn,
|
|
92
|
+
release: options.release || publicRelease(),
|
|
93
|
+
environment: options.environment || publicEnvironment(),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// never throw into the host app
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AIssueOptions } from '../core/types.js';
|
|
2
|
+
export { runWithBreadcrumbs } from '../node.js';
|
|
3
|
+
export { captureException, setUser, flush, addBreadcrumb, clearBreadcrumbs } from '../index.js';
|
|
4
|
+
export type { AIssueEvent, AIssueOptions, AutoBreadcrumbsOptions, Breadcrumb, BreadcrumbInput, CaptureContext, StackFrame, User, } from '../index.js';
|
|
5
|
+
/** `request` argument of Next's onRequestError hook. */
|
|
6
|
+
export interface NextRequestInfo {
|
|
7
|
+
path: string;
|
|
8
|
+
method: string;
|
|
9
|
+
headers: Record<string, string | string[] | undefined>;
|
|
10
|
+
}
|
|
11
|
+
/** `context` argument of Next's onRequestError hook. */
|
|
12
|
+
export interface NextErrorContext {
|
|
13
|
+
routerKind: string;
|
|
14
|
+
routePath: string;
|
|
15
|
+
routeType: string;
|
|
16
|
+
renderSource?: string;
|
|
17
|
+
revalidateReason?: string;
|
|
18
|
+
renderType?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Next.js instrumentation `register` hook. In the Node.js runtime it also captures uncaught
|
|
22
|
+
* exceptions and unhandled rejections; in the Edge runtime it only configures the SDK.
|
|
23
|
+
* Called by Next with no arguments; call it yourself to pass options.
|
|
24
|
+
*/
|
|
25
|
+
export declare function register(options?: AIssueOptions): void;
|
|
26
|
+
/**
|
|
27
|
+
* Next.js 15+ instrumentation `onRequestError` hook. Sends the error with the request path
|
|
28
|
+
* (query stripped), method, allowlisted headers, routePath / routeType and the error digest
|
|
29
|
+
* (the id Next shows in production error pages). 4xx errors are skipped.
|
|
30
|
+
*/
|
|
31
|
+
export declare function onRequestError(error: unknown, request: Readonly<NextRequestInfo>, context: Readonly<NextErrorContext>): Promise<void>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clearBreadcrumbs = exports.addBreadcrumb = exports.flush = exports.setUser = exports.captureException = exports.runWithBreadcrumbs = void 0;
|
|
4
|
+
exports.register = register;
|
|
5
|
+
exports.onRequestError = onRequestError;
|
|
6
|
+
/**
|
|
7
|
+
* aissue/nextjs: server side of Next.js (App and Pages Router), for instrumentation.ts:
|
|
8
|
+
*
|
|
9
|
+
* export { register, onRequestError } from 'aissue/nextjs';
|
|
10
|
+
*
|
|
11
|
+
* register() reads AISSUE_API_KEY / AISSUE_BASE_URL (or AISSUE_DSN). onRequestError is the
|
|
12
|
+
* Next.js 15+ hook that receives every server error (Server Components, route handlers,
|
|
13
|
+
* server actions, middleware).
|
|
14
|
+
*/
|
|
15
|
+
const client_js_1 = require("../core/client.js");
|
|
16
|
+
const event_js_1 = require("../core/event.js");
|
|
17
|
+
const index_js_1 = require("../index.js");
|
|
18
|
+
const node_js_1 = require("../node.js");
|
|
19
|
+
var node_js_2 = require("../node.js");
|
|
20
|
+
Object.defineProperty(exports, "runWithBreadcrumbs", { enumerable: true, get: function () { return node_js_2.runWithBreadcrumbs; } });
|
|
21
|
+
var index_js_2 = require("../index.js");
|
|
22
|
+
Object.defineProperty(exports, "captureException", { enumerable: true, get: function () { return index_js_2.captureException; } });
|
|
23
|
+
Object.defineProperty(exports, "setUser", { enumerable: true, get: function () { return index_js_2.setUser; } });
|
|
24
|
+
Object.defineProperty(exports, "flush", { enumerable: true, get: function () { return index_js_2.flush; } });
|
|
25
|
+
Object.defineProperty(exports, "addBreadcrumb", { enumerable: true, get: function () { return index_js_2.addBreadcrumb; } });
|
|
26
|
+
Object.defineProperty(exports, "clearBreadcrumbs", { enumerable: true, get: function () { return index_js_2.clearBreadcrumbs; } });
|
|
27
|
+
function nextRuntime() {
|
|
28
|
+
try {
|
|
29
|
+
// Referenced literally so Next.js can inline it per runtime.
|
|
30
|
+
return process.env.NEXT_RUNTIME;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Next.js instrumentation `register` hook. In the Node.js runtime it also captures uncaught
|
|
38
|
+
* exceptions and unhandled rejections; in the Edge runtime it only configures the SDK.
|
|
39
|
+
* Called by Next with no arguments; call it yourself to pass options.
|
|
40
|
+
*/
|
|
41
|
+
function register(options) {
|
|
42
|
+
try {
|
|
43
|
+
if (nextRuntime() === 'nodejs') {
|
|
44
|
+
const client = (0, client_js_1.setupClient)(options, { runtime: 'server', platform: 'node' });
|
|
45
|
+
if (client?.enabled) {
|
|
46
|
+
(0, node_js_1.installNodeHandlers)();
|
|
47
|
+
(0, node_js_1.installNodeBreadcrumbs)();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
(0, client_js_1.setupClient)(options, { runtime: 'server', platform: 'javascript' });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// never throw into the host app
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** notFound(), redirect(), dynamic-rendering bailouts: Next.js control flow, not bugs. */
|
|
59
|
+
function isNextControlFlow(error) {
|
|
60
|
+
const digest = error && typeof error === 'object' ? error.digest : undefined;
|
|
61
|
+
return (typeof digest === 'string' &&
|
|
62
|
+
/^(NEXT_REDIRECT|NEXT_NOT_FOUND|NEXT_HTTP_ERROR_FALLBACK|DYNAMIC_SERVER_USAGE|BAILOUT_TO_CLIENT_SIDE_RENDERING|NEXT_DYNAMIC_NO_SSR_CODE|NEXT_PRERENDER_INTERRUPTED)/.test(digest));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Next.js 15+ instrumentation `onRequestError` hook. Sends the error with the request path
|
|
66
|
+
* (query stripped), method, allowlisted headers, routePath / routeType and the error digest
|
|
67
|
+
* (the id Next shows in production error pages). 4xx errors are skipped.
|
|
68
|
+
*/
|
|
69
|
+
async function onRequestError(error, request, context) {
|
|
70
|
+
try {
|
|
71
|
+
if (isNextControlFlow(error))
|
|
72
|
+
return;
|
|
73
|
+
const status = (0, event_js_1.statusFromError)(error, 500);
|
|
74
|
+
if (status >= 400 && status <= 499)
|
|
75
|
+
return;
|
|
76
|
+
const digest = error && typeof error === 'object' ? error.digest : undefined;
|
|
77
|
+
const extra = {};
|
|
78
|
+
if (context) {
|
|
79
|
+
for (const key of ['routerKind', 'routePath', 'routeType', 'renderSource', 'revalidateReason', 'renderType']) {
|
|
80
|
+
if (context[key] !== undefined)
|
|
81
|
+
extra[key] = context[key];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (typeof digest === 'string')
|
|
85
|
+
extra.digest = digest;
|
|
86
|
+
(0, index_js_1.captureException)(error, {
|
|
87
|
+
errorCode: status,
|
|
88
|
+
path: request?.path,
|
|
89
|
+
method: request?.method,
|
|
90
|
+
headers: request?.headers,
|
|
91
|
+
extra,
|
|
92
|
+
});
|
|
93
|
+
// Serverless functions may be frozen right after the response; give the send a chance.
|
|
94
|
+
await (0, index_js_1.flush)(2000);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// never throw into the host app
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { AIssueOptions, HeadersInput } 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
|
+
export interface NodeOptions extends AIssueOptions {
|
|
5
|
+
/** Capture uncaught exceptions (default true). The process still exits as it would without AIssue. */
|
|
6
|
+
captureUncaughtExceptions?: boolean;
|
|
7
|
+
/** Capture unhandled promise rejections (default true). Node's --unhandled-rejections mode is respected. */
|
|
8
|
+
captureUnhandledRejections?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** Install process-level handlers (idempotent). Exported for aissue/nextjs. */
|
|
11
|
+
export declare function installNodeHandlers(options?: Pick<NodeOptions, 'captureUncaughtExceptions' | 'captureUnhandledRejections'>): void;
|
|
12
|
+
/**
|
|
13
|
+
* Automatic Node breadcrumbs (console, fetch, http/https requests) and a separate breadcrumb buffer
|
|
14
|
+
* per incoming http(s) request. Idempotent; does nothing when the SDK is disabled. Exported for aissue/nextjs.
|
|
15
|
+
*/
|
|
16
|
+
export declare function installNodeBreadcrumbs(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Run `fn` with its own, empty breadcrumb buffer, for work that is not an http request
|
|
19
|
+
* (queue jobs, cron tasks, custom servers). Incoming http(s) server requests get one automatically.
|
|
20
|
+
* Returns what `fn` returns.
|
|
21
|
+
*/
|
|
22
|
+
export declare function runWithBreadcrumbs<T>(fn: () => T): T;
|
|
23
|
+
/**
|
|
24
|
+
* Configure the SDK for Node.js and capture uncaught exceptions / unhandled rejections.
|
|
25
|
+
* Omitted options are read from AISSUE_API_KEY, AISSUE_BASE_URL (or AISSUE_DSN), AISSUE_ENVIRONMENT
|
|
26
|
+
* and the release env vars. Disabled by default when NODE_ENV is development or test.
|
|
27
|
+
*/
|
|
28
|
+
export declare function init(options?: NodeOptions): void;
|
|
29
|
+
/** The parts of an Express (or plain Node http) request that are used. */
|
|
30
|
+
export interface ExpressLikeRequest {
|
|
31
|
+
method?: string;
|
|
32
|
+
originalUrl?: string;
|
|
33
|
+
url?: string;
|
|
34
|
+
path?: string;
|
|
35
|
+
headers?: HeadersInput;
|
|
36
|
+
}
|
|
37
|
+
export interface ExpressErrorHandlerOptions<Req = any> {
|
|
38
|
+
/** Decide which errors are sent. Default: everything except 4xx (status 400-499). */
|
|
39
|
+
shouldHandleError?: (error: unknown, status: number) => boolean;
|
|
40
|
+
/** Opaque user id for the request (e.g. req => req.user?.id). Never return an email. */
|
|
41
|
+
getUserId?: (req: Req) => string | number | null | undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Express 4/5 error middleware. Add it after your routes and before other error handlers:
|
|
45
|
+
* app.use(expressErrorHandler());
|
|
46
|
+
* Captures the error with path, method, filtered query and allowlisted headers, then calls next(err).
|
|
47
|
+
*/
|
|
48
|
+
export declare function expressErrorHandler<Req extends ExpressLikeRequest = ExpressLikeRequest>(options?: ExpressErrorHandlerOptions<Req>): (err: unknown, req: Req, res: unknown, next: (err?: unknown) => void) => void;
|