Skip to content

Commit

Permalink
Print more path details in diagnose report (#958)
Browse files Browse the repository at this point in the history
Make the Node.js integration consistent with the other integrations and
have it print the same output per path.

Refactored the printing of the paths to a new helper function.
  • Loading branch information
tombruijn authored Nov 3, 2023
1 parent 5b2fac0 commit 285f89e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 28 deletions.
6 changes: 6 additions & 0 deletions .changesets/print-path-details-in-diagnose-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: "patch"
type: "change"
---

Print more path details in the diagnose CLI output. It will now print details like if a path exists, the ownership of a path and if it's writable or not to help debug issues locally.
55 changes: 28 additions & 27 deletions src/cli/diagnose.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { DiagnoseTool } = require("../diagnose")
const { processGetuid } = require("../utils")
const util = require("util")
const readline = require("readline")

Expand Down Expand Up @@ -165,36 +166,13 @@ export class Diagnose {

console.log(`Paths`)

const contents = data["paths"]["appsignal.log"]["content"]

console.log(` Current working directory`)
console.log(
` Path: ${format_value(data["paths"]["working_dir"]["path"])}`
)

this.printPath("Current working directory", data["paths"]["working_dir"])
this.print_newline()

console.log(` Log directory`)
console.log(
` Path: ${format_value(data["paths"]["log_dir_path"]["path"])}`
)

this.printPath("Log directory", data["paths"]["log_dir_path"])
this.print_newline()

console.log(` AppSignal client file`)
console.log(
` Path: ${format_value(data["paths"]["appsignal.cjs"]["path"])}`
)

this.printPath("AppSignal client file", data["paths"]["appsignal.cjs"])
this.print_newline()

console.log(` AppSignal log`)
console.log(
` Path: ${format_value(data["paths"]["appsignal.log"]["path"])}`
)
console.log(` Contents (last 10 lines):`)
console.log(contents.slice(contents.length - 10).join("\n"))

this.printPath("AppSignal log", data["paths"]["appsignal.log"])
this.print_newline()

console.log(`Diagnostics report`)
Expand Down Expand Up @@ -238,6 +216,29 @@ export class Diagnose {
}
}

printPath(label: string, path: Record<string, any>) {
console.log(` ${label}`)
console.log(` Path: ${format_value(path["path"])}`)
if (!path["exists"]) {
console.log(` Exists?: false`)
return
}
console.log(` Writable?: ${format_value(path["writable"])}`)
const processUid = processGetuid()
const fileUid = path["ownership"]["uid"]
const isOwner = processUid == fileUid
console.log(
` Ownership?: ${format_value(
isOwner
)} (file: ${fileUid}, process: ${processUid})`
)
const contents = path["content"]
if (contents) {
console.log(` Contents (last 10 lines):`)
console.log(contents.slice(contents.length - 10).join("\n"))
}
}

async sendReport(data: object) {
console.log(" Transmitting diagnostics report")
console.log("")
Expand Down
2 changes: 1 addition & 1 deletion test/integration/diagnose
Submodule diagnose updated 1 files
+15 −31 spec/diagnose_spec.rb

0 comments on commit 285f89e

Please sign in to comment.