Skip to content

Commit e37c108

Browse files
committed
Add --config flag to diagnose command
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.
1 parent c2f7b2b commit e37c108

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
bump: "patch"
3+
type: "add"
4+
---
5+
6+
Add the --config flag to diagnose command to specify a custom path for your AppSignal configuration file to
7+
be taken into account when running the diagnose of your AppSignal installation.

src/diagnose.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ export class DiagnoseTool {
158158
path: logFilePath ? path.dirname(logFilePath) : ""
159159
},
160160
"appsignal.cjs": {
161-
path: Configuration.clientFilePath || ""
161+
path:
162+
this.getCustomClientFilePath() || Configuration.clientFilePath || ""
162163
},
163164
"appsignal.log": {
164165
path: logFilePath || "",
@@ -217,13 +218,15 @@ export class DiagnoseTool {
217218
* object from the initialized client. Otherwise, return a default config object.
218219
*/
219220
private getConfigObject(): Configuration {
221+
const clientFilePath =
222+
this.getCustomClientFilePath() || Configuration.clientFilePath
220223
// The file is required to execute the client initialization
221224
// that stores the config object on the global object, making
222225
// it available calling `Client.config` later.
223-
if (Configuration.clientFilePath) {
226+
if (clientFilePath) {
224227
process.env._APPSIGNAL_DIAGNOSE = "true"
225228
try {
226-
require(Configuration.clientFilePath)
229+
require(clientFilePath)
227230
} catch (e: any) {
228231
Client.integrationLogger.error(
229232
`Error loading AppSignal client file ${e.message}`
@@ -273,6 +276,20 @@ export class DiagnoseTool {
273276
)
274277
}
275278

279+
private getCustomClientFilePath() {
280+
const flagIndex = process.argv.indexOf("--config")
281+
282+
if (flagIndex !== -1 && flagIndex + 1 < process.argv.length) {
283+
const filePath = process.argv[flagIndex + 1]
284+
285+
if (path.isAbsolute(filePath)) {
286+
return filePath
287+
} else {
288+
return path.resolve(filePath)
289+
}
290+
}
291+
}
292+
276293
public async sendReport(data: Record<string, any>) {
277294
data.config.options = this.getConfigData()
278295
data.config.sources = this.getSources()

0 commit comments

Comments
 (0)