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