• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Diagnostic report
2
3<!--introduced_in=v11.8.0-->
4<!-- type=misc -->
5
6> Stability: 2 - Stable
7
8<!-- name=report -->
9
10Delivers a JSON-formatted diagnostic summary, written to a file.
11
12The report is intended for development, test and production use, to capture
13and preserve information for problem determination. It includes JavaScript
14and native stack traces, heap statistics, platform information, resource
15usage etc. With the report option enabled, diagnostic reports can be triggered
16on unhandled exceptions, fatal errors and user signals, in addition to
17triggering programmatically through API calls.
18
19A complete example report that was generated on an uncaught exception
20is provided below for reference.
21
22```json
23{
24  "header": {
25    "reportVersion": 1,
26    "event": "exception",
27    "trigger": "Exception",
28    "filename": "report.20181221.005011.8974.0.001.json",
29    "dumpEventTime": "2018-12-21T00:50:11Z",
30    "dumpEventTimeStamp": "1545371411331",
31    "processId": 8974,
32    "cwd": "/home/nodeuser/project/node",
33    "commandLine": [
34      "/home/nodeuser/project/node/out/Release/node",
35      "--report-uncaught-exception",
36      "/home/nodeuser/project/node/test/report/test-exception.js",
37      "child"
38    ],
39    "nodejsVersion": "v12.0.0-pre",
40    "glibcVersionRuntime": "2.17",
41    "glibcVersionCompiler": "2.17",
42    "wordSize": "64 bit",
43    "arch": "x64",
44    "platform": "linux",
45    "componentVersions": {
46      "node": "12.0.0-pre",
47      "v8": "7.1.302.28-node.5",
48      "uv": "1.24.1",
49      "zlib": "1.2.11",
50      "ares": "1.15.0",
51      "modules": "68",
52      "nghttp2": "1.34.0",
53      "napi": "3",
54      "llhttp": "1.0.1",
55      "openssl": "1.1.0j"
56    },
57    "release": {
58      "name": "node"
59    },
60    "osName": "Linux",
61    "osRelease": "3.10.0-862.el7.x86_64",
62    "osVersion": "#1 SMP Wed Mar 21 18:14:51 EDT 2018",
63    "osMachine": "x86_64",
64    "cpus": [
65      {
66        "model": "Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz",
67        "speed": 2700,
68        "user": 88902660,
69        "nice": 0,
70        "sys": 50902570,
71        "idle": 241732220,
72        "irq": 0
73      },
74      {
75        "model": "Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz",
76        "speed": 2700,
77        "user": 88902660,
78        "nice": 0,
79        "sys": 50902570,
80        "idle": 241732220,
81        "irq": 0
82      }
83    ],
84    "networkInterfaces": [
85      {
86        "name": "en0",
87        "internal": false,
88        "mac": "13:10:de:ad:be:ef",
89        "address": "10.0.0.37",
90        "netmask": "255.255.255.0",
91        "family": "IPv4"
92      }
93    ],
94    "host": "test_machine"
95  },
96  "javascriptStack": {
97    "message": "Error: *** test-exception.js: throwing uncaught Error",
98    "stack": [
99      "at myException (/home/nodeuser/project/node/test/report/test-exception.js:9:11)",
100      "at Object.<anonymous> (/home/nodeuser/project/node/test/report/test-exception.js:12:3)",
101      "at Module._compile (internal/modules/cjs/loader.js:718:30)",
102      "at Object.Module._extensions..js (internal/modules/cjs/loader.js:729:10)",
103      "at Module.load (internal/modules/cjs/loader.js:617:32)",
104      "at tryModuleLoad (internal/modules/cjs/loader.js:560:12)",
105      "at Function.Module._load (internal/modules/cjs/loader.js:552:3)",
106      "at Function.Module.runMain (internal/modules/cjs/loader.js:771:12)",
107      "at executeUserCode (internal/bootstrap/node.js:332:15)"
108    ]
109  },
110  "nativeStack": [
111    {
112      "pc": "0x000055b57f07a9ef",
113      "symbol": "report::GetNodeReport(v8::Isolate*, node::Environment*, char const*, char const*, v8::Local<v8::String>, std::ostream&) [./node]"
114    },
115    {
116      "pc": "0x000055b57f07cf03",
117      "symbol": "report::GetReport(v8::FunctionCallbackInfo<v8::Value> const&) [./node]"
118    },
119    {
120      "pc": "0x000055b57f1bccfd",
121      "symbol": " [./node]"
122    },
123    {
124      "pc": "0x000055b57f1be048",
125      "symbol": "v8::internal::Builtin_HandleApiCall(int, v8::internal::Object**, v8::internal::Isolate*) [./node]"
126    },
127    {
128      "pc": "0x000055b57feeda0e",
129      "symbol": " [./node]"
130    }
131  ],
132  "javascriptHeap": {
133    "totalMemory": 6127616,
134    "totalCommittedMemory": 4357352,
135    "usedMemory": 3221136,
136    "availableMemory": 1521370240,
137    "memoryLimit": 1526909922,
138    "heapSpaces": {
139      "read_only_space": {
140        "memorySize": 524288,
141        "committedMemory": 39208,
142        "capacity": 515584,
143        "used": 30504,
144        "available": 485080
145      },
146      "new_space": {
147        "memorySize": 2097152,
148        "committedMemory": 2019312,
149        "capacity": 1031168,
150        "used": 985496,
151        "available": 45672
152      },
153      "old_space": {
154        "memorySize": 2273280,
155        "committedMemory": 1769008,
156        "capacity": 1974640,
157        "used": 1725488,
158        "available": 249152
159      },
160      "code_space": {
161        "memorySize": 696320,
162        "committedMemory": 184896,
163        "capacity": 152128,
164        "used": 152128,
165        "available": 0
166      },
167      "map_space": {
168        "memorySize": 536576,
169        "committedMemory": 344928,
170        "capacity": 327520,
171        "used": 327520,
172        "available": 0
173      },
174      "large_object_space": {
175        "memorySize": 0,
176        "committedMemory": 0,
177        "capacity": 1520590336,
178        "used": 0,
179        "available": 1520590336
180      },
181      "new_large_object_space": {
182        "memorySize": 0,
183        "committedMemory": 0,
184        "capacity": 0,
185        "used": 0,
186        "available": 0
187      }
188    }
189  },
190  "resourceUsage": {
191    "userCpuSeconds": 0.069595,
192    "kernelCpuSeconds": 0.019163,
193    "cpuConsumptionPercent": 0.000000,
194    "maxRss": 18079744,
195    "pageFaults": {
196      "IORequired": 0,
197      "IONotRequired": 4610
198    },
199    "fsActivity": {
200      "reads": 0,
201      "writes": 0
202    }
203  },
204  "uvthreadResourceUsage": {
205    "userCpuSeconds": 0.068457,
206    "kernelCpuSeconds": 0.019127,
207    "cpuConsumptionPercent": 0.000000,
208    "fsActivity": {
209      "reads": 0,
210      "writes": 0
211    }
212  },
213  "libuv": [
214    {
215      "type": "async",
216      "is_active": true,
217      "is_referenced": false,
218      "address": "0x0000000102910900",
219      "details": ""
220    },
221    {
222      "type": "timer",
223      "is_active": false,
224      "is_referenced": false,
225      "address": "0x00007fff5fbfeab0",
226      "repeat": 0,
227      "firesInMsFromNow": 94403548320796,
228      "expired": true
229    },
230    {
231      "type": "check",
232      "is_active": true,
233      "is_referenced": false,
234      "address": "0x00007fff5fbfeb48"
235    },
236    {
237      "type": "idle",
238      "is_active": false,
239      "is_referenced": true,
240      "address": "0x00007fff5fbfebc0"
241    },
242    {
243      "type": "prepare",
244      "is_active": false,
245      "is_referenced": false,
246      "address": "0x00007fff5fbfec38"
247    },
248    {
249      "type": "check",
250      "is_active": false,
251      "is_referenced": false,
252      "address": "0x00007fff5fbfecb0"
253    },
254    {
255      "type": "async",
256      "is_active": true,
257      "is_referenced": false,
258      "address": "0x000000010188f2e0"
259    },
260    {
261      "type": "tty",
262      "is_active": false,
263      "is_referenced": true,
264      "address": "0x000055b581db0e18",
265      "width": 204,
266      "height": 55,
267      "fd": 17,
268      "writeQueueSize": 0,
269      "readable": true,
270      "writable": true
271    },
272    {
273      "type": "signal",
274      "is_active": true,
275      "is_referenced": false,
276      "address": "0x000055b581d80010",
277      "signum": 28,
278      "signal": "SIGWINCH"
279    },
280    {
281      "type": "tty",
282      "is_active": true,
283      "is_referenced": true,
284      "address": "0x000055b581df59f8",
285      "width": 204,
286      "height": 55,
287      "fd": 19,
288      "writeQueueSize": 0,
289      "readable": true,
290      "writable": true
291    },
292    {
293      "type": "loop",
294      "is_active": true,
295      "address": "0x000055fc7b2cb180",
296      "loopIdleTimeSeconds": 22644.8
297    }
298  ],
299  "workers": [],
300  "environmentVariables": {
301    "REMOTEHOST": "REMOVED",
302    "MANPATH": "/opt/rh/devtoolset-3/root/usr/share/man:",
303    "XDG_SESSION_ID": "66126",
304    "HOSTNAME": "test_machine",
305    "HOST": "test_machine",
306    "TERM": "xterm-256color",
307    "SHELL": "/bin/csh",
308    "SSH_CLIENT": "REMOVED",
309    "PERL5LIB": "/opt/rh/devtoolset-3/root//usr/lib64/perl5/vendor_perl:/opt/rh/devtoolset-3/root/usr/lib/perl5:/opt/rh/devtoolset-3/root//usr/share/perl5/vendor_perl",
310    "OLDPWD": "/home/nodeuser/project/node/src",
311    "JAVACONFDIRS": "/opt/rh/devtoolset-3/root/etc/java:/etc/java",
312    "SSH_TTY": "/dev/pts/0",
313    "PCP_DIR": "/opt/rh/devtoolset-3/root",
314    "GROUP": "normaluser",
315    "USER": "nodeuser",
316    "LD_LIBRARY_PATH": "/opt/rh/devtoolset-3/root/usr/lib64:/opt/rh/devtoolset-3/root/usr/lib",
317    "HOSTTYPE": "x86_64-linux",
318    "XDG_CONFIG_DIRS": "/opt/rh/devtoolset-3/root/etc/xdg:/etc/xdg",
319    "MAIL": "/var/spool/mail/nodeuser",
320    "PATH": "/home/nodeuser/project/node:/opt/rh/devtoolset-3/root/usr/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin",
321    "PWD": "/home/nodeuser/project/node",
322    "LANG": "en_US.UTF-8",
323    "PS1": "\\u@\\h : \\[\\e[31m\\]\\w\\[\\e[m\\] >  ",
324    "SHLVL": "2",
325    "HOME": "/home/nodeuser",
326    "OSTYPE": "linux",
327    "VENDOR": "unknown",
328    "PYTHONPATH": "/opt/rh/devtoolset-3/root/usr/lib64/python2.7/site-packages:/opt/rh/devtoolset-3/root/usr/lib/python2.7/site-packages",
329    "MACHTYPE": "x86_64",
330    "LOGNAME": "nodeuser",
331    "XDG_DATA_DIRS": "/opt/rh/devtoolset-3/root/usr/share:/usr/local/share:/usr/share",
332    "LESSOPEN": "||/usr/bin/lesspipe.sh %s",
333    "INFOPATH": "/opt/rh/devtoolset-3/root/usr/share/info",
334    "XDG_RUNTIME_DIR": "/run/user/50141",
335    "_": "./node"
336  },
337  "userLimits": {
338    "core_file_size_blocks": {
339      "soft": "",
340      "hard": "unlimited"
341    },
342    "data_seg_size_kbytes": {
343      "soft": "unlimited",
344      "hard": "unlimited"
345    },
346    "file_size_blocks": {
347      "soft": "unlimited",
348      "hard": "unlimited"
349    },
350    "max_locked_memory_bytes": {
351      "soft": "unlimited",
352      "hard": 65536
353    },
354    "max_memory_size_kbytes": {
355      "soft": "unlimited",
356      "hard": "unlimited"
357    },
358    "open_files": {
359      "soft": "unlimited",
360      "hard": 4096
361    },
362    "stack_size_bytes": {
363      "soft": "unlimited",
364      "hard": "unlimited"
365    },
366    "cpu_time_seconds": {
367      "soft": "unlimited",
368      "hard": "unlimited"
369    },
370    "max_user_processes": {
371      "soft": "unlimited",
372      "hard": 4127290
373    },
374    "virtual_memory_kbytes": {
375      "soft": "unlimited",
376      "hard": "unlimited"
377    }
378  },
379  "sharedObjects": [
380    "/lib64/libdl.so.2",
381    "/lib64/librt.so.1",
382    "/lib64/libstdc++.so.6",
383    "/lib64/libm.so.6",
384    "/lib64/libgcc_s.so.1",
385    "/lib64/libpthread.so.0",
386    "/lib64/libc.so.6",
387    "/lib64/ld-linux-x86-64.so.2"
388  ]
389}
390```
391
392## Usage
393
394```bash
395node --report-uncaught-exception --report-on-signal \
396--report-on-fatalerror app.js
397```
398
399* `--report-uncaught-exception` Enables report to be generated on
400  un-caught exceptions. Useful when inspecting JavaScript stack in conjunction
401  with native stack and other runtime environment data.
402
403* `--report-on-signal` Enables report to be generated upon receiving
404  the specified (or predefined) signal to the running Node.js process. (See
405  below on how to modify the signal that triggers the report.) Default signal is
406  `SIGUSR2`. Useful when a report needs to be triggered from another program.
407  Application monitors may leverage this feature to collect report at regular
408  intervals and plot rich set of internal runtime data to their views.
409
410Signal based report generation is not supported in Windows.
411
412Under normal circumstances, there is no need to modify the report triggering
413signal. However, if `SIGUSR2` is already used for other purposes, then this
414flag helps to change the signal for report generation and preserve the original
415meaning of `SIGUSR2` for the said purposes.
416
417* `--report-on-fatalerror` Enables the report to be triggered on fatal errors
418  (internal errors within the Node.js runtime, such as out of memory)
419  that leads to termination of the application. Useful to inspect various
420  diagnostic data elements such as heap, stack, event loop state, resource
421  consumption etc. to reason about the fatal error.
422
423* `--report-compact` Write reports in a compact format, single-line JSON, more
424  easily consumable by log processing systems than the default multi-line format
425  designed for human consumption.
426
427* `--report-directory` Location at which the report will be
428  generated.
429
430* `--report-filename` Name of the file to which the report will be
431  written.
432
433* `--report-signal` Sets or resets the signal for report generation
434  (not supported on Windows). Default signal is `SIGUSR2`.
435
436A report can also be triggered via an API call from a JavaScript application:
437
438```js
439process.report.writeReport();
440```
441
442This function takes an optional additional argument `filename`, which is
443the name of a file into which the report is written.
444
445```js
446process.report.writeReport('./foo.json');
447```
448
449This function takes an optional additional argument `err` which is an `Error`
450object that will be used as the context for the JavaScript stack printed in the
451report. When using report to handle errors in a callback or an exception
452handler, this allows the report to include the location of the original error as
453well as where it was handled.
454
455```js
456try {
457  process.chdir('/non-existent-path');
458} catch (err) {
459  process.report.writeReport(err);
460}
461// Any other code
462```
463
464If both filename and error object are passed to `writeReport()` the
465error object must be the second parameter.
466
467```js
468try {
469  process.chdir('/non-existent-path');
470} catch (err) {
471  process.report.writeReport(filename, err);
472}
473// Any other code
474```
475
476The content of the diagnostic report can be returned as a JavaScript Object
477via an API call from a JavaScript application:
478
479```js
480const report = process.report.getReport();
481console.log(typeof report === 'object'); // true
482
483// Similar to process.report.writeReport() output
484console.log(JSON.stringify(report, null, 2));
485```
486
487This function takes an optional additional argument `err`, which is an `Error`
488object that will be used as the context for the JavaScript stack printed in the
489report.
490
491```js
492const report = process.report.getReport(new Error('custom error'));
493console.log(typeof report === 'object'); // true
494```
495
496The API versions are useful when inspecting the runtime state from within
497the application, in expectation of self-adjusting the resource consumption,
498load balancing, monitoring etc.
499
500The content of the report consists of a header section containing the event
501type, date, time, PID and Node.js version, sections containing JavaScript and
502native stack traces, a section containing V8 heap information, a section
503containing `libuv` handle information and an OS platform information section
504showing CPU and memory usage and system limits. An example report can be
505triggered using the Node.js REPL:
506
507```console
508$ node
509> process.report.writeReport();
510Writing Node.js report to file: report.20181126.091102.8480.0.001.json
511Node.js report completed
512>
513```
514
515When a report is written, start and end messages are issued to stderr
516and the filename of the report is returned to the caller. The default filename
517includes the date, time, PID and a sequence number. The sequence number helps
518in associating the report dump with the runtime state if generated multiple
519times for the same Node.js process.
520
521## Configuration
522
523Additional runtime configuration of report generation is available via
524the following properties of `process.report`:
525
526`reportOnFatalError` triggers diagnostic reporting on fatal errors when `true`.
527Defaults to `false`.
528
529`reportOnSignal` triggers diagnostic reporting on signal when `true`. This is
530not supported on Windows. Defaults to `false`.
531
532`reportOnUncaughtException` triggers diagnostic reporting on uncaught exception
533when `true`. Defaults to `false`.
534
535`signal` specifies the POSIX signal identifier that will be used
536to intercept external triggers for report generation. Defaults to
537`'SIGUSR2'`.
538
539`filename` specifies the name of the output file in the file system.
540Special meaning is attached to `stdout` and `stderr`. Usage of these
541will result in report being written to the associated standard streams.
542In cases where standard streams are used, the value in `directory` is ignored.
543URLs are not supported. Defaults to a composite filename that contains
544timestamp, PID and sequence number.
545
546`directory` specifies the filesystem directory where the report will be written.
547URLs are not supported. Defaults to the current working directory of the
548Node.js process.
549
550```js
551// Trigger report only on uncaught exceptions.
552process.report.reportOnFatalError = false;
553process.report.reportOnSignal = false;
554process.report.reportOnUncaughtException = true;
555
556// Trigger report for both internal errors as well as external signal.
557process.report.reportOnFatalError = true;
558process.report.reportOnSignal = true;
559process.report.reportOnUncaughtException = false;
560
561// Change the default signal to 'SIGQUIT' and enable it.
562process.report.reportOnFatalError = false;
563process.report.reportOnUncaughtException = false;
564process.report.reportOnSignal = true;
565process.report.signal = 'SIGQUIT';
566```
567
568Configuration on module initialization is also available via
569environment variables:
570
571```bash
572NODE_OPTIONS="--report-uncaught-exception \
573  --report-on-fatalerror --report-on-signal \
574  --report-signal=SIGUSR2  --report-filename=./report.json \
575  --report-directory=/home/nodeuser"
576```
577
578Specific API documentation can be found under
579[`process API documentation`][] section.
580
581## Interaction with workers
582<!-- YAML
583changes:
584  - version:
585      - v13.9.0
586      - v12.16.2
587    pr-url: https://github.com/nodejs/node/pull/31386
588    description: Workers are now included in the report.
589-->
590
591[`Worker`][] threads can create reports in the same way that the main thread
592does.
593
594Reports will include information on any Workers that are children of the current
595thread as part of the `workers` section, with each Worker generating a report
596in the standard report format.
597
598The thread which is generating the report will wait for the reports from Worker
599threads to finish. However, the latency for this will usually be low, as both
600running JavaScript and the event loop are interrupted to generate the report.
601
602[`Worker`]: worker_threads.md
603[`process API documentation`]: process.md
604