@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
@@ -34,12 +34,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
34
34
  // tslint:disable: no-string-literal
35
35
  jest.mock('fs');
36
36
  jest.mock('aws-sdk');
37
+ jest.mock('../prompt');
37
38
  const aws_sdk_1 = require("aws-sdk");
38
39
  const chalk_1 = require("chalk");
39
40
  const advanced_1 = require("clipanion/lib/advanced");
40
41
  const fs = __importStar(require("fs"));
41
42
  const path_1 = __importDefault(require("path"));
43
+ const constants_1 = require("../constants");
42
44
  const instrument_1 = require("../instrument");
45
+ const prompt_1 = require("../prompt");
43
46
  const fixtures_1 = require("./fixtures");
44
47
  // tslint:disable-next-line
45
48
  const { version } = require(path_1.default.join(__dirname, '../../../../package.json'));
@@ -101,6 +104,7 @@ UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:123456789012:function:la
101
104
  \\"Variables\\": {
102
105
  \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
103
106
  \\"DD_SITE\\": \\"datadoghq.com\\",
107
+ \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
104
108
  \\"DD_ENV\\": \\"staging\\",
105
109
  \\"DD_TAGS\\": \\"layer:api,team:intake\\",
106
110
  \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
@@ -120,6 +124,83 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
120
124
  \\"dd_sls_ci\\": \\"v${version}\\"
121
125
  }
122
126
  "
127
+ `);
128
+ }));
129
+ test('prints dry run data for lambda library and extension layers using kebab case args', () => __awaiter(void 0, void 0, void 0, function* () {
130
+ ;
131
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
132
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
133
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
134
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
135
+ Handler: 'index.handler',
136
+ Runtime: 'nodejs12.x',
137
+ },
138
+ }));
139
+ const cli = fixtures_1.makeCli();
140
+ const context = fixtures_1.createMockContext();
141
+ const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
142
+ process.env.DATADOG_API_KEY = '1234';
143
+ const code = yield cli.run([
144
+ 'lambda',
145
+ 'instrument',
146
+ '-f',
147
+ functionARN,
148
+ '--dry',
149
+ '--service',
150
+ 'middletier',
151
+ '--env',
152
+ 'staging',
153
+ '--version',
154
+ '0.2',
155
+ '--extra-tags',
156
+ 'layer:api,team:intake',
157
+ '--layer-version',
158
+ '10',
159
+ '--extension-version',
160
+ '5',
161
+ '--merge-xray-traces',
162
+ 'true',
163
+ '--flush-metrics-to-logs',
164
+ 'false',
165
+ '--log-level',
166
+ 'debug',
167
+ ], context);
168
+ const output = context.stdout.toString();
169
+ expect(code).toBe(0);
170
+ expect(output).toMatchInlineSnapshot(`
171
+ "${chalk_1.bold(chalk_1.yellow('[Warning]'))} Instrument your ${chalk_1.hex('#FF9900').bold('Lambda')} functions in a dev or staging environment first. Should the instrumentation result be unsatisfactory, run \`${chalk_1.bold('uninstrument')}\` with the same arguments to revert the changes.
172
+ \n${chalk_1.bold(chalk_1.yellow('[!]'))} Functions to be updated:
173
+ \t- ${chalk_1.bold('arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world')}\n
174
+ ${chalk_1.bold(chalk_1.cyan('[Dry Run] '))}Will apply the following updates:
175
+ UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
176
+ {
177
+ \\"FunctionName\\": \\"arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\\",
178
+ \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
179
+ \\"Environment\\": {
180
+ \\"Variables\\": {
181
+ \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
182
+ \\"DD_API_KEY\\": \\"1234\\",
183
+ \\"DD_SITE\\": \\"datadoghq.com\\",
184
+ \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
185
+ \\"DD_ENV\\": \\"staging\\",
186
+ \\"DD_TAGS\\": \\"layer:api,team:intake\\",
187
+ \\"DD_MERGE_XRAY_TRACES\\": \\"true\\",
188
+ \\"DD_SERVICE\\": \\"middletier\\",
189
+ \\"DD_TRACE_ENABLED\\": \\"true\\",
190
+ \\"DD_VERSION\\": \\"0.2\\",
191
+ \\"DD_LOG_LEVEL\\": \\"debug\\"
192
+ }
193
+ },
194
+ \\"Layers\\": [
195
+ \\"arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Extension:5\\",
196
+ \\"arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Node12-x:10\\"
197
+ ]
198
+ }
199
+ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
200
+ {
201
+ \\"dd_sls_ci\\": \\"v${version}\\"
202
+ }
203
+ "
123
204
  `);
124
205
  }));
125
206
  test('prints dry run data for lambda extension layer', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -169,6 +250,7 @@ UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:123456789012:function:la
169
250
  \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
170
251
  \\"DD_API_KEY\\": \\"1234\\",
171
252
  \\"DD_SITE\\": \\"datadoghq.com\\",
253
+ \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
172
254
  \\"DD_ENV\\": \\"staging\\",
173
255
  \\"DD_TAGS\\": \\"layer:api,team:intake\\",
174
256
  \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
@@ -186,6 +268,75 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
186
268
  \\"dd_sls_ci\\": \\"v${version}\\"
187
269
  }
188
270
  "
271
+ `);
272
+ }));
273
+ test('prints dry run data for lambda .NET layer', () => __awaiter(void 0, void 0, void 0, function* () {
274
+ ;
275
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
276
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
277
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
278
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
279
+ Runtime: 'dotnetcore3.1',
280
+ },
281
+ }));
282
+ const cli = fixtures_1.makeCli();
283
+ const context = fixtures_1.createMockContext();
284
+ const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
285
+ process.env.DATADOG_API_KEY = '1234';
286
+ const code = yield cli.run([
287
+ 'lambda',
288
+ 'instrument',
289
+ '-f',
290
+ functionARN,
291
+ '--dry',
292
+ '-v',
293
+ '129',
294
+ '--extra-tags',
295
+ 'layer:api,team:intake',
296
+ '--service',
297
+ 'middletier',
298
+ '--env',
299
+ 'staging',
300
+ '--version',
301
+ '0.2',
302
+ ], context);
303
+ const output = context.stdout.toString();
304
+ expect(code).toBe(0);
305
+ expect(output).toMatchInlineSnapshot(`
306
+ "${chalk_1.bold(chalk_1.yellow('[Warning]'))} Instrument your ${chalk_1.hex('#FF9900').bold('Lambda')} functions in a dev or staging environment first. Should the instrumentation result be unsatisfactory, run \`${chalk_1.bold('uninstrument')}\` with the same arguments to revert the changes.
307
+ \n${chalk_1.bold(chalk_1.yellow('[!]'))} Functions to be updated:
308
+ \t- ${chalk_1.bold('arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world')}\n
309
+ ${chalk_1.bold(chalk_1.cyan('[Dry Run] '))}Will apply the following updates:
310
+ UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
311
+ {
312
+ \\"FunctionName\\": \\"arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\\",
313
+ \\"Environment\\": {
314
+ \\"Variables\\": {
315
+ \\"DD_API_KEY\\": \\"1234\\",
316
+ \\"DD_SITE\\": \\"datadoghq.com\\",
317
+ \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
318
+ \\"DD_ENV\\": \\"staging\\",
319
+ \\"DD_TAGS\\": \\"layer:api,team:intake\\",
320
+ \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
321
+ \\"DD_SERVICE\\": \\"middletier\\",
322
+ \\"DD_TRACE_ENABLED\\": \\"true\\",
323
+ \\"DD_VERSION\\": \\"0.2\\",
324
+ \\"DD_FLUSH_TO_LOG\\": \\"true\\",
325
+ \\"CORECLR_ENABLE_PROFILING\\": \\"1\\",
326
+ \\"CORECLR_PROFILER\\": \\"{846F5F1C-F9AE-4B07-969E-05C26BC060D8}\\",
327
+ \\"CORECLR_PROFILER_PATH\\": \\"/opt/datadog/Datadog.Trace.ClrProfiler.Native.so\\",
328
+ \\"DD_DOTNET_TRACER_HOME\\": \\"/opt/datadog\\"
329
+ }
330
+ },
331
+ \\"Layers\\": [
332
+ \\"arn:aws:lambda:us-east-1:464622532012:layer:dd-trace-dotnet:129\\"
333
+ ]
334
+ }
335
+ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
336
+ {
337
+ \\"dd_sls_ci\\": \\"v${version}\\"
338
+ }
339
+ "
189
340
  `);
190
341
  }));
191
342
  test('instrumenting with source code integrations fails if not run within a git repo', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -218,7 +369,7 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
218
369
  '0.1',
219
370
  ], context);
220
371
  const output = context.stdout.toString();
221
- expect(output).toMatch(/.*Make sure the command is running within your git repository\..*/i);
372
+ expect(output.replace('\n', '')).toMatch(/.*Error: Couldn't get local git status.*/);
222
373
  }));
223
374
  test('instrumenting with source code integrations fails if DATADOG_API_KEY is not provided', () => __awaiter(void 0, void 0, void 0, function* () {
224
375
  ;
@@ -346,6 +497,7 @@ UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:123456789012:function:la
346
497
  \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
347
498
  \\"DD_API_KEY\\": \\"1234\\",
348
499
  \\"DD_SITE\\": \\"datadoghq.com\\",
500
+ \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
349
501
  \\"DD_ENV\\": \\"dummy\\",
350
502
  \\"DD_TAGS\\": \\"git.commit.sha:1be168ff837f043bde17c0314341c84271047b31\\",
351
503
  \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
@@ -473,7 +625,7 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
473
625
  const output = context.stdout.toString();
474
626
  expect(code).toBe(1);
475
627
  expect(output).toMatchInlineSnapshot(`
476
- "No functions specified for instrumentation.
628
+ "${chalk_1.red('[Error]')} No functions specified for instrumentation.
477
629
  "
478
630
  `);
479
631
  }));
@@ -491,7 +643,7 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
491
643
  yield command['execute']();
492
644
  const output = command.context.stdout.toString();
493
645
  expect(output).toMatchInlineSnapshot(`
494
- "No functions specified for instrumentation.
646
+ "${chalk_1.red('[Error]')} No functions specified for instrumentation.
495
647
  "
496
648
  `);
497
649
  }));
@@ -550,7 +702,7 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
550
702
  const output = context.stdout.toString();
551
703
  expect(code).toBe(1);
552
704
  expect(output).toMatchInlineSnapshot(`
553
- "Couldn't fetch lambda functions. Error: Can't instrument arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world, as current State is Failed (must be \\"Active\\") and Last Update Status is Unsuccessful (must be \\"Successful\\")
705
+ "${chalk_1.red('[Error]')} Couldn't fetch Lambda functions. Error: Can't instrument arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world, as current State is Failed (must be \\"Active\\") and Last Update Status is Unsuccessful (must be \\"Successful\\")
554
706
  "
555
707
  `);
556
708
  }));
@@ -581,7 +733,7 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
581
733
  const output = context.stdout.toString();
582
734
  expect(code).toBe(1);
583
735
  expect(output).toMatchInlineSnapshot(`
584
- "\\"extensionVersion\\" and \\"forwarder\\" should not be used at the same time.
736
+ "${chalk_1.red('[Error]')} \\"extensionVersion\\" and \\"forwarder\\" should not be used at the same time.
585
737
  "
586
738
  `);
587
739
  }));
@@ -622,6 +774,19 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
622
774
  output = command.context.stdout.toString();
623
775
  expect(output).toMatch('"--functions" and "--functions-regex" should not be used at the same time.\n');
624
776
  }));
777
+ test('aborts if pattern is set and no default region is specified', () => __awaiter(void 0, void 0, void 0, function* () {
778
+ ;
779
+ fs.readFile.mockImplementation((a, b, callback) => callback({}));
780
+ process.env = {};
781
+ const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
782
+ command['environment'] = 'staging';
783
+ command['service'] = 'middletier';
784
+ command['version'] = '2';
785
+ command['regExPattern'] = 'valid-pattern';
786
+ yield command['execute']();
787
+ const output = command.context.stdout.toString();
788
+ expect(output).toMatch(`${chalk_1.red('[Error]')} No default region specified. Use \`-r\`, \`--region\`.\n`);
789
+ }));
625
790
  test('aborts if the regEx pattern is an ARN', () => __awaiter(void 0, void 0, void 0, function* () {
626
791
  ;
627
792
  fs.readFile.mockImplementation((a, b, callback) => callback({}));
@@ -636,6 +801,469 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
636
801
  const output = command.context.stdout.toString();
637
802
  expect(output).toMatch(`"--functions-regex" isn't meant to be used with ARNs.\n`);
638
803
  }));
804
+ test('instrument multiple functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
805
+ const node14LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node14-x`;
806
+ const node12LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node12-x`;
807
+ const extensionLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension`;
808
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
809
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
810
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
811
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
812
+ FunctionName: 'lambda-hello-world',
813
+ Handler: 'index.handler',
814
+ Runtime: 'nodejs12.x',
815
+ },
816
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2': {
817
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
818
+ FunctionName: 'lambda-hello-world-2',
819
+ Handler: 'index.handler',
820
+ Runtime: 'nodejs14.x',
821
+ },
822
+ }, {
823
+ [`${node14LibraryLayer}:1`]: {
824
+ LayerVersionArn: `${node14LibraryLayer}:1`,
825
+ Version: 1,
826
+ },
827
+ [`${node12LibraryLayer}:1`]: {
828
+ LayerVersionArn: `${node12LibraryLayer}:1`,
829
+ Version: 1,
830
+ },
831
+ [`${extensionLayer}:1`]: {
832
+ LayerVersionArn: `${extensionLayer}:1`,
833
+ Version: 1,
834
+ },
835
+ }));
836
+ prompt_1.requestAWSCredentials.mockImplementation(() => {
837
+ process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_1.mockAwsAccessKeyId;
838
+ process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_1.mockAwsSecretAccessKey;
839
+ process.env[constants_1.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
840
+ });
841
+ prompt_1.requestDatadogEnvVars.mockImplementation(() => {
842
+ process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
843
+ process.env[constants_1.CI_API_KEY_ENV_VAR] = fixtures_1.mockDatadogApiKey;
844
+ });
845
+ prompt_1.requestFunctionSelection.mockImplementation(() => [
846
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
847
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
848
+ ]);
849
+ prompt_1.requestChangesConfirmation.mockImplementation(() => true);
850
+ const cli = fixtures_1.makeCli();
851
+ const context = fixtures_1.createMockContext();
852
+ const code = yield cli.run(['lambda', 'instrument', '-i'], context);
853
+ const output = context.stdout.toString();
854
+ expect(code).toBe(0);
855
+ expect(output).toMatchInlineSnapshot(`
856
+ "${chalk_1.bold(chalk_1.yellow('[!]'))} No existing AWS credentials found, let's set them up!
857
+ ${chalk_1.bold(chalk_1.yellow('[!]'))} Configure Datadog settings.
858
+ Fetching Lambda functions, this might take a while.
859
+ ${chalk_1.bold(chalk_1.yellow('[Warning]'))} The environment, service and version tags have not been configured. Learn more about Datadog unified service tagging: ${chalk_1.underline(chalk_1.blueBright('https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/#serverless-environment.'))}
860
+ ${chalk_1.bold(chalk_1.yellow('[Warning]'))} Instrument your ${chalk_1.hex('#FF9900').bold('Lambda')} functions in a dev or staging environment first. Should the instrumentation result be unsatisfactory, run \`${chalk_1.bold('uninstrument')}\` with the same arguments to revert the changes.\n
861
+ ${chalk_1.bold(chalk_1.yellow('[!]'))} Functions to be updated:
862
+ \t- ${chalk_1.bold('arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world')}
863
+ \t${chalk_1.bold(chalk_1.yellow('[Warning]'))} At least one latest layer version is being used. Ensure to lock in versions for production applications using \`--layerVersion\` and \`--extensionVersion\`.
864
+ \t- ${chalk_1.bold('arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2')}
865
+ \t${chalk_1.bold(chalk_1.yellow('[Warning]'))} At least one latest layer version is being used. Ensure to lock in versions for production applications using \`--layerVersion\` and \`--extensionVersion\`.\n
866
+ Will apply the following updates:
867
+ UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
868
+ {
869
+ \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world\\",
870
+ \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
871
+ \\"Environment\\": {
872
+ \\"Variables\\": {
873
+ \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
874
+ \\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
875
+ \\"DD_SITE\\": \\"datadoghq.com\\",
876
+ \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
877
+ \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
878
+ \\"DD_TRACE_ENABLED\\": \\"true\\",
879
+ \\"DD_FLUSH_TO_LOG\\": \\"true\\"
880
+ }
881
+ },
882
+ \\"Layers\\": [
883
+ \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
884
+ \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node12-x:1\\"
885
+ ]
886
+ }
887
+ TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
888
+ {
889
+ \\"dd_sls_ci\\": \\"v${version}\\"
890
+ }
891
+ UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
892
+ {
893
+ \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2\\",
894
+ \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
895
+ \\"Environment\\": {
896
+ \\"Variables\\": {
897
+ \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
898
+ \\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
899
+ \\"DD_SITE\\": \\"datadoghq.com\\",
900
+ \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
901
+ \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
902
+ \\"DD_TRACE_ENABLED\\": \\"true\\",
903
+ \\"DD_FLUSH_TO_LOG\\": \\"true\\"
904
+ }
905
+ },
906
+ \\"Layers\\": [
907
+ \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
908
+ \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node14-x:1\\"
909
+ ]
910
+ }
911
+ TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
912
+ {
913
+ \\"dd_sls_ci\\": \\"v${version}\\"
914
+ }
915
+ ${chalk_1.yellow('[!]')} Confirmation needed.
916
+ ${chalk_1.yellow('[!]')} Instrumenting functions.
917
+ "
918
+ `);
919
+ }));
920
+ test('instrument multiple specified functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
921
+ const node14LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node14-x`;
922
+ const node12LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node12-x`;
923
+ const extensionLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension`;
924
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
925
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
926
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
927
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
928
+ FunctionName: 'lambda-hello-world',
929
+ Handler: 'index.handler',
930
+ Runtime: 'nodejs12.x',
931
+ },
932
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2': {
933
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
934
+ FunctionName: 'lambda-hello-world-2',
935
+ Handler: 'index.handler',
936
+ Runtime: 'nodejs14.x',
937
+ },
938
+ }, {
939
+ [`${node14LibraryLayer}:1`]: {
940
+ LayerVersionArn: `${node14LibraryLayer}:1`,
941
+ Version: 1,
942
+ },
943
+ [`${node12LibraryLayer}:1`]: {
944
+ LayerVersionArn: `${node12LibraryLayer}:1`,
945
+ Version: 1,
946
+ },
947
+ [`${extensionLayer}:1`]: {
948
+ LayerVersionArn: `${extensionLayer}:1`,
949
+ Version: 1,
950
+ },
951
+ }));
952
+ prompt_1.requestAWSCredentials.mockImplementation(() => {
953
+ process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_1.mockAwsAccessKeyId;
954
+ process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_1.mockAwsSecretAccessKey;
955
+ process.env[constants_1.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
956
+ process.env[constants_1.AWS_SESSION_TOKEN_ENV_VAR] = 'some-session-token';
957
+ });
958
+ prompt_1.requestDatadogEnvVars.mockImplementation(() => {
959
+ process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
960
+ process.env[constants_1.CI_API_KEY_ENV_VAR] = fixtures_1.mockDatadogApiKey;
961
+ });
962
+ prompt_1.requestChangesConfirmation.mockImplementation(() => true);
963
+ const cli = fixtures_1.makeCli();
964
+ const context = fixtures_1.createMockContext();
965
+ const code = yield cli.run([
966
+ 'lambda',
967
+ 'instrument',
968
+ '-i',
969
+ '-f',
970
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
971
+ '-f',
972
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
973
+ ], context);
974
+ const output = context.stdout.toString();
975
+ expect(code).toBe(0);
976
+ expect(output).toMatchInlineSnapshot(`
977
+ "${chalk_1.bold(chalk_1.yellow('[!]'))} No existing AWS credentials found, let's set them up!
978
+ ${chalk_1.bold(chalk_1.yellow('[!]'))} Configure Datadog settings.
979
+ ${chalk_1.bold(chalk_1.yellow('[Warning]'))} The environment, service and version tags have not been configured. Learn more about Datadog unified service tagging: ${chalk_1.underline(chalk_1.blueBright('https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/#serverless-environment.'))}
980
+ ${chalk_1.bold(chalk_1.yellow('[Warning]'))} Instrument your ${chalk_1.hex('#FF9900').bold('Lambda')} functions in a dev or staging environment first. Should the instrumentation result be unsatisfactory, run \`${chalk_1.bold('uninstrument')}\` with the same arguments to revert the changes.\n
981
+ ${chalk_1.bold(chalk_1.yellow('[!]'))} Functions to be updated:
982
+ \t- ${chalk_1.bold('arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world')}
983
+ \t${chalk_1.bold(chalk_1.yellow('[Warning]'))} At least one latest layer version is being used. Ensure to lock in versions for production applications using \`--layerVersion\` and \`--extensionVersion\`.
984
+ \t- ${chalk_1.bold('arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2')}
985
+ \t${chalk_1.bold(chalk_1.yellow('[Warning]'))} At least one latest layer version is being used. Ensure to lock in versions for production applications using \`--layerVersion\` and \`--extensionVersion\`.\n
986
+ Will apply the following updates:
987
+ UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
988
+ {
989
+ \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world\\",
990
+ \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
991
+ \\"Environment\\": {
992
+ \\"Variables\\": {
993
+ \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
994
+ \\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
995
+ \\"DD_SITE\\": \\"datadoghq.com\\",
996
+ \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
997
+ \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
998
+ \\"DD_TRACE_ENABLED\\": \\"true\\",
999
+ \\"DD_FLUSH_TO_LOG\\": \\"true\\"
1000
+ }
1001
+ },
1002
+ \\"Layers\\": [
1003
+ \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
1004
+ \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node12-x:1\\"
1005
+ ]
1006
+ }
1007
+ TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1008
+ {
1009
+ \\"dd_sls_ci\\": \\"v${version}\\"
1010
+ }
1011
+ UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
1012
+ {
1013
+ \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2\\",
1014
+ \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
1015
+ \\"Environment\\": {
1016
+ \\"Variables\\": {
1017
+ \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
1018
+ \\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
1019
+ \\"DD_SITE\\": \\"datadoghq.com\\",
1020
+ \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
1021
+ \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
1022
+ \\"DD_TRACE_ENABLED\\": \\"true\\",
1023
+ \\"DD_FLUSH_TO_LOG\\": \\"true\\"
1024
+ }
1025
+ },
1026
+ \\"Layers\\": [
1027
+ \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
1028
+ \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node14-x:1\\"
1029
+ ]
1030
+ }
1031
+ TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
1032
+ {
1033
+ \\"dd_sls_ci\\": \\"v${version}\\"
1034
+ }
1035
+ ${chalk_1.yellow('[!]')} Confirmation needed.
1036
+ ${chalk_1.yellow('[!]')} Instrumenting functions.
1037
+ "
1038
+ `);
1039
+ }));
1040
+ test('aborts if a problem occurs while setting the AWS credentials interactively', () => __awaiter(void 0, void 0, void 0, function* () {
1041
+ ;
1042
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1043
+ prompt_1.requestAWSCredentials.mockImplementation(() => Promise.reject('Unexpected error'));
1044
+ const cli = fixtures_1.makeCli();
1045
+ const context = fixtures_1.createMockContext();
1046
+ const code = yield cli.run(['lambda', 'instrument', '-i'], context);
1047
+ const output = context.stdout.toString();
1048
+ expect(code).toBe(1);
1049
+ expect(output).toMatchInlineSnapshot(`
1050
+ "${chalk_1.bold(chalk_1.yellow('[!]'))} No existing AWS credentials found, let's set them up!
1051
+ ${chalk_1.red('[Error]')} Unexpected error
1052
+ "
1053
+ `);
1054
+ }));
1055
+ test('aborts if a problem occurs while setting the Datadog Environment Variables interactively', () => __awaiter(void 0, void 0, void 0, function* () {
1056
+ process.env = {
1057
+ [constants_1.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_1.mockAwsAccessKeyId,
1058
+ [constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_1.mockAwsSecretAccessKey,
1059
+ [constants_1.AWS_DEFAULT_REGION_ENV_VAR]: 'sa,-east-1',
1060
+ };
1061
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1062
+ prompt_1.requestDatadogEnvVars.mockImplementation(() => Promise.reject('Unexpected error'));
1063
+ const cli = fixtures_1.makeCli();
1064
+ const context = fixtures_1.createMockContext();
1065
+ const code = yield cli.run(['lambda', 'instrument', '-i'], context);
1066
+ const output = context.stdout.toString();
1067
+ expect(code).toBe(1);
1068
+ expect(output).toMatchInlineSnapshot(`
1069
+ "${chalk_1.bold(chalk_1.yellow('[!]'))} Configure Datadog settings.
1070
+ ${chalk_1.red('[Error]')} Unexpected error
1071
+ "
1072
+ `);
1073
+ }));
1074
+ test('aborts if there are no functions to instrument in the user AWS account', () => __awaiter(void 0, void 0, void 0, function* () {
1075
+ process.env = {
1076
+ [constants_1.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_1.mockAwsAccessKeyId,
1077
+ [constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_1.mockAwsSecretAccessKey,
1078
+ [constants_1.AWS_DEFAULT_REGION_ENV_VAR]: 'sa-east-1',
1079
+ [constants_1.CI_SITE_ENV_VAR]: 'datadoghq.com',
1080
+ [constants_1.CI_API_KEY_ENV_VAR]: fixtures_1.mockDatadogApiKey,
1081
+ };
1082
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1083
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
1084
+ const cli = fixtures_1.makeCli();
1085
+ const context = fixtures_1.createMockContext();
1086
+ const code = yield cli.run(['lambda', 'instrument', '-i'], context);
1087
+ const output = context.stdout.toString();
1088
+ expect(code).toBe(1);
1089
+ expect(output).toMatchInlineSnapshot(`
1090
+ "Fetching Lambda functions, this might take a while.
1091
+ ${chalk_1.red('[Error]')} Couldn't find any Lambda functions in the specified region.
1092
+ "
1093
+ `);
1094
+ }));
1095
+ test('aborts early when the aws-sdk throws an error while instrumenting interactively', () => __awaiter(void 0, void 0, void 0, function* () {
1096
+ process.env = {
1097
+ [constants_1.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_1.mockAwsAccessKeyId,
1098
+ [constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_1.mockAwsSecretAccessKey,
1099
+ [constants_1.AWS_DEFAULT_REGION_ENV_VAR]: 'sa-east-1',
1100
+ [constants_1.CI_SITE_ENV_VAR]: 'datadoghq.com',
1101
+ [constants_1.CI_API_KEY_ENV_VAR]: fixtures_1.mockDatadogApiKey,
1102
+ };
1103
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1104
+ aws_sdk_1.Lambda.mockImplementation(() => ({
1105
+ listFunctions: jest.fn().mockImplementation(() => ({ promise: () => Promise.reject('Lambda failed') })),
1106
+ }));
1107
+ const cli = fixtures_1.makeCli();
1108
+ const context = fixtures_1.createMockContext();
1109
+ const code = yield cli.run(['lambda', 'instrument', '-i'], context);
1110
+ const output = context.stdout.toString();
1111
+ expect(code).toBe(1);
1112
+ expect(output).toMatchInlineSnapshot(`
1113
+ "Fetching Lambda functions, this might take a while.
1114
+ ${chalk_1.red('[Error]')} Couldn't fetch Lambda functions. Error: Max retry count exceeded.
1115
+ "
1116
+ `);
1117
+ }));
1118
+ test('aborts early when a layer version is set for Java', () => __awaiter(void 0, void 0, void 0, function* () {
1119
+ ;
1120
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1121
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
1122
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
1123
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
1124
+ Runtime: 'java8.al2',
1125
+ },
1126
+ }));
1127
+ const cli = fixtures_1.makeCli();
1128
+ const context = fixtures_1.createMockContext();
1129
+ const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
1130
+ process.env.DATADOG_API_KEY = '1234';
1131
+ const code = yield cli.run([
1132
+ 'lambda',
1133
+ 'instrument',
1134
+ '-f',
1135
+ functionARN,
1136
+ '--dry',
1137
+ '-v',
1138
+ '6',
1139
+ '--extra-tags',
1140
+ 'layer:api,team:intake',
1141
+ '--service',
1142
+ 'middletier',
1143
+ '--env',
1144
+ 'staging',
1145
+ '--version',
1146
+ '0.2',
1147
+ ], context);
1148
+ const output = context.stdout.toString();
1149
+ expect(code).toBe(1);
1150
+ expect(output).toMatchInlineSnapshot(`
1151
+ "${chalk_1.red('[Error]')} Couldn't fetch Lambda functions. Error: Only the --extension-version argument should be set for the java8.al2 runtime. Please remove the --layer-version argument from the instrument command.
1152
+ "
1153
+ `);
1154
+ }));
1155
+ test('aborts early when a layer version is set for Ruby', () => __awaiter(void 0, void 0, void 0, function* () {
1156
+ ;
1157
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1158
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
1159
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
1160
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
1161
+ Runtime: 'ruby2.7',
1162
+ },
1163
+ }));
1164
+ const cli = fixtures_1.makeCli();
1165
+ const context = fixtures_1.createMockContext();
1166
+ const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
1167
+ process.env.DATADOG_API_KEY = '1234';
1168
+ const code = yield cli.run([
1169
+ 'lambda',
1170
+ 'instrument',
1171
+ '-f',
1172
+ functionARN,
1173
+ '--dry',
1174
+ '-v',
1175
+ '40',
1176
+ '--extra-tags',
1177
+ 'layer:api,team:intake',
1178
+ '--service',
1179
+ 'middletier',
1180
+ '--env',
1181
+ 'staging',
1182
+ '--version',
1183
+ '0.2',
1184
+ ], context);
1185
+ const output = context.stdout.toString();
1186
+ expect(code).toBe(1);
1187
+ expect(output).toMatchInlineSnapshot(`
1188
+ "${chalk_1.red('[Error]')} Couldn't fetch Lambda functions. Error: Only the --extension-version argument should be set for the ruby2.7 runtime. Please remove the --layer-version argument from the instrument command.
1189
+ "
1190
+ `);
1191
+ }));
1192
+ test('aborts early when a layer version is set for a Custom runtime', () => __awaiter(void 0, void 0, void 0, function* () {
1193
+ ;
1194
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1195
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
1196
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
1197
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
1198
+ Runtime: 'provided.al2',
1199
+ },
1200
+ }));
1201
+ const cli = fixtures_1.makeCli();
1202
+ const context = fixtures_1.createMockContext();
1203
+ const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
1204
+ process.env.DATADOG_API_KEY = '1234';
1205
+ const code = yield cli.run([
1206
+ 'lambda',
1207
+ 'instrument',
1208
+ '-f',
1209
+ functionARN,
1210
+ '--dry',
1211
+ '-v',
1212
+ '6',
1213
+ '--extra-tags',
1214
+ 'layer:api,team:intake',
1215
+ '--service',
1216
+ 'middletier',
1217
+ '--env',
1218
+ 'staging',
1219
+ '--version',
1220
+ '0.2',
1221
+ ], context);
1222
+ const output = context.stdout.toString();
1223
+ expect(code).toBe(1);
1224
+ expect(output).toMatchInlineSnapshot(`
1225
+ "${chalk_1.red('[Error]')} Couldn't fetch Lambda functions. Error: Only the --extension-version argument should be set for the provided.al2 runtime. Please remove the --layer-version argument from the instrument command.
1226
+ "
1227
+ `);
1228
+ }));
1229
+ test('aborts early when .NET is using ARM64 architecture', () => __awaiter(void 0, void 0, void 0, function* () {
1230
+ ;
1231
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1232
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
1233
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
1234
+ Architectures: ['arm64'],
1235
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
1236
+ Runtime: 'dotnetcore3.1',
1237
+ },
1238
+ }));
1239
+ const cli = fixtures_1.makeCli();
1240
+ const context = fixtures_1.createMockContext();
1241
+ const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
1242
+ process.env.DATADOG_API_KEY = '1234';
1243
+ const code = yield cli.run([
1244
+ 'lambda',
1245
+ 'instrument',
1246
+ '-f',
1247
+ functionARN,
1248
+ '--dry',
1249
+ '-v',
1250
+ '6',
1251
+ '--extra-tags',
1252
+ 'layer:api,team:intake',
1253
+ '--service',
1254
+ 'middletier',
1255
+ '--env',
1256
+ 'staging',
1257
+ '--version',
1258
+ '0.2',
1259
+ ], context);
1260
+ const output = context.stdout.toString();
1261
+ expect(code).toBe(1);
1262
+ expect(output).toMatchInlineSnapshot(`
1263
+ "${chalk_1.red('[Error]')} Couldn't fetch Lambda functions. Error: Instrumenting arm64 architecture is not currently supported for .NET. Please only instrument .NET functions using x86_64 architecture.
1264
+ "
1265
+ `);
1266
+ }));
639
1267
  });
640
1268
  describe('getSettings', () => {
641
1269
  test('uses config file settings', () => {
@@ -650,11 +1278,13 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
650
1278
  command['config']['tracing'] = 'false';
651
1279
  command['config']['logLevel'] = 'debug';
652
1280
  expect(command['getSettings']()).toEqual({
1281
+ captureLambdaPayload: false,
653
1282
  environment: undefined,
654
1283
  extensionVersion: 6,
655
1284
  extraTags: undefined,
656
1285
  flushMetricsToLogs: false,
657
1286
  forwarderARN: 'my-forwarder',
1287
+ interactive: false,
658
1288
  layerAWSAccount: 'another-account',
659
1289
  layerVersion: 2,
660
1290
  logLevel: 'debug',
@@ -682,8 +1312,10 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
682
1312
  command['logLevel'] = 'debug';
683
1313
  command['config']['logLevel'] = 'info';
684
1314
  expect(command['getSettings']()).toEqual({
1315
+ captureLambdaPayload: false,
685
1316
  flushMetricsToLogs: false,
686
1317
  forwarderARN: 'my-forwarder',
1318
+ interactive: false,
687
1319
  layerAWSAccount: 'my-account',
688
1320
  layerVersion: 1,
689
1321
  logLevel: 'debug',
@@ -713,30 +1345,37 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
713
1345
  process.env = {};
714
1346
  const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
715
1347
  const validSettings = {
1348
+ captureLambdaPayload: true,
716
1349
  extensionVersion: undefined,
717
1350
  flushMetricsToLogs: false,
718
1351
  forwarderARN: undefined,
1352
+ interactive: false,
719
1353
  layerAWSAccount: undefined,
720
1354
  layerVersion: undefined,
721
1355
  logLevel: undefined,
722
1356
  mergeXrayTraces: false,
723
1357
  tracingEnabled: true,
724
1358
  };
1359
+ command['config']['captureLambdaPayload'] = 'truE';
725
1360
  command['config']['flushMetricsToLogs'] = 'False';
726
1361
  command['config']['mergeXrayTraces'] = 'falSE';
727
1362
  command['config']['tracing'] = 'TRUE';
728
1363
  expect(command['getSettings']()).toEqual(validSettings);
1364
+ command['config']['captureLambdaPayload'] = 'true';
729
1365
  command['config']['flushMetricsToLogs'] = 'false';
730
1366
  command['config']['mergeXrayTraces'] = 'false';
731
1367
  command['config']['tracing'] = 'true';
732
1368
  expect(command['getSettings']()).toEqual(validSettings);
1369
+ validSettings.captureLambdaPayload = false;
733
1370
  validSettings.flushMetricsToLogs = true;
734
1371
  validSettings.mergeXrayTraces = true;
735
1372
  validSettings.tracingEnabled = false;
1373
+ command['captureLambdaPayload'] = 'faLSE';
736
1374
  command['flushMetricsToLogs'] = 'truE';
737
1375
  command['mergeXrayTraces'] = 'TRUe';
738
1376
  command['tracing'] = 'FALSE';
739
1377
  expect(command['getSettings']()).toEqual(validSettings);
1378
+ command['captureLambdaPayload'] = 'false';
740
1379
  command['flushMetricsToLogs'] = 'true';
741
1380
  command['mergeXrayTraces'] = 'true';
742
1381
  command['tracing'] = 'false';