Skip to content

Commit 13068b7

Browse files
authored
Rename apiKey config option to pushApiKey (#507)
Rename the `apiKey` config option to `pushApiKey` to match the naming in the other integrations (Ruby & Elixir). If the `apiKey` config option is set (which will be the case for everyone upgrading) the `pushApiKey` config option will be set with the `apiKey` value. It does only for the `apiKey` option given to the constructor, the env var is mapped to the new key by the config keys map.
1 parent df4163f commit 13068b7

File tree

18 files changed

+64
-33
lines changed

18 files changed

+64
-33
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const { Appsignal } = require("@appsignal/nodejs");
3333
const appsignal = new Appsignal({
3434
active: true,
3535
name: "<YOUR APPLICATION NAME>"
36-
apiKey: "<YOUR API KEY>"
36+
pushApiKey: "<YOUR API KEY>"
3737
});
3838

3939
// ...all the rest of your code goes here!

packages/apollo-server/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const { ApolloServer } = require("apollo-server")
3535
const appsignal = new Appsignal({
3636
active: true,
3737
name: "<YOUR APPLICATION NAME>",
38-
apiKey: "<YOUR API KEY>"
38+
pushApiKey: "<YOUR API KEY>"
3939
})
4040

4141
// The GraphQL schema

packages/apollo-server/test/example/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { createApolloPlugin } = require("../../../apollo-server")
44
const appsignal = new Appsignal({
55
active: true,
66
name: "<YOUR APPLICATION NAME>",
7-
apiKey: "<YOUR API KEY>"
7+
pushApiKey: "<YOUR API KEY>"
88
})
99

1010
const { ApolloServer, gql } = require("apollo-server")

packages/express/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const { Appsignal } = require("@appsignal/nodejs")
2929
const appsignal = new Appsignal({
3030
active: true,
3131
name: "<YOUR APPLICATION NAME>",
32-
apiKey: "<YOUR API KEY>"
32+
pushApiKey: "<YOUR API KEY>"
3333
})
3434

3535
const express = require("express")
@@ -51,7 +51,7 @@ const { Appsignal } = require("@appsignal/nodejs")
5151
const appsignal = new Appsignal({
5252
active: true,
5353
name: "<YOUR APPLICATION NAME>"
54-
apiKey: "<YOUR API KEY>"
54+
pushApiKey: "<YOUR API KEY>"
5555
})
5656

5757
const express = require("express")

packages/express/test/example/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { Appsignal } = require("../../../nodejs")
33
const appsignal = new Appsignal({
44
active: true,
55
name: "<YOUR APPLICATION NAME>",
6-
apiKey: "<YOUR API KEY>"
6+
pushApiKey: "<YOUR API KEY>"
77
})
88

99
const express = require("express")

packages/koa/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const { Appsignal } = require("@appsignal/nodejs");
2929
const appsignal = new Appsignal({
3030
active: true,
3131
name: "<YOUR APPLICATION NAME>",
32-
apiKey: "<YOUR API KEY>"
32+
pushApiKey: "<YOUR API KEY>"
3333
});
3434

3535
appsignal.instrument(require("@appsignal/koa"));

packages/koa/test/example/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { Appsignal } = require("../../../nodejs")
33
const appsignal = new Appsignal({
44
active: true,
55
name: "<YOUR APPLICATION NAME>",
6-
apiKey: "<YOUR API KEY>"
6+
pushApiKey: "<YOUR API KEY>"
77
})
88

99
appsignal.instrument(require("@appsignal/koa"))

packages/nextjs/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const { Appsignal } = require("@appsignal/nodejs");
3737
const appsignal = new Appsignal({
3838
active: true,
3939
name: "<YOUR APPLICATION NAME>",
40-
apiKey: "<YOUR API KEY>",
40+
pushApiKey: "<YOUR API KEY>",
4141
});
4242

4343
const { getRequestHandler } = require("@appsignal/nextjs");
@@ -82,7 +82,7 @@ const { Appsignal } = require("@appsignal/nodejs");
8282
const appsignal = new Appsignal({
8383
active: true,
8484
name: "<YOUR APPLICATION NAME>",
85-
apiKey: "<YOUR API KEY>",
85+
pushApiKey: "<YOUR API KEY>",
8686
});
8787

8888
const { getRequestHandler } = require("@appsignal/nextjs");
@@ -129,7 +129,7 @@ const { Appsignal } = require("@appsignal/nodejs");
129129
const appsignal = new Appsignal({
130130
active: true,
131131
name: "<YOUR APPLICATION NAME>",
132-
apiKey: "<YOUR API KEY>",
132+
pushApiKey: "<YOUR API KEY>",
133133
});
134134

135135
const {

packages/nextjs/test/example/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { Appsignal } = require("../../../nodejs")
55
const appsignal = new Appsignal({
66
active: true,
77
name: "<YOUR APPLICATION NAME>",
8-
apiKey: "<YOUR API KEY>"
8+
pushApiKey: "<YOUR API KEY>"
99
})
1010

1111
const { getRequestHandler } = require("../../../nextjs")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
bump: "patch"
3+
---
4+
5+
Rename the `apiKey` option to `pushApiKey` to match other AppSignal integrations. If `apiKey` is set it will automatically set `pushApiKey`. The `apiKey` option will be removed in the next major version of this package.

packages/nodejs/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const { Appsignal } = require("@appsignal/nodejs");
3333
const appsignal = new Appsignal({
3434
active: true,
3535
name: "<YOUR APPLICATION NAME>"
36-
apiKey: "<YOUR API KEY>"
36+
pushApiKey: "<YOUR API KEY>"
3737
});
3838

3939
// ...all the rest of your code goes here!

packages/nodejs/src/__tests__/client.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ jest.mock("../tracer")
77

88
describe("BaseClient", () => {
99
const name = "TEST APP"
10-
const apiKey = "TEST_API_KEY"
10+
const pushApiKey = "TEST_API_KEY"
1111

1212
let client: BaseClient
1313

1414
// enableMinutelyProbes is set to false so we don't leak timers
15-
const DEFAULT_OPTS = { name, apiKey, enableMinutelyProbes: false }
15+
const DEFAULT_OPTS = { name, pushApiKey, enableMinutelyProbes: false }
1616

1717
beforeEach(() => {
1818
client = new BaseClient({ ...DEFAULT_OPTS })

packages/nodejs/src/__tests__/config.test.ts

+28-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import os from "os"
12
import path from "path"
23
import { VERSION } from "../version"
34
import { Configuration } from "../config"
45

56
describe("Configuration", () => {
67
const name = "TEST APP"
7-
const apiKey = "TEST_API_KEY"
8+
const pushApiKey = "TEST_API_KEY"
89

910
let config: Configuration
1011
let initialEnv: { [key: string]: any }
@@ -110,9 +111,25 @@ describe("Configuration", () => {
110111
})
111112
})
112113

114+
describe("apiKey option", () => {
115+
it("sets the pushApiKey config option with the apiKey value", () => {
116+
const warnMock = jest.spyOn(console, "warn").mockImplementation(() => {})
117+
const apiKey = "my key"
118+
config = new Configuration({ apiKey })
119+
120+
expect(config.data.pushApiKey).toEqual(apiKey)
121+
expect(config.data.apiKey).toBeUndefined()
122+
expect(config.sources.initial.pushApiKey).toEqual(apiKey)
123+
expect(config.sources.initial.apiKey).toBeUndefined()
124+
expect(warnMock).toBeCalledWith(
125+
"DEPRECATED: The `apiKey` config option was renamed to `pushApiKey`. Please rename the config option given to the Appsignal module."
126+
)
127+
})
128+
})
129+
113130
describe("logFilePath", () => {
114131
it("uses the default log file path", () => {
115-
config = new Configuration({ name, apiKey })
132+
config = new Configuration({ name, pushApiKey })
116133

117134
expect(config.logFilePath).toEqual("/tmp/appsignal.log")
118135
})
@@ -193,7 +210,7 @@ describe("Configuration", () => {
193210
new Configuration({
194211
name,
195212
active: true,
196-
apiKey,
213+
pushApiKey,
197214
debug: true,
198215
dnsServers: ["8.8.8.8", "8.8.4.4"],
199216
enableHostMetrics: false,
@@ -242,7 +259,7 @@ describe("Configuration", () => {
242259
expect(env("_APPSIGNAL_PUSH_API_ENDPOINT")).toEqual(
243260
"https://push.appsignal.com"
244261
)
245-
expect(env("_APPSIGNAL_PUSH_API_KEY")).toEqual(apiKey)
262+
expect(env("_APPSIGNAL_PUSH_API_KEY")).toEqual(pushApiKey)
246263
expect(env("_APPSIGNAL_RUNNING_IN_CONTAINER")).toEqual("true")
247264
// Only set because `debug` is set to true
248265
// @TODO: https://github.com/appsignal/appsignal-nodejs/issues/379
@@ -255,23 +272,23 @@ describe("Configuration", () => {
255272
})
256273

257274
describe(".isValid", () => {
258-
it("is valid if apiKey is present", () => {
259-
config = new Configuration({ apiKey })
275+
it("is valid if pushApiKey is present", () => {
276+
config = new Configuration({ pushApiKey })
260277
expect(config.isValid).toBeTruthy()
261278
})
262279

263-
it("is invalid if apiKey is not present", () => {
280+
it("is invalid if pushApiKey is not present", () => {
264281
config = new Configuration({ name })
265282
expect(config.isValid).toBeFalsy()
266283
})
267284

268-
it("is invalid if apiKey is an empty string", () => {
269-
config = new Configuration({ name, apiKey: "" })
285+
it("is invalid if pushApiKey is an empty string", () => {
286+
config = new Configuration({ name, pushApiKey: "" })
270287
expect(config.isValid).toBeFalsy()
271288
})
272289

273-
it("is invalid if apiKey is a string with only whitespaces", () => {
274-
config = new Configuration({ name, apiKey: " " })
290+
it("is invalid if pushApiKey is a string with only whitespaces", () => {
291+
config = new Configuration({ name, pushApiKey: " " })
275292
expect(config.isValid).toBeFalsy()
276293
})
277294
})

packages/nodejs/src/config.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os from "os"
12
import path from "path"
23

34
import { VERSION } from "./version"
@@ -18,6 +19,13 @@ export class Configuration {
1819
sources: HashMap<Partial<AppsignalOptions>>
1920

2021
constructor(options: Partial<AppsignalOptions>) {
22+
if (options.apiKey) {
23+
console.warn(
24+
"DEPRECATED: The `apiKey` config option was renamed to `pushApiKey`. Please rename the config option given to the Appsignal module."
25+
)
26+
options.pushApiKey = options.apiKey
27+
delete options.apiKey
28+
}
2129
this.sources = {
2230
default: this._defaultValues(),
2331
env: this._loadFromEnvironment(),
@@ -42,7 +50,7 @@ export class Configuration {
4250
* Returns `true` if the current configuration is valid.
4351
*/
4452
public get isValid(): boolean {
45-
return (this.data.apiKey || "").trim() !== ""
53+
return (this.data.pushApiKey || "").trim() !== ""
4654
}
4755

4856
public get logFilePath(): string {

packages/nodejs/src/config/configmap.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const ENV_TO_KEY_MAPPING: { [key: string]: string } = {
2020
APPSIGNAL_LOG: "log",
2121
APPSIGNAL_LOG_PATH: "logPath",
2222
APPSIGNAL_PUSH_API_ENDPOINT: "endpoint",
23-
APPSIGNAL_PUSH_API_KEY: "apiKey",
23+
APPSIGNAL_PUSH_API_KEY: "pushApiKey",
2424
APPSIGNAL_REQUEST_HEADERS: "requestHeaders",
2525
APPSIGNAL_RUNNING_IN_CONTAINER: "runningInContainer",
2626
APPSIGNAL_SEND_PARAMS: "sendParams",
@@ -50,7 +50,7 @@ export const PRIVATE_ENV_MAPPING: { [key: string]: string } = {
5050
_APPSIGNAL_IGNORE_NAMESPACES: "ignoreNamespaces",
5151
_APPSIGNAL_LOG: "log",
5252
_APPSIGNAL_PUSH_API_ENDPOINT: "endpoint",
53-
_APPSIGNAL_PUSH_API_KEY: "apiKey",
53+
_APPSIGNAL_PUSH_API_KEY: "pushApiKey",
5454
_APPSIGNAL_RUNNING_IN_CONTAINER: "runningInContainer",
5555
_APPSIGNAL_TRANSACTION_DEBUG_MODE: "debug",
5656
_APPSIGNAL_WORKING_DIRECTORY_PATH: "workingDirectoryPath",
@@ -60,7 +60,7 @@ export const PRIVATE_ENV_MAPPING: { [key: string]: string } = {
6060

6161
export const JS_TO_RUBY_MAPPING: { [key: string]: string } = {
6262
active: "active",
63-
apiKey: "push_api_key",
63+
pushApiKey: "push_api_key",
6464
caFilePath: "ca_file_path",
6565
debug: "debug",
6666
dnsServers: "dns_servers",

packages/nodejs/src/diagnose.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export class DiagnoseTool {
114114
return new Promise((resolve, reject) => {
115115
const config = this.#config.data
116116
const params = new URLSearchParams({
117-
api_key: config["apiKey"] || "",
117+
api_key: config["pushApiKey"] || "",
118118
name: config["name"] || "",
119119
environment: config["environment"] || "",
120120
hostname: config["hostname"] || ""
@@ -230,7 +230,7 @@ export class DiagnoseTool {
230230

231231
const config = this.#config.data
232232
const params = new URLSearchParams({
233-
api_key: config["apiKey"] || "",
233+
api_key: config["pushApiKey"] || "",
234234
name: config["name"] || "",
235235
environment: config["environment"] || "",
236236
hostname: config["hostname"] || ""

packages/nodejs/src/interfaces/options.ts

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface AppsignalOptions {
2121
log: string
2222
logPath: string
2323
name: string
24+
pushApiKey: string
2425
requestHeaders: string[]
2526
revision: string
2627
runningInContainer: boolean

test/integration/diagnose

0 commit comments

Comments
 (0)