@datadog/datadog-ci 0.17.9 → 0.17.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/LICENSE-3rdparty.csv +2 -0
  2. package/README.md +9 -2
  3. package/dist/{commands/dependencies/index.d.ts → cli.d.ts} +0 -0
  4. package/dist/cli.js +34 -0
  5. package/dist/commands/{dsyms/index.d.ts → dependencies/cli.d.ts} +0 -0
  6. package/dist/commands/dependencies/{index.js → cli.js} +0 -0
  7. package/dist/commands/dependencies/upload.d.ts +1 -1
  8. package/dist/commands/{git-metadata/index.d.ts → dsyms/cli.d.ts} +0 -0
  9. package/dist/commands/dsyms/{index.js → cli.js} +0 -0
  10. package/dist/commands/dsyms/upload.d.ts +1 -1
  11. package/dist/commands/{junit/index.d.ts → git-metadata/cli.d.ts} +0 -0
  12. package/dist/commands/git-metadata/{index.js → cli.js} +0 -0
  13. package/dist/commands/git-metadata/upload.d.ts +1 -1
  14. package/dist/commands/git-metadata/upload.js +6 -1
  15. package/dist/commands/{lambda/index.d.ts → junit/cli.d.ts} +0 -0
  16. package/dist/commands/junit/{index.js → cli.js} +0 -0
  17. package/dist/commands/junit/upload.d.ts +1 -1
  18. package/dist/commands/junit/upload.js +1 -1
  19. package/dist/commands/lambda/__tests__/fixtures.d.ts +5 -1
  20. package/dist/commands/lambda/__tests__/fixtures.js +13 -2
  21. package/dist/commands/lambda/__tests__/functions/commons.test.js +400 -0
  22. package/dist/commands/lambda/__tests__/functions/instrument.test.js +229 -117
  23. package/dist/commands/lambda/__tests__/functions/uninstrument.test.js +80 -7
  24. package/dist/commands/lambda/__tests__/instrument.test.js +542 -111
  25. package/dist/commands/{sourcemaps/index.d.ts → lambda/__tests__/prompt.test.d.ts} +0 -0
  26. package/dist/commands/lambda/__tests__/prompt.test.js +216 -0
  27. package/dist/commands/lambda/__tests__/uninstrument.test.js +381 -17
  28. package/dist/commands/{trace/index.d.ts → lambda/cli.d.ts} +0 -0
  29. package/dist/commands/lambda/{index.js → cli.js} +0 -0
  30. package/dist/commands/lambda/constants.d.ts +27 -6
  31. package/dist/commands/lambda/constants.js +63 -6
  32. package/dist/commands/lambda/functions/commons.d.ts +49 -4
  33. package/dist/commands/lambda/functions/commons.js +198 -7
  34. package/dist/commands/lambda/functions/instrument.d.ts +5 -14
  35. package/dist/commands/lambda/functions/instrument.js +63 -80
  36. package/dist/commands/lambda/functions/uninstrument.d.ts +3 -2
  37. package/dist/commands/lambda/functions/uninstrument.js +23 -11
  38. package/dist/commands/lambda/instrument.d.ts +2 -1
  39. package/dist/commands/lambda/instrument.js +112 -58
  40. package/dist/commands/lambda/interfaces.d.ts +4 -1
  41. package/dist/commands/lambda/loggroup.js +3 -1
  42. package/dist/commands/lambda/prompt.d.ts +9 -0
  43. package/dist/commands/lambda/prompt.js +187 -0
  44. package/dist/commands/lambda/uninstrument.d.ts +2 -0
  45. package/dist/commands/lambda/uninstrument.js +107 -30
  46. package/dist/commands/sourcemaps/cli.d.ts +1 -0
  47. package/dist/commands/sourcemaps/{index.js → cli.js} +0 -0
  48. package/dist/commands/sourcemaps/upload.d.ts +1 -1
  49. package/dist/commands/synthetics/__tests__/cli.test.js +36 -13
  50. package/dist/commands/synthetics/__tests__/fixtures.js +1 -0
  51. package/dist/commands/synthetics/__tests__/run-test.test.js +48 -2
  52. package/dist/commands/synthetics/__tests__/utils.test.js +11 -4
  53. package/dist/commands/synthetics/__tests__/websocket.test.js +3 -3
  54. package/dist/commands/synthetics/cli.d.ts +1 -26
  55. package/dist/commands/synthetics/cli.js +2 -227
  56. package/dist/commands/synthetics/command.d.ts +27 -0
  57. package/dist/commands/synthetics/command.js +236 -0
  58. package/dist/commands/synthetics/index.d.ts +5 -1
  59. package/dist/commands/synthetics/index.js +31 -2
  60. package/dist/commands/synthetics/interfaces.d.ts +8 -3
  61. package/dist/commands/synthetics/interfaces.js +7 -3
  62. package/dist/commands/synthetics/reporters/default.js +5 -1
  63. package/dist/commands/synthetics/run-test.js +3 -1
  64. package/dist/commands/synthetics/utils.d.ts +3 -3
  65. package/dist/commands/synthetics/utils.js +17 -8
  66. package/dist/commands/trace/api.js +1 -1
  67. package/dist/commands/trace/cli.d.ts +1 -0
  68. package/dist/commands/trace/{index.js → cli.js} +0 -0
  69. package/dist/commands/trace/trace.d.ts +1 -1
  70. package/dist/helpers/__tests__/ci.test.js +97 -136
  71. package/dist/helpers/__tests__/user-provided-git.test.js +81 -27
  72. package/dist/helpers/__tests__/utils.test.js +4 -0
  73. package/dist/helpers/ci.js +54 -95
  74. package/dist/helpers/interfaces.d.ts +28 -2
  75. package/dist/helpers/user-provided-git.d.ts +2 -1
  76. package/dist/helpers/user-provided-git.js +29 -5
  77. package/dist/helpers/utils.d.ts +4 -0
  78. package/dist/helpers/utils.js +18 -1
  79. package/dist/index.d.ts +3 -1
  80. package/dist/index.js +23 -31
  81. package/package.json +10 -8
@@ -43,11 +43,13 @@ describe('instrument', () => {
43
43
  afterAll(() => {
44
44
  process.env = OLD_ENV;
45
45
  });
46
- test('calculates an update request with just lambda library layers', () => {
46
+ test('calculates an update request with just lambda library layers', () => __awaiter(void 0, void 0, void 0, function* () {
47
+ const runtime = 'nodejs12.x';
47
48
  const config = {
48
49
  FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
49
50
  Handler: 'index.handler',
50
51
  Layers: [],
52
+ Runtime: runtime,
51
53
  };
52
54
  const settings = {
53
55
  flushMetricsToLogs: false,
@@ -56,10 +58,8 @@ describe('instrument', () => {
56
58
  mergeXrayTraces: false,
57
59
  tracingEnabled: false,
58
60
  };
59
- const lambdaLibraryLayerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:Datadog-Node12-x`;
60
- const lambdaExtensionLayerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:Datadog-Extension`;
61
- const runtime = 'nodejs12.x';
62
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, lambdaLibraryLayerArn, lambdaExtensionLayerArn, runtime);
61
+ const region = 'sa-east-1';
62
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
63
63
  expect(updateRequest).toMatchInlineSnapshot(`
64
64
  Object {
65
65
  "Environment": Object {
@@ -78,13 +78,52 @@ describe('instrument', () => {
78
78
  ],
79
79
  }
80
80
  `);
81
- });
82
- test('calculates an update request with a lambda library, extension, and DATADOG_API_KEY', () => {
83
- process.env.DATADOG_API_KEY = '1234';
81
+ }));
82
+ test('calculates an update request with just lambda library layers in arm architecture', () => __awaiter(void 0, void 0, void 0, function* () {
83
+ const runtime = 'python3.9';
84
+ const config = {
85
+ Architectures: ['arm64'],
86
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
87
+ Handler: 'handler.hello',
88
+ Layers: [],
89
+ Runtime: runtime,
90
+ };
91
+ const settings = {
92
+ flushMetricsToLogs: false,
93
+ layerAWSAccount: fixtures_1.mockAwsAccount,
94
+ layerVersion: 11,
95
+ mergeXrayTraces: false,
96
+ tracingEnabled: false,
97
+ };
98
+ const region = 'sa-east-1';
99
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
100
+ expect(updateRequest).toMatchInlineSnapshot(`
101
+ Object {
102
+ "Environment": Object {
103
+ "Variables": Object {
104
+ "DD_FLUSH_TO_LOG": "false",
105
+ "DD_LAMBDA_HANDLER": "handler.hello",
106
+ "DD_MERGE_XRAY_TRACES": "false",
107
+ "DD_SITE": "datadoghq.com",
108
+ "DD_TRACE_ENABLED": "false",
109
+ },
110
+ },
111
+ "FunctionName": "arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world",
112
+ "Handler": "datadog_lambda.handler.handler",
113
+ "Layers": Array [
114
+ "arn:aws:lambda:sa-east-1:123456789012:layer:Datadog-Python39-ARM:11",
115
+ ],
116
+ }
117
+ `);
118
+ }));
119
+ test('calculates an update request with a lambda library, extension, and DATADOG_API_KEY', () => __awaiter(void 0, void 0, void 0, function* () {
120
+ process.env[constants_1.CI_API_KEY_ENV_VAR] = '1234';
121
+ const runtime = 'nodejs12.x';
84
122
  const config = {
85
123
  FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
86
124
  Handler: 'index.handler',
87
125
  Layers: [],
126
+ Runtime: runtime,
88
127
  };
89
128
  const settings = {
90
129
  extensionVersion: 6,
@@ -94,16 +133,13 @@ describe('instrument', () => {
94
133
  mergeXrayTraces: false,
95
134
  tracingEnabled: false,
96
135
  };
97
- const lambdaLibraryLayerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:Datadog-Node12-x`;
98
- const lambdaExtensionLayerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:Datadog-Extension`;
99
- const runtime = 'nodejs12.x';
100
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, lambdaLibraryLayerArn, lambdaExtensionLayerArn, runtime);
136
+ const region = 'sa-east-1';
137
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
101
138
  expect(updateRequest).toMatchInlineSnapshot(`
102
139
  Object {
103
140
  "Environment": Object {
104
141
  "Variables": Object {
105
142
  "DD_API_KEY": "1234",
106
- "DD_FLUSH_TO_LOG": "false",
107
143
  "DD_LAMBDA_HANDLER": "index.handler",
108
144
  "DD_MERGE_XRAY_TRACES": "false",
109
145
  "DD_SITE": "datadoghq.com",
@@ -118,13 +154,54 @@ describe('instrument', () => {
118
154
  ],
119
155
  }
120
156
  `);
121
- });
122
- test('calculates an update request with a lambda library, extension, and DATADOG_KMS_API_KEY', () => {
123
- process.env.DATADOG_KMS_API_KEY = '5678';
157
+ }));
158
+ test('calculates an update request with a lambda library, extension, and DATADOG_API_KEY_SECRET_ARN', () => __awaiter(void 0, void 0, void 0, function* () {
159
+ process.env[constants_1.CI_API_KEY_SECRET_ARN_ENV_VAR] = 'some-secret:arn:from:aws';
160
+ const runtime = 'python3.9';
161
+ const config = {
162
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
163
+ Handler: 'index.handler',
164
+ Layers: [],
165
+ Runtime: runtime,
166
+ };
167
+ const settings = {
168
+ extensionVersion: 11,
169
+ flushMetricsToLogs: false,
170
+ layerAWSAccount: fixtures_1.mockAwsAccount,
171
+ layerVersion: 49,
172
+ mergeXrayTraces: false,
173
+ tracingEnabled: false,
174
+ };
175
+ const region = 'sa-east-1';
176
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
177
+ expect(updateRequest).toMatchInlineSnapshot(`
178
+ Object {
179
+ "Environment": Object {
180
+ "Variables": Object {
181
+ "DD_API_KEY_SECRET_ARN": "some-secret:arn:from:aws",
182
+ "DD_LAMBDA_HANDLER": "index.handler",
183
+ "DD_MERGE_XRAY_TRACES": "false",
184
+ "DD_SITE": "datadoghq.com",
185
+ "DD_TRACE_ENABLED": "false",
186
+ },
187
+ },
188
+ "FunctionName": "arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world",
189
+ "Handler": "datadog_lambda.handler.handler",
190
+ "Layers": Array [
191
+ "arn:aws:lambda:sa-east-1:123456789012:layer:Datadog-Extension:11",
192
+ "arn:aws:lambda:sa-east-1:123456789012:layer:Datadog-Python39:49",
193
+ ],
194
+ }
195
+ `);
196
+ }));
197
+ test('calculates an update request with a lambda library, extension, and DATADOG_KMS_API_KEY', () => __awaiter(void 0, void 0, void 0, function* () {
198
+ process.env[constants_1.CI_KMS_API_KEY_ENV_VAR] = '5678';
199
+ const runtime = 'python3.6';
124
200
  const config = {
125
201
  FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
126
202
  Handler: 'index.handler',
127
203
  Layers: [],
204
+ Runtime: runtime,
128
205
  };
129
206
  const settings = {
130
207
  extensionVersion: 6,
@@ -134,15 +211,12 @@ describe('instrument', () => {
134
211
  mergeXrayTraces: false,
135
212
  tracingEnabled: false,
136
213
  };
137
- const lambdaLibraryLayerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:Datadog-Python36`;
138
- const lambdaExtensionLayerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:Datadog-Extension`;
139
- const runtime = 'python3.6';
140
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, lambdaLibraryLayerArn, lambdaExtensionLayerArn, runtime);
214
+ const region = 'sa-east-1';
215
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
141
216
  expect(updateRequest).toMatchInlineSnapshot(`
142
217
  Object {
143
218
  "Environment": Object {
144
219
  "Variables": Object {
145
- "DD_FLUSH_TO_LOG": "false",
146
220
  "DD_KMS_API_KEY": "5678",
147
221
  "DD_LAMBDA_HANDLER": "index.handler",
148
222
  "DD_MERGE_XRAY_TRACES": "false",
@@ -158,12 +232,77 @@ describe('instrument', () => {
158
232
  ],
159
233
  }
160
234
  `);
161
- });
162
- test('by default calculates an update request with DATADOG_SITE being set to datadoghq.com', () => {
235
+ }));
236
+ test('prioritizes the KMS API KEY when all of them are exported', () => __awaiter(void 0, void 0, void 0, function* () {
237
+ process.env = {
238
+ [constants_1.CI_API_KEY_ENV_VAR]: '1234',
239
+ [constants_1.CI_API_KEY_SECRET_ARN_ENV_VAR]: '5678',
240
+ [constants_1.CI_KMS_API_KEY_ENV_VAR]: 'should-be-selected',
241
+ };
242
+ const config = {
243
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
244
+ Handler: 'index.handler',
245
+ Layers: [],
246
+ };
247
+ const runtime = 'python3.9';
248
+ const region = 'sa-east-1';
249
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, {}, region, runtime);
250
+ expect(updateRequest).toMatchInlineSnapshot(`
251
+ Object {
252
+ "Environment": Object {
253
+ "Variables": Object {
254
+ "DD_KMS_API_KEY": "should-be-selected",
255
+ "DD_LAMBDA_HANDLER": "index.handler",
256
+ "DD_SITE": "datadoghq.com",
257
+ },
258
+ },
259
+ "FunctionName": "arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world",
260
+ "Handler": "datadog_lambda.handler.handler",
261
+ }
262
+ `);
263
+ }));
264
+ test("doesn't set DD_FLUSH_TO_LOGS when extension is being used", () => __awaiter(void 0, void 0, void 0, function* () {
265
+ process.env[constants_1.CI_API_KEY_ENV_VAR] = '1234';
266
+ const config = {
267
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
268
+ Handler: 'index.handler',
269
+ Layers: [],
270
+ };
271
+ const runtime = 'python3.9';
272
+ const region = 'sa-east-1';
273
+ const settings = {
274
+ extensionVersion: 13,
275
+ flushMetricsToLogs: true,
276
+ mergeXrayTraces: false,
277
+ tracingEnabled: false,
278
+ };
279
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
280
+ expect(updateRequest).toMatchInlineSnapshot(`
281
+ Object {
282
+ "Environment": Object {
283
+ "Variables": Object {
284
+ "DD_API_KEY": "1234",
285
+ "DD_LAMBDA_HANDLER": "index.handler",
286
+ "DD_MERGE_XRAY_TRACES": "false",
287
+ "DD_SITE": "datadoghq.com",
288
+ "DD_TRACE_ENABLED": "false",
289
+ },
290
+ },
291
+ "FunctionName": "arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world",
292
+ "Handler": "datadog_lambda.handler.handler",
293
+ "Layers": Array [
294
+ "arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:13",
295
+ ],
296
+ }
297
+ `);
298
+ }));
299
+ test('by default calculates an update request with DATADOG_SITE being set to datadoghq.com', () => __awaiter(void 0, void 0, void 0, function* () {
300
+ const runtime = 'python3.6';
163
301
  const config = {
164
302
  FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
165
303
  Handler: 'index.handler',
166
304
  Layers: [],
305
+ Runtime: runtime,
167
306
  };
168
307
  const settings = {
169
308
  flushMetricsToLogs: false,
@@ -171,10 +310,8 @@ describe('instrument', () => {
171
310
  mergeXrayTraces: false,
172
311
  tracingEnabled: false,
173
312
  };
174
- const lambdaLibraryLayerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:Datadog-Python36`;
175
- const lambdaExtensionLayerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:Datadog-Extension`;
176
- const runtime = 'python3.6';
177
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, lambdaLibraryLayerArn, lambdaExtensionLayerArn, runtime);
313
+ const region = 'sa-east-1';
314
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
178
315
  expect(updateRequest).toMatchInlineSnapshot(`
179
316
  Object {
180
317
  "Environment": Object {
@@ -190,8 +327,8 @@ describe('instrument', () => {
190
327
  "Handler": "datadog_lambda.handler.handler",
191
328
  }
192
329
  `);
193
- });
194
- test('calculates an update request with DATADOG_SITE being set to datadoghq.eu', () => {
330
+ }));
331
+ test('calculates an update request with DATADOG_SITE being set to datadoghq.eu', () => __awaiter(void 0, void 0, void 0, function* () {
195
332
  process.env.DATADOG_SITE = 'datadoghq.eu';
196
333
  const config = {
197
334
  FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
@@ -204,10 +341,9 @@ describe('instrument', () => {
204
341
  mergeXrayTraces: false,
205
342
  tracingEnabled: false,
206
343
  };
207
- const lambdaLibraryLayerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:Datadog-Python36`;
208
- const lambdaExtensionLayerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:Datadog-Extension`;
344
+ const region = 'sa-east-1';
209
345
  const runtime = 'python3.6';
210
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, lambdaLibraryLayerArn, lambdaExtensionLayerArn, runtime);
346
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
211
347
  expect(updateRequest).toMatchInlineSnapshot(`
212
348
  Object {
213
349
  "Environment": Object {
@@ -223,8 +359,8 @@ describe('instrument', () => {
223
359
  "Handler": "datadog_lambda.handler.handler",
224
360
  }
225
361
  `);
226
- });
227
- test('throws an error when an invalid DATADOG_SITE url is given', () => {
362
+ }));
363
+ test('throws an error when an invalid DATADOG_SITE url is given', () => __awaiter(void 0, void 0, void 0, function* () {
228
364
  process.env.DATADOG_SITE = 'datacathq.eu';
229
365
  const config = {
230
366
  FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
@@ -233,19 +369,26 @@ describe('instrument', () => {
233
369
  };
234
370
  const settings = {
235
371
  flushMetricsToLogs: false,
372
+ interactive: false,
236
373
  layerAWSAccount: fixtures_1.mockAwsAccount,
237
374
  layerVersion: 5,
238
375
  mergeXrayTraces: false,
239
376
  tracingEnabled: false,
240
377
  };
241
- const lambdaLibraryLayerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:Datadog-Python36`;
242
- const lambdaExtensionLayerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:Datadog-Extension`;
378
+ const region = 'us-east-1';
243
379
  const runtime = 'python3.6';
244
- expect(() => {
245
- instrument_1.calculateUpdateRequest(config, settings, lambdaLibraryLayerArn, lambdaExtensionLayerArn, runtime);
246
- }).toThrowError('Warning: Invalid site URL. Must be either datadoghq.com, datadoghq.eu, us3.datadoghq.com, or ddog-gov.com.');
247
- });
248
- test('throws an error when neither DATADOG_API_KEY nor DATADOG_KMS_API_KEY are given through the environment while using extensionVersion', () => {
380
+ let error;
381
+ try {
382
+ yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
383
+ }
384
+ catch (e) {
385
+ if (e instanceof Error) {
386
+ error = e;
387
+ }
388
+ }
389
+ expect(error === null || error === void 0 ? void 0 : error.message).toBe('Warning: Invalid site URL. Must be either datadoghq.com, datadoghq.eu, us3.datadoghq.com, us5.datadoghq.com, or ddog-gov.com.');
390
+ }));
391
+ test('throws an error when neither DATADOG_API_KEY nor DATADOG_KMS_API_KEY are given through the environment while using extensionVersion', () => __awaiter(void 0, void 0, void 0, function* () {
249
392
  const config = {
250
393
  FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
251
394
  Handler: 'index.handler',
@@ -259,47 +402,49 @@ describe('instrument', () => {
259
402
  mergeXrayTraces: false,
260
403
  tracingEnabled: false,
261
404
  };
262
- const lambdaLibraryLayerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:Datadog-Python36`;
263
- const lambdaExtensionLayerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:Datadog-Extension`;
405
+ const region = 'us-east-1';
264
406
  const runtime = 'python3.6';
265
- expect(() => {
266
- instrument_1.calculateUpdateRequest(config, settings, lambdaLibraryLayerArn, lambdaExtensionLayerArn, runtime);
267
- }).toThrowError("When 'extensionLayer' is set, DATADOG_API_KEY or DATADOG_KMS_API_KEY must also be set");
268
- });
269
- });
270
- describe('getExtensionArn', () => {
271
- const OLD_ENV = process.env;
272
- beforeEach(() => {
273
- jest.resetModules();
274
- process.env = {};
275
- });
276
- afterAll(() => {
277
- process.env = OLD_ENV;
278
- });
279
- test('gets sa-east-1 Lambda Extension layer ARN', () => __awaiter(void 0, void 0, void 0, function* () {
280
- const settings = {
281
- flushMetricsToLogs: false,
282
- layerAWSAccount: fixtures_1.mockAwsAccount,
283
- mergeXrayTraces: false,
284
- tracingEnabled: false,
285
- };
286
- const region = 'sa-east-1';
287
- const layerArn = instrument_1.getExtensionArn(settings, region);
288
- expect(layerArn).toEqual(`arn:aws:lambda:${region}:${fixtures_1.mockAwsAccount}:layer:Datadog-Extension`);
407
+ let error;
408
+ try {
409
+ yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
410
+ }
411
+ catch (e) {
412
+ if (e instanceof Error) {
413
+ error = e;
414
+ }
415
+ }
416
+ expect(error === null || error === void 0 ? void 0 : error.message).toBe("When 'extensionLayer' is set, DATADOG_API_KEY, DATADOG_KMS_API_KEY, or DATADOG_API_KEY_SECRET_ARN must also be set");
289
417
  }));
290
- test('gets sa-east-1 gov cloud Lambda Extension layer ARN', () => __awaiter(void 0, void 0, void 0, function* () {
418
+ test('throws error when trying to add `DD_API_KEY_SECRET_ARN` while using sync metrics in a node runtime', () => __awaiter(void 0, void 0, void 0, function* () {
419
+ process.env[constants_1.CI_API_KEY_SECRET_ARN_ENV_VAR] = 'some-secret:arn:from:aws';
420
+ const runtime = 'nodejs14.x';
421
+ const region = 'us-east-1';
422
+ const config = {
423
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
424
+ Handler: 'index.handler',
425
+ Layers: [],
426
+ Runtime: runtime,
427
+ };
291
428
  const settings = {
292
429
  flushMetricsToLogs: false,
293
430
  layerAWSAccount: fixtures_1.mockAwsAccount,
431
+ layerVersion: 13,
294
432
  mergeXrayTraces: false,
295
433
  tracingEnabled: false,
296
434
  };
297
- const region = 'us-gov-1';
298
- const layerArn = instrument_1.getExtensionArn(settings, region);
299
- expect(layerArn).toEqual(`arn:aws-us-gov:lambda:${region}:${constants_1.GOVCLOUD_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension`);
435
+ let error;
436
+ try {
437
+ yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
438
+ }
439
+ catch (e) {
440
+ if (e instanceof Error) {
441
+ error = e;
442
+ }
443
+ }
444
+ expect(error === null || error === void 0 ? void 0 : error.message).toBe('`apiKeySecretArn` is not supported for Node runtimes when using Synchronous Metrics. Use either `apiKey` or `apiKmsKey`.');
300
445
  }));
301
446
  });
302
- describe('getFunctionConfig', () => {
447
+ describe('getInstrumentedFunctionConfig', () => {
303
448
  const OLD_ENV = process.env;
304
449
  beforeEach(() => {
305
450
  jest.resetModules();
@@ -325,7 +470,7 @@ describe('instrument', () => {
325
470
  const config = (yield lambda
326
471
  .getFunction({ FunctionName: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument' })
327
472
  .promise()).Configuration;
328
- yield expect(instrument_1.getFunctionConfig(lambda, cloudWatch, config, 'us-east-1', settings)).rejects.toThrow();
473
+ yield expect(instrument_1.getInstrumentedFunctionConfig(lambda, cloudWatch, config, 'us-east-1', settings)).rejects.toThrow();
329
474
  }));
330
475
  test('replaces the layer arn when the version has changed', () => __awaiter(void 0, void 0, void 0, function* () {
331
476
  var _a;
@@ -349,7 +494,7 @@ describe('instrument', () => {
349
494
  const config = (yield lambda
350
495
  .getFunction({ FunctionName: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument' })
351
496
  .promise()).Configuration;
352
- const result = yield instrument_1.getFunctionConfig(lambda, cloudWatch, config, 'us-east-1', settings);
497
+ const result = yield instrument_1.getInstrumentedFunctionConfig(lambda, cloudWatch, config, 'us-east-1', settings);
353
498
  expect((_a = result.updateRequest) === null || _a === void 0 ? void 0 : _a.Layers).toMatchInlineSnapshot(`
354
499
  Array [
355
500
  "arn:aws:lambda:us-east-1:464622532012:layer:AnotherLayer:10",
@@ -387,7 +532,8 @@ describe('instrument', () => {
387
532
  const config = (yield lambda
388
533
  .getFunction({ FunctionName: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument' })
389
534
  .promise()).Configuration;
390
- expect((yield instrument_1.getFunctionConfig(lambda, cloudWatch, config, 'us-east-1', settings)).updateRequest).toBeUndefined();
535
+ expect((yield instrument_1.getInstrumentedFunctionConfig(lambda, cloudWatch, config, 'us-east-1', settings))
536
+ .updateRequest).toBeUndefined();
391
537
  }));
392
538
  test('uses the GovCloud lambda layer when a GovCloud region is detected', () => __awaiter(void 0, void 0, void 0, function* () {
393
539
  var _b;
@@ -407,7 +553,7 @@ describe('instrument', () => {
407
553
  const config = (yield lambda
408
554
  .getFunction({ FunctionName: 'arn:aws-us-gov:lambda:us-gov-east-1:000000000000:function:autoinstrument' })
409
555
  .promise()).Configuration;
410
- const result = yield instrument_1.getFunctionConfig(lambda, cloudWatch, config, 'us-gov-east-1', settings);
556
+ const result = yield instrument_1.getInstrumentedFunctionConfig(lambda, cloudWatch, config, 'us-gov-east-1', settings);
411
557
  expect((_b = result.updateRequest) === null || _b === void 0 ? void 0 : _b.Layers).toMatchInlineSnapshot(`
412
558
  Array [
413
559
  "arn:aws-us-gov:lambda:us-gov-east-1:002406178527:layer:Datadog-Node12-x:30",
@@ -435,7 +581,7 @@ describe('instrument', () => {
435
581
  const config = (yield lambda
436
582
  .getFunction({ FunctionName: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument' })
437
583
  .promise()).Configuration;
438
- const result = yield instrument_1.getFunctionConfig(lambda, cloudWatch, config, 'us-east-1', settings);
584
+ const result = yield instrument_1.getInstrumentedFunctionConfig(lambda, cloudWatch, config, 'us-east-1', settings);
439
585
  expect(result).toBeDefined();
440
586
  expect(result.logGroupConfiguration).toMatchInlineSnapshot(`
441
587
  Object {
@@ -444,7 +590,7 @@ describe('instrument', () => {
444
590
  `);
445
591
  }));
446
592
  });
447
- describe('getLambdaConfigs', () => {
593
+ describe('getInstrumentedFunctionConfigs', () => {
448
594
  const OLD_ENV = process.env;
449
595
  beforeEach(() => {
450
596
  jest.resetModules();
@@ -472,7 +618,7 @@ describe('instrument', () => {
472
618
  tracingEnabled: false,
473
619
  version: '0.2',
474
620
  };
475
- const result = yield instrument_1.getFunctionConfigs(lambda, cloudWatch, 'us-east-1', ['arn:aws:lambda:us-east-1:000000000000:function:autoinstrument'], settings);
621
+ const result = yield instrument_1.getInstrumentedFunctionConfigs(lambda, cloudWatch, 'us-east-1', ['arn:aws:lambda:us-east-1:000000000000:function:autoinstrument'], settings);
476
622
  expect(result.length).toEqual(1);
477
623
  expect(result[0].updateRequest).toMatchInlineSnapshot(`
478
624
  Object {
@@ -531,14 +677,14 @@ describe('instrument', () => {
531
677
  tracingEnabled: false,
532
678
  version: '0.2',
533
679
  };
534
- const result = yield instrument_1.getFunctionConfigs(lambda, cloudWatch, 'us-east-1', [
680
+ const result = yield instrument_1.getInstrumentedFunctionConfigs(lambda, cloudWatch, 'us-east-1', [
535
681
  'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument',
536
682
  'arn:aws:lambda:us-east-1:000000000000:function:another-func',
537
683
  ], settings);
538
684
  expect(result.length).toEqual(2);
539
685
  }));
540
686
  });
541
- describe('getLambdaConfigsFromRegEx', () => {
687
+ describe('getInstrumentedFunctionConfigsFromRegEx', () => {
542
688
  const OLD_ENV = process.env;
543
689
  beforeEach(() => {
544
690
  jest.resetModules();
@@ -570,7 +716,7 @@ describe('instrument', () => {
570
716
  mergeXrayTraces: false,
571
717
  tracingEnabled: false,
572
718
  };
573
- const result = yield instrument_1.getLambdaConfigsFromRegEx(lambda, cloudWatch, 'us-east-1', 'autoinstrument-scr.', settings);
719
+ const result = yield instrument_1.getInstrumentedFunctionConfigsFromRegEx(lambda, cloudWatch, 'us-east-1', 'autoinstrument-scr.', settings);
574
720
  expect(result.length).toEqual(1);
575
721
  expect(result[0].updateRequest).toMatchInlineSnapshot(`
576
722
  Object {
@@ -607,41 +753,7 @@ describe('instrument', () => {
607
753
  mergeXrayTraces: false,
608
754
  tracingEnabled: false,
609
755
  };
610
- yield expect(instrument_1.getLambdaConfigsFromRegEx(lambda, cloudWatch, 'us-east-1', 'fake-pattern', settings)).rejects.toStrictEqual(new Error('Max retry count exceeded.'));
611
- }));
612
- });
613
- describe('getLayerArn', () => {
614
- const OLD_ENV = process.env;
615
- beforeEach(() => {
616
- jest.resetModules();
617
- process.env = {};
618
- });
619
- afterAll(() => {
620
- process.env = OLD_ENV;
621
- });
622
- test('gets sa-east-1 Node12 Lambda Library layer ARN', () => __awaiter(void 0, void 0, void 0, function* () {
623
- const runtime = 'nodejs12.x';
624
- const settings = {
625
- flushMetricsToLogs: false,
626
- layerAWSAccount: fixtures_1.mockAwsAccount,
627
- mergeXrayTraces: false,
628
- tracingEnabled: false,
629
- };
630
- const region = 'sa-east-1';
631
- const layerArn = instrument_1.getLayerArn(runtime, settings, region);
632
- expect(layerArn).toEqual(`arn:aws:lambda:${region}:${fixtures_1.mockAwsAccount}:layer:Datadog-Node12-x`);
633
- }));
634
- test('gets sa-east-1 Python37 gov cloud Lambda Library layer ARN', () => __awaiter(void 0, void 0, void 0, function* () {
635
- const runtime = 'python3.7';
636
- const settings = {
637
- flushMetricsToLogs: false,
638
- layerAWSAccount: fixtures_1.mockAwsAccount,
639
- mergeXrayTraces: false,
640
- tracingEnabled: false,
641
- };
642
- const region = 'us-gov-1';
643
- const layerArn = instrument_1.getLayerArn(runtime, settings, region);
644
- expect(layerArn).toEqual(`arn:aws-us-gov:lambda:${region}:${constants_1.GOVCLOUD_LAYER_AWS_ACCOUNT}:layer:Datadog-Python37`);
756
+ yield expect(instrument_1.getInstrumentedFunctionConfigsFromRegEx(lambda, cloudWatch, 'us-east-1', 'fake-pattern', settings)).rejects.toStrictEqual(new Error('Max retry count exceeded.'));
645
757
  }));
646
758
  });
647
759
  });