GeezerVison is showing github.com — src: add cli option to preserve env vars on dr · nodejs/node@2e3ca1b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/cli.md +10Lines changed: 10 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2049,6 +2049,15 @@ Enables report to be generated upon receiving the specified (or predefined) | 2049 | 2049 | signal to the running Node.js process. The signal to trigger the report is | 2050 | 2050 | specified through `--report-signal`. | 2051 | 2051 |
| | 2052 | +### `--report-exclude-env` | | 2053 | + | | 2054 | +<!-- YAML | | 2055 | +added: REPLACEME | | 2056 | +--> | | 2057 | + | | 2058 | +When `--report-exclude-env` is passed the diagnostic report generated will not | | 2059 | +contain the `environmentVariables` data. | | 2060 | + | 2052 | 2061 | ### `--report-signal=signal` | 2053 | 2062 |
| 2054 | 2063 | <!-- YAML | @@ -3136,6 +3145,7 @@ one is included in the list below. | 3136 | 3145 | * `--redirect-warnings` | 3137 | 3146 | * `--report-compact` | 3138 | 3147 | * `--report-dir`, `--report-directory` | | 3148 | +* `--report-exclude-env` | 3139 | 3149 | * `--report-exclude-network` | 3140 | 3150 | * `--report-filename` | 3141 | 3151 | * `--report-on-fatalerror` | |
Collapse file Copy file name to clipboardExpand all lines: doc/api/process.md +10Lines changed: 10 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -3478,6 +3478,16 @@ const { report } = require('node:process'); | 3478 | 3478 | console.log(`Report on exception: ${report.reportOnUncaughtException}`); | 3479 | 3479 | ``` | 3480 | 3480 |
| | 3481 | +### `process.report.excludeEnv` | | 3482 | +
| | 3483 | +<!-- YAML | | 3484 | +added: REPLACEME | | 3485 | +--> | | 3486 | +
| | 3487 | +* {boolean} | | 3488 | +
| | 3489 | +If `true`, a diagnostic report is generated without the environment variables. | | 3490 | +
| 3481 | 3491 | ### `process.report.signal` | 3482 | 3492 |
| 3483 | 3493 | <!-- YAML | |
Collapse file Copy file name to clipboardExpand all lines: doc/api/report.md +7Lines changed: 7 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 10 | 10 |
| 11 | 11 | <!-- YAML | 12 | 12 | changes: | | 13 | + - version: REPLACEME | | 14 | + pr-url: https://github.com/nodejs/node/pull/55697 | | 15 | + description: Added `--report-exclude-env` option for excluding environment variables from report generation. | 13 | 16 | - version: v22.0.0 | 14 | 17 | pr-url: https://github.com/nodejs/node/pull/51645 | 15 | 18 | description: Added `--report-exclude-network` option for excluding networking operations that can slow down report generation in some cases. | @@ -507,6 +510,10 @@ meaning of `SIGUSR2` for the said purposes. | 507 | 510 | in `libuv.*.(remote|local)Endpoint.host` from the diagnostic report. | 508 | 511 | By default this is not set and the network interfaces are included. | 509 | 512 |
| | 513 | +* `--report-exclude-env` Exclude `environmentVariables` from the | | 514 | + diagnostic report. By default this is not set and the environment | | 515 | + variables are included. | | 516 | + | 510 | 517 | A report can also be triggered via an API call from a JavaScript application: | 511 | 518 |
| 512 | 519 | ```js | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/process/report.js +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -105,6 +105,13 @@ const report = { | 105 | 105 |
| 106 | 106 | nr.setReportOnUncaughtException(trigger); | 107 | 107 | }, | | 108 | + get excludeEnv() { | | 109 | + return nr.getExcludeEnv(); | | 110 | + }, | | 111 | + set excludeEnv(b) { | | 112 | + validateBoolean(b, 'excludeEnv'); | | 113 | + nr.setExcludeEnv(b); | | 114 | + }, | 108 | 115 | }; | 109 | 116 |
| 110 | 117 | function addSignalHandler(sig) { | |
Collapse file Copy file name to clipboardExpand all lines: src/env-inl.h +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -915,6 +915,10 @@ inline bool Environment::is_in_heapsnapshot_heap_limit_callback() const { | 915 | 915 | return is_in_heapsnapshot_heap_limit_callback_; | 916 | 916 | } | 917 | 917 |
| | 918 | +inline bool Environment::report_exclude_env() const { | | 919 | + return options_->report_exclude_env; | | 920 | +} | | 921 | + | 918 | 922 | inline void Environment::AddHeapSnapshotNearHeapLimitCallback() { | 919 | 923 | DCHECK(!heapsnapshot_near_heap_limit_callback_added_); | 920 | 924 | heapsnapshot_near_heap_limit_callback_added_ = true; | |
Collapse file Copy file name to clipboardExpand all lines: src/env.h +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1048,6 +1048,8 @@ class Environment final : public MemoryRetainer { | 1048 | 1048 | inline void set_heap_snapshot_near_heap_limit(uint32_t limit); | 1049 | 1049 | inline bool is_in_heapsnapshot_heap_limit_callback() const; | 1050 | 1050 |
| | 1051 | + inline bool report_exclude_env() const; | | 1052 | + | 1051 | 1053 | inline void AddHeapSnapshotNearHeapLimitCallback(); | 1052 | 1054 |
| 1053 | 1055 | inline void RemoveHeapSnapshotNearHeapLimitCallback(size_t heap_limit); | |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.cc +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -895,6 +895,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | 895 | 895 | &EnvironmentOptions::tls_max_v1_3, | 896 | 896 | kAllowedInEnvvar); | 897 | 897 |
| | 898 | + AddOption("--report-exclude-env", | | 899 | + "Exclude environment variables when generating report" | | 900 | + " (default: false)", | | 901 | + &EnvironmentOptions::report_exclude_env, | | 902 | + kAllowedInEnvvar); | 898 | 903 | AddOption("--report-exclude-network", | 899 | 904 | "exclude network interface diagnostics." | 900 | 905 | " (default: false)", | |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -251,6 +251,7 @@ class EnvironmentOptions : public Options { | 251 | 251 |
| 252 | 252 | std::vector<std::string> user_argv; | 253 | 253 |
| | 254 | + bool report_exclude_env = false; | 254 | 255 | bool report_exclude_network = false; | 255 | 256 |
| 256 | 257 | inline DebugOptions* get_debug_options() { return &debug_options_; } | |
Collapse file Copy file name to clipboardExpand all lines: src/node_report.cc +46-9Lines changed: 46 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -61,7 +61,8 @@ static void WriteNodeReport(Isolate* isolate, | 61 | 61 | std::ostream& out, | 62 | 62 | Local<Value> error, | 63 | 63 | bool compact, | 64 | | - bool exclude_network = false); | | 64 | + bool exclude_network = false, | | 65 | + bool exclude_env = false); | 65 | 66 | static void PrintVersionInformation(JSONWriter* writer, | 66 | 67 | bool exclude_network = false); | 67 | 68 | static void PrintJavaScriptErrorStack(JSONWriter* writer, | @@ -78,6 +79,7 @@ static void PrintJavaScriptErrorProperties(JSONWriter* writer, | 78 | 79 | static void PrintNativeStack(JSONWriter* writer); | 79 | 80 | static void PrintResourceUsage(JSONWriter* writer); | 80 | 81 | static void PrintGCStatistics(JSONWriter* writer, Isolate* isolate); | | 82 | +static void PrintEnvironmentVariables(JSONWriter* writer); | 81 | 83 | static void PrintSystemInformation(JSONWriter* writer); | 82 | 84 | static void PrintLoadedLibraries(JSONWriter* writer); | 83 | 85 | static void PrintComponentVersions(JSONWriter* writer); | @@ -95,7 +97,8 @@ static void WriteNodeReport(Isolate* isolate, | 95 | 97 | std::ostream& out, | 96 | 98 | Local<Value> error, | 97 | 99 | bool compact, | 98 | | - bool exclude_network) { | | 100 | + bool exclude_network, | | 101 | + bool exclude_env) { | 99 | 102 | // Obtain the current time and the pid. | 100 | 103 | TIME_TYPE tm_struct; | 101 | 104 | DiagnosticFilename::LocalTime(&tm_struct); | @@ -251,6 +254,9 @@ static void WriteNodeReport(Isolate* isolate, | 251 | 254 | writer.json_arrayend(); | 252 | 255 |
| 253 | 256 | // Report operating system information | | 257 | + if (exclude_env == false) { | | 258 | + PrintEnvironmentVariables(&writer); | | 259 | + } | 254 | 260 | PrintSystemInformation(&writer); | 255 | 261 |
| 256 | 262 | writer.json_objectend(); | @@ -696,8 +702,7 @@ static void PrintResourceUsage(JSONWriter* writer) { | 696 | 702 | #endif // RUSAGE_THREAD | 697 | 703 | } | 698 | 704 |
| 699 | | -// Report operating system information. | 700 | | -static void PrintSystemInformation(JSONWriter* writer) { | | 705 | +static void PrintEnvironmentVariables(JSONWriter* writer) { | 701 | 706 | uv_env_item_t* envitems; | 702 | 707 | int envcount; | 703 | 708 | int r; | @@ -717,7 +722,10 @@ static void PrintSystemInformation(JSONWriter* writer) { | 717 | 722 | } | 718 | 723 |
| 719 | 724 | writer->json_objectend(); | | 725 | +} | 720 | 726 |
| | 727 | +// Report operating system information. | | 728 | +static void PrintSystemInformation(JSONWriter* writer) { | 721 | 729 | #ifndef _WIN32 | 722 | 730 | static struct { | 723 | 731 | const char* description; | @@ -917,6 +925,10 @@ std::string TriggerNodeReport(Isolate* isolate, | 917 | 925 | bool exclude_network = env != nullptr ? env->options()->report_exclude_network | 918 | 926 | : per_process::cli_options->per_isolate | 919 | 927 | ->per_env->report_exclude_network; | | 928 | + bool exclude_env = | | 929 | + env != nullptr | | 930 | + ? env->report_exclude_env() | | 931 | + : per_process::cli_options->per_isolate->per_env->report_exclude_env; | 920 | 932 |
| 921 | 933 | report::WriteNodeReport(isolate, | 922 | 934 | env, | @@ -926,7 +938,8 @@ std::string TriggerNodeReport(Isolate* isolate, | 926 | 938 | *outstream, | 927 | 939 | error, | 928 | 940 | compact, | 929 | | - exclude_network); | | 941 | + exclude_network, | | 942 | + exclude_env); | 930 | 943 |
| 931 | 944 | // Do not close stdout/stderr, only close files we opened. | 932 | 945 | if (outfile.is_open()) { | @@ -980,8 +993,20 @@ void GetNodeReport(Isolate* isolate, | 980 | 993 | bool exclude_network = env != nullptr ? env->options()->report_exclude_network | 981 | 994 | : per_process::cli_options->per_isolate | 982 | 995 | ->per_env->report_exclude_network; | 983 | | - report::WriteNodeReport( | 984 | | - isolate, env, message, trigger, "", out, error, false, exclude_network); | | 996 | + bool exclude_env = | | 997 | + env != nullptr | | 998 | + ? env->report_exclude_env() | | 999 | + : per_process::cli_options->per_isolate->per_env->report_exclude_env; | | 1000 | + report::WriteNodeReport(isolate, | | 1001 | + env, | | 1002 | + message, | | 1003 | + trigger, | | 1004 | + "", | | 1005 | + out, | | 1006 | + error, | | 1007 | + false, | | 1008 | + exclude_network, | | 1009 | + exclude_env); | 985 | 1010 | } | 986 | 1011 |
| 987 | 1012 | // External function to trigger a report, writing to a supplied stream. | @@ -997,8 +1022,20 @@ void GetNodeReport(Environment* env, | 997 | 1022 | bool exclude_network = env != nullptr ? env->options()->report_exclude_network | 998 | 1023 | : per_process::cli_options->per_isolate | 999 | 1024 | ->per_env->report_exclude_network; | 1000 | | - report::WriteNodeReport( | 1001 | | - isolate, env, message, trigger, "", out, error, false, exclude_network); | | 1025 | + bool exclude_env = | | 1026 | + env != nullptr | | 1027 | + ? env->report_exclude_env() | | 1028 | + : per_process::cli_options->per_isolate->per_env->report_exclude_env; | | 1029 | + report::WriteNodeReport(isolate, | | 1030 | + env, | | 1031 | + message, | | 1032 | + trigger, | | 1033 | + "", | | 1034 | + out, | | 1035 | + error, | | 1036 | + false, | | 1037 | + exclude_network, | | 1038 | + exclude_env); | 1002 | 1039 | } | 1003 | 1040 |
| 1004 | 1041 | } // namespace node |
Collapse file Copy file name to clipboardExpand all lines: src/node_report_module.cc +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -95,6 +95,17 @@ static void SetExcludeNetwork(const FunctionCallbackInfo<Value>& info) { | 95 | 95 | env->options()->report_exclude_network = info[0]->IsTrue(); | 96 | 96 | } | 97 | 97 |
| | 98 | +static void GetExcludeEnv(const FunctionCallbackInfo<Value>& info) { | | 99 | + Environment* env = Environment::GetCurrent(info); | | 100 | + info.GetReturnValue().Set(env->report_exclude_env()); | | 101 | +} | | 102 | + | | 103 | +static void SetExcludeEnv(const FunctionCallbackInfo<Value>& info) { | | 104 | + Environment* env = Environment::GetCurrent(info); | | 105 | + CHECK(info[0]->IsBoolean()); | | 106 | + env->options()->report_exclude_env = info[0]->IsTrue(); | | 107 | +} | | 108 | + | 98 | 109 | static void GetDirectory(const FunctionCallbackInfo<Value>& info) { | 99 | 110 | Mutex::ScopedLock lock(per_process::cli_options_mutex); | 100 | 111 | Environment* env = Environment::GetCurrent(info); | @@ -187,6 +198,8 @@ static void Initialize(Local<Object> exports, | 187 | 198 | SetMethod(context, exports, "setCompact", SetCompact); | 188 | 199 | SetMethod(context, exports, "getExcludeNetwork", GetExcludeNetwork); | 189 | 200 | SetMethod(context, exports, "setExcludeNetwork", SetExcludeNetwork); | | 201 | + SetMethod(context, exports, "getExcludeEnv", GetExcludeEnv); | | 202 | + SetMethod(context, exports, "setExcludeEnv", SetExcludeEnv); | 190 | 203 | SetMethod(context, exports, "getDirectory", GetDirectory); | 191 | 204 | SetMethod(context, exports, "setDirectory", SetDirectory); | 192 | 205 | SetMethod(context, exports, "getFilename", GetFilename); | @@ -215,6 +228,8 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { | 215 | 228 | registry->Register(SetCompact); | 216 | 229 | registry->Register(GetExcludeNetwork); | 217 | 230 | registry->Register(SetExcludeNetwork); | | 231 | + registry->Register(GetExcludeEnv); | | 232 | + registry->Register(SetExcludeEnv); | 218 | 233 | registry->Register(GetDirectory); | 219 | 234 | registry->Register(SetDirectory); | 220 | 235 | registry->Register(GetFilename); | |
|