Skip to content

Commit 9edaf31

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 9edaf31

27 files changed

+3439
-2
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

doc/api/util.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,26 @@ util.formatWithOptions({ colors: true }, 'See object %O', { foo: 42 });
270270
// when printed to a terminal.
271271
```
272272

273+
## util.getNodeReport()
274+
<!-- YAML
275+
added: v11.0.0
276+
-->
277+
278+
* Returns: {string}
279+
280+
Returns the nore report as a string.
281+
282+
Generates a human readable diagnostic summary. The report is intended for
283+
development, test and production use, to capture and preserve information
284+
for problem determination. It includes JavaScript and native stack traces,
285+
heap statistics, platform information and resource usage etc.
286+
287+
```js
288+
const util = require('util');
289+
const report = util.getNodeReport();
290+
console.log(report);
291+
```
292+
273293
## util.getSystemErrorName(err)
274294
<!-- YAML
275295
added: v9.7.0
@@ -755,6 +775,55 @@ added: v8.0.0
755775
* {symbol} that can be used to declare custom promisified variants of functions,
756776
see [Custom promisified functions][].
757777

778+
## util.setReportEvents(events)
779+
<!-- YAML
780+
added: v11.0.0
781+
-->
782+
783+
* `events` {string}
784+
785+
Runtime configuration of node report data capture. The string can be a comma-
786+
separated list of one or more of:
787+
`exception`: auto-generate a report on unhandled exceptions
788+
`fatalerror`: auto-generate a report on unhandled internal fault
789+
(such as out of memory errors or native assertions)
790+
`signal`: auto-generate a report in response to a signal raised on the process.
791+
This is convinient for collecting snapshot information of the running process at
792+
custom program points.
793+
794+
```js
795+
const util = require('util');
796+
// trigger report only on uncaught exceptions
797+
util.setReportEvents('exception');
798+
799+
// trigger for both internal error and external signal
800+
util.setReportEvents('fatalerror+signal');
801+
```
802+
803+
## util.setReportSignal(signal)
804+
<!-- YAML
805+
added: v11.0.0
806+
-->
807+
808+
* `signal` {string}
809+
810+
Runtime modification to the node report data capture signal (default SIGUSR2).
811+
Convinient when the execution environment already uses SIGUSR2 for other
812+
purposes and wants Node to use another one for report generation purpose.
813+
814+
```js
815+
const util = require('util');
816+
util.setReportSignal('SIGQUIT');
817+
```
818+
819+
Multiple signals are allowed, in which case supply them as `OR` separated:
820+
821+
```js
822+
const util = require('util');
823+
util.setReportSignal('SIGUSR2|SIGQUIT');
824+
```
825+
This function does not work on Windows.
826+
758827
## Class: util.TextDecoder
759828
<!-- YAML
760829
added: v8.3.0
@@ -919,6 +988,34 @@ encoded bytes.
919988

920989
The encoding supported by the `TextEncoder` instance. Always set to `'utf-8'`.
921990

991+
## util.triggerNodeReport([filename])
992+
<!-- YAML
993+
added: v11.0.0
994+
-->
995+
996+
* `filename` {string} The file to write into. **Default:** an empty string.
997+
* Returns: {string}
998+
999+
Returns the filename of the generated report.
1000+
1001+
Triggers and produces the node report (a human readable snapshot of the internal
1002+
state of Node runtime), writes into a file at the location from where this Node
1003+
process was launched.
1004+
1005+
```js
1006+
const util = require('util');
1007+
util.triggerNodeReport();
1008+
```
1009+
1010+
When a report is triggered, start and end messages are issued to stderr and the
1011+
filename of the report is returned to the caller. The default filename includes
1012+
the date, time, PID and a sequence number. Alternatively, a filename can be
1013+
specified as a parameter on the triggerNodeReport() call.
1014+
1015+
```js
1016+
util.triggerNodeReport('myReportName');
1017+
```
1018+
9221019
## util.types
9231020
<!-- YAML
9241021
added: v10.0.0

lib/util.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,3 +1540,28 @@ module.exports = exports = {
15401540
'util.puts is deprecated. Use console.log instead.',
15411541
'DEP0027')
15421542
};
1543+
1544+
const {
1545+
triggerNodeReport,
1546+
getNodeReport,
1547+
setReportEvents,
1548+
setReportSignal,
1549+
setReportFileName,
1550+
setReportDirectory,
1551+
setReportverbose,
1552+
} = process.binding('util');
1553+
1554+
if (triggerNodeReport !== undefined)
1555+
exports.triggerNodeReport = triggerNodeReport;
1556+
if (getNodeReport !== undefined)
1557+
exports.getNodeReport = getNodeReport;
1558+
if (setReportEvents !== undefined)
1559+
exports.setReportEvents = setReportEvents;
1560+
if (setReportSignal !== undefined)
1561+
exports.setReportSignal = setReportSignal;
1562+
if (setReportFileName !== undefined)
1563+
exports.setReportFileName = setReportFileName;
1564+
if (setReportDirectory !== undefined)
1565+
exports.setReportDirectory = setReportDirectory;
1566+
if (setReportverbose !== undefined)
1567+
exports.setReportverbose = setReportverbose;

node.gyp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,33 @@
626626
'src/tls_wrap.h'
627627
],
628628
}],
629+
[ 'node_report=="true"', {
630+
'sources': [
631+
'src/node_report.cc',
632+
'src/node_report_module.cc',
633+
'src/node_report_utils.cc',
634+
],
635+
'defines': [
636+
'NODE_REPORT',
637+
'NODEREPORT_VERSION="1.0.0"',
638+
],
639+
'conditions': [
640+
['OS=="win"', {
641+
'libraries': [
642+
'dbghelp.lib',
643+
'Netapi32.lib',
644+
'PsApi.lib',
645+
'Ws2_32.lib',
646+
],
647+
'dll_files': [
648+
'dbghelp.dll',
649+
'Netapi32.dll',
650+
'PsApi.dll',
651+
'Ws2_32.dll',
652+
],
653+
}],
654+
],
655+
}],
629656
],
630657
},
631658
{

0 commit comments

Comments
 (0)