diff --git a/packages/nodejs/.changesets/log-stdout-on-heroku.md b/packages/nodejs/.changesets/log-stdout-on-heroku.md new file mode 100644 index 00000000..f6e02620 --- /dev/null +++ b/packages/nodejs/.changesets/log-stdout-on-heroku.md @@ -0,0 +1,5 @@ +--- +bump: "patch" +--- + +Default log output to app STDOUT on Heroku dyno's. This makes the AppSignal logs available in the Heroku app's logs. diff --git a/packages/nodejs/src/__tests__/config.test.ts b/packages/nodejs/src/__tests__/config.test.ts index bc370cfc..2ca2b7a2 100644 --- a/packages/nodejs/src/__tests__/config.test.ts +++ b/packages/nodejs/src/__tests__/config.test.ts @@ -62,6 +62,23 @@ describe("Configuration", () => { expect(config.data).toEqual(expectedDefaultConfig) expect(config.sources.default).toEqual(expectedDefaultConfig) + expect(config.sources.system).toEqual({}) + expect(config.sources.initial).toEqual({}) + expect(config.sources.env).toEqual({}) + }) + }) + + describe("system values", () => { + it("sets log output to stdout on Heroku", () => { + process.env.DYNO = "web.1" + const systemConfig = { log: "stdout" } + config = new Configuration({}) + delete process.env.DYNO + + expect(config.data).toEqual({ ...expectedDefaultConfig, ...systemConfig }) + + expect(config.sources.default).toEqual(expectedDefaultConfig) + expect(config.sources.system).toEqual(systemConfig) expect(config.sources.initial).toEqual({}) expect(config.sources.env).toEqual({}) }) @@ -84,6 +101,7 @@ describe("Configuration", () => { expect(config.data).toEqual(options) expect(config.sources.default).toEqual(expectedDefaultConfig) + expect(config.sources.system).toEqual({}) expect(config.sources.initial).toEqual(initialOptions) expect(config.sources.env).toEqual({}) }) @@ -106,6 +124,7 @@ describe("Configuration", () => { expect(config.data).toEqual(expectedConfig) expect(config.sources.default).toEqual(expectedDefaultConfig) + expect(config.sources.system).toEqual({}) expect(config.sources.initial).toEqual({}) expect(config.sources.env).toEqual(envOptions) }) diff --git a/packages/nodejs/src/config.ts b/packages/nodejs/src/config.ts index efe18ca5..04eb9dee 100644 --- a/packages/nodejs/src/config.ts +++ b/packages/nodejs/src/config.ts @@ -28,6 +28,7 @@ export class Configuration { } this.sources = { default: this._defaultValues(), + system: this._systemValues(), env: this._loadFromEnvironment(), initial: options } @@ -94,6 +95,19 @@ export class Configuration { } } + /** + * Config options based on the host environment. + * + * @private + */ + private _systemValues(): { [key: string]: any } { + const config = {} as { [key: string]: any } + if (process.env.DYNO) { + config["log"] = "stdout" + } + return config + } + /** * Loads environment variables into a key-value structure. * diff --git a/test/integration/diagnose b/test/integration/diagnose index 497d875f..d31c4d99 160000 --- a/test/integration/diagnose +++ b/test/integration/diagnose @@ -1 +1 @@ -Subproject commit 497d875f2d812e1c001f4052f6904a463993b14e +Subproject commit d31c4d9970d3118cc17a057d902b9fd38c03e5c6