@datadog/datadog-ci 2.4.0 → 2.4.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 (36) hide show
  1. package/LICENSE-3rdparty.csv +1 -0
  2. package/dist/commands/lambda/__tests__/functions/commons.test.js +97 -2
  3. package/dist/commands/lambda/__tests__/functions/commons.test.js.map +1 -1
  4. package/dist/commands/lambda/__tests__/instrument.test.js +174 -394
  5. package/dist/commands/lambda/__tests__/instrument.test.js.map +1 -1
  6. package/dist/commands/lambda/__tests__/loggroup.test.js +68 -2
  7. package/dist/commands/lambda/__tests__/loggroup.test.js.map +1 -1
  8. package/dist/commands/lambda/__tests__/uninstrument.test.js +615 -551
  9. package/dist/commands/lambda/__tests__/uninstrument.test.js.map +1 -1
  10. package/dist/commands/lambda/functions/commons.d.ts +4 -2
  11. package/dist/commands/lambda/functions/commons.js +71 -12
  12. package/dist/commands/lambda/functions/commons.js.map +1 -1
  13. package/dist/commands/lambda/instrument.d.ts +2 -0
  14. package/dist/commands/lambda/instrument.js +27 -12
  15. package/dist/commands/lambda/instrument.js.map +1 -1
  16. package/dist/commands/lambda/interfaces.d.ts +6 -0
  17. package/dist/commands/lambda/loggroup.js +7 -1
  18. package/dist/commands/lambda/loggroup.js.map +1 -1
  19. package/dist/commands/lambda/renderer.d.ts +74 -2
  20. package/dist/commands/lambda/renderer.js +98 -5
  21. package/dist/commands/lambda/renderer.js.map +1 -1
  22. package/dist/commands/lambda/uninstrument.js +13 -17
  23. package/dist/commands/lambda/uninstrument.js.map +1 -1
  24. package/dist/commands/synthetics/index.d.ts +1 -0
  25. package/dist/commands/synthetics/index.js +3 -1
  26. package/dist/commands/synthetics/index.js.map +1 -1
  27. package/dist/helpers/__tests__/user-provided-git.test.js +2 -1
  28. package/dist/helpers/__tests__/user-provided-git.test.js.map +1 -1
  29. package/dist/helpers/ci.js +27 -29
  30. package/dist/helpers/ci.js.map +1 -1
  31. package/dist/helpers/user-provided-git.js +0 -3
  32. package/dist/helpers/user-provided-git.js.map +1 -1
  33. package/dist/helpers/utils.d.ts +1 -1
  34. package/dist/helpers/utils.js +1 -1
  35. package/dist/helpers/utils.js.map +1 -1
  36. package/package.json +5 -3
@@ -27,23 +27,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
27
27
  step((generator = generator.apply(thisArg, _arguments || [])).next());
28
28
  });
29
29
  };
30
- var __importDefault = (this && this.__importDefault) || function (mod) {
31
- return (mod && mod.__esModule) ? mod : { "default": mod };
32
- };
33
30
  Object.defineProperty(exports, "__esModule", { value: true });
34
31
  jest.mock('fs');
35
32
  jest.mock('aws-sdk');
36
33
  jest.mock('../prompt');
37
34
  jest.mock('../renderer', () => require('../__mocks__/renderer'));
35
+ jest.mock('../../../../package.json', () => ({ version: 'XXXX' }));
38
36
  const fs = __importStar(require("fs"));
39
- const path_1 = __importDefault(require("path"));
40
37
  const aws_sdk_1 = require("aws-sdk");
41
38
  const advanced_1 = require("clipanion/lib/advanced");
42
39
  const constants_1 = require("../constants");
43
40
  const instrument_1 = require("../instrument");
44
41
  const prompt_1 = require("../prompt");
45
42
  const fixtures_1 = require("./fixtures");
46
- const { version } = require(path_1.default.join(__dirname, '../../../../package.json'));
47
43
  describe('lambda', () => {
48
44
  describe('instrument', () => {
49
45
  describe('execute', () => {
@@ -90,41 +86,7 @@ describe('lambda', () => {
90
86
  ], context);
91
87
  const output = context.stdout.toString();
92
88
  expect(code).toBe(0);
93
- expect(output).toMatchInlineSnapshot(`
94
- "\n[Dry Run] 🐶 Instrumenting Lambda function
95
- \n[Warning] Instrument your Lambda functions in a dev or staging environment first. Should the instrumentation result be unsatisfactory, run \`uninstrument\` with the same arguments to revert the changes.
96
- \n[!] Functions to be updated:
97
- \t- arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\n
98
- [Dry Run] Will apply the following updates:
99
- UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
100
- {
101
- \\"FunctionName\\": \\"arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\\",
102
- \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
103
- \\"Environment\\": {
104
- \\"Variables\\": {
105
- \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
106
- \\"DD_SITE\\": \\"datadoghq.com\\",
107
- \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
108
- \\"DD_ENV\\": \\"staging\\",
109
- \\"DD_TAGS\\": \\"layer:api,team:intake\\",
110
- \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
111
- \\"DD_SERVICE\\": \\"middletier\\",
112
- \\"DD_TRACE_ENABLED\\": \\"true\\",
113
- \\"DD_VERSION\\": \\"0.2\\",
114
- \\"DD_FLUSH_TO_LOG\\": \\"true\\",
115
- \\"DD_LOG_LEVEL\\": \\"debug\\"
116
- }
117
- },
118
- \\"Layers\\": [
119
- \\"arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Node12-x:10\\"
120
- ]
121
- }
122
- TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
123
- {
124
- \\"dd_sls_ci\\": \\"v${version}\\"
125
- }
126
- "
127
- `);
89
+ expect(output).toMatchSnapshot();
128
90
  }));
129
91
  test('prints dry run data for lambda library and extension layers using kebab case args', () => __awaiter(void 0, void 0, void 0, function* () {
130
92
  ;
@@ -168,42 +130,7 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
168
130
  ], context);
169
131
  const output = context.stdout.toString();
170
132
  expect(code).toBe(0);
171
- expect(output).toMatchInlineSnapshot(`
172
- "\n[Dry Run] 🐶 Instrumenting Lambda function
173
- \n[Warning] Instrument your Lambda functions in a dev or staging environment first. Should the instrumentation result be unsatisfactory, run \`uninstrument\` with the same arguments to revert the changes.
174
- \n[!] Functions to be updated:
175
- \t- arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\n
176
- [Dry Run] Will apply the following updates:
177
- UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
178
- {
179
- \\"FunctionName\\": \\"arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\\",
180
- \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
181
- \\"Environment\\": {
182
- \\"Variables\\": {
183
- \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
184
- \\"DD_API_KEY\\": \\"1234\\",
185
- \\"DD_SITE\\": \\"datadoghq.com\\",
186
- \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
187
- \\"DD_ENV\\": \\"staging\\",
188
- \\"DD_TAGS\\": \\"layer:api,team:intake\\",
189
- \\"DD_MERGE_XRAY_TRACES\\": \\"true\\",
190
- \\"DD_SERVICE\\": \\"middletier\\",
191
- \\"DD_TRACE_ENABLED\\": \\"true\\",
192
- \\"DD_VERSION\\": \\"0.2\\",
193
- \\"DD_LOG_LEVEL\\": \\"debug\\"
194
- }
195
- },
196
- \\"Layers\\": [
197
- \\"arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Extension:5\\",
198
- \\"arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Node12-x:10\\"
199
- ]
200
- }
201
- TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
202
- {
203
- \\"dd_sls_ci\\": \\"v${version}\\"
204
- }
205
- "
206
- `);
133
+ expect(output).toMatchSnapshot();
207
134
  }));
208
135
  test('prints dry run data for lambda extension layer', () => __awaiter(void 0, void 0, void 0, function* () {
209
136
  ;
@@ -239,40 +166,7 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
239
166
  ], context);
240
167
  const output = context.stdout.toString();
241
168
  expect(code).toBe(0);
242
- expect(output).toMatchInlineSnapshot(`
243
- "\n[Dry Run] 🐶 Instrumenting Lambda function
244
- \n[Warning] Instrument your Lambda functions in a dev or staging environment first. Should the instrumentation result be unsatisfactory, run \`uninstrument\` with the same arguments to revert the changes.
245
- \n[!] Functions to be updated:
246
- \t- arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\n
247
- [Dry Run] Will apply the following updates:
248
- UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
249
- {
250
- \\"FunctionName\\": \\"arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\\",
251
- \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
252
- \\"Environment\\": {
253
- \\"Variables\\": {
254
- \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
255
- \\"DD_API_KEY\\": \\"1234\\",
256
- \\"DD_SITE\\": \\"datadoghq.com\\",
257
- \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
258
- \\"DD_ENV\\": \\"staging\\",
259
- \\"DD_TAGS\\": \\"layer:api,team:intake\\",
260
- \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
261
- \\"DD_SERVICE\\": \\"middletier\\",
262
- \\"DD_TRACE_ENABLED\\": \\"true\\",
263
- \\"DD_VERSION\\": \\"0.2\\"
264
- }
265
- },
266
- \\"Layers\\": [
267
- \\"arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Extension:6\\"
268
- ]
269
- }
270
- TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
271
- {
272
- \\"dd_sls_ci\\": \\"v${version}\\"
273
- }
274
- "
275
- `);
169
+ expect(output).toMatchSnapshot();
276
170
  }));
277
171
  test('prints dry run data for lambda .NET layer', () => __awaiter(void 0, void 0, void 0, function* () {
278
172
  ;
@@ -307,43 +201,7 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
307
201
  ], context);
308
202
  const output = context.stdout.toString();
309
203
  expect(code).toBe(0);
310
- expect(output).toMatchInlineSnapshot(`
311
- "\n[Dry Run] 🐶 Instrumenting Lambda function
312
- \n[Warning] Instrument your Lambda functions in a dev or staging environment first. Should the instrumentation result be unsatisfactory, run \`uninstrument\` with the same arguments to revert the changes.
313
- \n[!] Functions to be updated:
314
- \t- arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\n
315
- [Dry Run] Will apply the following updates:
316
- UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
317
- {
318
- \\"FunctionName\\": \\"arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\\",
319
- \\"Environment\\": {
320
- \\"Variables\\": {
321
- \\"DD_API_KEY\\": \\"1234\\",
322
- \\"DD_SITE\\": \\"datadoghq.com\\",
323
- \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
324
- \\"DD_ENV\\": \\"staging\\",
325
- \\"DD_TAGS\\": \\"layer:api,team:intake\\",
326
- \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
327
- \\"DD_SERVICE\\": \\"middletier\\",
328
- \\"DD_TRACE_ENABLED\\": \\"true\\",
329
- \\"DD_VERSION\\": \\"0.2\\",
330
- \\"DD_FLUSH_TO_LOG\\": \\"true\\",
331
- \\"CORECLR_ENABLE_PROFILING\\": \\"1\\",
332
- \\"CORECLR_PROFILER\\": \\"{846F5F1C-F9AE-4B07-969E-05C26BC060D8}\\",
333
- \\"CORECLR_PROFILER_PATH\\": \\"/opt/datadog/Datadog.Trace.ClrProfiler.Native.so\\",
334
- \\"DD_DOTNET_TRACER_HOME\\": \\"/opt/datadog\\"
335
- }
336
- },
337
- \\"Layers\\": [
338
- \\"arn:aws:lambda:us-east-1:464622532012:layer:dd-trace-dotnet:129\\"
339
- ]
340
- }
341
- TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
342
- {
343
- \\"dd_sls_ci\\": \\"v${version}\\"
344
- }
345
- "
346
- `);
204
+ expect(output).toMatchSnapshot();
347
205
  }));
348
206
  test('instrumenting with source code integrations fails if not run within a git repo', () => __awaiter(void 0, void 0, void 0, function* () {
349
207
  ;
@@ -437,6 +295,10 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
437
295
  remote: 'git.repository_url:git@github.com:datadog/test.git',
438
296
  isClean: true,
439
297
  }));
298
+ const mockUploadFunction = jest.spyOn(instrumentCommand.prototype, 'uploadGitData');
299
+ mockUploadFunction.mockImplementation(() => {
300
+ return;
301
+ });
440
302
  const cli = new advanced_1.Cli();
441
303
  cli.register(instrumentCommand);
442
304
  yield cli.run([
@@ -455,41 +317,54 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
455
317
  '0.1',
456
318
  ], context);
457
319
  const output = context.stdout.toString();
458
- expect(output).toMatchInlineSnapshot(`
459
- "\n🐶 Instrumenting Lambda function\n
460
- [Warning] Instrument your Lambda functions in a dev or staging environment first. Should the instrumentation result be unsatisfactory, run \`uninstrument\` with the same arguments to revert the changes.
461
- \n[!] Functions to be updated:
462
- \t- arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\n
463
- Will apply the following updates:
464
- UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
465
- {
466
- \\"FunctionName\\": \\"arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\\",
467
- \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
468
- \\"Environment\\": {
469
- \\"Variables\\": {
470
- \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
471
- \\"DD_API_KEY\\": \\"1234\\",
472
- \\"DD_SITE\\": \\"datadoghq.com\\",
473
- \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
474
- \\"DD_ENV\\": \\"dummy\\",
475
- \\"DD_TAGS\\": \\"git.commit.sha:1be168ff837f043bde17c0314341c84271047b31,git.repository_url:git.repository_url:github.com/datadog/test.git\\",
476
- \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
477
- \\"DD_SERVICE\\": \\"dummy\\",
478
- \\"DD_TRACE_ENABLED\\": \\"true\\",
479
- \\"DD_VERSION\\": \\"0.1\\",
480
- \\"DD_FLUSH_TO_LOG\\": \\"true\\"
481
- }
482
- },
483
- \\"Layers\\": [
484
- \\"arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Node12-x:10\\"
485
- ]
486
- }
487
- TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
488
- {
489
- \\"dd_sls_ci\\": \\"v${version}\\"
490
- }
491
- "
492
- `);
320
+ expect(output).toMatchSnapshot();
321
+ expect(mockUploadFunction).toHaveBeenCalledTimes(1);
322
+ }));
323
+ test('ensure no git metadata upload flag works', () => __awaiter(void 0, void 0, void 0, function* () {
324
+ ;
325
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
326
+ const lambda = fixtures_1.makeMockLambda({
327
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
328
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
329
+ Handler: 'index.handler',
330
+ Runtime: 'nodejs12.x',
331
+ },
332
+ });
333
+ aws_sdk_1.Lambda.mockImplementation(() => lambda);
334
+ process.env.DATADOG_API_KEY = '1234';
335
+ const context = fixtures_1.createMockContext();
336
+ const instrumentCommand = instrument_1.InstrumentCommand;
337
+ const mockGitStatus = jest.spyOn(instrumentCommand.prototype, 'getCurrentGitStatus');
338
+ mockGitStatus.mockImplementation(() => ({
339
+ ahead: 0,
340
+ hash: '1be168ff837f043bde17c0314341c84271047b31',
341
+ remote: 'git.repository_url:git@github.com:datadog/test.git',
342
+ isClean: true,
343
+ }));
344
+ const mockUploadFunction = jest.spyOn(instrumentCommand.prototype, 'uploadGitData');
345
+ mockUploadFunction.mockImplementation(() => {
346
+ return;
347
+ });
348
+ const cli = new advanced_1.Cli();
349
+ cli.register(instrumentCommand);
350
+ yield cli.run([
351
+ 'lambda',
352
+ 'instrument',
353
+ '--function',
354
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
355
+ '--layerVersion',
356
+ '10',
357
+ '--no-upload-git-metadata',
358
+ '--service',
359
+ 'dummy',
360
+ '--env',
361
+ 'dummy',
362
+ '--version',
363
+ '0.1',
364
+ ], context);
365
+ const output = context.stdout.toString();
366
+ expect(mockUploadFunction).toHaveBeenCalledTimes(0);
367
+ expect(output).toMatchSnapshot();
493
368
  }));
494
369
  test('ensure the instrument command ran from a local git repo ahead of the origin fails', () => __awaiter(void 0, void 0, void 0, function* () {
495
370
  ;
@@ -859,71 +734,7 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
859
734
  const code = yield cli.run(['lambda', 'instrument', '-i', '--no-source-code-integration'], context);
860
735
  const output = context.stdout.toString();
861
736
  expect(code).toBe(0);
862
- expect(output).toMatchInlineSnapshot(`
863
- "\n🐶 Instrumenting Lambda function
864
- [!] No AWS credentials found, let's set them up! Or you can re-run the command and supply the AWS credentials in the same way when you invoke the AWS CLI.
865
- \n[!] Configure AWS region.
866
- \n[!] Configure Datadog settings.
867
- \n[Warning] The environment, service and version tags have not been configured. Learn more about Datadog unified service tagging: https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/#serverless-environment.
868
- \n[Warning] Instrument your Lambda functions in a dev or staging environment first. Should the instrumentation result be unsatisfactory, run \`uninstrument\` with the same arguments to revert the changes.
869
- \n[!] Functions to be updated:
870
- \t- arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
871
- \t[Warning] At least one latest layer version is being used. Ensure to lock in versions for production applications using \`--layerVersion\` and \`--extensionVersion\`.
872
- \t- arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
873
- \t[Warning] At least one latest layer version is being used. Ensure to lock in versions for production applications using \`--layerVersion\` and \`--extensionVersion\`.\n
874
- Will apply the following updates:
875
- UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
876
- {
877
- \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world\\",
878
- \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
879
- \\"Environment\\": {
880
- \\"Variables\\": {
881
- \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
882
- \\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
883
- \\"DD_SITE\\": \\"datadoghq.com\\",
884
- \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
885
- \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
886
- \\"DD_TRACE_ENABLED\\": \\"true\\",
887
- \\"DD_FLUSH_TO_LOG\\": \\"true\\"
888
- }
889
- },
890
- \\"Layers\\": [
891
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
892
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node12-x:1\\"
893
- ]
894
- }
895
- TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
896
- {
897
- \\"dd_sls_ci\\": \\"v${version}\\"
898
- }
899
- UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
900
- {
901
- \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2\\",
902
- \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
903
- \\"Environment\\": {
904
- \\"Variables\\": {
905
- \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
906
- \\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
907
- \\"DD_SITE\\": \\"datadoghq.com\\",
908
- \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
909
- \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
910
- \\"DD_TRACE_ENABLED\\": \\"true\\",
911
- \\"DD_FLUSH_TO_LOG\\": \\"true\\"
912
- }
913
- },
914
- \\"Layers\\": [
915
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
916
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node14-x:1\\"
917
- ]
918
- }
919
- TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
920
- {
921
- \\"dd_sls_ci\\": \\"v${version}\\"
922
- }
923
- [!] Confirmation needed.
924
- [!] Instrumenting functions.
925
- "
926
- `);
737
+ expect(output).toMatchSnapshot();
927
738
  }));
928
739
  test('instrument multiple specified functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
929
740
  const node14LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node14-x`;
@@ -993,71 +804,7 @@ TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
993
804
  ], context);
994
805
  const output = context.stdout.toString();
995
806
  expect(code).toBe(0);
996
- expect(output).toMatchInlineSnapshot(`
997
- "\n🐶 Instrumenting Lambda function
998
- [!] No AWS credentials found, let's set them up! Or you can re-run the command and supply the AWS credentials in the same way when you invoke the AWS CLI.
999
- \n[!] Configure AWS region.
1000
- \n[!] Configure Datadog settings.
1001
- \n[Warning] The environment, service and version tags have not been configured. Learn more about Datadog unified service tagging: https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/#serverless-environment.
1002
- \n[Warning] Instrument your Lambda functions in a dev or staging environment first. Should the instrumentation result be unsatisfactory, run \`uninstrument\` with the same arguments to revert the changes.
1003
- \n[!] Functions to be updated:
1004
- \t- arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1005
- \t[Warning] At least one latest layer version is being used. Ensure to lock in versions for production applications using \`--layerVersion\` and \`--extensionVersion\`.
1006
- \t- arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
1007
- \t[Warning] At least one latest layer version is being used. Ensure to lock in versions for production applications using \`--layerVersion\` and \`--extensionVersion\`.\n
1008
- Will apply the following updates:
1009
- UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1010
- {
1011
- \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world\\",
1012
- \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
1013
- \\"Environment\\": {
1014
- \\"Variables\\": {
1015
- \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
1016
- \\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
1017
- \\"DD_SITE\\": \\"datadoghq.com\\",
1018
- \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
1019
- \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
1020
- \\"DD_TRACE_ENABLED\\": \\"true\\",
1021
- \\"DD_FLUSH_TO_LOG\\": \\"true\\"
1022
- }
1023
- },
1024
- \\"Layers\\": [
1025
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
1026
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node12-x:1\\"
1027
- ]
1028
- }
1029
- TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1030
- {
1031
- \\"dd_sls_ci\\": \\"v${version}\\"
1032
- }
1033
- UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
1034
- {
1035
- \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2\\",
1036
- \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
1037
- \\"Environment\\": {
1038
- \\"Variables\\": {
1039
- \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
1040
- \\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
1041
- \\"DD_SITE\\": \\"datadoghq.com\\",
1042
- \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
1043
- \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
1044
- \\"DD_TRACE_ENABLED\\": \\"true\\",
1045
- \\"DD_FLUSH_TO_LOG\\": \\"true\\"
1046
- }
1047
- },
1048
- \\"Layers\\": [
1049
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
1050
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node14-x:1\\"
1051
- ]
1052
- }
1053
- TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
1054
- {
1055
- \\"dd_sls_ci\\": \\"v${version}\\"
1056
- }
1057
- [!] Confirmation needed.
1058
- [!] Instrumenting functions.
1059
- "
1060
- `);
807
+ expect(output).toMatchSnapshot();
1061
808
  }));
1062
809
  test('aborts if a problem occurs while setting the AWS credentials interactively', () => __awaiter(void 0, void 0, void 0, function* () {
1063
810
  ;
@@ -1140,48 +887,7 @@ TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1140
887
  const code = yield cli.run(['lambda', 'instrument', '-i', '--no-source-code-integration'], context);
1141
888
  const output = context.stdout.toString();
1142
889
  expect(code).toBe(0);
1143
- expect(output).toMatchInlineSnapshot(`
1144
- "\n🐶 Instrumenting Lambda function
1145
- [!] No AWS credentials found, let's set them up! Or you can re-run the command and supply the AWS credentials in the same way when you invoke the AWS CLI.
1146
- \n[!] Configure AWS region.
1147
- \n[!] Configure Datadog settings.
1148
- \n[Warning] Instrument your Lambda functions in a dev or staging environment first. Should the instrumentation result be unsatisfactory, run \`uninstrument\` with the same arguments to revert the changes.
1149
- \n[!] Functions to be updated:
1150
- \t- arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1151
- \t[Warning] At least one latest layer version is being used. Ensure to lock in versions for production applications using \`--layerVersion\` and \`--extensionVersion\`.
1152
-
1153
- Will apply the following updates:
1154
- UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1155
- {
1156
- \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world\\",
1157
- \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
1158
- \\"Environment\\": {
1159
- \\"Variables\\": {
1160
- \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
1161
- \\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
1162
- \\"DD_SITE\\": \\"datadoghq.com\\",
1163
- \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
1164
- \\"DD_ENV\\": \\"sandbox\\",
1165
- \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
1166
- \\"DD_SERVICE\\": \\"testServiceName\\",
1167
- \\"DD_TRACE_ENABLED\\": \\"true\\",
1168
- \\"DD_VERSION\\": \\"1.0.0\\",
1169
- \\"DD_FLUSH_TO_LOG\\": \\"true\\"
1170
- }
1171
- },
1172
- \\"Layers\\": [
1173
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
1174
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node12-x:1\\"
1175
- ]
1176
- }
1177
- TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1178
- {
1179
- \\"dd_sls_ci\\": \\"v${version}\\"
1180
- }
1181
- [!] Confirmation needed.
1182
- [!] Instrumenting functions.
1183
- "
1184
- `);
890
+ expect(output).toMatchSnapshot();
1185
891
  }));
1186
892
  test('when not provided it does not set DD_ENV, DD_SERVICE, and DD_VERSION tags in interactive mode', () => __awaiter(void 0, void 0, void 0, function* () {
1187
893
  const node12LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node12-x`;
@@ -1227,46 +933,7 @@ TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1227
933
  const code = yield cli.run(['lambda', 'instrument', '-i', '--no-source-code-integration'], context);
1228
934
  const output = context.stdout.toString();
1229
935
  expect(code).toBe(0);
1230
- expect(output).toMatchInlineSnapshot(`
1231
- "\n🐶 Instrumenting Lambda function
1232
- [!] No AWS credentials found, let's set them up! Or you can re-run the command and supply the AWS credentials in the same way when you invoke the AWS CLI.
1233
- \n[!] Configure AWS region.
1234
- \n[!] Configure Datadog settings.
1235
- \n[Warning] The environment, service and version tags have not been configured. Learn more about Datadog unified service tagging: https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/#serverless-environment.
1236
- \n[Warning] Instrument your Lambda functions in a dev or staging environment first. Should the instrumentation result be unsatisfactory, run \`uninstrument\` with the same arguments to revert the changes.
1237
- \n[!] Functions to be updated:
1238
- \t- arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1239
- \t[Warning] At least one latest layer version is being used. Ensure to lock in versions for production applications using \`--layerVersion\` and \`--extensionVersion\`.
1240
-
1241
- Will apply the following updates:
1242
- UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1243
- {
1244
- \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world\\",
1245
- \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
1246
- \\"Environment\\": {
1247
- \\"Variables\\": {
1248
- \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
1249
- \\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
1250
- \\"DD_SITE\\": \\"datadoghq.com\\",
1251
- \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
1252
- \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
1253
- \\"DD_TRACE_ENABLED\\": \\"true\\",
1254
- \\"DD_FLUSH_TO_LOG\\": \\"true\\"
1255
- }
1256
- },
1257
- \\"Layers\\": [
1258
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
1259
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node12-x:1\\"
1260
- ]
1261
- }
1262
- TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1263
- {
1264
- \\"dd_sls_ci\\": \\"v${version}\\"
1265
- }
1266
- [!] Confirmation needed.
1267
- [!] Instrumenting functions.
1268
- "
1269
- `);
936
+ expect(output).toMatchSnapshot();
1270
937
  }));
1271
938
  test('aborts if there are no functions to instrument in the user AWS account', () => __awaiter(void 0, void 0, void 0, function* () {
1272
939
  process.env = {
@@ -1472,6 +1139,119 @@ TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1472
1139
  "
1473
1140
  `);
1474
1141
  }));
1142
+ test('prints which functions failed to instrument without aborting when at least one function was instrumented correctly', () => __awaiter(void 0, void 0, void 0, function* () {
1143
+ ;
1144
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1145
+ const failingLambdas = [
1146
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
1147
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-2-us-east-1',
1148
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
1149
+ ];
1150
+ aws_sdk_1.Lambda.mockImplementation(() => (Object.assign(Object.assign({}, fixtures_1.makeMockLambda({
1151
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1': {
1152
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
1153
+ FunctionName: 'lambda-1-us-east-1',
1154
+ Handler: 'index.handler',
1155
+ Runtime: 'nodejs12.x',
1156
+ },
1157
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-2-us-east-1': {
1158
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-2-us-east-1',
1159
+ FunctionName: 'lambda-2-us-east-1',
1160
+ Handler: 'index.handler',
1161
+ Runtime: 'nodejs12.x',
1162
+ },
1163
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-3-us-east-1': {
1164
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-3-us-east-1',
1165
+ FunctionName: 'lambda-3-us-east-1',
1166
+ Handler: 'index.handler',
1167
+ Runtime: 'nodejs12.x',
1168
+ },
1169
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2': {
1170
+ FunctionArn: 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
1171
+ FunctionName: 'lambda-1-us-east-2',
1172
+ Handler: 'index.handler',
1173
+ Runtime: 'nodejs14.x',
1174
+ },
1175
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-2-us-east-2': {
1176
+ FunctionArn: 'arn:aws:lambda:us-east-2:123456789012:function:lambda-2-us-east-2',
1177
+ FunctionName: 'lambda-2-us-east-2',
1178
+ Handler: 'index.handler',
1179
+ Runtime: 'nodejs16.x',
1180
+ },
1181
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-3-us-east-2': {
1182
+ FunctionArn: 'arn:aws:lambda:us-east-2:123456789012:function:lambda-3-us-east-2',
1183
+ FunctionName: 'lambda-3-us-east-2',
1184
+ Handler: 'index.handler',
1185
+ Runtime: 'nodejs18.x',
1186
+ },
1187
+ })), { updateFunctionConfiguration: jest.fn().mockImplementation((updateRequest) => {
1188
+ if (failingLambdas.includes(updateRequest['FunctionName'])) {
1189
+ return { promise: () => Promise.reject(Error('Unexpected error updating request')) };
1190
+ }
1191
+ return { promise: () => Promise.resolve() };
1192
+ }) })));
1193
+ const cli = fixtures_1.makeCli();
1194
+ const context = fixtures_1.createMockContext();
1195
+ const code = yield cli.run([
1196
+ 'lambda',
1197
+ 'instrument',
1198
+ '-f',
1199
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
1200
+ '-f',
1201
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-2-us-east-1',
1202
+ '-f',
1203
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-3-us-east-1',
1204
+ '-f',
1205
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
1206
+ '-f',
1207
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-2-us-east-2',
1208
+ '-f',
1209
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-3-us-east-2',
1210
+ ], context);
1211
+ const output = context.stdout.toString();
1212
+ expect(code).toBe(0);
1213
+ expect(output).toMatchSnapshot();
1214
+ }));
1215
+ test('aborts when every lambda function fails to update on instrument', () => __awaiter(void 0, void 0, void 0, function* () {
1216
+ ;
1217
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1218
+ const failingLambdas = [
1219
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
1220
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
1221
+ ];
1222
+ aws_sdk_1.Lambda.mockImplementation(() => (Object.assign(Object.assign({}, fixtures_1.makeMockLambda({
1223
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1': {
1224
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
1225
+ FunctionName: 'lambda-1-us-east-1',
1226
+ Handler: 'index.handler',
1227
+ Runtime: 'nodejs12.x',
1228
+ },
1229
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2': {
1230
+ FunctionArn: 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
1231
+ FunctionName: 'lambda-1-us-east-2',
1232
+ Handler: 'index.handler',
1233
+ Runtime: 'nodejs14.x',
1234
+ },
1235
+ })), { updateFunctionConfiguration: jest.fn().mockImplementation((updateRequest) => {
1236
+ if (failingLambdas.includes(updateRequest['FunctionName'])) {
1237
+ return { promise: () => Promise.reject(Error('Unexpected error updating request')) };
1238
+ }
1239
+ return { promise: () => Promise.resolve() };
1240
+ }) })));
1241
+ const cli = fixtures_1.makeCli();
1242
+ const context = fixtures_1.createMockContext();
1243
+ const code = yield cli.run([
1244
+ 'lambda',
1245
+ 'instrument',
1246
+ '-f',
1247
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
1248
+ '-f',
1249
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
1250
+ ], context);
1251
+ const output = context.stdout.toString();
1252
+ expect(code).toBe(1);
1253
+ expect(output).toMatchSnapshot();
1254
+ }));
1475
1255
  });
1476
1256
  describe('getSettings', () => {
1477
1257
  test('uses config file settings', () => {