Skip to content

Commit

Permalink
Add --config flag to diagnose command
Browse files Browse the repository at this point in the history
Users can specify where they hold the AppSignal client config in their
apps using the `--config` flag. This value if given will be taken into
account to preload the file and to validate the config.
  • Loading branch information
luismiramirez committed Jul 21, 2023
1 parent c2f7b2b commit e37c108
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changesets/add---config-flag-to-diagnose-command.md
@@ -0,0 +1,7 @@
---
bump: "patch"
type: "add"
---

Add the --config flag to diagnose command to specify a custom path for your AppSignal configuration file to
be taken into account when running the diagnose of your AppSignal installation.
23 changes: 20 additions & 3 deletions src/diagnose.ts
Expand Up @@ -158,7 +158,8 @@ export class DiagnoseTool {
path: logFilePath ? path.dirname(logFilePath) : ""
},
"appsignal.cjs": {
path: Configuration.clientFilePath || ""
path:
this.getCustomClientFilePath() || Configuration.clientFilePath || ""
},
"appsignal.log": {
path: logFilePath || "",
Expand Down Expand Up @@ -217,13 +218,15 @@ export class DiagnoseTool {
* object from the initialized client. Otherwise, return a default config object.
*/
private getConfigObject(): Configuration {
const clientFilePath =
this.getCustomClientFilePath() || Configuration.clientFilePath
// The file is required to execute the client initialization
// that stores the config object on the global object, making
// it available calling `Client.config` later.
if (Configuration.clientFilePath) {
if (clientFilePath) {
process.env._APPSIGNAL_DIAGNOSE = "true"
try {
require(Configuration.clientFilePath)
require(clientFilePath)
} catch (e: any) {
Client.integrationLogger.error(
`Error loading AppSignal client file ${e.message}`
Expand Down Expand Up @@ -273,6 +276,20 @@ export class DiagnoseTool {
)
}

private getCustomClientFilePath() {
const flagIndex = process.argv.indexOf("--config")

if (flagIndex !== -1 && flagIndex + 1 < process.argv.length) {
const filePath = process.argv[flagIndex + 1]

if (path.isAbsolute(filePath)) {
return filePath
} else {
return path.resolve(filePath)
}
}
}

public async sendReport(data: Record<string, any>) {
data.config.options = this.getConfigData()
data.config.sources = this.getSources()
Expand Down

0 comments on commit e37c108

Please sign in to comment.