-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Print diagnose report from CLI (#401)
* Add diagnose integration tests * Run diagnose integration tests on CI * Add cli/diagnose with header and library section * Add extension installation report * Add configuration section to diagnose * Add config diagnose link * Add API key validation section * Add the paths section * Add diagnose reports section * Add diagnostics report section * Restore diagnose report sending * Move report sending to separate function * Restore --(no-)send-report options * Update diagnose_tests to remove log paths from Node.js diagnose * Print specific list of configuration values in diagnose * Remove logFilePath from JS_TO_RUBY_MAPPING * Add linux arm override to diagnose * Update diagnose_tests to silence debug output on CI * Update packages/nodejs/src/cli/diagnose.ts Co-authored-by: Tom de Bruijn <[email protected]> * Add changeset for diagnose Co-authored-by: Tom de Bruijn <[email protected]>
- Loading branch information
1 parent
e42193a
commit 87155be
Showing
7 changed files
with
300 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "test/integration/diagnose"] | ||
path = test/integration/diagnose | ||
url = [email protected]:appsignal/diagnose_tests.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
bump: "minor" | ||
--- | ||
|
||
Format and print the diagnose report in a human-readable format. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,76 +2,6 @@ | |
|
||
"use strict" | ||
|
||
const https = require("https") | ||
const path = require("path") | ||
const util = require("util") | ||
const fs = require("fs") | ||
const { DiagnoseTool } = require("../dist/diagnose") | ||
|
||
// enable diagnose mode | ||
process.env["_APPSIGNAL_DIAGNOSE"] = "true" | ||
|
||
// providing --send-report sends the report. --no-send-report stops the report from being sent | ||
// it can also be passed by @appsignal/cli | ||
const shouldSendReport = process.argv.includes("--send-report") && !process.argv.includes("--no-send-report") | ||
|
||
const tool = new DiagnoseTool({}) | ||
|
||
console.log(` | ||
🔧 AppSignal Diagnose Tool | ||
Use this information to debug your configuration. | ||
More information is available on the documentation site. | ||
https://docs.appsignal.com/ | ||
This diagnose output ${ | ||
shouldSendReport ? "was" : "was not" | ||
} sent to AppSignal, contact us at [email protected] if you need help. | ||
`) | ||
|
||
if (!process.env["APPSIGNAL_PUSH_API_KEY"]) { | ||
throw new Error( | ||
`No Push API key found. Set the APPSIGNAL_PUSH_API_KEY environment variable to your Push API key and try again.` | ||
) | ||
} | ||
|
||
const data = tool.generate() | ||
const json = JSON.stringify(data) | ||
|
||
const opts = { | ||
port: 443, | ||
method: "POST", | ||
host: "appsignal.com", | ||
path: "/diag", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Content-Length": json.length | ||
}, | ||
cert: fs.readFileSync(path.resolve(__dirname, "../cert/cacert.pem"), "utf-8") | ||
} | ||
|
||
if (shouldSendReport) { | ||
const req = https.request(opts, res => { | ||
res.setEncoding("utf8") | ||
|
||
// print token to the console | ||
res.on("data", chunk => { | ||
const { token } = JSON.parse(chunk.toString()) | ||
console.log("Your diagnose token is:", token) | ||
console.log( | ||
`👀 View this report: https://appsignal.com/diagnose/${token}` | ||
) | ||
}) | ||
}) | ||
|
||
req.on("error", e => { | ||
console.error(`Problem with diagnose request: ${e.message}`) | ||
}) | ||
|
||
// Write data to request body | ||
req.write(json) | ||
req.end() | ||
} | ||
|
||
console.log(util.inspect(data, { depth: null, colors: true }), "\n") | ||
console.log("✅ Done!") | ||
const { Diagnose } = require("../dist/cli/diagnose") | ||
const diagnose = new Diagnose() | ||
diagnose.run() |
Oops, something went wrong.