Skip to content

Commit

Permalink
Print diagnose report from CLI (#401)
Browse files Browse the repository at this point in the history
* 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
jeffkreeftmeijer and tombruijn authored Jul 8, 2021
1 parent e42193a commit 87155be
Show file tree
Hide file tree
Showing 7 changed files with 300 additions and 73 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
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
35 changes: 35 additions & 0 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ blocks:
- name: "@appsignal/nodejs - nodejs"
commands:
- mono test --package=@appsignal/nodejs
- name: "@appsignal/nodejs - nodejs - diagnose"
commands:
- git submodule init
- git submodule update
- LANGUAGE=nodejs test/integration/diagnose/bin/test
- name: "@appsignal/nodejs-ext - nodejs-ext"
commands:
- mono test --package=@appsignal/nodejs-ext
Expand Down Expand Up @@ -125,6 +130,11 @@ blocks:
- name: "@appsignal/nodejs - nodejs"
commands:
- mono test --package=@appsignal/nodejs
- name: "@appsignal/nodejs - nodejs - diagnose"
commands:
- git submodule init
- git submodule update
- LANGUAGE=nodejs test/integration/diagnose/bin/test
- name: "@appsignal/nodejs-ext - nodejs-ext"
commands:
- mono test --package=@appsignal/nodejs-ext
Expand Down Expand Up @@ -177,6 +187,11 @@ blocks:
- name: "@appsignal/nodejs - nodejs"
commands:
- mono test --package=@appsignal/nodejs
- name: "@appsignal/nodejs - nodejs - diagnose"
commands:
- git submodule init
- git submodule update
- LANGUAGE=nodejs test/integration/diagnose/bin/test
- name: "@appsignal/nodejs-ext - nodejs-ext"
commands:
- mono test --package=@appsignal/nodejs-ext
Expand Down Expand Up @@ -229,6 +244,11 @@ blocks:
- name: "@appsignal/nodejs - nodejs"
commands:
- mono test --package=@appsignal/nodejs
- name: "@appsignal/nodejs - nodejs - diagnose"
commands:
- git submodule init
- git submodule update
- LANGUAGE=nodejs test/integration/diagnose/bin/test
- name: "@appsignal/nodejs-ext - nodejs-ext"
commands:
- mono test --package=@appsignal/nodejs-ext
Expand Down Expand Up @@ -281,6 +301,11 @@ blocks:
- name: "@appsignal/nodejs - nodejs"
commands:
- mono test --package=@appsignal/nodejs
- name: "@appsignal/nodejs - nodejs - diagnose"
commands:
- git submodule init
- git submodule update
- LANGUAGE=nodejs test/integration/diagnose/bin/test
- name: "@appsignal/nodejs-ext - nodejs-ext"
commands:
- mono test --package=@appsignal/nodejs-ext
Expand Down Expand Up @@ -333,6 +358,11 @@ blocks:
- name: "@appsignal/nodejs - nodejs"
commands:
- mono test --package=@appsignal/nodejs
- name: "@appsignal/nodejs - nodejs - diagnose"
commands:
- git submodule init
- git submodule update
- LANGUAGE=nodejs test/integration/diagnose/bin/test
- name: "@appsignal/nodejs-ext - nodejs-ext"
commands:
- mono test --package=@appsignal/nodejs-ext
Expand Down Expand Up @@ -385,6 +415,11 @@ blocks:
- name: "@appsignal/nodejs - nodejs"
commands:
- mono test --package=@appsignal/nodejs
- name: "@appsignal/nodejs - nodejs - diagnose"
commands:
- git submodule init
- git submodule update
- LANGUAGE=nodejs test/integration/diagnose/bin/test
- name: "@appsignal/nodejs-ext - nodejs-ext"
commands:
- mono test --package=@appsignal/nodejs-ext
Expand Down
5 changes: 5 additions & 0 deletions build_matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ matrix:
path: "packages/nodejs"
variations:
- name: "nodejs"
extra_tests:
diagnose:
- git submodule init
- git submodule update
- LANGUAGE=nodejs test/integration/diagnose/bin/test
- package: "@appsignal/nodejs-ext"
path: "packages/nodejs-ext"
variations:
Expand Down
5 changes: 5 additions & 0 deletions packages/nodejs/.changesets/diagnose.md
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.
76 changes: 3 additions & 73 deletions packages/nodejs/bin/diagnose
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading

0 comments on commit 87155be

Please sign in to comment.