@datadog/datadog-ci 0.17.12 → 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 (43) hide show
  1. package/README.md +6 -1
  2. package/dist/commands/junit/upload.js +1 -1
  3. package/dist/commands/lambda/__tests__/fixtures.d.ts +5 -1
  4. package/dist/commands/lambda/__tests__/fixtures.js +13 -2
  5. package/dist/commands/lambda/__tests__/functions/commons.test.js +221 -0
  6. package/dist/commands/lambda/__tests__/functions/instrument.test.js +64 -42
  7. package/dist/commands/lambda/__tests__/instrument.test.js +425 -4
  8. package/dist/commands/lambda/__tests__/prompt.test.d.ts +1 -0
  9. package/dist/commands/lambda/__tests__/prompt.test.js +216 -0
  10. package/dist/commands/lambda/__tests__/uninstrument.test.js +310 -4
  11. package/dist/commands/lambda/constants.d.ts +10 -0
  12. package/dist/commands/lambda/constants.js +36 -2
  13. package/dist/commands/lambda/functions/commons.d.ts +15 -0
  14. package/dist/commands/lambda/functions/commons.js +105 -2
  15. package/dist/commands/lambda/functions/instrument.d.ts +1 -1
  16. package/dist/commands/lambda/functions/instrument.js +17 -7
  17. package/dist/commands/lambda/functions/uninstrument.js +1 -0
  18. package/dist/commands/lambda/instrument.d.ts +2 -0
  19. package/dist/commands/lambda/instrument.js +100 -47
  20. package/dist/commands/lambda/interfaces.d.ts +4 -0
  21. package/dist/commands/lambda/prompt.d.ts +9 -0
  22. package/dist/commands/lambda/prompt.js +187 -0
  23. package/dist/commands/lambda/uninstrument.d.ts +1 -0
  24. package/dist/commands/lambda/uninstrument.js +68 -30
  25. package/dist/commands/synthetics/__tests__/cli.test.js +1 -0
  26. package/dist/commands/synthetics/__tests__/fixtures.js +1 -0
  27. package/dist/commands/synthetics/__tests__/run-test.test.js +48 -2
  28. package/dist/commands/synthetics/__tests__/utils.test.js +11 -0
  29. package/dist/commands/synthetics/command.d.ts +1 -0
  30. package/dist/commands/synthetics/command.js +11 -5
  31. package/dist/commands/synthetics/interfaces.d.ts +8 -3
  32. package/dist/commands/synthetics/interfaces.js +7 -3
  33. package/dist/commands/synthetics/reporters/default.js +5 -1
  34. package/dist/commands/synthetics/run-test.js +3 -1
  35. package/dist/commands/synthetics/utils.d.ts +3 -0
  36. package/dist/commands/synthetics/utils.js +20 -1
  37. package/dist/commands/trace/api.js +1 -1
  38. package/dist/helpers/__tests__/ci.test.js +71 -24
  39. package/dist/helpers/__tests__/user-provided-git.test.js +69 -27
  40. package/dist/helpers/ci.js +1 -1
  41. package/dist/helpers/user-provided-git.d.ts +2 -1
  42. package/dist/helpers/user-provided-git.js +18 -3
  43. 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\\",
@@ -346,6 +428,7 @@ UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:123456789012:function:la
346
428
  \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
347
429
  \\"DD_API_KEY\\": \\"1234\\",
348
430
  \\"DD_SITE\\": \\"datadoghq.com\\",
431
+ \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
349
432
  \\"DD_ENV\\": \\"dummy\\",
350
433
  \\"DD_TAGS\\": \\"git.commit.sha:1be168ff837f043bde17c0314341c84271047b31\\",
351
434
  \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
@@ -473,7 +556,7 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
473
556
  const output = context.stdout.toString();
474
557
  expect(code).toBe(1);
475
558
  expect(output).toMatchInlineSnapshot(`
476
- "No functions specified for instrumentation.
559
+ "${chalk_1.red('[Error]')} No functions specified for instrumentation.
477
560
  "
478
561
  `);
479
562
  }));
@@ -491,7 +574,7 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
491
574
  yield command['execute']();
492
575
  const output = command.context.stdout.toString();
493
576
  expect(output).toMatchInlineSnapshot(`
494
- "No functions specified for instrumentation.
577
+ "${chalk_1.red('[Error]')} No functions specified for instrumentation.
495
578
  "
496
579
  `);
497
580
  }));
@@ -550,7 +633,7 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
550
633
  const output = context.stdout.toString();
551
634
  expect(code).toBe(1);
552
635
  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\\")
636
+ "${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
637
  "
555
638
  `);
556
639
  }));
@@ -581,7 +664,7 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
581
664
  const output = context.stdout.toString();
582
665
  expect(code).toBe(1);
583
666
  expect(output).toMatchInlineSnapshot(`
584
- "\\"extensionVersion\\" and \\"forwarder\\" should not be used at the same time.
667
+ "${chalk_1.red('[Error]')} \\"extensionVersion\\" and \\"forwarder\\" should not be used at the same time.
585
668
  "
586
669
  `);
587
670
  }));
@@ -622,6 +705,19 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
622
705
  output = command.context.stdout.toString();
623
706
  expect(output).toMatch('"--functions" and "--functions-regex" should not be used at the same time.\n');
624
707
  }));
708
+ test('aborts if pattern is set and no default region is specified', () => __awaiter(void 0, void 0, void 0, function* () {
709
+ ;
710
+ fs.readFile.mockImplementation((a, b, callback) => callback({}));
711
+ process.env = {};
712
+ const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
713
+ command['environment'] = 'staging';
714
+ command['service'] = 'middletier';
715
+ command['version'] = '2';
716
+ command['regExPattern'] = 'valid-pattern';
717
+ yield command['execute']();
718
+ const output = command.context.stdout.toString();
719
+ expect(output).toMatch(`${chalk_1.red('[Error]')} No default region specified. Use \`-r\`, \`--region\`.\n`);
720
+ }));
625
721
  test('aborts if the regEx pattern is an ARN', () => __awaiter(void 0, void 0, void 0, function* () {
626
722
  ;
627
723
  fs.readFile.mockImplementation((a, b, callback) => callback({}));
@@ -636,6 +732,320 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
636
732
  const output = command.context.stdout.toString();
637
733
  expect(output).toMatch(`"--functions-regex" isn't meant to be used with ARNs.\n`);
638
734
  }));
735
+ test('instrument multiple functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
736
+ const node14LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node14-x`;
737
+ const node12LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node12-x`;
738
+ const extensionLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension`;
739
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
740
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
741
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
742
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
743
+ FunctionName: 'lambda-hello-world',
744
+ Handler: 'index.handler',
745
+ Runtime: 'nodejs12.x',
746
+ },
747
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2': {
748
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
749
+ FunctionName: 'lambda-hello-world-2',
750
+ Handler: 'index.handler',
751
+ Runtime: 'nodejs14.x',
752
+ },
753
+ }, {
754
+ [`${node14LibraryLayer}:1`]: {
755
+ LayerVersionArn: `${node14LibraryLayer}:1`,
756
+ Version: 1,
757
+ },
758
+ [`${node12LibraryLayer}:1`]: {
759
+ LayerVersionArn: `${node12LibraryLayer}:1`,
760
+ Version: 1,
761
+ },
762
+ [`${extensionLayer}:1`]: {
763
+ LayerVersionArn: `${extensionLayer}:1`,
764
+ Version: 1,
765
+ },
766
+ }));
767
+ prompt_1.requestAWSCredentials.mockImplementation(() => {
768
+ process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_1.mockAwsAccessKeyId;
769
+ process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_1.mockAwsSecretAccessKey;
770
+ process.env[constants_1.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
771
+ });
772
+ prompt_1.requestDatadogEnvVars.mockImplementation(() => {
773
+ process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
774
+ process.env[constants_1.CI_API_KEY_ENV_VAR] = fixtures_1.mockDatadogApiKey;
775
+ });
776
+ prompt_1.requestFunctionSelection.mockImplementation(() => [
777
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
778
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
779
+ ]);
780
+ prompt_1.requestChangesConfirmation.mockImplementation(() => true);
781
+ const cli = fixtures_1.makeCli();
782
+ const context = fixtures_1.createMockContext();
783
+ const code = yield cli.run(['lambda', 'instrument', '-i'], context);
784
+ const output = context.stdout.toString();
785
+ expect(code).toBe(0);
786
+ expect(output).toMatchInlineSnapshot(`
787
+ "${chalk_1.bold(chalk_1.yellow('[!]'))} No existing AWS credentials found, let's set them up!
788
+ ${chalk_1.bold(chalk_1.yellow('[!]'))} Configure Datadog settings.
789
+ Fetching Lambda functions, this might take a while.
790
+ ${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.'))}
791
+ ${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
792
+ ${chalk_1.bold(chalk_1.yellow('[!]'))} Functions to be updated:
793
+ \t- ${chalk_1.bold('arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world')}
794
+ \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\`.
795
+ \t- ${chalk_1.bold('arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2')}
796
+ \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
797
+ Will apply the following updates:
798
+ UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
799
+ {
800
+ \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world\\",
801
+ \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
802
+ \\"Environment\\": {
803
+ \\"Variables\\": {
804
+ \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
805
+ \\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
806
+ \\"DD_SITE\\": \\"datadoghq.com\\",
807
+ \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
808
+ \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
809
+ \\"DD_TRACE_ENABLED\\": \\"true\\",
810
+ \\"DD_FLUSH_TO_LOG\\": \\"true\\"
811
+ }
812
+ },
813
+ \\"Layers\\": [
814
+ \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
815
+ \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node12-x:1\\"
816
+ ]
817
+ }
818
+ TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
819
+ {
820
+ \\"dd_sls_ci\\": \\"v${version}\\"
821
+ }
822
+ UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
823
+ {
824
+ \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2\\",
825
+ \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
826
+ \\"Environment\\": {
827
+ \\"Variables\\": {
828
+ \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
829
+ \\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
830
+ \\"DD_SITE\\": \\"datadoghq.com\\",
831
+ \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
832
+ \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
833
+ \\"DD_TRACE_ENABLED\\": \\"true\\",
834
+ \\"DD_FLUSH_TO_LOG\\": \\"true\\"
835
+ }
836
+ },
837
+ \\"Layers\\": [
838
+ \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
839
+ \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node14-x:1\\"
840
+ ]
841
+ }
842
+ TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
843
+ {
844
+ \\"dd_sls_ci\\": \\"v${version}\\"
845
+ }
846
+ ${chalk_1.yellow('[!]')} Confirmation needed.
847
+ ${chalk_1.yellow('[!]')} Instrumenting functions.
848
+ "
849
+ `);
850
+ }));
851
+ test('instrument multiple specified functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
852
+ const node14LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node14-x`;
853
+ const node12LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node12-x`;
854
+ const extensionLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension`;
855
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
856
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
857
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
858
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
859
+ FunctionName: 'lambda-hello-world',
860
+ Handler: 'index.handler',
861
+ Runtime: 'nodejs12.x',
862
+ },
863
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2': {
864
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
865
+ FunctionName: 'lambda-hello-world-2',
866
+ Handler: 'index.handler',
867
+ Runtime: 'nodejs14.x',
868
+ },
869
+ }, {
870
+ [`${node14LibraryLayer}:1`]: {
871
+ LayerVersionArn: `${node14LibraryLayer}:1`,
872
+ Version: 1,
873
+ },
874
+ [`${node12LibraryLayer}:1`]: {
875
+ LayerVersionArn: `${node12LibraryLayer}:1`,
876
+ Version: 1,
877
+ },
878
+ [`${extensionLayer}:1`]: {
879
+ LayerVersionArn: `${extensionLayer}:1`,
880
+ Version: 1,
881
+ },
882
+ }));
883
+ prompt_1.requestAWSCredentials.mockImplementation(() => {
884
+ process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_1.mockAwsAccessKeyId;
885
+ process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_1.mockAwsSecretAccessKey;
886
+ process.env[constants_1.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
887
+ process.env[constants_1.AWS_SESSION_TOKEN_ENV_VAR] = 'some-session-token';
888
+ });
889
+ prompt_1.requestDatadogEnvVars.mockImplementation(() => {
890
+ process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
891
+ process.env[constants_1.CI_API_KEY_ENV_VAR] = fixtures_1.mockDatadogApiKey;
892
+ });
893
+ prompt_1.requestChangesConfirmation.mockImplementation(() => true);
894
+ const cli = fixtures_1.makeCli();
895
+ const context = fixtures_1.createMockContext();
896
+ const code = yield cli.run([
897
+ 'lambda',
898
+ 'instrument',
899
+ '-i',
900
+ '-f',
901
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
902
+ '-f',
903
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
904
+ ], context);
905
+ const output = context.stdout.toString();
906
+ expect(code).toBe(0);
907
+ expect(output).toMatchInlineSnapshot(`
908
+ "${chalk_1.bold(chalk_1.yellow('[!]'))} No existing AWS credentials found, let's set them up!
909
+ ${chalk_1.bold(chalk_1.yellow('[!]'))} Configure Datadog settings.
910
+ ${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.'))}
911
+ ${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
912
+ ${chalk_1.bold(chalk_1.yellow('[!]'))} Functions to be updated:
913
+ \t- ${chalk_1.bold('arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world')}
914
+ \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\`.
915
+ \t- ${chalk_1.bold('arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2')}
916
+ \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
917
+ Will apply the following updates:
918
+ UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
919
+ {
920
+ \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world\\",
921
+ \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
922
+ \\"Environment\\": {
923
+ \\"Variables\\": {
924
+ \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
925
+ \\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
926
+ \\"DD_SITE\\": \\"datadoghq.com\\",
927
+ \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
928
+ \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
929
+ \\"DD_TRACE_ENABLED\\": \\"true\\",
930
+ \\"DD_FLUSH_TO_LOG\\": \\"true\\"
931
+ }
932
+ },
933
+ \\"Layers\\": [
934
+ \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
935
+ \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node12-x:1\\"
936
+ ]
937
+ }
938
+ TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
939
+ {
940
+ \\"dd_sls_ci\\": \\"v${version}\\"
941
+ }
942
+ UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
943
+ {
944
+ \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2\\",
945
+ \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
946
+ \\"Environment\\": {
947
+ \\"Variables\\": {
948
+ \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
949
+ \\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
950
+ \\"DD_SITE\\": \\"datadoghq.com\\",
951
+ \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
952
+ \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
953
+ \\"DD_TRACE_ENABLED\\": \\"true\\",
954
+ \\"DD_FLUSH_TO_LOG\\": \\"true\\"
955
+ }
956
+ },
957
+ \\"Layers\\": [
958
+ \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
959
+ \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node14-x:1\\"
960
+ ]
961
+ }
962
+ TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
963
+ {
964
+ \\"dd_sls_ci\\": \\"v${version}\\"
965
+ }
966
+ ${chalk_1.yellow('[!]')} Confirmation needed.
967
+ ${chalk_1.yellow('[!]')} Instrumenting functions.
968
+ "
969
+ `);
970
+ }));
971
+ test('aborts if a problem occurs while setting the AWS credentials interactively', () => __awaiter(void 0, void 0, void 0, function* () {
972
+ ;
973
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
974
+ prompt_1.requestAWSCredentials.mockImplementation(() => Promise.reject('Unexpected error'));
975
+ const cli = fixtures_1.makeCli();
976
+ const context = fixtures_1.createMockContext();
977
+ const code = yield cli.run(['lambda', 'instrument', '-i'], context);
978
+ const output = context.stdout.toString();
979
+ expect(code).toBe(1);
980
+ expect(output).toMatchInlineSnapshot(`
981
+ "${chalk_1.bold(chalk_1.yellow('[!]'))} No existing AWS credentials found, let's set them up!
982
+ ${chalk_1.red('[Error]')} Unexpected error
983
+ "
984
+ `);
985
+ }));
986
+ test('aborts if a problem occurs while setting the Datadog Environment Variables interactively', () => __awaiter(void 0, void 0, void 0, function* () {
987
+ process.env = {
988
+ [constants_1.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_1.mockAwsAccessKeyId,
989
+ [constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_1.mockAwsSecretAccessKey,
990
+ [constants_1.AWS_DEFAULT_REGION_ENV_VAR]: 'sa,-east-1',
991
+ };
992
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
993
+ prompt_1.requestDatadogEnvVars.mockImplementation(() => Promise.reject('Unexpected error'));
994
+ const cli = fixtures_1.makeCli();
995
+ const context = fixtures_1.createMockContext();
996
+ const code = yield cli.run(['lambda', 'instrument', '-i'], context);
997
+ const output = context.stdout.toString();
998
+ expect(code).toBe(1);
999
+ expect(output).toMatchInlineSnapshot(`
1000
+ "${chalk_1.bold(chalk_1.yellow('[!]'))} Configure Datadog settings.
1001
+ ${chalk_1.red('[Error]')} Unexpected error
1002
+ "
1003
+ `);
1004
+ }));
1005
+ test('aborts if there are no functions to instrument in the user AWS account', () => __awaiter(void 0, void 0, void 0, function* () {
1006
+ process.env = {
1007
+ [constants_1.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_1.mockAwsAccessKeyId,
1008
+ [constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_1.mockAwsSecretAccessKey,
1009
+ [constants_1.AWS_DEFAULT_REGION_ENV_VAR]: 'sa-east-1',
1010
+ [constants_1.CI_SITE_ENV_VAR]: 'datadoghq.com',
1011
+ [constants_1.CI_API_KEY_ENV_VAR]: fixtures_1.mockDatadogApiKey,
1012
+ };
1013
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1014
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
1015
+ const cli = fixtures_1.makeCli();
1016
+ const context = fixtures_1.createMockContext();
1017
+ const code = yield cli.run(['lambda', 'instrument', '-i'], context);
1018
+ const output = context.stdout.toString();
1019
+ expect(code).toBe(1);
1020
+ expect(output).toMatchInlineSnapshot(`
1021
+ "Fetching Lambda functions, this might take a while.
1022
+ ${chalk_1.red('[Error]')} Couldn't find any Lambda functions in the specified region.
1023
+ "
1024
+ `);
1025
+ }));
1026
+ test('aborts early when the aws-sdk throws an error while instrumenting interactively', () => __awaiter(void 0, void 0, void 0, function* () {
1027
+ process.env = {
1028
+ [constants_1.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_1.mockAwsAccessKeyId,
1029
+ [constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_1.mockAwsSecretAccessKey,
1030
+ [constants_1.AWS_DEFAULT_REGION_ENV_VAR]: 'sa-east-1',
1031
+ [constants_1.CI_SITE_ENV_VAR]: 'datadoghq.com',
1032
+ [constants_1.CI_API_KEY_ENV_VAR]: fixtures_1.mockDatadogApiKey,
1033
+ };
1034
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1035
+ aws_sdk_1.Lambda.mockImplementation(() => ({
1036
+ listFunctions: jest.fn().mockImplementation(() => ({ promise: () => Promise.reject('Lambda failed') })),
1037
+ }));
1038
+ const cli = fixtures_1.makeCli();
1039
+ const context = fixtures_1.createMockContext();
1040
+ const code = yield cli.run(['lambda', 'instrument', '-i'], context);
1041
+ const output = context.stdout.toString();
1042
+ expect(code).toBe(1);
1043
+ expect(output).toMatchInlineSnapshot(`
1044
+ "Fetching Lambda functions, this might take a while.
1045
+ ${chalk_1.red('[Error]')} Couldn't fetch Lambda functions. Error: Max retry count exceeded.
1046
+ "
1047
+ `);
1048
+ }));
639
1049
  });
640
1050
  describe('getSettings', () => {
641
1051
  test('uses config file settings', () => {
@@ -650,11 +1060,13 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
650
1060
  command['config']['tracing'] = 'false';
651
1061
  command['config']['logLevel'] = 'debug';
652
1062
  expect(command['getSettings']()).toEqual({
1063
+ captureLambdaPayload: false,
653
1064
  environment: undefined,
654
1065
  extensionVersion: 6,
655
1066
  extraTags: undefined,
656
1067
  flushMetricsToLogs: false,
657
1068
  forwarderARN: 'my-forwarder',
1069
+ interactive: false,
658
1070
  layerAWSAccount: 'another-account',
659
1071
  layerVersion: 2,
660
1072
  logLevel: 'debug',
@@ -682,8 +1094,10 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
682
1094
  command['logLevel'] = 'debug';
683
1095
  command['config']['logLevel'] = 'info';
684
1096
  expect(command['getSettings']()).toEqual({
1097
+ captureLambdaPayload: false,
685
1098
  flushMetricsToLogs: false,
686
1099
  forwarderARN: 'my-forwarder',
1100
+ interactive: false,
687
1101
  layerAWSAccount: 'my-account',
688
1102
  layerVersion: 1,
689
1103
  logLevel: 'debug',
@@ -713,30 +1127,37 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
713
1127
  process.env = {};
714
1128
  const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
715
1129
  const validSettings = {
1130
+ captureLambdaPayload: true,
716
1131
  extensionVersion: undefined,
717
1132
  flushMetricsToLogs: false,
718
1133
  forwarderARN: undefined,
1134
+ interactive: false,
719
1135
  layerAWSAccount: undefined,
720
1136
  layerVersion: undefined,
721
1137
  logLevel: undefined,
722
1138
  mergeXrayTraces: false,
723
1139
  tracingEnabled: true,
724
1140
  };
1141
+ command['config']['captureLambdaPayload'] = 'truE';
725
1142
  command['config']['flushMetricsToLogs'] = 'False';
726
1143
  command['config']['mergeXrayTraces'] = 'falSE';
727
1144
  command['config']['tracing'] = 'TRUE';
728
1145
  expect(command['getSettings']()).toEqual(validSettings);
1146
+ command['config']['captureLambdaPayload'] = 'true';
729
1147
  command['config']['flushMetricsToLogs'] = 'false';
730
1148
  command['config']['mergeXrayTraces'] = 'false';
731
1149
  command['config']['tracing'] = 'true';
732
1150
  expect(command['getSettings']()).toEqual(validSettings);
1151
+ validSettings.captureLambdaPayload = false;
733
1152
  validSettings.flushMetricsToLogs = true;
734
1153
  validSettings.mergeXrayTraces = true;
735
1154
  validSettings.tracingEnabled = false;
1155
+ command['captureLambdaPayload'] = 'faLSE';
736
1156
  command['flushMetricsToLogs'] = 'truE';
737
1157
  command['mergeXrayTraces'] = 'TRUe';
738
1158
  command['tracing'] = 'FALSE';
739
1159
  expect(command['getSettings']()).toEqual(validSettings);
1160
+ command['captureLambdaPayload'] = 'false';
740
1161
  command['flushMetricsToLogs'] = 'true';
741
1162
  command['mergeXrayTraces'] = 'true';
742
1163
  command['tracing'] = 'false';
@@ -0,0 +1 @@
1
+ export {};