@datadog/datadog-ci 0.17.12 → 0.18.1

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 (60) hide show
  1. package/README.md +6 -1
  2. package/dist/commands/git-metadata/__tests__/git.test.js +44 -2
  3. package/dist/commands/git-metadata/__tests__/library.test.d.ts +1 -0
  4. package/dist/commands/git-metadata/__tests__/library.test.js +82 -0
  5. package/dist/commands/git-metadata/git.d.ts +1 -2
  6. package/dist/commands/git-metadata/git.js +13 -25
  7. package/dist/commands/git-metadata/index.d.ts +1 -0
  8. package/dist/commands/git-metadata/index.js +13 -0
  9. package/dist/commands/git-metadata/library.d.ts +6 -0
  10. package/dist/commands/git-metadata/library.js +68 -0
  11. package/dist/commands/git-metadata/upload.d.ts +1 -2
  12. package/dist/commands/git-metadata/upload.js +31 -27
  13. package/dist/commands/junit/upload.js +1 -1
  14. package/dist/commands/lambda/__tests__/fixtures.d.ts +5 -1
  15. package/dist/commands/lambda/__tests__/fixtures.js +13 -2
  16. package/dist/commands/lambda/__tests__/functions/commons.test.js +267 -2
  17. package/dist/commands/lambda/__tests__/functions/instrument.test.js +64 -42
  18. package/dist/commands/lambda/__tests__/functions/uninstrument.test.js +34 -0
  19. package/dist/commands/lambda/__tests__/instrument.test.js +644 -5
  20. package/dist/commands/lambda/__tests__/prompt.test.d.ts +1 -0
  21. package/dist/commands/lambda/__tests__/prompt.test.js +216 -0
  22. package/dist/commands/lambda/__tests__/uninstrument.test.js +310 -4
  23. package/dist/commands/lambda/constants.d.ts +46 -16
  24. package/dist/commands/lambda/constants.js +66 -18
  25. package/dist/commands/lambda/functions/commons.d.ts +20 -3
  26. package/dist/commands/lambda/functions/commons.js +116 -9
  27. package/dist/commands/lambda/functions/instrument.d.ts +1 -1
  28. package/dist/commands/lambda/functions/instrument.js +69 -26
  29. package/dist/commands/lambda/functions/uninstrument.js +23 -7
  30. package/dist/commands/lambda/instrument.d.ts +2 -0
  31. package/dist/commands/lambda/instrument.js +104 -48
  32. package/dist/commands/lambda/interfaces.d.ts +4 -0
  33. package/dist/commands/lambda/prompt.d.ts +9 -0
  34. package/dist/commands/lambda/prompt.js +187 -0
  35. package/dist/commands/lambda/uninstrument.d.ts +1 -0
  36. package/dist/commands/lambda/uninstrument.js +68 -30
  37. package/dist/commands/synthetics/__tests__/cli.test.js +1 -0
  38. package/dist/commands/synthetics/__tests__/fixtures.js +1 -0
  39. package/dist/commands/synthetics/__tests__/run-test.test.js +48 -2
  40. package/dist/commands/synthetics/__tests__/utils.test.js +38 -0
  41. package/dist/commands/synthetics/command.d.ts +1 -0
  42. package/dist/commands/synthetics/command.js +11 -5
  43. package/dist/commands/synthetics/crypto.d.ts +2 -1
  44. package/dist/commands/synthetics/interfaces.d.ts +13 -4
  45. package/dist/commands/synthetics/interfaces.js +7 -3
  46. package/dist/commands/synthetics/reporters/default.js +5 -1
  47. package/dist/commands/synthetics/run-test.d.ts +2 -0
  48. package/dist/commands/synthetics/run-test.js +3 -1
  49. package/dist/commands/synthetics/utils.d.ts +4 -0
  50. package/dist/commands/synthetics/utils.js +44 -16
  51. package/dist/commands/trace/api.js +1 -1
  52. package/dist/helpers/__tests__/ci.test.js +71 -24
  53. package/dist/helpers/__tests__/user-provided-git.test.js +69 -27
  54. package/dist/helpers/ci.js +1 -1
  55. package/dist/helpers/git.js +1 -1
  56. package/dist/helpers/user-provided-git.d.ts +2 -1
  57. package/dist/helpers/user-provided-git.js +18 -3
  58. package/dist/index.d.ts +2 -1
  59. package/dist/index.js +3 -1
  60. package/package.json +1 -1
@@ -10,6 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  /* tslint:disable:no-string-literal */
13
+ jest.mock('aws-sdk');
14
+ const aws_sdk_1 = require("aws-sdk");
13
15
  const constants_1 = require("../../constants");
14
16
  const commons_1 = require("../../functions/commons");
15
17
  const instrument_1 = require("../../instrument");
@@ -26,7 +28,7 @@ describe('commons', () => {
26
28
  'arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:10',
27
29
  ];
28
30
  const region = 'sa-east-1';
29
- const lambdaLibraryLayerName = constants_1.RUNTIME_LAYER_LOOKUP[runtime];
31
+ const lambdaLibraryLayerName = constants_1.LAYER_LOOKUP[runtime];
30
32
  const fullLambdaLibraryLayerArn = commons_1.getLayerArn(config, config.Runtime, region) + ':49';
31
33
  const fullExtensionLayerArn = commons_1.getLayerArn(config, constants_1.EXTENSION_LAYER_KEY, region) + ':11';
32
34
  layerARNs = commons_1.addLayerArn(fullLambdaLibraryLayerArn, lambdaLibraryLayerName, layerARNs);
@@ -47,7 +49,7 @@ describe('commons', () => {
47
49
  'arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:11',
48
50
  ];
49
51
  const region = 'sa-east-1';
50
- const lambdaLibraryLayerName = constants_1.RUNTIME_LAYER_LOOKUP[runtime];
52
+ const lambdaLibraryLayerName = constants_1.LAYER_LOOKUP[runtime];
51
53
  const fullLambdaLibraryLayerArn = commons_1.getLayerArn(config, config.Runtime, region) + ':49';
52
54
  const fullExtensionLayerArn = commons_1.getLayerArn(config, constants_1.EXTENSION_LAYER_KEY, region) + ':11';
53
55
  layerARNs = commons_1.addLayerArn(fullLambdaLibraryLayerArn, lambdaLibraryLayerName, layerARNs);
@@ -144,6 +146,197 @@ describe('commons', () => {
144
146
  expect(functionsGroup).toBeUndefined();
145
147
  });
146
148
  });
149
+ describe('findLatestLayerVersion', () => {
150
+ test('finds latests version for Python39', () => __awaiter(void 0, void 0, void 0, function* () {
151
+ const layer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Python39`;
152
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}, {
153
+ [`${layer}:1`]: {
154
+ LayerVersionArn: `${layer}:1`,
155
+ Version: 1,
156
+ },
157
+ [`${layer}:2`]: {
158
+ LayerVersionArn: `${layer}:2`,
159
+ Version: 2,
160
+ },
161
+ [`${layer}:10`]: {
162
+ LayerVersionArn: `${layer}:10`,
163
+ Version: 10,
164
+ },
165
+ [`${layer}:20`]: {
166
+ LayerVersionArn: `${layer}:20`,
167
+ Version: 20,
168
+ },
169
+ [`${layer}:30`]: {
170
+ LayerVersionArn: `${layer}:30`,
171
+ Version: 30,
172
+ },
173
+ [`${layer}:31`]: {
174
+ LayerVersionArn: `${layer}:31`,
175
+ Version: 31,
176
+ },
177
+ [`${layer}:32`]: {
178
+ LayerVersionArn: `${layer}:32`,
179
+ Version: 32,
180
+ },
181
+ }));
182
+ const runtime = 'python3.9';
183
+ const region = 'sa-east-1';
184
+ const expectedLatestVersion = 32;
185
+ const latestVersionFound = yield commons_1.findLatestLayerVersion(runtime, region);
186
+ expect(latestVersionFound).toBe(expectedLatestVersion);
187
+ }));
188
+ test('finds latests version for Node14', () => __awaiter(void 0, void 0, void 0, function* () {
189
+ const layer = `arn:aws:lambda:us-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node14-x`;
190
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}, {
191
+ [`${layer}:1`]: {
192
+ LayerVersionArn: `${layer}:1`,
193
+ Version: 1,
194
+ },
195
+ [`${layer}:10`]: {
196
+ LayerVersionArn: `${layer}:10`,
197
+ Version: 10,
198
+ },
199
+ [`${layer}:20`]: {
200
+ LayerVersionArn: `${layer}:20`,
201
+ Version: 20,
202
+ },
203
+ [`${layer}:30`]: {
204
+ LayerVersionArn: `${layer}:30`,
205
+ Version: 30,
206
+ },
207
+ [`${layer}:40`]: {
208
+ LayerVersionArn: `${layer}:40`,
209
+ Version: 40,
210
+ },
211
+ [`${layer}:41`]: {
212
+ LayerVersionArn: `${layer}:41`,
213
+ Version: 41,
214
+ },
215
+ }));
216
+ const runtime = 'nodejs14.x';
217
+ const region = 'us-east-1';
218
+ const expectedLatestVersion = 41;
219
+ const latestVersionFound = yield commons_1.findLatestLayerVersion(runtime, region);
220
+ expect(latestVersionFound).toBe(expectedLatestVersion);
221
+ }));
222
+ test('returns 0 when no layer can be found', () => __awaiter(void 0, void 0, void 0, function* () {
223
+ ;
224
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}, {}));
225
+ const runtime = 'python3.7';
226
+ const region = 'us-east-1';
227
+ const expectedLatestVersion = 0;
228
+ const latestVersionFound = yield commons_1.findLatestLayerVersion(runtime, region);
229
+ expect(latestVersionFound).toBe(expectedLatestVersion);
230
+ }));
231
+ });
232
+ describe('isMissingAWSCredentials', () => {
233
+ const OLD_ENV = process.env;
234
+ beforeEach(() => {
235
+ jest.resetModules();
236
+ process.env = {};
237
+ });
238
+ afterAll(() => {
239
+ process.env = OLD_ENV;
240
+ });
241
+ test('returns true when any AWS credential is missing', () => {
242
+ process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = 'SOME-AWS-SECRET-ACCESS-KEY';
243
+ expect(commons_1.isMissingAWSCredentials()).toBe(true);
244
+ // Reset env
245
+ process.env = {};
246
+ process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = 'SOME-AWS-ACCESS-KEY-ID';
247
+ expect(commons_1.isMissingAWSCredentials()).toBe(true);
248
+ });
249
+ test('returns false when AWS credentials are set', () => {
250
+ process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = 'SOME-AWS-ACCESS-KEY-ID';
251
+ process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = 'SOME-AWS-SECRET-ACCESS-KEY';
252
+ expect(commons_1.isMissingAWSCredentials()).toBe(false);
253
+ });
254
+ });
255
+ describe('isMissingDatadogEnvVars', () => {
256
+ const OLD_ENV = process.env;
257
+ beforeEach(() => {
258
+ jest.resetModules();
259
+ process.env = {};
260
+ });
261
+ afterAll(() => {
262
+ process.env = OLD_ENV;
263
+ });
264
+ test('returns true when any Datadog Env Var is missing', () => {
265
+ process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
266
+ expect(commons_1.isMissingDatadogEnvVars()).toBe(true);
267
+ // Reset env
268
+ process.env = {};
269
+ process.env[constants_1.CI_API_KEY_ENV_VAR] = 'SOME-DATADOG-API-KEY';
270
+ expect(commons_1.isMissingDatadogEnvVars()).toBe(true);
271
+ process.env = {};
272
+ process.env[constants_1.CI_KMS_API_KEY_ENV_VAR] = 'SOME-AWS-KMS-API-KEY-CONTAINING-DATADOG-API-KEY';
273
+ expect(commons_1.isMissingDatadogEnvVars()).toBe(true);
274
+ process.env = {};
275
+ process.env[constants_1.CI_API_KEY_SECRET_ARN_ENV_VAR] = 'SOME-AWS-SECRET-ARN-CONTAINING-DATADOG-API-KEY';
276
+ expect(commons_1.isMissingDatadogEnvVars()).toBe(true);
277
+ });
278
+ test('returns false when Datadog Env Vars are set with DATADOG_API_KEY', () => {
279
+ process.env[constants_1.CI_API_KEY_ENV_VAR] = 'SOME-DATADOG-API-KEY';
280
+ process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
281
+ expect(commons_1.isMissingDatadogEnvVars()).toBe(false);
282
+ });
283
+ test('returns false when Datadog Env Vars are set with DATADOG_KMS_API_KEY', () => {
284
+ process.env[constants_1.CI_KMS_API_KEY_ENV_VAR] = 'SOME-AWS-KMS-API-KEY-CONTAINING-DATADOG-API-KEY';
285
+ process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
286
+ expect(commons_1.isMissingDatadogEnvVars()).toBe(false);
287
+ });
288
+ test('returns false when Datadog Env Vars are set with DATADOG_API_KEY_SECRET_ARN', () => {
289
+ process.env[constants_1.CI_API_KEY_SECRET_ARN_ENV_VAR] = 'SOME-AWS-SECRET-ARN-CONTAINING-DATADOG-API-KEY';
290
+ process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
291
+ expect(commons_1.isMissingDatadogEnvVars()).toBe(false);
292
+ });
293
+ });
294
+ describe('isMissingDatadogSiteEnvVar', () => {
295
+ const OLD_ENV = process.env;
296
+ beforeEach(() => {
297
+ jest.resetModules();
298
+ process.env = {};
299
+ });
300
+ afterAll(() => {
301
+ process.env = OLD_ENV;
302
+ });
303
+ test('returns true when Datadog Site Env Var is missing', () => {
304
+ expect(commons_1.isMissingDatadogSiteEnvVar()).toBe(true);
305
+ });
306
+ test('returns false when Datadog Site Env Var is set', () => {
307
+ process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
308
+ expect(commons_1.isMissingDatadogSiteEnvVar()).toBe(false);
309
+ });
310
+ test('returns true when Datadog Site Env Var is set and is not a valid Datadog site', () => {
311
+ process.env[constants_1.CI_SITE_ENV_VAR] = 'datacathq.com';
312
+ expect(commons_1.isMissingDatadogSiteEnvVar()).toBe(true);
313
+ });
314
+ });
315
+ describe('isMissingAnyDatadogApiKeyEnvVar', () => {
316
+ const OLD_ENV = process.env;
317
+ beforeEach(() => {
318
+ jest.resetModules();
319
+ process.env = {};
320
+ });
321
+ afterAll(() => {
322
+ process.env = OLD_ENV;
323
+ });
324
+ test('returns true when no Datadog Api Key is set', () => {
325
+ expect(commons_1.isMissingAnyDatadogApiKeyEnvVar()).toBe(true);
326
+ });
327
+ test('returns false when DATADOG_API_KEY is set', () => {
328
+ process.env[constants_1.CI_API_KEY_ENV_VAR] = 'SOME-DATADOG-API-KEY';
329
+ expect(commons_1.isMissingAnyDatadogApiKeyEnvVar()).toBe(false);
330
+ });
331
+ test('returns false when DATADOG_KMS_API_KEY is set', () => {
332
+ process.env[constants_1.CI_KMS_API_KEY_ENV_VAR] = 'SOME-AWS-KMS-API-KEY-CONTAINING-DATADOG-API-KEY';
333
+ expect(commons_1.isMissingAnyDatadogApiKeyEnvVar()).toBe(false);
334
+ });
335
+ test('returns false when DATADOG_API_KEY_SECRET_ARN is set', () => {
336
+ process.env[constants_1.CI_API_KEY_SECRET_ARN_ENV_VAR] = 'SOME-AWS-SECRET-ARN-CONTAINING-DATADOG-API-KEY';
337
+ expect(commons_1.isMissingAnyDatadogApiKeyEnvVar()).toBe(false);
338
+ });
339
+ });
147
340
  describe('getLayerArn', () => {
148
341
  const OLD_ENV = process.env;
149
342
  beforeEach(() => {
@@ -266,6 +459,34 @@ describe('commons', () => {
266
459
  expect(layerArn).toEqual(`arn:aws-us-gov:lambda:${region}:${constants_1.GOVCLOUD_LAYER_AWS_ACCOUNT}:layer:Datadog-Python39-ARM`);
267
460
  }));
268
461
  });
462
+ describe('getLayerNameWithVersion', () => {
463
+ const OLD_ENV = process.env;
464
+ beforeEach(() => {
465
+ jest.resetModules();
466
+ process.env = {};
467
+ });
468
+ afterAll(() => {
469
+ process.env = OLD_ENV;
470
+ });
471
+ test('returns the correct name and version given an extension layer arn', () => {
472
+ const layerName = constants_1.DD_LAMBDA_EXTENSION_LAYER_NAME;
473
+ const version = '16';
474
+ const layerNameWithVersion = `${layerName}:${version}`;
475
+ const layerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:${layerNameWithVersion}`;
476
+ expect(commons_1.getLayerNameWithVersion(layerArn)).toBe(layerNameWithVersion);
477
+ });
478
+ test('returns the correct name and version given a library layer arn', () => {
479
+ const layerName = 'Datadog-Python39';
480
+ const version = '59';
481
+ const layerNameWithVersion = `${layerName}:${version}`;
482
+ const layerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:${layerNameWithVersion}`;
483
+ expect(commons_1.getLayerNameWithVersion(layerArn)).toBe(layerNameWithVersion);
484
+ });
485
+ test('returns undefined if arn is incomplete', () => {
486
+ const layerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:Datadog-Python39`;
487
+ expect(commons_1.getLayerNameWithVersion(layerArn)).toBe(undefined);
488
+ });
489
+ });
269
490
  describe('getRegion', () => {
270
491
  test('should return the expected region', () => {
271
492
  const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
@@ -347,4 +568,48 @@ describe('commons', () => {
347
568
  });
348
569
  }));
349
570
  });
571
+ describe('Correctly handles multiple runtimes', () => {
572
+ test('returns true if all runtimes are uniform', () => __awaiter(void 0, void 0, void 0, function* () {
573
+ const configs = [
574
+ {
575
+ functionARN: 'arn:aws:lambda:us-east-1:000000000000:function:func1',
576
+ lambdaConfig: {
577
+ FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:func1',
578
+ Handler: 'index.handler',
579
+ Runtime: 'nodejs14.x',
580
+ },
581
+ },
582
+ {
583
+ functionARN: 'arn:aws:lambda:us-east-1:000000000000:function:func2',
584
+ lambdaConfig: {
585
+ FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:func2',
586
+ Handler: 'index.handler',
587
+ Runtime: 'nodejs12.x',
588
+ },
589
+ },
590
+ ];
591
+ expect(commons_1.checkRuntimeTypesAreUniform(configs)).toBe(true);
592
+ }));
593
+ test('returns false if runtimes are not uniform', () => __awaiter(void 0, void 0, void 0, function* () {
594
+ const configs = [
595
+ {
596
+ functionARN: 'arn:aws:lambda:us-east-1:000000000000:function:func1',
597
+ lambdaConfig: {
598
+ FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:func1',
599
+ Handler: 'index.handler',
600
+ Runtime: 'nodejs14.x',
601
+ },
602
+ },
603
+ {
604
+ functionARN: 'arn:aws:lambda:us-east-1:000000000000:function:func2',
605
+ lambdaConfig: {
606
+ FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:func2',
607
+ Handler: 'index.handler',
608
+ Runtime: 'python3.9',
609
+ },
610
+ },
611
+ ];
612
+ expect(commons_1.checkRuntimeTypesAreUniform(configs)).toBe(false);
613
+ }));
614
+ });
350
615
  });
@@ -43,7 +43,7 @@ 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
47
  const runtime = 'nodejs12.x';
48
48
  const config = {
49
49
  FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
@@ -59,7 +59,7 @@ describe('instrument', () => {
59
59
  tracingEnabled: false,
60
60
  };
61
61
  const region = 'sa-east-1';
62
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, region, runtime);
62
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
63
63
  expect(updateRequest).toMatchInlineSnapshot(`
64
64
  Object {
65
65
  "Environment": Object {
@@ -78,8 +78,8 @@ describe('instrument', () => {
78
78
  ],
79
79
  }
80
80
  `);
81
- });
82
- test('calculates an update request with just lambda library layers in arm architecture', () => {
81
+ }));
82
+ test('calculates an update request with just lambda library layers in arm architecture', () => __awaiter(void 0, void 0, void 0, function* () {
83
83
  const runtime = 'python3.9';
84
84
  const config = {
85
85
  Architectures: ['arm64'],
@@ -96,7 +96,7 @@ describe('instrument', () => {
96
96
  tracingEnabled: false,
97
97
  };
98
98
  const region = 'sa-east-1';
99
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, region, runtime);
99
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
100
100
  expect(updateRequest).toMatchInlineSnapshot(`
101
101
  Object {
102
102
  "Environment": Object {
@@ -115,8 +115,8 @@ describe('instrument', () => {
115
115
  ],
116
116
  }
117
117
  `);
118
- });
119
- test('calculates an update request with a lambda library, extension, and DATADOG_API_KEY', () => {
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
120
  process.env[constants_1.CI_API_KEY_ENV_VAR] = '1234';
121
121
  const runtime = 'nodejs12.x';
122
122
  const config = {
@@ -134,7 +134,7 @@ describe('instrument', () => {
134
134
  tracingEnabled: false,
135
135
  };
136
136
  const region = 'sa-east-1';
137
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, region, runtime);
137
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
138
138
  expect(updateRequest).toMatchInlineSnapshot(`
139
139
  Object {
140
140
  "Environment": Object {
@@ -154,8 +154,8 @@ describe('instrument', () => {
154
154
  ],
155
155
  }
156
156
  `);
157
- });
158
- test('calculates an update request with a lambda library, extension, and DATADOG_API_KEY_SECRET_ARN', () => {
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
159
  process.env[constants_1.CI_API_KEY_SECRET_ARN_ENV_VAR] = 'some-secret:arn:from:aws';
160
160
  const runtime = 'python3.9';
161
161
  const config = {
@@ -173,7 +173,7 @@ describe('instrument', () => {
173
173
  tracingEnabled: false,
174
174
  };
175
175
  const region = 'sa-east-1';
176
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, region, runtime);
176
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
177
177
  expect(updateRequest).toMatchInlineSnapshot(`
178
178
  Object {
179
179
  "Environment": Object {
@@ -193,8 +193,8 @@ describe('instrument', () => {
193
193
  ],
194
194
  }
195
195
  `);
196
- });
197
- test('calculates an update request with a lambda library, extension, and DATADOG_KMS_API_KEY', () => {
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
198
  process.env[constants_1.CI_KMS_API_KEY_ENV_VAR] = '5678';
199
199
  const runtime = 'python3.6';
200
200
  const config = {
@@ -212,7 +212,7 @@ describe('instrument', () => {
212
212
  tracingEnabled: false,
213
213
  };
214
214
  const region = 'sa-east-1';
215
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, region, runtime);
215
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
216
216
  expect(updateRequest).toMatchInlineSnapshot(`
217
217
  Object {
218
218
  "Environment": Object {
@@ -232,8 +232,8 @@ describe('instrument', () => {
232
232
  ],
233
233
  }
234
234
  `);
235
- });
236
- test('prioritizes the KMS API KEY when all of them are exported', () => {
235
+ }));
236
+ test('prioritizes the KMS API KEY when all of them are exported', () => __awaiter(void 0, void 0, void 0, function* () {
237
237
  process.env = {
238
238
  [constants_1.CI_API_KEY_ENV_VAR]: '1234',
239
239
  [constants_1.CI_API_KEY_SECRET_ARN_ENV_VAR]: '5678',
@@ -246,7 +246,7 @@ describe('instrument', () => {
246
246
  };
247
247
  const runtime = 'python3.9';
248
248
  const region = 'sa-east-1';
249
- const updateRequest = instrument_1.calculateUpdateRequest(config, {}, region, runtime);
249
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, {}, region, runtime);
250
250
  expect(updateRequest).toMatchInlineSnapshot(`
251
251
  Object {
252
252
  "Environment": Object {
@@ -260,8 +260,8 @@ describe('instrument', () => {
260
260
  "Handler": "datadog_lambda.handler.handler",
261
261
  }
262
262
  `);
263
- });
264
- test("doesn't set DD_FLUSH_TO_LOGS when extension is being used", () => {
263
+ }));
264
+ test("doesn't set DD_FLUSH_TO_LOGS when extension is being used", () => __awaiter(void 0, void 0, void 0, function* () {
265
265
  process.env[constants_1.CI_API_KEY_ENV_VAR] = '1234';
266
266
  const config = {
267
267
  FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
@@ -276,7 +276,7 @@ describe('instrument', () => {
276
276
  mergeXrayTraces: false,
277
277
  tracingEnabled: false,
278
278
  };
279
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, region, runtime);
279
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
280
280
  expect(updateRequest).toMatchInlineSnapshot(`
281
281
  Object {
282
282
  "Environment": Object {
@@ -295,8 +295,8 @@ describe('instrument', () => {
295
295
  ],
296
296
  }
297
297
  `);
298
- });
299
- test('by default calculates an update request with DATADOG_SITE being set to datadoghq.com', () => {
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
300
  const runtime = 'python3.6';
301
301
  const config = {
302
302
  FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
@@ -311,7 +311,7 @@ describe('instrument', () => {
311
311
  tracingEnabled: false,
312
312
  };
313
313
  const region = 'sa-east-1';
314
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, region, runtime);
314
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
315
315
  expect(updateRequest).toMatchInlineSnapshot(`
316
316
  Object {
317
317
  "Environment": Object {
@@ -327,8 +327,8 @@ describe('instrument', () => {
327
327
  "Handler": "datadog_lambda.handler.handler",
328
328
  }
329
329
  `);
330
- });
331
- 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* () {
332
332
  process.env.DATADOG_SITE = 'datadoghq.eu';
333
333
  const config = {
334
334
  FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
@@ -343,7 +343,7 @@ describe('instrument', () => {
343
343
  };
344
344
  const region = 'sa-east-1';
345
345
  const runtime = 'python3.6';
346
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, region, runtime);
346
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
347
347
  expect(updateRequest).toMatchInlineSnapshot(`
348
348
  Object {
349
349
  "Environment": Object {
@@ -359,8 +359,8 @@ describe('instrument', () => {
359
359
  "Handler": "datadog_lambda.handler.handler",
360
360
  }
361
361
  `);
362
- });
363
- 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* () {
364
364
  process.env.DATADOG_SITE = 'datacathq.eu';
365
365
  const config = {
366
366
  FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
@@ -369,6 +369,7 @@ describe('instrument', () => {
369
369
  };
370
370
  const settings = {
371
371
  flushMetricsToLogs: false,
372
+ interactive: false,
372
373
  layerAWSAccount: fixtures_1.mockAwsAccount,
373
374
  layerVersion: 5,
374
375
  mergeXrayTraces: false,
@@ -376,11 +377,18 @@ describe('instrument', () => {
376
377
  };
377
378
  const region = 'us-east-1';
378
379
  const runtime = 'python3.6';
379
- expect(() => {
380
- instrument_1.calculateUpdateRequest(config, settings, region, runtime);
381
- }).toThrowError('Warning: Invalid site URL. Must be either datadoghq.com, datadoghq.eu, us3.datadoghq.com, us5.datadoghq.com, or ddog-gov.com.');
382
- });
383
- 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* () {
384
392
  const config = {
385
393
  FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
386
394
  Handler: 'index.handler',
@@ -396,11 +404,18 @@ describe('instrument', () => {
396
404
  };
397
405
  const region = 'us-east-1';
398
406
  const runtime = 'python3.6';
399
- expect(() => {
400
- instrument_1.calculateUpdateRequest(config, settings, region, runtime);
401
- }).toThrowError("When 'extensionLayer' is set, DATADOG_API_KEY, DATADOG_KMS_API_KEY, or DATADOG_API_KEY_SECRET_ARN must also be set");
402
- });
403
- test('throws error when trying to add `DD_API_KEY_SECRET_ARN` while using sync metrics in a node runtime', () => {
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");
417
+ }));
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* () {
404
419
  process.env[constants_1.CI_API_KEY_SECRET_ARN_ENV_VAR] = 'some-secret:arn:from:aws';
405
420
  const runtime = 'nodejs14.x';
406
421
  const region = 'us-east-1';
@@ -417,10 +432,17 @@ describe('instrument', () => {
417
432
  mergeXrayTraces: false,
418
433
  tracingEnabled: false,
419
434
  };
420
- expect(() => {
421
- instrument_1.calculateUpdateRequest(config, settings, region, runtime);
422
- }).toThrowError('`apiKeySecretArn` is not supported for Node runtimes when using Synchronous Metrics. Use either `apiKey` or `apiKmsKey`.');
423
- });
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`.');
445
+ }));
424
446
  });
425
447
  describe('getInstrumentedFunctionConfig', () => {
426
448
  const OLD_ENV = process.env;
@@ -235,6 +235,40 @@ describe('uninstrument', () => {
235
235
  }
236
236
  `);
237
237
  }));
238
+ test('correctly removes .NET env vars', () => __awaiter(void 0, void 0, void 0, function* () {
239
+ const lambda = fixtures_1.makeMockLambda({
240
+ 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument': {
241
+ Environment: {
242
+ Variables: {
243
+ [constants_1.FLUSH_TO_LOG_ENV_VAR]: 'false',
244
+ [constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
245
+ [constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
246
+ [constants_1.SITE_ENV_VAR]: 'datadoghq.com',
247
+ [constants_1.TRACE_ENABLED_ENV_VAR]: 'false',
248
+ [constants_1.SERVICE_ENV_VAR]: 'middletier',
249
+ [constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
250
+ [constants_1.VERSION_ENV_VAR]: '0.2',
251
+ [constants_1.ENABLE_PROFILING_ENV_VAR]: '1',
252
+ [constants_1.PROFILER_ENV_VAR]: '{846F5F1C-F9AE-4B07-969E-05C26BC060D8}',
253
+ [constants_1.PROFILER_PATH_ENV_VAR]: '/opt/datadog/Datadog.Trace.ClrProfiler.Native.so',
254
+ [constants_1.DOTNET_TRACER_HOME_ENV_VAR]: '/opt/datadog',
255
+ },
256
+ },
257
+ FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument',
258
+ Runtime: 'dotnetcore3.1',
259
+ },
260
+ });
261
+ const cloudWatch = fixtures_1.makeMockCloudWatchLogs({});
262
+ const result = yield uninstrument_1.getUninstrumentedFunctionConfigs(lambda, cloudWatch, ['arn:aws:lambda:us-east-1:000000000000:function:uninstrument'], undefined);
263
+ expect(result[0].updateRequest).toMatchInlineSnapshot(`
264
+ Object {
265
+ "Environment": Object {
266
+ "Variables": Object {},
267
+ },
268
+ "FunctionName": "arn:aws:lambda:us-east-1:000000000000:function:uninstrument",
269
+ }
270
+ `);
271
+ }));
238
272
  });
239
273
  describe('getUninstrumentedFunctionConfig', () => {
240
274
  const OLD_ENV = process.env;