lighthouse 13.6.0-dev.20261111 → 13.6.0-dev.20261116
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/.agents/skills/update-ard-port/SKILL.md +1 -1
- package/cli/bin.js +8 -3
- package/cli/open-file.d.ts +7 -0
- package/cli/open-file.js +48 -0
- package/cli/printer.js +1 -1
- package/cli/run.js +6 -4
- package/cli/sentry-prompt.js +2 -1
- package/cli/test/smokehouse/frontends/smokehouse-bin.js +1 -1
- package/cli/test/smokehouse/lighthouse-runners/cli.js +1 -2
- package/cli/test/smokehouse/report-assert.js +1 -2
- package/cli/test/smokehouse/smokehouse.js +1 -2
- package/core/audits/autocomplete.js +1 -2
- package/core/audits/bootup-time.js +1 -2
- package/core/audits/errors-in-console.js +1 -2
- package/core/audits/mainthread-work-breakdown.js +1 -2
- package/core/audits/metrics.d.ts +2 -2
- package/core/audits/metrics.js +1 -1
- package/core/computed/computed-artifact.js +1 -2
- package/core/computed/entity-classification.d.ts +3 -3
- package/core/computed/entity-classification.js +5 -3
- package/core/computed/js-bundles.js +1 -2
- package/core/computed/load-simulator.d.ts +5 -3
- package/core/computed/load-simulator.js +9 -2
- package/core/computed/metrics/responsiveness.d.ts +5 -3
- package/core/computed/metrics/responsiveness.js +1 -1
- package/core/computed/metrics/time-to-first-byte.js +3 -1
- package/core/computed/metrics/timing-summary.d.ts +7 -5
- package/core/computed/metrics/timing-summary.js +3 -4
- package/core/computed/navigation-insights.d.ts +5 -3
- package/core/computed/navigation-insights.js +1 -1
- package/core/computed/network-analysis.js +1 -2
- package/core/computed/page-dependency-graph.d.ts +5 -3
- package/core/computed/page-dependency-graph.js +1 -1
- package/core/computed/trace-engine-result.d.ts +7 -5
- package/core/computed/trace-engine-result.js +9 -5
- package/core/computed/unused-css.d.ts +2 -2
- package/core/computed/unused-css.js +1 -1
- package/core/config/config.js +1 -2
- package/core/gather/base-artifacts.js +1 -2
- package/core/gather/driver/environment.js +1 -2
- package/core/gather/driver/execution-context.js +2 -0
- package/core/gather/driver/navigation.js +1 -2
- package/core/gather/driver/network-monitor.js +1 -2
- package/core/gather/driver/prepare.js +1 -2
- package/core/gather/driver/storage.js +1 -2
- package/core/gather/driver/target-manager.js +1 -2
- package/core/gather/driver/wait-for-condition.js +6 -5
- package/core/gather/driver.js +1 -2
- package/core/gather/gatherers/agentic/ard.js +1 -1
- package/core/gather/gatherers/agentic/llms-txt.js +1 -2
- package/core/gather/gatherers/css-usage.js +5 -1
- package/core/gather/gatherers/image-elements.js +1 -2
- package/core/gather/gatherers/seo/robots-txt.js +1 -2
- package/core/gather/gatherers/stacks.js +1 -2
- package/core/gather/gatherers/stylesheets.js +10 -3
- package/core/gather/navigation-runner.js +1 -1
- package/core/gather/runner-helpers.js +1 -2
- package/core/gather/session.js +1 -2
- package/core/gather/snapshot-runner.js +1 -2
- package/core/gather/timespan-runner.js +1 -2
- package/core/lib/asset-saver.js +1 -2
- package/core/lib/csp-evaluator.js +1 -1
- package/core/lib/i18n/i18n.js +1 -2
- package/core/lib/lantern-trace-saver.js +19 -13
- package/core/lib/lighthouse-logger.d.ts +127 -0
- package/core/lib/lighthouse-logger.js +319 -0
- package/core/lib/median-run.d.ts +16 -6
- package/core/lib/median-run.js +13 -6
- package/core/lib/network-recorder.js +1 -2
- package/core/lib/network-request.d.ts +2 -2
- package/core/lib/network-request.js +1 -1
- package/core/lib/page-functions.js +4 -3
- package/core/lib/script-helpers.d.ts +23 -8
- package/core/lib/script-helpers.js +7 -6
- package/core/lib/sentry-reporter.d.ts +59 -0
- package/core/lib/sentry-reporter.js +281 -0
- package/core/lib/sentry.d.ts +7 -7
- package/core/lib/sentry.js +31 -39
- package/core/lib/stack-packs.js +1 -1
- package/core/lib/timing-trace-saver.d.ts +2 -2
- package/core/lib/timing-trace-saver.js +1 -1
- package/core/lib/tracehouse/main-thread-tasks.d.ts +7 -0
- package/core/lib/tracehouse/main-thread-tasks.js +18 -6
- package/core/lib/tracehouse/task-summary.d.ts +16 -4
- package/core/lib/tracehouse/task-summary.js +6 -5
- package/core/lib/tracehouse/trace-processor.d.ts +6 -6
- package/core/lib/tracehouse/trace-processor.js +1 -1
- package/core/lib/traces/metric-trace-events.js +1 -2
- package/core/lib/url-utils.d.ts +4 -4
- package/core/lib/url-utils.js +1 -1
- package/core/runner.js +1 -2
- package/dist/report/bundle.esm.js +10 -10
- package/dist/report/flow.js +13 -13
- package/dist/report/standalone.js +11 -11
- package/package.json +9 -12
- package/report/renderer/text-encoding.d.ts +3 -5
- package/report/renderer/text-encoding.js +19 -33
- package/report/types/augment-dom.d.ts +0 -4
- package/shared/util.js +10 -2
- package/third-party/ard/README.md +2 -2
- package/third-party/ard/ard.js +1 -1
- package/third-party/ard/schema-validator.js +42 -2
- package/tsconfig.json +2 -42
- package/types/artifacts.d.ts +7 -1
- package/types/internal/node.d.ts +1 -0
- package/types/internal/test.d.ts +5 -0
- package/report/types/buffer.d.ts +0 -19
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export type SeverityLevel = "fatal" | "error" | "warning" | "log" | "info" | "debug";
|
|
2
|
+
export type Breadcrumb = {
|
|
3
|
+
message?: string;
|
|
4
|
+
category?: string;
|
|
5
|
+
level?: SeverityLevel;
|
|
6
|
+
data?: Record<string, any>;
|
|
7
|
+
timestamp?: number;
|
|
8
|
+
};
|
|
9
|
+
export type EnvironmentData = {
|
|
10
|
+
release?: string;
|
|
11
|
+
environment?: string;
|
|
12
|
+
serverName?: string;
|
|
13
|
+
};
|
|
14
|
+
export type CaptureOptions = {
|
|
15
|
+
level?: SeverityLevel;
|
|
16
|
+
tags?: Record<string, any>;
|
|
17
|
+
extra?: Record<string, any>;
|
|
18
|
+
fingerprint?: string[];
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* @param {string} dsn
|
|
22
|
+
* @param {EnvironmentData=} environmentData
|
|
23
|
+
*/
|
|
24
|
+
export function createSentryReporter(dsn: string, environmentData?: EnvironmentData | undefined): {
|
|
25
|
+
/** @param {Record<string, any>} newTags */
|
|
26
|
+
setTags(newTags: Record<string, any>): void;
|
|
27
|
+
/** @param {Record<string, any>} newExtras */
|
|
28
|
+
setExtras(newExtras: Record<string, any>): void;
|
|
29
|
+
/**
|
|
30
|
+
* @param {string} name
|
|
31
|
+
* @param {Record<string, any>|null} context
|
|
32
|
+
*/
|
|
33
|
+
setContext(name: string, context: Record<string, any> | null): void;
|
|
34
|
+
/** @param {Breadcrumb} breadcrumb */
|
|
35
|
+
addBreadcrumb(breadcrumb: Breadcrumb): void;
|
|
36
|
+
/**
|
|
37
|
+
* @param {string} message
|
|
38
|
+
* @param {SeverityLevel|CaptureOptions=} levelOrOpts
|
|
39
|
+
*/
|
|
40
|
+
captureMessage(message: string, levelOrOpts?: (SeverityLevel | CaptureOptions) | undefined): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* @param {unknown} err
|
|
43
|
+
* @param {CaptureOptions=} opts
|
|
44
|
+
*/
|
|
45
|
+
captureException(err: unknown, opts?: CaptureOptions | undefined): Promise<void>;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Parses a V8 stack into Sentry frames, oldest call first.
|
|
49
|
+
* @param {unknown} stack
|
|
50
|
+
*/
|
|
51
|
+
export function parseStack(stack: unknown): {
|
|
52
|
+
filename: string;
|
|
53
|
+
module: string;
|
|
54
|
+
function: string;
|
|
55
|
+
lineno: number | undefined;
|
|
56
|
+
colno: number | undefined;
|
|
57
|
+
in_app: boolean;
|
|
58
|
+
}[];
|
|
59
|
+
//# sourceMappingURL=sentry-reporter.d.ts.map
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A minimal Sentry client that sends events with `fetch` using Sentry's envelope protocol.
|
|
9
|
+
* See https://develop.sentry.dev/sdk/data-model/envelopes/
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import os from 'os';
|
|
13
|
+
import path from 'path';
|
|
14
|
+
import {types} from 'util';
|
|
15
|
+
|
|
16
|
+
import log from './lighthouse-logger.js';
|
|
17
|
+
|
|
18
|
+
/** @typedef {'fatal'|'error'|'warning'|'log'|'info'|'debug'} SeverityLevel */
|
|
19
|
+
/** @typedef {{message?: string, category?: string, level?: SeverityLevel, data?: Record<string, any>, timestamp?: number}} Breadcrumb */
|
|
20
|
+
/** @typedef {{release?: string, environment?: string, serverName?: string}} EnvironmentData */
|
|
21
|
+
/** @typedef {{level?: SeverityLevel, tags?: Record<string, any>, extra?: Record<string, any>, fingerprint?: string[]}} CaptureOptions */
|
|
22
|
+
|
|
23
|
+
const MAX_BREADCRUMBS = 100;
|
|
24
|
+
const MAX_FRAMES = 50;
|
|
25
|
+
const MAX_LINKED_ERRORS = 5;
|
|
26
|
+
const SEND_TIMEOUT_MS = 5000;
|
|
27
|
+
const DEFAULT_RETRY_AFTER_S = 60;
|
|
28
|
+
|
|
29
|
+
// Same as @sentry/node's stack line parser so frames (and issue grouping) stay similar.
|
|
30
|
+
const FRAME_RE = /at (?:async )?(?:(.+?)\s+\()?(?:(.+):(\d+):(\d+)?|([^)]+))\)?/;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Same as @sentry/core: drop any Windows drive letter and use forward slashes.
|
|
34
|
+
* @param {string} p
|
|
35
|
+
*/
|
|
36
|
+
function normalizePath(p) {
|
|
37
|
+
return p.replace(/^[A-Za-z]:/, '').replace(/\\/g, '/');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const BASE_PATH = normalizePath(process.argv[1] ? path.dirname(process.argv[1]) : process.cwd());
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Same as @sentry/node's module naming, e.g. `core.lib:sentry` or `puppeteer-core.lib:foo`.
|
|
44
|
+
* @param {string} filename
|
|
45
|
+
*/
|
|
46
|
+
function getModule(filename) {
|
|
47
|
+
const {dir, name} = path.posix.parse(normalizePath(filename));
|
|
48
|
+
const nodeModulesIndex = dir.lastIndexOf('/node_modules');
|
|
49
|
+
if (nodeModulesIndex > -1) {
|
|
50
|
+
return `${dir.slice(nodeModulesIndex + 14).replace(/\//g, '.')}:${name}`;
|
|
51
|
+
}
|
|
52
|
+
if (dir === BASE_PATH || dir.startsWith(`${BASE_PATH}/`)) {
|
|
53
|
+
const moduleName = dir.slice(BASE_PATH.length + 1).replace(/\//g, '.');
|
|
54
|
+
return moduleName ? `${moduleName}:${name}` : name;
|
|
55
|
+
}
|
|
56
|
+
return name;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Parses a V8 stack into Sentry frames, oldest call first.
|
|
61
|
+
* @param {unknown} stack
|
|
62
|
+
*/
|
|
63
|
+
function parseStack(stack) {
|
|
64
|
+
if (typeof stack !== 'string') return [];
|
|
65
|
+
|
|
66
|
+
const frames = [];
|
|
67
|
+
const lines = stack.split('\n').filter(line => /^\s+at /.test(line)).slice(0, MAX_FRAMES);
|
|
68
|
+
for (const line of lines) {
|
|
69
|
+
const match = FRAME_RE.exec(line);
|
|
70
|
+
if (!match) continue;
|
|
71
|
+
|
|
72
|
+
let filename = match[2] || match[5];
|
|
73
|
+
if (filename.startsWith('file://')) {
|
|
74
|
+
filename = filename.slice(7);
|
|
75
|
+
// `file:///C:/foo.js` -> `C:/foo.js`
|
|
76
|
+
if (/^\/[A-Za-z]:/.test(filename)) filename = filename.slice(1);
|
|
77
|
+
try {
|
|
78
|
+
filename = decodeURI(filename);
|
|
79
|
+
} catch {}
|
|
80
|
+
}
|
|
81
|
+
const slashFilename = filename.replace(/\\/g, '/');
|
|
82
|
+
const isAbsolute = slashFilename.startsWith('/') || /^[A-Za-z]:\//.test(slashFilename);
|
|
83
|
+
const inApp = isAbsolute && !slashFilename.includes('/node_modules/');
|
|
84
|
+
|
|
85
|
+
frames.push({
|
|
86
|
+
filename,
|
|
87
|
+
module: getModule(filename),
|
|
88
|
+
function: match[1] || '<anonymous>',
|
|
89
|
+
lineno: match[3] ? Number(match[3]) : undefined,
|
|
90
|
+
colno: match[4] ? Number(match[4]) : undefined,
|
|
91
|
+
in_app: inApp,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return frames.reverse();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @param {unknown} value
|
|
99
|
+
* @return {value is Error}
|
|
100
|
+
*/
|
|
101
|
+
function isError(value) {
|
|
102
|
+
// `isNativeError` also handles errors from other realms (e.g. `vm` contexts).
|
|
103
|
+
return value instanceof Error || types.isNativeError(value);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @param {unknown} err
|
|
108
|
+
*/
|
|
109
|
+
function exceptionValues(err) {
|
|
110
|
+
const values = [];
|
|
111
|
+
/** @type {unknown} */
|
|
112
|
+
let current = err;
|
|
113
|
+
while (isError(current) && values.length < MAX_LINKED_ERRORS) {
|
|
114
|
+
values.push({
|
|
115
|
+
type: current.name,
|
|
116
|
+
value: current.message,
|
|
117
|
+
mechanism: {type: 'generic', handled: true},
|
|
118
|
+
stacktrace: {frames: parseStack(current.stack)},
|
|
119
|
+
});
|
|
120
|
+
current = current.cause;
|
|
121
|
+
}
|
|
122
|
+
// Non-Error throwables (strings, plain objects, ...).
|
|
123
|
+
if (!values.length) {
|
|
124
|
+
const message = err && typeof err === 'object' && 'message' in err ? err.message : err;
|
|
125
|
+
values.push({
|
|
126
|
+
type: 'Error',
|
|
127
|
+
value: String(message),
|
|
128
|
+
mechanism: {type: 'generic', handled: true},
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
// Sentry expects the root cause first, and the captured error last.
|
|
132
|
+
return values.reverse();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* A JSON.stringify replacer that handles values that would otherwise throw or be lost.
|
|
137
|
+
* Based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value
|
|
138
|
+
*/
|
|
139
|
+
function safeJsonReplacer() {
|
|
140
|
+
/** @type {unknown[]} */
|
|
141
|
+
const ancestors = [];
|
|
142
|
+
/**
|
|
143
|
+
* @this {unknown}
|
|
144
|
+
* @param {string} key
|
|
145
|
+
* @param {unknown} value
|
|
146
|
+
*/
|
|
147
|
+
return function(key, value) {
|
|
148
|
+
if (typeof value === 'bigint') return String(value);
|
|
149
|
+
if (value instanceof Error) {
|
|
150
|
+
value = {name: value.name, message: value.message, stack: value.stack};
|
|
151
|
+
}
|
|
152
|
+
if (typeof value !== 'object' || value === null) return value;
|
|
153
|
+
|
|
154
|
+
while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this) ancestors.pop();
|
|
155
|
+
if (ancestors.includes(value)) return '[Circular]';
|
|
156
|
+
ancestors.push(value);
|
|
157
|
+
return value;
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @param {string} dsn
|
|
163
|
+
* @param {EnvironmentData=} environmentData
|
|
164
|
+
*/
|
|
165
|
+
function createSentryReporter(dsn, environmentData = {}) {
|
|
166
|
+
const sdkVersion = environmentData.release || 'unknown';
|
|
167
|
+
const {protocol, username: publicKey, host, pathname} = new URL(dsn);
|
|
168
|
+
const endpoint = `${protocol}//${host}/api/${pathname.slice(1)}/envelope/`;
|
|
169
|
+
const auth = `Sentry sentry_version=7, sentry_key=${publicKey}, ` +
|
|
170
|
+
`sentry_client=lighthouse/${sdkVersion}`;
|
|
171
|
+
|
|
172
|
+
/** @type {Record<string, any>} */
|
|
173
|
+
const tags = {};
|
|
174
|
+
/** @type {Record<string, any>} */
|
|
175
|
+
const extra = {};
|
|
176
|
+
/** @type {Record<string, any>} */
|
|
177
|
+
const contexts = {
|
|
178
|
+
os: {name: os.type(), version: os.release()},
|
|
179
|
+
runtime: {name: 'node', version: process.version},
|
|
180
|
+
};
|
|
181
|
+
/** @type {Breadcrumb[]} */
|
|
182
|
+
const breadcrumbs = [];
|
|
183
|
+
// Set when Sentry rate limits us (HTTP 429); nothing is sent until then.
|
|
184
|
+
let disabledUntil = 0;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Never throws: a failure to report an error must not affect Lighthouse.
|
|
188
|
+
* @param {() => Record<string, any>} getEvent
|
|
189
|
+
* @param {CaptureOptions} opts
|
|
190
|
+
* @return {Promise<void>}
|
|
191
|
+
*/
|
|
192
|
+
async function send(getEvent, opts) {
|
|
193
|
+
if (Date.now() < disabledUntil) return;
|
|
194
|
+
|
|
195
|
+
try {
|
|
196
|
+
const eventId = crypto.randomUUID().replace(/-/g, '');
|
|
197
|
+
const fullEvent = {
|
|
198
|
+
event_id: eventId,
|
|
199
|
+
timestamp: Date.now() / 1000,
|
|
200
|
+
platform: 'node',
|
|
201
|
+
level: opts.level,
|
|
202
|
+
release: environmentData.release,
|
|
203
|
+
environment: environmentData.environment,
|
|
204
|
+
server_name: environmentData.serverName,
|
|
205
|
+
tags: {...tags, ...opts.tags},
|
|
206
|
+
extra: {...extra, ...opts.extra},
|
|
207
|
+
contexts,
|
|
208
|
+
breadcrumbs,
|
|
209
|
+
fingerprint: opts.fingerprint,
|
|
210
|
+
sdk: {name: 'lighthouse', version: sdkVersion},
|
|
211
|
+
...getEvent(),
|
|
212
|
+
};
|
|
213
|
+
const envelope = [
|
|
214
|
+
JSON.stringify({event_id: eventId, sent_at: new Date().toISOString()}),
|
|
215
|
+
JSON.stringify({type: 'event'}),
|
|
216
|
+
JSON.stringify(fullEvent, safeJsonReplacer()),
|
|
217
|
+
].join('\n');
|
|
218
|
+
|
|
219
|
+
const response = await fetch(endpoint, {
|
|
220
|
+
method: 'POST',
|
|
221
|
+
headers: {'Content-Type': 'application/x-sentry-envelope', 'X-Sentry-Auth': auth},
|
|
222
|
+
body: envelope,
|
|
223
|
+
signal: AbortSignal.timeout(SEND_TIMEOUT_MS),
|
|
224
|
+
});
|
|
225
|
+
await response.body?.cancel();
|
|
226
|
+
if (!response.ok) log.verbose('sentry', `Failed to send event: HTTP ${response.status}`);
|
|
227
|
+
if (response.status === 429) {
|
|
228
|
+
const retryAfter = Number(response.headers.get('Retry-After'));
|
|
229
|
+
const seconds = retryAfter > 0 ? retryAfter : DEFAULT_RETRY_AFTER_S;
|
|
230
|
+
disabledUntil = Date.now() + seconds * 1000;
|
|
231
|
+
}
|
|
232
|
+
} catch (err) {
|
|
233
|
+
log.verbose('sentry', `Failed to send event: ${err}`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return {
|
|
238
|
+
/** @param {Record<string, any>} newTags */
|
|
239
|
+
setTags(newTags) {
|
|
240
|
+
Object.assign(tags, newTags);
|
|
241
|
+
},
|
|
242
|
+
/** @param {Record<string, any>} newExtras */
|
|
243
|
+
setExtras(newExtras) {
|
|
244
|
+
Object.assign(extra, newExtras);
|
|
245
|
+
},
|
|
246
|
+
/**
|
|
247
|
+
* @param {string} name
|
|
248
|
+
* @param {Record<string, any>|null} context
|
|
249
|
+
*/
|
|
250
|
+
setContext(name, context) {
|
|
251
|
+
if (context) contexts[name] = context;
|
|
252
|
+
else delete contexts[name];
|
|
253
|
+
},
|
|
254
|
+
/** @param {Breadcrumb} breadcrumb */
|
|
255
|
+
addBreadcrumb(breadcrumb) {
|
|
256
|
+
breadcrumbs.push({timestamp: Date.now() / 1000, ...breadcrumb});
|
|
257
|
+
if (breadcrumbs.length > MAX_BREADCRUMBS) breadcrumbs.shift();
|
|
258
|
+
},
|
|
259
|
+
/**
|
|
260
|
+
* @param {string} message
|
|
261
|
+
* @param {SeverityLevel|CaptureOptions=} levelOrOpts
|
|
262
|
+
*/
|
|
263
|
+
captureMessage(message, levelOrOpts) {
|
|
264
|
+
const opts = typeof levelOrOpts === 'string' ? {level: levelOrOpts} : levelOrOpts;
|
|
265
|
+
return send(() => ({message}), {...opts, level: opts?.level || 'info'});
|
|
266
|
+
},
|
|
267
|
+
/**
|
|
268
|
+
* @param {unknown} err
|
|
269
|
+
* @param {CaptureOptions=} opts
|
|
270
|
+
*/
|
|
271
|
+
captureException(err, opts) {
|
|
272
|
+
const getEvent = () => ({exception: {values: exceptionValues(err)}});
|
|
273
|
+
return send(getEvent, {...opts, level: opts?.level || 'error'});
|
|
274
|
+
},
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export {
|
|
279
|
+
createSentryReporter,
|
|
280
|
+
parseStack,
|
|
281
|
+
};
|
package/core/lib/sentry.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export namespace Sentry {
|
|
2
2
|
export { init };
|
|
3
|
-
export
|
|
3
|
+
export let captureMessage: (message: string, levelOrOpts?: SeverityLevel | CaptureOptions) => Promise<void>;
|
|
4
4
|
export { noop as captureBreadcrumb };
|
|
5
5
|
export { noop as getContext };
|
|
6
6
|
export { noop as setContext };
|
|
@@ -15,19 +15,19 @@ export namespace Sentry {
|
|
|
15
15
|
}) => Promise<void>;
|
|
16
16
|
export function _shouldSample(): boolean;
|
|
17
17
|
}
|
|
18
|
-
export type Breadcrumb = import("
|
|
19
|
-
export type
|
|
20
|
-
export type
|
|
21
|
-
export type
|
|
18
|
+
export type Breadcrumb = import("./sentry-reporter.js").Breadcrumb;
|
|
19
|
+
export type EnvironmentData = import("./sentry-reporter.js").EnvironmentData;
|
|
20
|
+
export type SeverityLevel = import("./sentry-reporter.js").SeverityLevel;
|
|
21
|
+
export type CaptureOptions = import("./sentry-reporter.js").CaptureOptions;
|
|
22
22
|
/**
|
|
23
23
|
* When called, replaces noops with actual Sentry implementation.
|
|
24
|
-
* @param {{url: string, flags: LH.CliFlags, config?: LH.Config, environmentData:
|
|
24
|
+
* @param {{url: string, flags: LH.CliFlags, config?: LH.Config, environmentData: EnvironmentData}} opts
|
|
25
25
|
*/
|
|
26
26
|
declare function init(opts: {
|
|
27
27
|
url: string;
|
|
28
28
|
flags: LH.CliFlags;
|
|
29
29
|
config?: LH.Config;
|
|
30
|
-
environmentData:
|
|
30
|
+
environmentData: EnvironmentData;
|
|
31
31
|
}): Promise<void>;
|
|
32
32
|
declare function noop(): void;
|
|
33
33
|
export {};
|
package/core/lib/sentry.js
CHANGED
|
@@ -4,14 +4,13 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import log from 'lighthouse-logger';
|
|
8
|
-
|
|
7
|
+
import log from './lighthouse-logger.js';
|
|
9
8
|
import {initializeConfig} from '../config/config.js';
|
|
10
9
|
|
|
11
|
-
/** @typedef {import('
|
|
12
|
-
/** @typedef {import('
|
|
13
|
-
/** @typedef {import('
|
|
14
|
-
/** @typedef {import('
|
|
10
|
+
/** @typedef {import('./sentry-reporter.js').Breadcrumb} Breadcrumb */
|
|
11
|
+
/** @typedef {import('./sentry-reporter.js').EnvironmentData} EnvironmentData */
|
|
12
|
+
/** @typedef {import('./sentry-reporter.js').SeverityLevel} SeverityLevel */
|
|
13
|
+
/** @typedef {import('./sentry-reporter.js').CaptureOptions} CaptureOptions */
|
|
15
14
|
|
|
16
15
|
const SENTRY_URL = 'https://a6bb0da87ee048cc9ae2a345fc09ab2e:63a7029f46f74265981b7e005e0f69f8@sentry.io/174697';
|
|
17
16
|
|
|
@@ -26,8 +25,8 @@ const noop = () => { };
|
|
|
26
25
|
*/
|
|
27
26
|
const sentryDelegate = {
|
|
28
27
|
init,
|
|
29
|
-
/** @type {(message: string,
|
|
30
|
-
captureMessage:
|
|
28
|
+
/** @type {(message: string, levelOrOpts?: SeverityLevel|CaptureOptions) => Promise<void>} */
|
|
29
|
+
captureMessage: async () => { },
|
|
31
30
|
/** @type {(breadcrumb: Breadcrumb) => void} */
|
|
32
31
|
captureBreadcrumb: noop,
|
|
33
32
|
/** @type {() => any} */
|
|
@@ -43,7 +42,7 @@ const sentryDelegate = {
|
|
|
43
42
|
|
|
44
43
|
/**
|
|
45
44
|
* When called, replaces noops with actual Sentry implementation.
|
|
46
|
-
* @param {{url: string, flags: LH.CliFlags, config?: LH.Config, environmentData:
|
|
45
|
+
* @param {{url: string, flags: LH.CliFlags, config?: LH.Config, environmentData: EnvironmentData}} opts
|
|
47
46
|
*/
|
|
48
47
|
async function init(opts) {
|
|
49
48
|
// If error reporting is disabled, leave the functions as a noop
|
|
@@ -57,11 +56,8 @@ async function init(opts) {
|
|
|
57
56
|
}
|
|
58
57
|
|
|
59
58
|
try {
|
|
60
|
-
const
|
|
61
|
-
Sentry.
|
|
62
|
-
...opts.environmentData,
|
|
63
|
-
dsn: SENTRY_URL,
|
|
64
|
-
});
|
|
59
|
+
const {createSentryReporter} = await import('./sentry-reporter.js');
|
|
60
|
+
const Sentry = createSentryReporter(SENTRY_URL, opts.environmentData);
|
|
65
61
|
|
|
66
62
|
/** @type {LH.Config.Settings | LH.CliFlags} */
|
|
67
63
|
let settings = opts.flags;
|
|
@@ -95,15 +91,16 @@ async function init(opts) {
|
|
|
95
91
|
// Keep a record of exceptions per audit/gatherer so we can just report once
|
|
96
92
|
const sentryExceptionCache = new Map();
|
|
97
93
|
// Special case captureException to return a Promise so we don't process.exit too early
|
|
98
|
-
sentryDelegate.captureException = async (err, opts
|
|
94
|
+
sentryDelegate.captureException = async (err, opts) => {
|
|
99
95
|
// Ignore if there wasn't an error
|
|
100
96
|
if (!err) return;
|
|
97
|
+
opts = opts || {};
|
|
101
98
|
|
|
102
99
|
// Ignore expected errors
|
|
103
100
|
// @ts-expect-error Non-standard property added to flag error as not needing capturing.
|
|
104
101
|
if (err.expected) return;
|
|
105
102
|
|
|
106
|
-
const tags = opts.tags
|
|
103
|
+
const tags = {...opts.tags};
|
|
107
104
|
if (tags.audit) {
|
|
108
105
|
const key = `audit-${tags.audit}-${err.message}`;
|
|
109
106
|
if (sentryExceptionCache.has(key)) return;
|
|
@@ -116,36 +113,31 @@ async function init(opts) {
|
|
|
116
113
|
sentryExceptionCache.set(key, true);
|
|
117
114
|
}
|
|
118
115
|
|
|
116
|
+
/** @type {string[]|undefined} */
|
|
117
|
+
let fingerprint;
|
|
119
118
|
// @ts-expect-error - properties added to protocol method LighthouseErrors.
|
|
120
119
|
if (err.protocolMethod) {
|
|
121
|
-
// Protocol errors all share same stack trace, so add more to fingerprint
|
|
120
|
+
// Protocol errors all share same stack trace, so add more to fingerprint.
|
|
121
|
+
// Numbers (positions, ids, etc.) are normalized so they don't split one error into
|
|
122
|
+
// many issues.
|
|
123
|
+
// @ts-expect-error - properties added to protocol method LighthouseErrors.
|
|
124
|
+
const protocolError = String(err.protocolError ?? '').replace(/\d+/g, '<n>');
|
|
122
125
|
// @ts-expect-error - properties added to protocol method LighthouseErrors.
|
|
123
|
-
|
|
126
|
+
fingerprint = ['{{ default }}', err.protocolMethod, protocolError];
|
|
124
127
|
|
|
125
|
-
opts.tags = opts.tags || {};
|
|
126
128
|
// @ts-expect-error - properties added to protocol method LighthouseErrors.
|
|
127
|
-
|
|
129
|
+
tags.protocolMethod = err.protocolMethod;
|
|
128
130
|
}
|
|
129
131
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
// Add extra details
|
|
140
|
-
let extra;
|
|
141
|
-
if (opts.extra) extra = {...opts.extra};
|
|
142
|
-
// @ts-expect-error Non-standard property
|
|
143
|
-
if (err.extra) extra = {...extra, ...err.extra};
|
|
144
|
-
if (extra) {
|
|
145
|
-
scope.setExtras(extra);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
Sentry.captureException(err);
|
|
132
|
+
// @ts-expect-error Non-standard property
|
|
133
|
+
const extra = {...opts.extra, ...err.extra};
|
|
134
|
+
|
|
135
|
+
await Sentry.captureException(err, {
|
|
136
|
+
// @ts-expect-error - allow any string.
|
|
137
|
+
level: opts.level,
|
|
138
|
+
tags,
|
|
139
|
+
extra,
|
|
140
|
+
fingerprint,
|
|
149
141
|
});
|
|
150
142
|
};
|
|
151
143
|
} catch (e) {
|
package/core/lib/stack-packs.js
CHANGED
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
export function generateTraceEvents(entries: LH.Artifacts.MeasureEntry[], threadId?: number | undefined): import("..").TraceEvent[];
|
|
15
15
|
/**
|
|
16
16
|
* Writes a trace file to disk
|
|
17
|
-
* @param {LH.Result} lhr
|
|
17
|
+
* @param {Pick<LH.Result, 'timing'>} lhr
|
|
18
18
|
* @return {string}
|
|
19
19
|
*/
|
|
20
|
-
export function createTraceString(lhr: LH.Result): string;
|
|
20
|
+
export function createTraceString(lhr: Pick<LH.Result, "timing">): string;
|
|
21
21
|
//# sourceMappingURL=timing-trace-saver.d.ts.map
|
|
@@ -84,6 +84,13 @@ export class MainThreadTasks {
|
|
|
84
84
|
* @return {TaskNode[]}
|
|
85
85
|
*/
|
|
86
86
|
static _createTasksFromStartAndEndEvents(taskStartEvents: LH.TraceEvent[], taskEndEvents: LH.TraceEvent[], traceEndTs: number): TaskNode[];
|
|
87
|
+
/**
|
|
88
|
+
* Extends the endTime (and duration) of `task` and its ancestors so that each ends no earlier
|
|
89
|
+
* than `endTime`.
|
|
90
|
+
* @param {TaskNode|undefined} task
|
|
91
|
+
* @param {number} endTime
|
|
92
|
+
*/
|
|
93
|
+
static _extendAncestorEndTimes(task: TaskNode | undefined, endTime: number): void;
|
|
87
94
|
/**
|
|
88
95
|
* This function iterates through the tasks to set the `.parent`/`.children` properties of tasks
|
|
89
96
|
* according to their implied nesting structure. If any of these relationships seem impossible based on
|
|
@@ -213,6 +213,21 @@ class MainThreadTasks {
|
|
|
213
213
|
return tasks;
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
+
/**
|
|
217
|
+
* Extends the endTime (and duration) of `task` and its ancestors so that each ends no earlier
|
|
218
|
+
* than `endTime`.
|
|
219
|
+
* @param {TaskNode|undefined} task
|
|
220
|
+
* @param {number} endTime
|
|
221
|
+
*/
|
|
222
|
+
static _extendAncestorEndTimes(task, endTime) {
|
|
223
|
+
let cur = task;
|
|
224
|
+
while (cur && cur.endTime < endTime) {
|
|
225
|
+
cur.duration += endTime - cur.endTime;
|
|
226
|
+
cur.endTime = endTime;
|
|
227
|
+
cur = cur.parent;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
216
231
|
/**
|
|
217
232
|
* This function iterates through the tasks to set the `.parent`/`.children` properties of tasks
|
|
218
233
|
* according to their implied nesting structure. If any of these relationships seem impossible based on
|
|
@@ -269,12 +284,7 @@ class MainThreadTasks {
|
|
|
269
284
|
currentTask.duration += timeDelta;
|
|
270
285
|
|
|
271
286
|
// Recursively extend parent endTimes, as needed.
|
|
272
|
-
|
|
273
|
-
while (cur && cur.endTime < nextTask.endTime) {
|
|
274
|
-
cur.duration += nextTask.endTime - cur.endTime;
|
|
275
|
-
cur.endTime = nextTask.endTime;
|
|
276
|
-
cur = cur.parent;
|
|
277
|
-
}
|
|
287
|
+
MainThreadTasks._extendAncestorEndTimes(currentTask.parent, nextTask.endTime);
|
|
278
288
|
} else if (nextTask.unbounded) {
|
|
279
289
|
// It's ending at traceEndTs, it means we were missing the end event. We'll truncate it to the parent.
|
|
280
290
|
nextTask.endTime = currentTask.endTime;
|
|
@@ -312,6 +322,8 @@ class MainThreadTasks {
|
|
|
312
322
|
actualParentTask.parent = grandparentTask;
|
|
313
323
|
actualParentTask.startTime = actualChildTask.startTime;
|
|
314
324
|
actualParentTask.duration = actualParentTask.endTime - actualParentTask.startTime;
|
|
325
|
+
// The new parent may now end after its ancestors, so extend them as needed.
|
|
326
|
+
MainThreadTasks._extendAncestorEndTimes(grandparentTask, actualParentTask.endTime);
|
|
315
327
|
currentTask = actualParentTask;
|
|
316
328
|
nextTask = actualChildTask;
|
|
317
329
|
} else {
|
|
@@ -3,15 +3,27 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export function getJavaScriptURLs(records: LH.Artifacts.NetworkRequest[]): Set<string>;
|
|
5
5
|
/**
|
|
6
|
-
* @param {
|
|
6
|
+
* @param {{attributableURLs: string[], event?: {name: string}}} task
|
|
7
7
|
* @param {Set<string>} jsURLs
|
|
8
8
|
* @return {string}
|
|
9
9
|
*/
|
|
10
|
-
export function getAttributableURLForTask(task:
|
|
10
|
+
export function getAttributableURLForTask(task: {
|
|
11
|
+
attributableURLs: string[];
|
|
12
|
+
event?: {
|
|
13
|
+
name: string;
|
|
14
|
+
};
|
|
15
|
+
}, jsURLs: Set<string>): string;
|
|
11
16
|
/**
|
|
12
|
-
* @param {LH.Artifacts.TaskNode[]} tasks
|
|
17
|
+
* @param {Array<{attributableURLs: string[], selfTime: number, group: LH.Artifacts.TaskNode['group'], event?: {name: string}}>} tasks
|
|
13
18
|
* @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
|
|
14
19
|
* @return {Map<string, Record<string, number>>}
|
|
15
20
|
*/
|
|
16
|
-
export function getExecutionTimingsByURL(tasks:
|
|
21
|
+
export function getExecutionTimingsByURL(tasks: Array<{
|
|
22
|
+
attributableURLs: string[];
|
|
23
|
+
selfTime: number;
|
|
24
|
+
group: LH.Artifacts.TaskNode["group"];
|
|
25
|
+
event?: {
|
|
26
|
+
name: string;
|
|
27
|
+
};
|
|
28
|
+
}>, networkRecords: Array<LH.Artifacts.NetworkRequest>): Map<string, Record<string, number>>;
|
|
17
29
|
//# sourceMappingURL=task-summary.d.ts.map
|
|
@@ -38,7 +38,7 @@ function getJavaScriptURLs(records) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
* @param {
|
|
41
|
+
* @param {{attributableURLs: string[], event?: {name: string}}} task
|
|
42
42
|
* @param {Set<string>} jsURLs
|
|
43
43
|
* @return {string}
|
|
44
44
|
*/
|
|
@@ -49,16 +49,17 @@ function getAttributableURLForTask(task, jsURLs) {
|
|
|
49
49
|
// If we can't find what URL was responsible for this execution, attribute it to the root page
|
|
50
50
|
// or Chrome depending on the type of work.
|
|
51
51
|
if (!attributableURL || attributableURL === 'about:blank') {
|
|
52
|
-
if (BROWSER_TASK_NAMES_SET.has(task.event.name)) attributableURL = 'Browser';
|
|
53
|
-
else if (BROWSER_GC_TASK_NAMES_SET.has(task.event.name))
|
|
54
|
-
|
|
52
|
+
if (task.event && BROWSER_TASK_NAMES_SET.has(task.event.name)) attributableURL = 'Browser';
|
|
53
|
+
else if (task.event && BROWSER_GC_TASK_NAMES_SET.has(task.event.name)) {
|
|
54
|
+
attributableURL = 'Browser GC';
|
|
55
|
+
} else attributableURL = 'Unattributable';
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
return attributableURL;
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
/**
|
|
61
|
-
* @param {LH.Artifacts.TaskNode[]} tasks
|
|
62
|
+
* @param {Array<{attributableURLs: string[], selfTime: number, group: LH.Artifacts.TaskNode['group'], event?: {name: string}}>} tasks
|
|
62
63
|
* @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
|
|
63
64
|
* @return {Map<string, Record<string, number>>}
|
|
64
65
|
*/
|