report-toolkit Command-Line Usage
report-toolkit provides a command-line utility, rtk. This usage documentation provides detailed descriptions of all commands and options for rtk.
- General Usage Guidelines
- Global Options
- The
diffCommand - The
inspectCommand - The
redactCommand - The
transformCommand - Common Output Options
- Transformer-Specific Options
General Usage Guidelines
rtk Requires a Command
You must supply a command to rtk. A single command must immediately follow the rtk executable.
rtk redact report-file.json
Correct Usage
Command is first argument
rtk report-file.json redact
Incorrect Usage
Command in wrong position
Available Commands
The command must be one of the following:
About Flags
Any “boolean” flag—an option without an argument—can be explicitly disabled by prepending --no- to the option name. For example, to explicitly disable color output when comparing report-A.json to report-B.json:
rtk --no-color diff report-A.json report-B.json
This is applicable to both global and command-specific boolean flags.
About Configuration
Configuration will be read from a JavaScript file named .rtkrc.js or rtk.config.js. If one is not found in the current working directory, the search for one of these files will continue until one is found, the current user’s “home” directory is found, or the root of the filesystem is found (see cosmiconfig for further details on the file-finding algorithm).
Other formats, including JSON, YAML, TOML, etc., are explicitly not supported. Configuration cannot be stored in a package.json, either. Sorry!
TODO: Write configuration docs and link to them; see #66
Global Options
These options can be used in tandem with any command.
In the case of --help and --version, no command is required.
--rc </path/to/.rtkrc.js>
Supply an explicit path to a report-toolkit config file. This option is only necessary if your config file has non-standard location and/or name.
Example: Run inspect Using Config my-config.js
rtk --rc my-config.js inspect report-A.json
The same restrictions as described above in About Configuration apply.
--color / --no-color
Color output is enabled by default when a TTY is available. If there is no TTY (like in a subprocess, or when piped), specify --color to force color.
Example: Force Color Output When Comparing report-A.json and report-B.json
rtk diff --color report-A.json report-B.json
Example: Disable Color Output When Inspecting report.json
rtk inspect --no-color report.json
--debug / --verbose
Enables debug output. --verbose is an alias of --debug; their behavior is identical.
This can be noisy.
Using --debug is equivalent to setting the environment variable DEBUG=rtk*. Further granularity can be achieved by appending package or module name(s) separated by colons, e.g., DEBUG=rtk:cli* will show all debug output from the CLI package. Package names follow a pattern of rtk:<package name>[:..submodule name or path].
Debug output is sent to STDERR.
--help
Displays help text, then exits. --help can be used by itself (to see global
options and the list of commands), or combined with any command to see command-specific options.
Example: Print Help Text
rtk --help
Example: Print Help Text for inspect Command
rtk inspect --help
--version
Outputs the version of rtk to STDOUT then exits.
Example: Print Version of Installed rtk Executable
rtk --version
The diff Command
The diff command compares two (2) Diagnostic Report files and outputs the difference. Unlike a typical diff tool, the output is purpose-built for comparing reports.
Basic Usage: rtk diff <file-A> <file-B>
To use diff with the defaults:
rtk diff report-A.json report-B.json
diff requires two (2) paths to Diagnostic Report files.
diff: Output Description
The output of diff contains four (4) fields:
- Op: Shorthand for “operation”:
- (M)odified: The field exists in both reports, but differs
- (A)dded: The field exists in the first report only
- (D)eleted: The field exists in the second report only
- Field: The field path which differs, represented in “dot” notation.
- (path to first report): The value in the field of the first report (if present)
- (path to second report): The value in the field of the second report (if present)
In the default, tabular output, each “Op” and “Field” pair will be color-coded based on its operation. “Modified” is yellow, “deleted” is red, and “added” is green.
Unlike other commands, the output of diff depends on the order of the two files given; the results will be the same, but reversed.
diff: Defaults
This section describes the default behavior of rtk diff.
- Output: a human-readable, tabular view (in color, where available)
- Secrets are redacted from Diagnostic Reports before comparison
- To increase the signal-to-noise ratio,
diffincludes only this following set of fields:headerenvironmentVariablesuserLimitssharedObejctslibuv
- Furthermore, these nested fields are excluded from the
headerfield:header.filenameheader.dumpEventTimeheader.dumpEventTimeStampheader.cpus
diff-specific Options
This group of options allows the user to fine-tune which fields (properties) rtk diff considers when comparing report files.
diff: Options
--includeProp <field>, -i <field>
Explicitly include one or more fields in the comparison. If this option is used, rtk will only consider the field(s) specified (and any nested fields or array items).
This option can be used multiple times.
Example: Include a Single Field
To only compare field header (and its nested fields) when comparing report-A.json and report-B.json:
rtk diff --includeProp header report-A.json report-B.json
Example: Include Multiple fields
To only compare fields header.commandLine (and its items) and header.cwd when comparing report-A.json and report-B.json:
rtk diff -i header.commandLine -i header.cwd report-A.json report-B.json
--excludeProp <field>, -x <field>
Explicitly exclude one or more fields in the comparison. If this option is used, rtk will consider the defaults, then further exclude the specified fields.
This option can be used multiple times.
Example: Exclude a Single Field
To exclude field header (and its nested fields) when comparing report-A.json and report-B.json (but otherwise use the defaults):
rtk diff --excludeProp header report-A.json report-B.json
Example: Exclude Multiple Fields
To exclude fields header.commandLine (and its items) and header.cwd when comparing report-A.json and report-B.json (but otherwise use the defaults):
rtk diff -x header.commandLine -x header.cwd report-A.json report-B.json
--all
By default, rtk excludes certain properties to reduce noise. Use --all if you would like to include the entire Diagnostic Report when comparing.
--all cannot be used with --includeProp/-i or --excludeProp/-x.
Example: Compare All Fields
To compare the entirety of report-A.json and report-B.json:
rtk diff --all report-A.json report-B.json
diff: Additional Options
diff supports the following common output options:
The inspect Command
The inspect command runs heuristics, called Rules, on one or more Diagnostic Reports. If a Rule finds a potential problem, it will output a message. Some messages may be warnings, and others may be purely informational.
The purpose of inspect is to automate the discovery of potential problems in a Node.js process. These may range from runaway resource consumption, to nonstandard configuration, to hung event loops. If a developer can closely inspect a Diagnostic Report to uncover a problem, a Rule can automate this process. Also: developers like to automate things.
inspect draws heavily from ESLint. Like ESLint, report-toolkit ships with built-in Rules and a recommended configuration. Also like ESLint, developers can create and distribute their own Rules.
Basic Usage: rtk inspect <file..>
To use inspect with the default “recommended” configuration:
rtk inspect report.json
To use inspect with the default “recommended” configuration across three (3) report files:
rtk inspect report-A.json report-B.json report-C.json
inspect: Output Description
inspect’s output contains four (4) fields:
- Severity: The “severity” of a Message. One of the following, in decreasing order of severity:
- ERROR: The associated Message highlights an issue that should be investigated.
- WARNING: The associated Message highlights an issue that might need investigation.
- INFO: The associated Message is purely informational.
- File: The Diagnostic Report file referenced, or
(multiple files)if the Message is aggregated from across multiple files. - Rule: The name (unique identifier) of the Rule which sent the Message.
- Message: A human-readable explanation of the issue.
In the default, tabular output, the severities ERROR, WARNING and INFO will be respectively highlighted in red, yellow, and blue.
inspect: Defaults
- Output: a human-readable, tabular view (in color, where available)
- Secrets are redacted from Diagnostic Reports before Rule execution
- The minimum severity level is
WARNING;INFOmessages will be suppressed. - Without a configuration file present, the “recommended” set of Rules will be run:
- At the time of this writing, this is all built-in Rules.
- Each Rule uses its default configuration.
- With a configuration file present, the Rules used and configurations thereof will be as declared by the configuration file.
inspect: Options
inspect allows filtering of Messages by their severity.
--severity <severity>
The minimum threshold for Message severity, as defined by severity. In other words, any Message with a severity “lower” than this will be suppressed.
Allowed values for severity, in descending order of severity:
ERRORWARNINGINFO
The severity argument is case-insensitive. The default severity is WARNING.
Example: Inspect report.json, Including “Info”, “Warning” and “Error”-severity Messages
rtk inspect --severity info report.json
Example: Inspect report.json, Including Only “Error”-severity Messages
rtk inspect --severity ERROR report.json
inspect: Additional Options
inspect supports the following common output options:
The redact Command
Node.js Diagnostic Reports contain the entirety of a process’ execution environment in the environmentVariables field.
environmentVariables can contain things like API keys, tokens, and other secrets. It’s important to keep these secrets from leaking, and a Node.js Diagnostic Report is one potential source of leaks.
When provided one or more report files, redact command redacts known secrets and secret-ish values from this field—while retaining the key name. Values are replaced with the string [REDACTED].
The redact command is essentially a shortcut for transform -t redact.
Basic Usage: rtk redact <file..>
This command will echo a redacted version of report.json to STDOUT:
rtk redact report.json
redact: Output Description
The output is the input—Node.js Diagnostic Reports—but with secrets redacted from the environmentVariables field.
redact: Defaults
The default behavior of redact is to output the same format which Node.js Diagnostic Report files use: pretty-printed JSON.
redact: Options
--replace
Redacts file(s) in-place. In other words, this reads the file(s), redacts secrets, and overwrites them.
When --replace is used, redact will not echo anything to STDOUT.
redact: Additional Options
redact does not support transformers, and is limited to JSON output! If you need to use a transformer, use the transform command instead (which redacts by default).
Since redact defaults to pretty-printed output, it supports --no-pretty.
The transform Command
transform converts a Node.js Diagnostic Report into a different format.
While --transform can be used with the output of other commands, the transform command works directly on report files.
As with any other command, reports will be redacted by default.
Basic Usage: rtk transform <file..>
To transform Node.js Diagnostic Report file report.json into non-pretty-printed (ugly?) JSON:
rtk transform report.json
The behavior of the below example is identical to rtk redact report.json:
rtk transform --pretty report.json
Generally, you will use the --transform <transformer> option to change the transformer. Notably, the transform command works with any transformer.
To transform Node.js Diagnostic Report file report.json into CSV (for reasons):
rtk transform report.json -t csv
transform: Output Description
The output of transform is based entirely on which transform(s) are used.
transform: Defaults
The default behavior of transform is to output the original Node.js Diagnostic Report file(s), redacted, and in compressed (non-pretty-printed) JSON format.
transform: Additional Options
transform supports the following common output options:
Common Output Options
Most of these options are available across most commands. Exceptions include:
- The
redactandtransformcommands do not allow-o, due to ambiguous behavior when given multiple files; use--replaceinstead. - The
redactcommand doesn’t allow--show-secrets-unsafe, because that would be pointless.
--output <file>, -o <file>
Redirect output to a file.
Example: Write Output of Comparison of report-A.json and report-B.json to File
rtk diff report-A.json report-B.json -o diff-output.txt
The above is equivalent to the following in a POSIX shell:
rtk diff report-A.json report-B.json > diff-output.txt
Example: Write Output of Comparison of report-A.json and report-B.json to File, in Pretty-Printed JSON Format
rtk diff report-A.json report-B.json --transform json --pretty -o diff-output.json
--show-secrets-unsafe
This will disable automatic redaction of secrets from the environmentVariables field.
Example: Disable Redacting of Secrets
# danger!rtk diff --show-secrets-unsafe report-A.json report-B.json
--transform <transformer>, -t <transformer>
Transforms command output into various formats.
This option can be repeated, creating a transformer chain. This works when the output of a transformer is valid input for a subsequent transformer. Note that each transformer can only be used once.
Allowed values of transformer:
- csv
- CSV output; nested fields are expanded, so each field has its own column.
- filter
Filter the output by including/excluding fields. Only works with the
transformcommand.- json
- JSON output
- newline
Output in newline-delimited JSON format (A.K.A.
ndjsonand other aliases); useful for streams.- stack-hash
Takes a hash of the stack trace from the
javascriptStackfield, and outputs in a JSON format suitable for collection of metrics. Only works with thetransformcommand.- table
- Output in colorful, human-readable tabular format (default behavior).
Example: Output Diff of report-A.json and report-B.json as CSV
rtk diff -t csv report-A.json report-B.json
Example: Output Inspection of report.json as JSON
rtk inspect -t json report.json
Example: Output Diff of report-A.json and report-B.json as Newline-Delimited JSON
rtk diff -t newline report-A.json report-B.json
Example: Output Inspection of report-A.json and report-B.json in Tabular Format (Default)
rtk inspect -t table report-A.json report-B.json
For further customization of transformer output, see Transformer-Specific Options.
Transformer-Specific Options
Transformers, when used either via the transform command, or the --transform / -t option, have their own options. These options only apply when the transformer in question is used.
json Transformer Options
The json transformer has only one (1) option, --pretty.
--pretty
Pretty-prints the JSON output. When used with diff, this defaults to false.
Example: Output Inspection of report.json as Pretty-Printed JSON
rtk inspect -t json --pretty report.json
Example: Redact and Output report.json as Non-Pretty-Printed JSON
rtk redact --no-pretty report.json
table Transformer Options
These options allow tweaking of the tabular display.
--max-width <columns>
Sets the maximum width, columns, of the table output. By default, the table will stretch the length of the terminal. In a non-TTY situation, the default width will be 80 characters.
If --no-truncate is used, this option will be ignored.
Example: Ouptut Diff of report-A.json and report-B.json in Tabular Format, With a Max Table Width of 72 Characters
rtk diff -t table --max-width 72 report-A.json report-B.json
--truncate
Truncate the values displayed in the table to fit the columns. This is enabled by default, as certain fields (e.g., environmentVariables.PATH) are likely to be very long.
Example: Output Inspection of report.json in Tabular Format, Without Truncating Values
rtk inspect -t table --no-truncate report.json