Skip to content

Commit

Permalink
Load client file if present when running diagnose
Browse files Browse the repository at this point in the history
The client file is loaded to take its values into account when running
the diagnose script.
  • Loading branch information
luismiramirez committed May 11, 2023
1 parent 71e08d5 commit 624b38b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changesets/load-the-client-file-when-running-the-diagnose.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: "patch"
type: "add"
---

Load the AppSignal app configuration file when running the diagnose to include the configuration in the diagnose report.
20 changes: 19 additions & 1 deletion src/diagnose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { URL } from "url"
import { isWritable, installReportPath, processGetuid } from "./utils"
import { Extension } from "./extension"
import { Configuration } from "./config"
import { Client } from "./client"
import { AGENT_VERSION, VERSION } from "./version"
import { JS_TO_RUBY_MAPPING } from "./config/configmap"
import { AppsignalOptions } from "./config/options"
Expand Down Expand Up @@ -34,7 +35,7 @@ export class DiagnoseTool {
#extension: Extension

constructor() {
this.#config = new Configuration({})
this.#config = this.getConfigObject()
this.#extension = new Extension()
}

Expand Down Expand Up @@ -211,6 +212,23 @@ export class DiagnoseTool {
return this.optionsObject(this.#config.data)
}

/**
* If it can load the client from the `appsignal.cjs` file, get the config
* object from the initialized client. Otherwise, return a default config object.
*/
private getConfigObject(): Configuration {
const temporaryConfig = new Configuration({})

// 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 (temporaryConfig.clientFilePath) {
require(temporaryConfig.clientFilePath)
}

return Client.config ?? temporaryConfig
}

/**
* Converts an AppsignalOptions object into a plain JS object,
* re-mapping its keys to snake_case names as they appear
Expand Down

0 comments on commit 624b38b

Please sign in to comment.