@datadog/datadog-ci 2.3.2 → 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 (42) hide show
  1. package/LICENSE-3rdparty.csv +1 -0
  2. package/README.md +3 -2
  3. package/dist/commands/git-metadata/library.d.ts +1 -0
  4. package/dist/commands/git-metadata/library.js +14 -1
  5. package/dist/commands/git-metadata/library.js.map +1 -1
  6. package/dist/commands/lambda/__tests__/functions/commons.test.js +97 -2
  7. package/dist/commands/lambda/__tests__/functions/commons.test.js.map +1 -1
  8. package/dist/commands/lambda/__tests__/instrument.test.js +141 -420
  9. package/dist/commands/lambda/__tests__/instrument.test.js.map +1 -1
  10. package/dist/commands/lambda/__tests__/loggroup.test.js +68 -2
  11. package/dist/commands/lambda/__tests__/loggroup.test.js.map +1 -1
  12. package/dist/commands/lambda/__tests__/uninstrument.test.js +615 -551
  13. package/dist/commands/lambda/__tests__/uninstrument.test.js.map +1 -1
  14. package/dist/commands/lambda/functions/commons.d.ts +4 -2
  15. package/dist/commands/lambda/functions/commons.js +71 -12
  16. package/dist/commands/lambda/functions/commons.js.map +1 -1
  17. package/dist/commands/lambda/instrument.d.ts +2 -1
  18. package/dist/commands/lambda/instrument.js +29 -23
  19. package/dist/commands/lambda/instrument.js.map +1 -1
  20. package/dist/commands/lambda/interfaces.d.ts +6 -0
  21. package/dist/commands/lambda/loggroup.js +7 -1
  22. package/dist/commands/lambda/loggroup.js.map +1 -1
  23. package/dist/commands/lambda/renderer.d.ts +83 -2
  24. package/dist/commands/lambda/renderer.js +108 -5
  25. package/dist/commands/lambda/renderer.js.map +1 -1
  26. package/dist/commands/lambda/uninstrument.js +13 -17
  27. package/dist/commands/lambda/uninstrument.js.map +1 -1
  28. package/dist/commands/synthetics/index.d.ts +1 -0
  29. package/dist/commands/synthetics/index.js +3 -1
  30. package/dist/commands/synthetics/index.js.map +1 -1
  31. package/dist/helpers/__tests__/user-provided-git.test.js +2 -1
  32. package/dist/helpers/__tests__/user-provided-git.test.js.map +1 -1
  33. package/dist/helpers/__tests__/utils.test.js +7 -0
  34. package/dist/helpers/__tests__/utils.test.js.map +1 -1
  35. package/dist/helpers/ci.js +27 -29
  36. package/dist/helpers/ci.js.map +1 -1
  37. package/dist/helpers/user-provided-git.js +0 -3
  38. package/dist/helpers/user-provided-git.js.map +1 -1
  39. package/dist/helpers/utils.d.ts +2 -1
  40. package/dist/helpers/utils.js +13 -2
  41. package/dist/helpers/utils.js.map +1 -1
  42. package/package.json +7 -5
@@ -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
  ;
@@ -416,7 +274,7 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
416
274
  const output = context.stdout.toString();
417
275
  expect(output).toMatch('Error: Local git repository is dirty');
418
276
  }));
419
- test('ensure source code integration git remotes get formatted correctly', () => __awaiter(void 0, void 0, void 0, function* () {
277
+ test('ensure source code integration flag works from a clean repo', () => __awaiter(void 0, void 0, void 0, function* () {
420
278
  ;
421
279
  fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
422
280
  const lambda = fixtures_1.makeMockLambda({
@@ -430,17 +288,20 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
430
288
  process.env.DATADOG_API_KEY = '1234';
431
289
  const context = fixtures_1.createMockContext();
432
290
  const instrumentCommand = instrument_1.InstrumentCommand;
433
- const instrumentCommandSpy = jest.spyOn(instrumentCommand.prototype, 'filterAndFormatGitRemote');
434
291
  const mockGitStatus = jest.spyOn(instrumentCommand.prototype, 'getCurrentGitStatus');
435
292
  mockGitStatus.mockImplementation(() => ({
436
293
  ahead: 0,
437
294
  hash: '1be168ff837f043bde17c0314341c84271047b31',
438
- remote: 'https://github.com/datadog/test.git',
295
+ remote: 'git.repository_url:git@github.com:datadog/test.git',
439
296
  isClean: true,
440
297
  }));
298
+ const mockUploadFunction = jest.spyOn(instrumentCommand.prototype, 'uploadGitData');
299
+ mockUploadFunction.mockImplementation(() => {
300
+ return;
301
+ });
441
302
  const cli = new advanced_1.Cli();
442
303
  cli.register(instrumentCommand);
443
- const cliInput = [
304
+ yield cli.run([
444
305
  'lambda',
445
306
  'instrument',
446
307
  '--function',
@@ -454,28 +315,12 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
454
315
  'dummy',
455
316
  '--version',
456
317
  '0.1',
457
- ];
458
- yield cli.run(cliInput, context);
459
- mockGitStatus.mockImplementation(() => ({
460
- ahead: 0,
461
- hash: '1be168ff837f043bde17c0314341c84271047b31',
462
- remote: 'git@github.com:datadog/test.git',
463
- isClean: true,
464
- }));
465
- yield cli.run(cliInput, context);
466
- mockGitStatus.mockImplementation(() => ({
467
- ahead: 0,
468
- hash: '1be168ff837f043bde17c0314341c84271047b31',
469
- remote: 'github.com/datadog/test.git',
470
- isClean: true,
471
- }));
472
- yield cli.run(cliInput, context);
473
- expect(instrumentCommandSpy).toHaveBeenCalledTimes(3);
474
- expect(instrumentCommandSpy).toHaveNthReturnedWith(1, 'github.com/datadog/test.git');
475
- expect(instrumentCommandSpy).toHaveNthReturnedWith(2, 'github.com/datadog/test.git');
476
- expect(instrumentCommandSpy).toHaveNthReturnedWith(3, 'github.com/datadog/test.git');
318
+ ], context);
319
+ const output = context.stdout.toString();
320
+ expect(output).toMatchSnapshot();
321
+ expect(mockUploadFunction).toHaveBeenCalledTimes(1);
477
322
  }));
478
- test('ensure source code integration flag works from a clean repo', () => __awaiter(void 0, void 0, void 0, function* () {
323
+ test('ensure no git metadata upload flag works', () => __awaiter(void 0, void 0, void 0, function* () {
479
324
  ;
480
325
  fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
481
326
  const lambda = fixtures_1.makeMockLambda({
@@ -496,6 +341,10 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
496
341
  remote: 'git.repository_url:git@github.com:datadog/test.git',
497
342
  isClean: true,
498
343
  }));
344
+ const mockUploadFunction = jest.spyOn(instrumentCommand.prototype, 'uploadGitData');
345
+ mockUploadFunction.mockImplementation(() => {
346
+ return;
347
+ });
499
348
  const cli = new advanced_1.Cli();
500
349
  cli.register(instrumentCommand);
501
350
  yield cli.run([
@@ -505,7 +354,7 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
505
354
  'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
506
355
  '--layerVersion',
507
356
  '10',
508
- '-s',
357
+ '--no-upload-git-metadata',
509
358
  '--service',
510
359
  'dummy',
511
360
  '--env',
@@ -514,41 +363,8 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
514
363
  '0.1',
515
364
  ], context);
516
365
  const output = context.stdout.toString();
517
- expect(output).toMatchInlineSnapshot(`
518
- "\n🐶 Instrumenting Lambda function\n
519
- [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.
520
- \n[!] Functions to be updated:
521
- \t- arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\n
522
- Will apply the following updates:
523
- UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
524
- {
525
- \\"FunctionName\\": \\"arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world\\",
526
- \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
527
- \\"Environment\\": {
528
- \\"Variables\\": {
529
- \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
530
- \\"DD_API_KEY\\": \\"1234\\",
531
- \\"DD_SITE\\": \\"datadoghq.com\\",
532
- \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
533
- \\"DD_ENV\\": \\"dummy\\",
534
- \\"DD_TAGS\\": \\"git.commit.sha:1be168ff837f043bde17c0314341c84271047b31,git.repository_url:git.repository_url:github.com/datadog/test.git\\",
535
- \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
536
- \\"DD_SERVICE\\": \\"dummy\\",
537
- \\"DD_TRACE_ENABLED\\": \\"true\\",
538
- \\"DD_VERSION\\": \\"0.1\\",
539
- \\"DD_FLUSH_TO_LOG\\": \\"true\\"
540
- }
541
- },
542
- \\"Layers\\": [
543
- \\"arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Node12-x:10\\"
544
- ]
545
- }
546
- TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
547
- {
548
- \\"dd_sls_ci\\": \\"v${version}\\"
549
- }
550
- "
551
- `);
366
+ expect(mockUploadFunction).toHaveBeenCalledTimes(0);
367
+ expect(output).toMatchSnapshot();
552
368
  }));
553
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* () {
554
370
  ;
@@ -918,71 +734,7 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
918
734
  const code = yield cli.run(['lambda', 'instrument', '-i', '--no-source-code-integration'], context);
919
735
  const output = context.stdout.toString();
920
736
  expect(code).toBe(0);
921
- expect(output).toMatchInlineSnapshot(`
922
- "\n🐶 Instrumenting Lambda function
923
- [!] 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.
924
- \n[!] Configure AWS region.
925
- \n[!] Configure Datadog settings.
926
- \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.
927
- \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.
928
- \n[!] Functions to be updated:
929
- \t- arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
930
- \t[Warning] At least one latest layer version is being used. Ensure to lock in versions for production applications using \`--layerVersion\` and \`--extensionVersion\`.
931
- \t- arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
932
- \t[Warning] At least one latest layer version is being used. Ensure to lock in versions for production applications using \`--layerVersion\` and \`--extensionVersion\`.\n
933
- Will apply the following updates:
934
- UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
935
- {
936
- \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world\\",
937
- \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
938
- \\"Environment\\": {
939
- \\"Variables\\": {
940
- \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
941
- \\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
942
- \\"DD_SITE\\": \\"datadoghq.com\\",
943
- \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
944
- \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
945
- \\"DD_TRACE_ENABLED\\": \\"true\\",
946
- \\"DD_FLUSH_TO_LOG\\": \\"true\\"
947
- }
948
- },
949
- \\"Layers\\": [
950
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
951
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node12-x:1\\"
952
- ]
953
- }
954
- TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
955
- {
956
- \\"dd_sls_ci\\": \\"v${version}\\"
957
- }
958
- UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
959
- {
960
- \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2\\",
961
- \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
962
- \\"Environment\\": {
963
- \\"Variables\\": {
964
- \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
965
- \\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
966
- \\"DD_SITE\\": \\"datadoghq.com\\",
967
- \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
968
- \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
969
- \\"DD_TRACE_ENABLED\\": \\"true\\",
970
- \\"DD_FLUSH_TO_LOG\\": \\"true\\"
971
- }
972
- },
973
- \\"Layers\\": [
974
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
975
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node14-x:1\\"
976
- ]
977
- }
978
- TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
979
- {
980
- \\"dd_sls_ci\\": \\"v${version}\\"
981
- }
982
- [!] Confirmation needed.
983
- [!] Instrumenting functions.
984
- "
985
- `);
737
+ expect(output).toMatchSnapshot();
986
738
  }));
987
739
  test('instrument multiple specified functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
988
740
  const node14LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node14-x`;
@@ -1052,71 +804,7 @@ TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1052
804
  ], context);
1053
805
  const output = context.stdout.toString();
1054
806
  expect(code).toBe(0);
1055
- expect(output).toMatchInlineSnapshot(`
1056
- "\n🐶 Instrumenting Lambda function
1057
- [!] 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.
1058
- \n[!] Configure AWS region.
1059
- \n[!] Configure Datadog settings.
1060
- \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.
1061
- \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.
1062
- \n[!] Functions to be updated:
1063
- \t- arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1064
- \t[Warning] At least one latest layer version is being used. Ensure to lock in versions for production applications using \`--layerVersion\` and \`--extensionVersion\`.
1065
- \t- arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
1066
- \t[Warning] At least one latest layer version is being used. Ensure to lock in versions for production applications using \`--layerVersion\` and \`--extensionVersion\`.\n
1067
- Will apply the following updates:
1068
- UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1069
- {
1070
- \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world\\",
1071
- \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
1072
- \\"Environment\\": {
1073
- \\"Variables\\": {
1074
- \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
1075
- \\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
1076
- \\"DD_SITE\\": \\"datadoghq.com\\",
1077
- \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
1078
- \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
1079
- \\"DD_TRACE_ENABLED\\": \\"true\\",
1080
- \\"DD_FLUSH_TO_LOG\\": \\"true\\"
1081
- }
1082
- },
1083
- \\"Layers\\": [
1084
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
1085
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node12-x:1\\"
1086
- ]
1087
- }
1088
- TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1089
- {
1090
- \\"dd_sls_ci\\": \\"v${version}\\"
1091
- }
1092
- UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
1093
- {
1094
- \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2\\",
1095
- \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
1096
- \\"Environment\\": {
1097
- \\"Variables\\": {
1098
- \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
1099
- \\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
1100
- \\"DD_SITE\\": \\"datadoghq.com\\",
1101
- \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
1102
- \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
1103
- \\"DD_TRACE_ENABLED\\": \\"true\\",
1104
- \\"DD_FLUSH_TO_LOG\\": \\"true\\"
1105
- }
1106
- },
1107
- \\"Layers\\": [
1108
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
1109
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node14-x:1\\"
1110
- ]
1111
- }
1112
- TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
1113
- {
1114
- \\"dd_sls_ci\\": \\"v${version}\\"
1115
- }
1116
- [!] Confirmation needed.
1117
- [!] Instrumenting functions.
1118
- "
1119
- `);
807
+ expect(output).toMatchSnapshot();
1120
808
  }));
1121
809
  test('aborts if a problem occurs while setting the AWS credentials interactively', () => __awaiter(void 0, void 0, void 0, function* () {
1122
810
  ;
@@ -1199,48 +887,7 @@ TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1199
887
  const code = yield cli.run(['lambda', 'instrument', '-i', '--no-source-code-integration'], context);
1200
888
  const output = context.stdout.toString();
1201
889
  expect(code).toBe(0);
1202
- expect(output).toMatchInlineSnapshot(`
1203
- "\n🐶 Instrumenting Lambda function
1204
- [!] 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.
1205
- \n[!] Configure AWS region.
1206
- \n[!] Configure Datadog settings.
1207
- \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.
1208
- \n[!] Functions to be updated:
1209
- \t- arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1210
- \t[Warning] At least one latest layer version is being used. Ensure to lock in versions for production applications using \`--layerVersion\` and \`--extensionVersion\`.
1211
-
1212
- Will apply the following updates:
1213
- UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1214
- {
1215
- \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world\\",
1216
- \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
1217
- \\"Environment\\": {
1218
- \\"Variables\\": {
1219
- \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
1220
- \\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
1221
- \\"DD_SITE\\": \\"datadoghq.com\\",
1222
- \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
1223
- \\"DD_ENV\\": \\"sandbox\\",
1224
- \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
1225
- \\"DD_SERVICE\\": \\"testServiceName\\",
1226
- \\"DD_TRACE_ENABLED\\": \\"true\\",
1227
- \\"DD_VERSION\\": \\"1.0.0\\",
1228
- \\"DD_FLUSH_TO_LOG\\": \\"true\\"
1229
- }
1230
- },
1231
- \\"Layers\\": [
1232
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
1233
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node12-x:1\\"
1234
- ]
1235
- }
1236
- TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1237
- {
1238
- \\"dd_sls_ci\\": \\"v${version}\\"
1239
- }
1240
- [!] Confirmation needed.
1241
- [!] Instrumenting functions.
1242
- "
1243
- `);
890
+ expect(output).toMatchSnapshot();
1244
891
  }));
1245
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* () {
1246
893
  const node12LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node12-x`;
@@ -1286,46 +933,7 @@ TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1286
933
  const code = yield cli.run(['lambda', 'instrument', '-i', '--no-source-code-integration'], context);
1287
934
  const output = context.stdout.toString();
1288
935
  expect(code).toBe(0);
1289
- expect(output).toMatchInlineSnapshot(`
1290
- "\n🐶 Instrumenting Lambda function
1291
- [!] 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.
1292
- \n[!] Configure AWS region.
1293
- \n[!] Configure Datadog settings.
1294
- \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.
1295
- \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.
1296
- \n[!] Functions to be updated:
1297
- \t- arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1298
- \t[Warning] At least one latest layer version is being used. Ensure to lock in versions for production applications using \`--layerVersion\` and \`--extensionVersion\`.
1299
-
1300
- Will apply the following updates:
1301
- UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1302
- {
1303
- \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world\\",
1304
- \\"Handler\\": \\"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler\\",
1305
- \\"Environment\\": {
1306
- \\"Variables\\": {
1307
- \\"DD_LAMBDA_HANDLER\\": \\"index.handler\\",
1308
- \\"DD_API_KEY\\": \\"02aeb762fff59ac0d5ad1536cd9633bd\\",
1309
- \\"DD_SITE\\": \\"datadoghq.com\\",
1310
- \\"DD_CAPTURE_LAMBDA_PAYLOAD\\": \\"false\\",
1311
- \\"DD_MERGE_XRAY_TRACES\\": \\"false\\",
1312
- \\"DD_TRACE_ENABLED\\": \\"true\\",
1313
- \\"DD_FLUSH_TO_LOG\\": \\"true\\"
1314
- }
1315
- },
1316
- \\"Layers\\": [
1317
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:1\\",
1318
- \\"arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Node12-x:1\\"
1319
- ]
1320
- }
1321
- TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1322
- {
1323
- \\"dd_sls_ci\\": \\"v${version}\\"
1324
- }
1325
- [!] Confirmation needed.
1326
- [!] Instrumenting functions.
1327
- "
1328
- `);
936
+ expect(output).toMatchSnapshot();
1329
937
  }));
1330
938
  test('aborts if there are no functions to instrument in the user AWS account', () => __awaiter(void 0, void 0, void 0, function* () {
1331
939
  process.env = {
@@ -1531,6 +1139,119 @@ TagResource -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
1531
1139
  "
1532
1140
  `);
1533
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
+ }));
1534
1255
  });
1535
1256
  describe('getSettings', () => {
1536
1257
  test('uses config file settings', () => {