Skip to content

Commit 31bb1ee

Browse files
node-report: merge into core
Make node-report part of core runtime, to satisfy its tier1 status on diagnostic tooling. No new functionalities have been added, changes that are required for melding it as a built-in capability has been affected on the module version of node-report (https://github.com/nodejs/node-report) Refs: nodejs#19661 Refs: nodejs#18760 Refs: nodejs/node-report#103
1 parent 6e9e150 commit 31bb1ee

27 files changed

+3439
-76
lines changed

configure

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,11 @@ parser.add_option('--without-npm',
488488
dest='without_npm',
489489
help='do not install the bundled npm (package manager)')
490490

491+
parser.add_option('--without-node-report',
492+
action='store_true',
493+
dest='without_node_report',
494+
help='build without node-report'),
495+
491496
parser.add_option('--without-perfctr',
492497
action='store_true',
493498
dest='without_perfctr',
@@ -903,6 +908,7 @@ def configure_node(o):
903908
o['variables']['OS'] = 'android'
904909
o['variables']['node_prefix'] = options.prefix
905910
o['variables']['node_install_npm'] = b(not options.without_npm)
911+
o['variables']['node_report'] = b(not options.without_node_report)
906912
o['default_configuration'] = 'Debug' if options.debug else 'Release'
907913

908914
host_arch = host_arch_win() if os.name == 'nt' else host_arch_cc()

doc/api/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* [Internationalization](intl.html)
3737
* [Modules](modules.html)
3838
* [Net](net.html)
39+
* [Node Report](node_report.html)
3940
* [OS](os.html)
4041
* [Path](path.html)
4142
* [Performance Hooks](perf_hooks.html)

doc/api/node_report.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# node-report
2+
3+
Delivers a human-readable diagnostic summary, written to file
4+
or retrieved as a text.
5+
6+
The report is intended for development, test and production
7+
use, to capture and preserve information for problem determination.
8+
It includes JavaScript and native stack traces, heap statistics,
9+
platform information and resource usage etc. With the report enabled,
10+
reports can be triggered on unhandled exceptions, fatal errors, signals.
11+
12+
Many capabilities are available as APIs too, for being consumed in-process.
13+
14+
Iin-built node-report function is supported in Node.js versions 11.0.0 onwards.
15+
For Node.js versions 8 and below, please use it's [npm counterpart][] instead.
16+
17+
## Usage
18+
19+
```bash
20+
node --report-events fatalerror,signal,exception app.js
21+
```
22+
A report will be triggered automatically on unhandled exceptions and fatal
23+
error events (for example out of memory errors), and can also be triggered
24+
by sending a USR2 signal to a Node.js process (not supported on Windows).
25+
26+
A report can also be triggered via an API call from a JavaScript
27+
application.
28+
29+
```js
30+
const util = require('util');
31+
util.triggerReport();
32+
```
33+
The content of a report can also be returned as a JavaScript string via an
34+
API call from a JavaScript application.
35+
36+
```js
37+
const util = require('util');
38+
const report_str = util.getReport();
39+
console.log(report_str);
40+
```
41+
42+
These APIs can be used without adding the automatic exception
43+
and fatal error hooks and the signal handler.
44+
45+
Content of the report consists of a header section containing the event
46+
type, date, time, PID and Node version, sections containing JavaScript and
47+
native stack traces, a section containing V8 heap information, a section
48+
containing libuv handle information and an OS platform information section
49+
showing CPU and memory usage and system limits. An example report can be
50+
triggered using the Node.js REPL:
51+
52+
```raw
53+
$ node
54+
> const util = require('util');
55+
> util.triggerReport();
56+
Writing Node.js report to file: node-report.20180820.091102.8480.001.txt
57+
Node.js report completed
58+
>
59+
```
60+
61+
When a report is triggered, start and end messages are issued to stderr
62+
and the filename of the report is returned to the caller. The default filename
63+
includes the date, time, PID and a sequence number. Alternatively, a filename
64+
can be specified as a parameter on the `triggerReport()` call.
65+
66+
```js
67+
require('util').triggerReport('myReportName');
68+
```
69+
70+
Both `triggerReport()` and `getReport()` can take an optional `Error` object
71+
as a parameter. If an `Error` object is provided, the message and stack trace
72+
from the object will be included in the report in the `JavaScript Exception
73+
Details` section.
74+
When using node-report to handle errors in a callback or an exception handler
75+
this allows the report to include the location of the original error as well
76+
as where it was handled.
77+
If both a filename and `Error` object are passed to `triggerReport()` the
78+
`Error` object should be the second parameter.
79+
80+
```js
81+
try {
82+
process.chdir('/foo/foo');
83+
} catch (err) {
84+
util.triggerReport(err);
85+
}
86+
// ...
87+
```
88+
89+
## Configuration
90+
91+
Additional configuration is available using the following APIs:
92+
93+
```js
94+
const util = require('util');
95+
util.setEvents('exception+fatalerror+signal');
96+
util.setSignal('SIGUSR2|SIGQUIT');
97+
util.setFileName('stdout|stderr|<filename>');
98+
util.setDirectory('<full path>');
99+
util.setVerbose('yes|no');
100+
```
101+
102+
Configuration on module initialization is also available via
103+
environment variables:
104+
105+
```bash
106+
export NODEREPORT_EVENTS=exception+fatalerror+signal+apicall
107+
export NODEREPORT_SIGNAL=SIGUSR2|SIGQUIT
108+
export NODEREPORT_FILENAME=stdout|stderr|<filename>
109+
export NODEREPORT_DIRECTORY=<full path>
110+
export NODEREPORT_VERBOSE=yes|no
111+
```
112+
113+
Detailed API documentation can be found under [`util`][] section.
114+
115+
[npm counterpart]: https://www.npmjs.com/package/node-report
116+
[`util`]: util.html

0 commit comments

Comments
 (0)