@datadog/datadog-ci 2.4.0 → 2.5.0

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 (203) hide show
  1. package/LICENSE-3rdparty.csv +1 -0
  2. package/dist/commands/dsyms/upload.js +2 -1
  3. package/dist/commands/dsyms/upload.js.map +1 -1
  4. package/dist/commands/flutter-symbols/helpers.js +1 -1
  5. package/dist/commands/flutter-symbols/helpers.js.map +1 -1
  6. package/dist/commands/flutter-symbols/upload.js +1 -1
  7. package/dist/commands/flutter-symbols/upload.js.map +1 -1
  8. package/dist/commands/lambda/functions/commons.d.ts +4 -2
  9. package/dist/commands/lambda/functions/commons.js +71 -12
  10. package/dist/commands/lambda/functions/commons.js.map +1 -1
  11. package/dist/commands/lambda/instrument.d.ts +2 -0
  12. package/dist/commands/lambda/instrument.js +28 -13
  13. package/dist/commands/lambda/instrument.js.map +1 -1
  14. package/dist/commands/lambda/interfaces.d.ts +6 -0
  15. package/dist/commands/lambda/loggroup.js +7 -1
  16. package/dist/commands/lambda/loggroup.js.map +1 -1
  17. package/dist/commands/lambda/renderer.d.ts +74 -2
  18. package/dist/commands/lambda/renderer.js +98 -5
  19. package/dist/commands/lambda/renderer.js.map +1 -1
  20. package/dist/commands/lambda/uninstrument.js +14 -18
  21. package/dist/commands/lambda/uninstrument.js.map +1 -1
  22. package/dist/commands/react-native/upload.js +2 -2
  23. package/dist/commands/react-native/upload.js.map +1 -1
  24. package/dist/commands/react-native/xcode.js +5 -0
  25. package/dist/commands/react-native/xcode.js.map +1 -1
  26. package/dist/commands/synthetics/api.d.ts +2 -1
  27. package/dist/commands/synthetics/api.js +7 -0
  28. package/dist/commands/synthetics/api.js.map +1 -1
  29. package/dist/commands/synthetics/command.js +11 -2
  30. package/dist/commands/synthetics/command.js.map +1 -1
  31. package/dist/commands/synthetics/index.d.ts +1 -0
  32. package/dist/commands/synthetics/index.js +3 -1
  33. package/dist/commands/synthetics/index.js.map +1 -1
  34. package/dist/commands/synthetics/interfaces.d.ts +4 -1
  35. package/dist/commands/synthetics/reporters/default.d.ts +3 -2
  36. package/dist/commands/synthetics/reporters/default.js +19 -5
  37. package/dist/commands/synthetics/reporters/default.js.map +1 -1
  38. package/dist/commands/synthetics/reporters/junit.d.ts +2 -2
  39. package/dist/commands/synthetics/reporters/junit.js +1 -1
  40. package/dist/commands/synthetics/reporters/junit.js.map +1 -1
  41. package/dist/commands/synthetics/run-test.js +9 -1
  42. package/dist/commands/synthetics/run-test.js.map +1 -1
  43. package/dist/commands/synthetics/utils.d.ts +4 -2
  44. package/dist/commands/synthetics/utils.js +14 -5
  45. package/dist/commands/synthetics/utils.js.map +1 -1
  46. package/dist/helpers/ci.js +27 -29
  47. package/dist/helpers/ci.js.map +1 -1
  48. package/dist/helpers/user-provided-git.js +0 -3
  49. package/dist/helpers/user-provided-git.js.map +1 -1
  50. package/dist/helpers/utils.d.ts +3 -3
  51. package/dist/helpers/utils.js +10 -6
  52. package/dist/helpers/utils.js.map +1 -1
  53. package/package.json +7 -5
  54. package/dist/commands/dsyms/__tests__/upload.test.d.ts +0 -1
  55. package/dist/commands/dsyms/__tests__/upload.test.js +0 -297
  56. package/dist/commands/dsyms/__tests__/upload.test.js.map +0 -1
  57. package/dist/commands/dsyms/__tests__/utils.test.d.ts +0 -1
  58. package/dist/commands/dsyms/__tests__/utils.test.js +0 -99
  59. package/dist/commands/dsyms/__tests__/utils.test.js.map +0 -1
  60. package/dist/commands/flutter-symbols/__tests__/upload.test.d.ts +0 -1
  61. package/dist/commands/flutter-symbols/__tests__/upload.test.js +0 -538
  62. package/dist/commands/flutter-symbols/__tests__/upload.test.js.map +0 -1
  63. package/dist/commands/git-metadata/__tests__/git.test.d.ts +0 -1
  64. package/dist/commands/git-metadata/__tests__/git.test.js +0 -148
  65. package/dist/commands/git-metadata/__tests__/git.test.js.map +0 -1
  66. package/dist/commands/git-metadata/__tests__/library.test.d.ts +0 -1
  67. package/dist/commands/git-metadata/__tests__/library.test.js +0 -103
  68. package/dist/commands/git-metadata/__tests__/library.test.js.map +0 -1
  69. package/dist/commands/git-metadata/__tests__/upload.test.d.ts +0 -1
  70. package/dist/commands/git-metadata/__tests__/upload.test.js +0 -60
  71. package/dist/commands/git-metadata/__tests__/upload.test.js.map +0 -1
  72. package/dist/commands/junit/__tests__/api.test.d.ts +0 -1
  73. package/dist/commands/junit/__tests__/api.test.js +0 -9
  74. package/dist/commands/junit/__tests__/api.test.js.map +0 -1
  75. package/dist/commands/junit/__tests__/upload.test.d.ts +0 -1
  76. package/dist/commands/junit/__tests__/upload.test.js +0 -283
  77. package/dist/commands/junit/__tests__/upload.test.js.map +0 -1
  78. package/dist/commands/lambda/__tests__/fixtures.d.ts +0 -49
  79. package/dist/commands/lambda/__tests__/fixtures.js +0 -88
  80. package/dist/commands/lambda/__tests__/fixtures.js.map +0 -1
  81. package/dist/commands/lambda/__tests__/functions/commons.test.d.ts +0 -1
  82. package/dist/commands/lambda/__tests__/functions/commons.test.js +0 -621
  83. package/dist/commands/lambda/__tests__/functions/commons.test.js.map +0 -1
  84. package/dist/commands/lambda/__tests__/functions/instrument.part1.test.d.ts +0 -1
  85. package/dist/commands/lambda/__tests__/functions/instrument.part1.test.js +0 -350
  86. package/dist/commands/lambda/__tests__/functions/instrument.part1.test.js.map +0 -1
  87. package/dist/commands/lambda/__tests__/functions/instrument.part2.test.d.ts +0 -1
  88. package/dist/commands/lambda/__tests__/functions/instrument.part2.test.js +0 -583
  89. package/dist/commands/lambda/__tests__/functions/instrument.part2.test.js.map +0 -1
  90. package/dist/commands/lambda/__tests__/functions/uninstrument.test.d.ts +0 -1
  91. package/dist/commands/lambda/__tests__/functions/uninstrument.test.js +0 -477
  92. package/dist/commands/lambda/__tests__/functions/uninstrument.test.js.map +0 -1
  93. package/dist/commands/lambda/__tests__/functions/versionChecker.test.d.ts +0 -1
  94. package/dist/commands/lambda/__tests__/functions/versionChecker.test.js +0 -33
  95. package/dist/commands/lambda/__tests__/functions/versionChecker.test.js.map +0 -1
  96. package/dist/commands/lambda/__tests__/instrument.test.d.ts +0 -1
  97. package/dist/commands/lambda/__tests__/instrument.test.js +0 -1698
  98. package/dist/commands/lambda/__tests__/instrument.test.js.map +0 -1
  99. package/dist/commands/lambda/__tests__/loggroup.test.d.ts +0 -1
  100. package/dist/commands/lambda/__tests__/loggroup.test.js +0 -266
  101. package/dist/commands/lambda/__tests__/loggroup.test.js.map +0 -1
  102. package/dist/commands/lambda/__tests__/prompt.test.d.ts +0 -1
  103. package/dist/commands/lambda/__tests__/prompt.test.js +0 -235
  104. package/dist/commands/lambda/__tests__/prompt.test.js.map +0 -1
  105. package/dist/commands/lambda/__tests__/tags.test.d.ts +0 -1
  106. package/dist/commands/lambda/__tests__/tags.test.js +0 -253
  107. package/dist/commands/lambda/__tests__/tags.test.js.map +0 -1
  108. package/dist/commands/lambda/__tests__/uninstrument.test.d.ts +0 -1
  109. package/dist/commands/lambda/__tests__/uninstrument.test.js +0 -615
  110. package/dist/commands/lambda/__tests__/uninstrument.test.js.map +0 -1
  111. package/dist/commands/metric/__tests__/metric.test.d.ts +0 -1
  112. package/dist/commands/metric/__tests__/metric.test.js +0 -97
  113. package/dist/commands/metric/__tests__/metric.test.js.map +0 -1
  114. package/dist/commands/react-native/__tests__/codepush.test.d.ts +0 -1
  115. package/dist/commands/react-native/__tests__/codepush.test.js +0 -153
  116. package/dist/commands/react-native/__tests__/codepush.test.js.map +0 -1
  117. package/dist/commands/react-native/__tests__/interfaces.test.d.ts +0 -1
  118. package/dist/commands/react-native/__tests__/interfaces.test.js +0 -52
  119. package/dist/commands/react-native/__tests__/interfaces.test.js.map +0 -1
  120. package/dist/commands/react-native/__tests__/upload.test.d.ts +0 -1
  121. package/dist/commands/react-native/__tests__/upload.test.js +0 -176
  122. package/dist/commands/react-native/__tests__/upload.test.js.map +0 -1
  123. package/dist/commands/react-native/__tests__/xcode.test.d.ts +0 -1
  124. package/dist/commands/react-native/__tests__/xcode.test.js +0 -417
  125. package/dist/commands/react-native/__tests__/xcode.test.js.map +0 -1
  126. package/dist/commands/sourcemaps/__tests__/upload.test.d.ts +0 -1
  127. package/dist/commands/sourcemaps/__tests__/upload.test.js +0 -270
  128. package/dist/commands/sourcemaps/__tests__/upload.test.js.map +0 -1
  129. package/dist/commands/sourcemaps/__tests__/utils.test.d.ts +0 -1
  130. package/dist/commands/sourcemaps/__tests__/utils.test.js +0 -31
  131. package/dist/commands/sourcemaps/__tests__/utils.test.js.map +0 -1
  132. package/dist/commands/synthetics/__tests__/api.test.d.ts +0 -1
  133. package/dist/commands/synthetics/__tests__/api.test.js +0 -273
  134. package/dist/commands/synthetics/__tests__/api.test.js.map +0 -1
  135. package/dist/commands/synthetics/__tests__/cli.test.d.ts +0 -1
  136. package/dist/commands/synthetics/__tests__/cli.test.js +0 -391
  137. package/dist/commands/synthetics/__tests__/cli.test.js.map +0 -1
  138. package/dist/commands/synthetics/__tests__/fixtures.d.ts +0 -119
  139. package/dist/commands/synthetics/__tests__/fixtures.js +0 -386
  140. package/dist/commands/synthetics/__tests__/fixtures.js.map +0 -1
  141. package/dist/commands/synthetics/__tests__/mobile.test.d.ts +0 -1
  142. package/dist/commands/synthetics/__tests__/mobile.test.js +0 -228
  143. package/dist/commands/synthetics/__tests__/mobile.test.js.map +0 -1
  144. package/dist/commands/synthetics/__tests__/reporters/default.test.d.ts +0 -1
  145. package/dist/commands/synthetics/__tests__/reporters/default.test.js +0 -202
  146. package/dist/commands/synthetics/__tests__/reporters/default.test.js.map +0 -1
  147. package/dist/commands/synthetics/__tests__/reporters/junit.test.d.ts +0 -1
  148. package/dist/commands/synthetics/__tests__/reporters/junit.test.js +0 -339
  149. package/dist/commands/synthetics/__tests__/reporters/junit.test.js.map +0 -1
  150. package/dist/commands/synthetics/__tests__/run-test.test.d.ts +0 -1
  151. package/dist/commands/synthetics/__tests__/run-test.test.js +0 -419
  152. package/dist/commands/synthetics/__tests__/run-test.test.js.map +0 -1
  153. package/dist/commands/synthetics/__tests__/tunnel/crypto.test.d.ts +0 -1
  154. package/dist/commands/synthetics/__tests__/tunnel/crypto.test.js +0 -21
  155. package/dist/commands/synthetics/__tests__/tunnel/crypto.test.js.map +0 -1
  156. package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.d.ts +0 -1
  157. package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.js +0 -80
  158. package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.js.map +0 -1
  159. package/dist/commands/synthetics/__tests__/tunnel/websocket.test.d.ts +0 -1
  160. package/dist/commands/synthetics/__tests__/tunnel/websocket.test.js +0 -111
  161. package/dist/commands/synthetics/__tests__/tunnel/websocket.test.js.map +0 -1
  162. package/dist/commands/synthetics/__tests__/utils.test.d.ts +0 -1
  163. package/dist/commands/synthetics/__tests__/utils.test.js +0 -933
  164. package/dist/commands/synthetics/__tests__/utils.test.js.map +0 -1
  165. package/dist/commands/tag/__tests__/tag.test.d.ts +0 -1
  166. package/dist/commands/tag/__tests__/tag.test.js +0 -77
  167. package/dist/commands/tag/__tests__/tag.test.js.map +0 -1
  168. package/dist/commands/trace/__tests__/trace.test.d.ts +0 -1
  169. package/dist/commands/trace/__tests__/trace.test.js +0 -64
  170. package/dist/commands/trace/__tests__/trace.test.js.map +0 -1
  171. package/dist/helpers/__tests__/ci.test.d.ts +0 -1
  172. package/dist/helpers/__tests__/ci.test.js +0 -197
  173. package/dist/helpers/__tests__/ci.test.js.map +0 -1
  174. package/dist/helpers/__tests__/plist.test.d.ts +0 -1
  175. package/dist/helpers/__tests__/plist.test.js +0 -31
  176. package/dist/helpers/__tests__/plist.test.js.map +0 -1
  177. package/dist/helpers/__tests__/retry.test.d.ts +0 -1
  178. package/dist/helpers/__tests__/retry.test.js +0 -99
  179. package/dist/helpers/__tests__/retry.test.js.map +0 -1
  180. package/dist/helpers/__tests__/tags.test.d.ts +0 -1
  181. package/dist/helpers/__tests__/tags.test.js +0 -17
  182. package/dist/helpers/__tests__/tags.test.js.map +0 -1
  183. package/dist/helpers/__tests__/upload.test.d.ts +0 -1
  184. package/dist/helpers/__tests__/upload.test.js +0 -185
  185. package/dist/helpers/__tests__/upload.test.js.map +0 -1
  186. package/dist/helpers/__tests__/user-provided-git.test.d.ts +0 -1
  187. package/dist/helpers/__tests__/user-provided-git.test.js +0 -118
  188. package/dist/helpers/__tests__/user-provided-git.test.js.map +0 -1
  189. package/dist/helpers/__tests__/utils.test.d.ts +0 -1
  190. package/dist/helpers/__tests__/utils.test.js +0 -382
  191. package/dist/helpers/__tests__/utils.test.js.map +0 -1
  192. package/dist/helpers/__tests__/validation.test.d.ts +0 -1
  193. package/dist/helpers/__tests__/validation.test.js +0 -21
  194. package/dist/helpers/__tests__/validation.test.js.map +0 -1
  195. package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.d.ts +0 -1
  196. package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.js +0 -106
  197. package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.js.map +0 -1
  198. package/dist/helpers/git/__tests__/format-git-span-data.test.d.ts +0 -1
  199. package/dist/helpers/git/__tests__/format-git-span-data.test.js +0 -67
  200. package/dist/helpers/git/__tests__/format-git-span-data.test.js.map +0 -1
  201. package/dist/helpers/git/__tests__/get-git-data.test.d.ts +0 -1
  202. package/dist/helpers/git/__tests__/get-git-data.test.js +0 -60
  203. package/dist/helpers/git/__tests__/get-git-data.test.js.map +0 -1
@@ -1,1698 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
- var __importDefault = (this && this.__importDefault) || function (mod) {
31
- return (mod && mod.__esModule) ? mod : { "default": mod };
32
- };
33
- Object.defineProperty(exports, "__esModule", { value: true });
34
- jest.mock('fs');
35
- jest.mock('aws-sdk');
36
- jest.mock('../prompt');
37
- jest.mock('../renderer', () => require('../__mocks__/renderer'));
38
- const fs = __importStar(require("fs"));
39
- const path_1 = __importDefault(require("path"));
40
- const aws_sdk_1 = require("aws-sdk");
41
- const advanced_1 = require("clipanion/lib/advanced");
42
- const constants_1 = require("../constants");
43
- const instrument_1 = require("../instrument");
44
- const prompt_1 = require("../prompt");
45
- const fixtures_1 = require("./fixtures");
46
- const { version } = require(path_1.default.join(__dirname, '../../../../package.json'));
47
- describe('lambda', () => {
48
- describe('instrument', () => {
49
- describe('execute', () => {
50
- const OLD_ENV = process.env;
51
- beforeEach(() => {
52
- jest.resetModules();
53
- process.env = {};
54
- });
55
- afterAll(() => {
56
- process.env = OLD_ENV;
57
- });
58
- test('prints dry run data for lambda library layer', () => __awaiter(void 0, void 0, void 0, function* () {
59
- ;
60
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
61
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
62
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
63
- FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
64
- Handler: 'index.handler',
65
- Runtime: 'nodejs12.x',
66
- },
67
- }));
68
- const cli = fixtures_1.makeCli();
69
- const context = fixtures_1.createMockContext();
70
- const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
71
- const code = yield cli.run([
72
- 'lambda',
73
- 'instrument',
74
- '-f',
75
- functionARN,
76
- '--dry',
77
- '--layerVersion',
78
- '10',
79
- '--logLevel',
80
- 'debug',
81
- '--service',
82
- 'middletier',
83
- '--env',
84
- 'staging',
85
- '--version',
86
- '0.2',
87
- '--extra-tags',
88
- 'layer:api,team:intake',
89
- '--no-source-code-integration',
90
- ], context);
91
- const output = context.stdout.toString();
92
- 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
- `);
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
- '--no-source-code-integration',
168
- ], context);
169
- const output = context.stdout.toString();
170
- 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
- `);
207
- }));
208
- test('prints dry run data for lambda extension layer', () => __awaiter(void 0, void 0, void 0, function* () {
209
- ;
210
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
211
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
212
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
213
- FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
214
- Handler: 'index.handler',
215
- Runtime: 'nodejs12.x',
216
- },
217
- }));
218
- const cli = fixtures_1.makeCli();
219
- const context = fixtures_1.createMockContext();
220
- const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
221
- process.env.DATADOG_API_KEY = '1234';
222
- const code = yield cli.run([
223
- 'lambda',
224
- 'instrument',
225
- '-f',
226
- functionARN,
227
- '--dry',
228
- '--extensionVersion',
229
- '6',
230
- '--service',
231
- 'middletier',
232
- '--env',
233
- 'staging',
234
- '--version',
235
- '0.2',
236
- '--extra-tags',
237
- 'layer:api,team:intake',
238
- '--no-source-code-integration',
239
- ], context);
240
- const output = context.stdout.toString();
241
- 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
- `);
276
- }));
277
- test('prints dry run data for lambda .NET layer', () => __awaiter(void 0, void 0, void 0, function* () {
278
- ;
279
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
280
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
281
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
282
- FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
283
- Runtime: 'dotnetcore3.1',
284
- },
285
- }));
286
- const cli = fixtures_1.makeCli();
287
- const context = fixtures_1.createMockContext();
288
- const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
289
- process.env.DATADOG_API_KEY = '1234';
290
- const code = yield cli.run([
291
- 'lambda',
292
- 'instrument',
293
- '-f',
294
- functionARN,
295
- '--dry',
296
- '-v',
297
- '129',
298
- '--extra-tags',
299
- 'layer:api,team:intake',
300
- '--service',
301
- 'middletier',
302
- '--env',
303
- 'staging',
304
- '--version',
305
- '0.2',
306
- '--no-source-code-integration',
307
- ], context);
308
- const output = context.stdout.toString();
309
- 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
- `);
347
- }));
348
- test('instrumenting with source code integrations fails if not run within a git repo', () => __awaiter(void 0, void 0, void 0, function* () {
349
- ;
350
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
351
- const lambda = fixtures_1.makeMockLambda({
352
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
353
- FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
354
- Handler: 'index.handler',
355
- Runtime: 'nodejs12.x',
356
- },
357
- });
358
- aws_sdk_1.Lambda.mockImplementation(() => lambda);
359
- process.env.DATADOG_API_KEY = '1234';
360
- const cli = fixtures_1.makeCli();
361
- const context = fixtures_1.createMockContext();
362
- yield cli.run([
363
- 'lambda',
364
- 'instrument',
365
- '--function',
366
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
367
- '--layerVersion',
368
- '10',
369
- '-s',
370
- '--service',
371
- 'dummy',
372
- '--env',
373
- 'dummy',
374
- '--version',
375
- '0.1',
376
- ], context);
377
- const output = context.stdout.toString();
378
- expect(output.replace('\n', '')).toMatch(/.*Error: Couldn't get local git status.*/);
379
- }));
380
- test('ensure the instrument command ran from a dirty git repo fails', () => __awaiter(void 0, void 0, void 0, function* () {
381
- ;
382
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
383
- const lambda = fixtures_1.makeMockLambda({
384
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
385
- FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
386
- Handler: 'index.handler',
387
- Runtime: 'nodejs12.x',
388
- },
389
- });
390
- aws_sdk_1.Lambda.mockImplementation(() => lambda);
391
- process.env.DATADOG_API_KEY = '1234';
392
- const context = fixtures_1.createMockContext();
393
- const instrumentCommand = instrument_1.InstrumentCommand;
394
- const mockGitStatus = jest.spyOn(instrumentCommand.prototype, 'getCurrentGitStatus');
395
- mockGitStatus.mockImplementation(() => ({
396
- ahead: 0,
397
- isClean: false,
398
- }));
399
- const cli = new advanced_1.Cli();
400
- cli.register(instrumentCommand);
401
- yield cli.run([
402
- 'lambda',
403
- 'instrument',
404
- '--function',
405
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
406
- '--layerVersion',
407
- '10',
408
- '-s',
409
- '--service',
410
- 'dummy',
411
- '--env',
412
- 'dummy',
413
- '--version',
414
- '0.1',
415
- ], context);
416
- const output = context.stdout.toString();
417
- expect(output).toMatch('Error: Local git repository is dirty');
418
- }));
419
- test('ensure source code integration flag works from a clean repo', () => __awaiter(void 0, void 0, void 0, function* () {
420
- ;
421
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
422
- const lambda = fixtures_1.makeMockLambda({
423
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
424
- FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
425
- Handler: 'index.handler',
426
- Runtime: 'nodejs12.x',
427
- },
428
- });
429
- aws_sdk_1.Lambda.mockImplementation(() => lambda);
430
- process.env.DATADOG_API_KEY = '1234';
431
- const context = fixtures_1.createMockContext();
432
- const instrumentCommand = instrument_1.InstrumentCommand;
433
- const mockGitStatus = jest.spyOn(instrumentCommand.prototype, 'getCurrentGitStatus');
434
- mockGitStatus.mockImplementation(() => ({
435
- ahead: 0,
436
- hash: '1be168ff837f043bde17c0314341c84271047b31',
437
- remote: 'git.repository_url:git@github.com:datadog/test.git',
438
- isClean: true,
439
- }));
440
- const cli = new advanced_1.Cli();
441
- cli.register(instrumentCommand);
442
- yield cli.run([
443
- 'lambda',
444
- 'instrument',
445
- '--function',
446
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
447
- '--layerVersion',
448
- '10',
449
- '-s',
450
- '--service',
451
- 'dummy',
452
- '--env',
453
- 'dummy',
454
- '--version',
455
- '0.1',
456
- ], context);
457
- 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
- `);
493
- }));
494
- 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
- ;
496
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
497
- const lambda = fixtures_1.makeMockLambda({
498
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
499
- FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
500
- Handler: 'index.handler',
501
- Runtime: 'nodejs12.x',
502
- },
503
- });
504
- aws_sdk_1.Lambda.mockImplementation(() => lambda);
505
- process.env.DATADOG_API_KEY = '1234';
506
- const context = fixtures_1.createMockContext();
507
- const instrumentCommand = instrument_1.InstrumentCommand;
508
- const mockGitStatus = jest.spyOn(instrumentCommand.prototype, 'getCurrentGitStatus');
509
- mockGitStatus.mockImplementation(() => ({
510
- ahead: 1,
511
- isClean: true,
512
- }));
513
- const cli = new advanced_1.Cli();
514
- cli.register(instrumentCommand);
515
- yield cli.run([
516
- 'lambda',
517
- 'instrument',
518
- '--function',
519
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
520
- '--layerVersion',
521
- '10',
522
- '-s',
523
- '--service',
524
- 'dummy',
525
- '--env',
526
- 'dummy',
527
- '--version',
528
- '0.1',
529
- ], context);
530
- const output = context.stdout.toString();
531
- expect(output).toMatch('Error: Local changes have not been pushed remotely. Aborting git data tagging.');
532
- }));
533
- test('runs function update command for lambda library layer', () => __awaiter(void 0, void 0, void 0, function* () {
534
- ;
535
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
536
- const lambda = fixtures_1.makeMockLambda({
537
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
538
- FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
539
- Handler: 'index.handler',
540
- Runtime: 'nodejs12.x',
541
- },
542
- });
543
- aws_sdk_1.Lambda.mockImplementation(() => lambda);
544
- const cli = fixtures_1.makeCli();
545
- const context = fixtures_1.createMockContext();
546
- yield cli.run([
547
- 'lambda',
548
- 'instrument',
549
- '--function',
550
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
551
- '--layerVersion',
552
- '10',
553
- '--no-source-code-integration',
554
- ], context);
555
- expect(lambda.updateFunctionConfiguration).toHaveBeenCalled();
556
- }));
557
- test('runs function update command for lambda extension layer', () => __awaiter(void 0, void 0, void 0, function* () {
558
- ;
559
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
560
- const lambda = fixtures_1.makeMockLambda({
561
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
562
- FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
563
- Handler: 'index.handler',
564
- Runtime: 'nodejs12.x',
565
- },
566
- });
567
- aws_sdk_1.Lambda.mockImplementation(() => lambda);
568
- const cli = fixtures_1.makeCli();
569
- const context = fixtures_1.createMockContext();
570
- process.env.DATADOG_API_KEY = '1234';
571
- yield cli.run([
572
- 'lambda',
573
- 'instrument',
574
- '--function',
575
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
576
- '--extensionVersion',
577
- '6',
578
- '--no-source-code-integration',
579
- ], context);
580
- expect(lambda.updateFunctionConfiguration).toHaveBeenCalled();
581
- }));
582
- test('aborts early when no functions are specified', () => __awaiter(void 0, void 0, void 0, function* () {
583
- ;
584
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
585
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
586
- const cli = fixtures_1.makeCli();
587
- const context = fixtures_1.createMockContext();
588
- const code = yield cli.run([
589
- 'lambda',
590
- 'instrument',
591
- '--layerVersion',
592
- '10',
593
- '--service',
594
- 'middletier',
595
- '--env',
596
- 'staging',
597
- '--version',
598
- '0.2',
599
- ], context);
600
- const output = context.stdout.toString();
601
- expect(code).toBe(1);
602
- expect(output).toMatchInlineSnapshot(`
603
- "\n🐶 Instrumenting Lambda function
604
- [Error] No functions specified to instrument.
605
- "
606
- `);
607
- }));
608
- test('aborts early when no functions are specified while using config file', () => __awaiter(void 0, void 0, void 0, function* () {
609
- ;
610
- fs.readFile.mockImplementation((a, b, callback) => callback({}));
611
- process.env = {};
612
- const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
613
- command['config']['layerVersion'] = '60';
614
- command['config']['extensionVersion'] = '10';
615
- command['config']['region'] = 'ap-southeast-1';
616
- command['config']['service'] = 'middletier';
617
- command['config']['environment'] = 'staging';
618
- command['config']['version'] = '0.2';
619
- yield command['execute']();
620
- const output = command.context.stdout.toString();
621
- expect(output).toMatchInlineSnapshot(`
622
- "\n🐶 Instrumenting Lambda function
623
- [Error] No functions specified to instrument.
624
- "
625
- `);
626
- }));
627
- test("aborts early when function regions can't be found", () => __awaiter(void 0, void 0, void 0, function* () {
628
- ;
629
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
630
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
631
- const cli = fixtures_1.makeCli();
632
- const context = fixtures_1.createMockContext();
633
- const code = yield cli.run([
634
- 'lambda',
635
- 'instrument',
636
- '--function',
637
- 'my-func',
638
- '--layerVersion',
639
- '10',
640
- '--service',
641
- 'middletier',
642
- '--env',
643
- 'staging',
644
- '--version',
645
- '0.2',
646
- '--no-source-code-integration',
647
- ], context);
648
- const output = context.stdout.toString();
649
- expect(code).toBe(1);
650
- expect(output).toMatch(`Couldn't group functions. Error: No default region specified for ["my-func"]. Use -r, --region, or use a full functionARN\n`);
651
- }));
652
- test('aborts if a function is not in an Active state with LastUpdateStatus Successful', () => __awaiter(void 0, void 0, void 0, function* () {
653
- ;
654
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
655
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
656
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
657
- FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
658
- Handler: 'index.handler',
659
- LastUpdateStatus: 'Unsuccessful',
660
- Runtime: 'nodejs12.x',
661
- State: 'Failed',
662
- },
663
- }));
664
- const cli = fixtures_1.makeCli();
665
- const context = fixtures_1.createMockContext();
666
- const code = yield cli.run([
667
- 'lambda',
668
- 'instrument',
669
- '--function',
670
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
671
- '--layerVersion',
672
- '10',
673
- '--service',
674
- 'middletier',
675
- '--env',
676
- 'staging',
677
- '--version',
678
- '0.2',
679
- '--no-source-code-integration',
680
- ], context);
681
- const output = context.stdout.toString();
682
- expect(code).toBe(1);
683
- expect(output).toMatchInlineSnapshot(`
684
- "\n🐶 Instrumenting Lambda function
685
- [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\\")
686
- "
687
- `);
688
- }));
689
- test('aborts early when extensionVersion and forwarder are set', () => __awaiter(void 0, void 0, void 0, function* () {
690
- ;
691
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
692
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
693
- const cli = fixtures_1.makeCli();
694
- const context = fixtures_1.createMockContext();
695
- const code = yield cli.run([
696
- 'lambda',
697
- 'instrument',
698
- '--function',
699
- 'test-function-arn',
700
- '--forwarder',
701
- 'arn:aws:lambda:sa-east-1:000000000000:function:datadog-forwarder',
702
- '--extensionVersion',
703
- '6',
704
- '--region',
705
- 'us-east-1',
706
- '--service',
707
- 'middletier',
708
- '--env',
709
- 'staging',
710
- '--version',
711
- '0.2',
712
- ], context);
713
- const output = context.stdout.toString();
714
- expect(code).toBe(1);
715
- expect(output).toMatchInlineSnapshot(`
716
- "\n🐶 Instrumenting Lambda function
717
- [Error] \\"extensionVersion\\" and \\"forwarder\\" should not be used at the same time.
718
- "
719
- `);
720
- }));
721
- test('check if functions are not empty while using config file', () => __awaiter(void 0, void 0, void 0, function* () {
722
- ;
723
- fs.readFile.mockImplementation((a, b, callback) => callback({}));
724
- process.env = {};
725
- const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
726
- command['config']['layerVersion'] = '60';
727
- command['config']['extensionVersion'] = '10';
728
- command['config']['region'] = 'ap-southeast-1';
729
- command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
730
- yield command['execute']();
731
- expect(command['config']['functions']).toHaveLength(1);
732
- }));
733
- test('aborts if functions and a pattern are set at the same time', () => __awaiter(void 0, void 0, void 0, function* () {
734
- ;
735
- fs.readFile.mockImplementation((a, b, callback) => callback({}));
736
- process.env = {};
737
- let command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
738
- command['config']['environment'] = 'staging';
739
- command['config']['service'] = 'middletier';
740
- command['config']['version'] = '2';
741
- command['config']['region'] = 'ap-southeast-1';
742
- command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
743
- command['regExPattern'] = 'valid-pattern';
744
- command['sourceCodeIntegration'] = false;
745
- yield command['execute']();
746
- let output = command.context.stdout.toString();
747
- expect(output).toMatch('Functions in config file and "--functions-regex" should not be used at the same time.\n');
748
- command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
749
- command['environment'] = 'staging';
750
- command['service'] = 'middletier';
751
- command['version'] = '2';
752
- command['region'] = 'ap-southeast-1';
753
- command['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
754
- command['regExPattern'] = 'valid-pattern';
755
- command['sourceCodeIntegration'] = false;
756
- yield command['execute']();
757
- output = command.context.stdout.toString();
758
- expect(output).toMatch('"--functions" and "--functions-regex" should not be used at the same time.\n');
759
- }));
760
- test('aborts if pattern is set and no default region is specified', () => __awaiter(void 0, void 0, void 0, function* () {
761
- ;
762
- fs.readFile.mockImplementation((a, b, callback) => callback({}));
763
- process.env = {};
764
- const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
765
- command['environment'] = 'staging';
766
- command['service'] = 'middletier';
767
- command['version'] = '2';
768
- command['regExPattern'] = 'valid-pattern';
769
- command['sourceCodeIntegration'] = false;
770
- yield command['execute']();
771
- const output = command.context.stdout.toString();
772
- expect(output).toMatch('[Error] No default region specified. Use `-r`, `--region`.\n');
773
- }));
774
- test('aborts if the regEx pattern is an ARN', () => __awaiter(void 0, void 0, void 0, function* () {
775
- ;
776
- fs.readFile.mockImplementation((a, b, callback) => callback({}));
777
- process.env = {};
778
- const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
779
- command['environment'] = 'staging';
780
- command['service'] = 'middletier';
781
- command['version'] = '2';
782
- command['region'] = 'ap-southeast-1';
783
- command['regExPattern'] = 'arn:aws:lambda:ap-southeast-1:123456789012:function:*';
784
- command['sourceCodeIntegration'] = false;
785
- yield command['execute']();
786
- const output = command.context.stdout.toString();
787
- expect(output).toMatch(`"--functions-regex" isn't meant to be used with ARNs.\n`);
788
- }));
789
- test('instrument multiple functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
790
- const node18LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node18-x`;
791
- const node16LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node16-x`;
792
- const node14LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node14-x`;
793
- const node12LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node12-x`;
794
- const extensionLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension`;
795
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
796
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
797
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
798
- FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
799
- FunctionName: 'lambda-hello-world',
800
- Handler: 'index.handler',
801
- Runtime: 'nodejs12.x',
802
- },
803
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2': {
804
- FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
805
- FunctionName: 'lambda-hello-world-2',
806
- Handler: 'index.handler',
807
- Runtime: 'nodejs14.x',
808
- },
809
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-3': {
810
- FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-3',
811
- FunctionName: 'lambda-hello-world-3',
812
- Handler: 'index.handler',
813
- Runtime: 'nodejs16.x',
814
- },
815
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-4': {
816
- FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-3',
817
- FunctionName: 'lambda-hello-world-4',
818
- Handler: 'index.handler',
819
- Runtime: 'nodejs18.x',
820
- },
821
- }, {
822
- [`${node14LibraryLayer}:1`]: {
823
- LayerVersionArn: `${node14LibraryLayer}:1`,
824
- Version: 1,
825
- },
826
- [`${node12LibraryLayer}:1`]: {
827
- LayerVersionArn: `${node12LibraryLayer}:1`,
828
- Version: 1,
829
- },
830
- [`${node16LibraryLayer}:1`]: {
831
- LayerVersionArn: `${node16LibraryLayer}:1`,
832
- Version: 1,
833
- },
834
- [`${node18LibraryLayer}:1`]: {
835
- LayerVersionArn: `${node18LibraryLayer}:1`,
836
- Version: 1,
837
- },
838
- [`${extensionLayer}:1`]: {
839
- LayerVersionArn: `${extensionLayer}:1`,
840
- Version: 1,
841
- },
842
- }));
843
- prompt_1.requestAWSCredentials.mockImplementation(() => {
844
- process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_1.mockAwsAccessKeyId;
845
- process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_1.mockAwsSecretAccessKey;
846
- process.env[constants_1.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
847
- });
848
- prompt_1.requestDatadogEnvVars.mockImplementation(() => {
849
- process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
850
- process.env[constants_1.CI_API_KEY_ENV_VAR] = fixtures_1.mockDatadogApiKey;
851
- });
852
- prompt_1.requestFunctionSelection.mockImplementation(() => [
853
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
854
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
855
- ]);
856
- prompt_1.requestChangesConfirmation.mockImplementation(() => true);
857
- const cli = fixtures_1.makeCli();
858
- const context = fixtures_1.createMockContext();
859
- const code = yield cli.run(['lambda', 'instrument', '-i', '--no-source-code-integration'], context);
860
- const output = context.stdout.toString();
861
- 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
- `);
927
- }));
928
- test('instrument multiple specified functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
929
- const node14LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node14-x`;
930
- const node16LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node16-x`;
931
- const node12LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node12-x`;
932
- const extensionLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension`;
933
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
934
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
935
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
936
- FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
937
- FunctionName: 'lambda-hello-world',
938
- Handler: 'index.handler',
939
- Runtime: 'nodejs12.x',
940
- },
941
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2': {
942
- FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
943
- FunctionName: 'lambda-hello-world-2',
944
- Handler: 'index.handler',
945
- Runtime: 'nodejs14.x',
946
- },
947
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-3': {
948
- FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-3',
949
- FunctionName: 'lambda-hello-world-3',
950
- Handler: 'index.handler',
951
- Runtime: 'nodejs16.x',
952
- },
953
- }, {
954
- [`${node14LibraryLayer}:1`]: {
955
- LayerVersionArn: `${node14LibraryLayer}:1`,
956
- Version: 1,
957
- },
958
- [`${node12LibraryLayer}:1`]: {
959
- LayerVersionArn: `${node12LibraryLayer}:1`,
960
- Version: 1,
961
- },
962
- [`${node16LibraryLayer}:1`]: {
963
- LayerVersionArn: `${node16LibraryLayer}:1`,
964
- Version: 1,
965
- },
966
- [`${extensionLayer}:1`]: {
967
- LayerVersionArn: `${extensionLayer}:1`,
968
- Version: 1,
969
- },
970
- }));
971
- prompt_1.requestAWSCredentials.mockImplementation(() => {
972
- process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_1.mockAwsAccessKeyId;
973
- process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_1.mockAwsSecretAccessKey;
974
- process.env[constants_1.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
975
- process.env[constants_1.AWS_SESSION_TOKEN_ENV_VAR] = 'some-session-token';
976
- });
977
- prompt_1.requestDatadogEnvVars.mockImplementation(() => {
978
- process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
979
- process.env[constants_1.CI_API_KEY_ENV_VAR] = fixtures_1.mockDatadogApiKey;
980
- });
981
- prompt_1.requestChangesConfirmation.mockImplementation(() => true);
982
- const cli = fixtures_1.makeCli();
983
- const context = fixtures_1.createMockContext();
984
- const code = yield cli.run([
985
- 'lambda',
986
- 'instrument',
987
- '-i',
988
- '-f',
989
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
990
- '-f',
991
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
992
- '--no-source-code-integration',
993
- ], context);
994
- const output = context.stdout.toString();
995
- 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
- `);
1061
- }));
1062
- test('aborts if a problem occurs while setting the AWS credentials interactively', () => __awaiter(void 0, void 0, void 0, function* () {
1063
- ;
1064
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1065
- prompt_1.requestAWSCredentials.mockImplementation(() => Promise.reject('Unexpected error'));
1066
- const cli = fixtures_1.makeCli();
1067
- const context = fixtures_1.createMockContext();
1068
- const code = yield cli.run(['lambda', 'instrument', '-i'], context);
1069
- const output = context.stdout.toString();
1070
- expect(code).toBe(1);
1071
- expect(output).toMatchInlineSnapshot(`
1072
- "\n🐶 Instrumenting Lambda function
1073
- [!] 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.
1074
- [Error] Unexpected error
1075
- "
1076
- `);
1077
- }));
1078
- test('aborts if a problem occurs while setting the Datadog Environment Variables interactively', () => __awaiter(void 0, void 0, void 0, function* () {
1079
- process.env = {
1080
- [constants_1.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_1.mockAwsAccessKeyId,
1081
- [constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_1.mockAwsSecretAccessKey,
1082
- [constants_1.AWS_DEFAULT_REGION_ENV_VAR]: 'sa,-east-1',
1083
- };
1084
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1085
- prompt_1.requestDatadogEnvVars.mockImplementation(() => Promise.reject('Unexpected error'));
1086
- const cli = fixtures_1.makeCli();
1087
- const context = fixtures_1.createMockContext();
1088
- const code = yield cli.run(['lambda', 'instrument', '-i'], context);
1089
- const output = context.stdout.toString();
1090
- expect(code).toBe(1);
1091
- expect(output).toMatchInlineSnapshot(`
1092
- "\n🐶 Instrumenting Lambda function
1093
- \n[!] Configure AWS region.
1094
- \n[!] Configure Datadog settings.
1095
- [Error] Unexpected error
1096
- "
1097
- `);
1098
- }));
1099
- test('when provided it sets DD_ENV, DD_SERVICE, and DD_VERSION environment variables in interactive mode', () => __awaiter(void 0, void 0, void 0, function* () {
1100
- const node12LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node12-x`;
1101
- const extensionLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension`;
1102
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1103
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
1104
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
1105
- FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
1106
- FunctionName: 'lambda-hello-world',
1107
- Handler: 'index.handler',
1108
- Runtime: 'nodejs12.x',
1109
- },
1110
- }, {
1111
- [`${node12LibraryLayer}:1`]: {
1112
- LayerVersionArn: `${node12LibraryLayer}:1`,
1113
- Version: 1,
1114
- },
1115
- [`${extensionLayer}:1`]: {
1116
- LayerVersionArn: `${extensionLayer}:1`,
1117
- Version: 1,
1118
- },
1119
- }));
1120
- prompt_1.requestAWSCredentials.mockImplementation(() => {
1121
- process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_1.mockAwsAccessKeyId;
1122
- process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_1.mockAwsSecretAccessKey;
1123
- process.env[constants_1.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
1124
- });
1125
- prompt_1.requestDatadogEnvVars.mockImplementation(() => {
1126
- process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
1127
- process.env[constants_1.CI_API_KEY_ENV_VAR] = fixtures_1.mockDatadogApiKey;
1128
- });
1129
- prompt_1.requestFunctionSelection.mockImplementation(() => [
1130
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
1131
- ]);
1132
- prompt_1.requestChangesConfirmation.mockImplementation(() => true);
1133
- prompt_1.requestEnvServiceVersion.mockImplementation(() => {
1134
- process.env[constants_1.ENVIRONMENT_ENV_VAR] = fixtures_1.mockDatadogEnv;
1135
- process.env[constants_1.SERVICE_ENV_VAR] = fixtures_1.mockDatadogService;
1136
- process.env[constants_1.VERSION_ENV_VAR] = fixtures_1.mockDatadogVersion;
1137
- });
1138
- const cli = fixtures_1.makeCli();
1139
- const context = fixtures_1.createMockContext();
1140
- const code = yield cli.run(['lambda', 'instrument', '-i', '--no-source-code-integration'], context);
1141
- const output = context.stdout.toString();
1142
- 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
- `);
1185
- }));
1186
- 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
- const node12LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node12-x`;
1188
- const extensionLayer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension`;
1189
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1190
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
1191
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
1192
- FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
1193
- FunctionName: 'lambda-hello-world',
1194
- Handler: 'index.handler',
1195
- Runtime: 'nodejs12.x',
1196
- },
1197
- }, {
1198
- [`${node12LibraryLayer}:1`]: {
1199
- LayerVersionArn: `${node12LibraryLayer}:1`,
1200
- Version: 1,
1201
- },
1202
- [`${extensionLayer}:1`]: {
1203
- LayerVersionArn: `${extensionLayer}:1`,
1204
- Version: 1,
1205
- },
1206
- }));
1207
- prompt_1.requestAWSCredentials.mockImplementation(() => {
1208
- process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_1.mockAwsAccessKeyId;
1209
- process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_1.mockAwsSecretAccessKey;
1210
- process.env[constants_1.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
1211
- });
1212
- prompt_1.requestDatadogEnvVars.mockImplementation(() => {
1213
- process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
1214
- process.env[constants_1.CI_API_KEY_ENV_VAR] = fixtures_1.mockDatadogApiKey;
1215
- });
1216
- prompt_1.requestFunctionSelection.mockImplementation(() => [
1217
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
1218
- ]);
1219
- prompt_1.requestChangesConfirmation.mockImplementation(() => true);
1220
- prompt_1.requestEnvServiceVersion.mockImplementation(() => {
1221
- process.env[constants_1.ENVIRONMENT_ENV_VAR] = undefined;
1222
- process.env[constants_1.SERVICE_ENV_VAR] = undefined;
1223
- process.env[constants_1.VERSION_ENV_VAR] = undefined;
1224
- });
1225
- const cli = fixtures_1.makeCli();
1226
- const context = fixtures_1.createMockContext();
1227
- const code = yield cli.run(['lambda', 'instrument', '-i', '--no-source-code-integration'], context);
1228
- const output = context.stdout.toString();
1229
- 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
- `);
1270
- }));
1271
- test('aborts if there are no functions to instrument in the user AWS account', () => __awaiter(void 0, void 0, void 0, function* () {
1272
- process.env = {
1273
- [constants_1.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_1.mockAwsAccessKeyId,
1274
- [constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_1.mockAwsSecretAccessKey,
1275
- [constants_1.AWS_DEFAULT_REGION_ENV_VAR]: 'sa-east-1',
1276
- [constants_1.CI_SITE_ENV_VAR]: 'datadoghq.com',
1277
- [constants_1.CI_API_KEY_ENV_VAR]: fixtures_1.mockDatadogApiKey,
1278
- };
1279
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1280
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
1281
- const cli = fixtures_1.makeCli();
1282
- const context = fixtures_1.createMockContext();
1283
- const code = yield cli.run(['lambda', 'instrument', '-i'], context);
1284
- const output = context.stdout.toString();
1285
- expect(code).toBe(1);
1286
- expect(output).toMatchInlineSnapshot(`
1287
- "\n🐶 Instrumenting Lambda function
1288
- \n[!] Configure AWS region.
1289
- [Error] Couldn't find any Lambda functions in the specified region.
1290
- "
1291
- `);
1292
- }));
1293
- test('aborts early when the aws-sdk throws an error while instrumenting interactively', () => __awaiter(void 0, void 0, void 0, function* () {
1294
- process.env = {
1295
- [constants_1.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_1.mockAwsAccessKeyId,
1296
- [constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_1.mockAwsSecretAccessKey,
1297
- [constants_1.AWS_DEFAULT_REGION_ENV_VAR]: 'sa-east-1',
1298
- [constants_1.CI_SITE_ENV_VAR]: 'datadoghq.com',
1299
- [constants_1.CI_API_KEY_ENV_VAR]: fixtures_1.mockDatadogApiKey,
1300
- };
1301
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1302
- aws_sdk_1.Lambda.mockImplementation(() => ({
1303
- listFunctions: jest.fn().mockImplementation(() => ({ promise: () => Promise.reject('ListFunctionsError') })),
1304
- }));
1305
- const cli = fixtures_1.makeCli();
1306
- const context = fixtures_1.createMockContext();
1307
- const code = yield cli.run(['lambda', 'instrument', '-i'], context);
1308
- const output = context.stdout.toString();
1309
- expect(code).toBe(1);
1310
- expect(output).toMatchInlineSnapshot(`
1311
- "\n🐶 Instrumenting Lambda function
1312
- \n[!] Configure AWS region.
1313
- [Error] Couldn't fetch Lambda functions. Error: Max retry count exceeded. ListFunctionsError
1314
- "
1315
- `);
1316
- }));
1317
- test('aborts early when a layer version is set for Ruby', () => __awaiter(void 0, void 0, void 0, function* () {
1318
- ;
1319
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1320
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
1321
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
1322
- FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
1323
- Runtime: 'ruby2.7',
1324
- },
1325
- }));
1326
- const cli = fixtures_1.makeCli();
1327
- const context = fixtures_1.createMockContext();
1328
- const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
1329
- process.env.DATADOG_API_KEY = '1234';
1330
- const code = yield cli.run([
1331
- 'lambda',
1332
- 'instrument',
1333
- '-f',
1334
- functionARN,
1335
- '--dry',
1336
- '-v',
1337
- '40',
1338
- '--extra-tags',
1339
- 'layer:api,team:intake',
1340
- '--service',
1341
- 'middletier',
1342
- '--env',
1343
- 'staging',
1344
- '--version',
1345
- '0.2',
1346
- '--no-source-code-integration',
1347
- ], context);
1348
- const output = context.stdout.toString();
1349
- expect(code).toBe(1);
1350
- expect(output).toMatchInlineSnapshot(`
1351
- "\n[Dry Run] 🐶 Instrumenting Lambda function
1352
- [Error] Couldn't fetch Lambda functions. Error: Only the --extension-version argument should be set for the ruby2.7 runtime. Please remove the --layer-version argument from the instrument command.
1353
- "
1354
- `);
1355
- }));
1356
- test('aborts early when a layer version is set for a Custom runtime', () => __awaiter(void 0, void 0, void 0, function* () {
1357
- ;
1358
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1359
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
1360
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
1361
- FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
1362
- Runtime: 'provided.al2',
1363
- },
1364
- }));
1365
- const cli = fixtures_1.makeCli();
1366
- const context = fixtures_1.createMockContext();
1367
- const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
1368
- process.env.DATADOG_API_KEY = '1234';
1369
- const code = yield cli.run([
1370
- 'lambda',
1371
- 'instrument',
1372
- '-f',
1373
- functionARN,
1374
- '--dry',
1375
- '-v',
1376
- '6',
1377
- '--extra-tags',
1378
- 'layer:api,team:intake',
1379
- '--service',
1380
- 'middletier',
1381
- '--env',
1382
- 'staging',
1383
- '--version',
1384
- '0.2',
1385
- '--no-source-code-integration',
1386
- ], context);
1387
- const output = context.stdout.toString();
1388
- expect(code).toBe(1);
1389
- expect(output).toMatchInlineSnapshot(`
1390
- "\n[Dry Run] 🐶 Instrumenting Lambda function
1391
- [Error] Couldn't fetch Lambda functions. Error: Only the --extension-version argument should be set for the provided.al2 runtime. Please remove the --layer-version argument from the instrument command.
1392
- "
1393
- `);
1394
- }));
1395
- test('aborts early when .NET is using ARM64 architecture', () => __awaiter(void 0, void 0, void 0, function* () {
1396
- ;
1397
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1398
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
1399
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
1400
- Architectures: ['arm64'],
1401
- FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
1402
- Runtime: 'dotnetcore3.1',
1403
- },
1404
- }));
1405
- const cli = fixtures_1.makeCli();
1406
- const context = fixtures_1.createMockContext();
1407
- const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
1408
- process.env.DATADOG_API_KEY = '1234';
1409
- const code = yield cli.run([
1410
- 'lambda',
1411
- 'instrument',
1412
- '-f',
1413
- functionARN,
1414
- '--dry',
1415
- '-v',
1416
- '6',
1417
- '--extra-tags',
1418
- 'layer:api,team:intake',
1419
- '--service',
1420
- 'middletier',
1421
- '--env',
1422
- 'staging',
1423
- '--version',
1424
- '0.2',
1425
- '--no-source-code-integration',
1426
- ], context);
1427
- const output = context.stdout.toString();
1428
- expect(code).toBe(1);
1429
- expect(output).toMatchInlineSnapshot(`
1430
- "\n[Dry Run] 🐶 Instrumenting Lambda function
1431
- [Error] Couldn't fetch Lambda functions. Error: Instrumenting arm64 architecture is not supported for the given dd-extension version. Please choose the latest dd-extension version or use x86_64 architecture.
1432
- "
1433
- `);
1434
- }));
1435
- test('instruments correctly with profile when provided', () => __awaiter(void 0, void 0, void 0, function* () {
1436
- var _a;
1437
- const credentials = {
1438
- accessKeyId: fixtures_1.mockAwsAccessKeyId,
1439
- getPromise: () => Promise.resolve(),
1440
- needsRefresh: () => false,
1441
- secretAccessKey: fixtures_1.mockAwsSecretAccessKey,
1442
- };
1443
- aws_sdk_1.SharedIniFileCredentials.mockImplementation(() => credentials);
1444
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
1445
- 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
1446
- FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
1447
- Handler: 'index.handler',
1448
- Runtime: 'nodejs14.x',
1449
- },
1450
- }));
1451
- const cli = fixtures_1.makeCli();
1452
- const context = fixtures_1.createMockContext();
1453
- const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
1454
- const code = yield cli.run(['lambda', 'instrument', '-f', functionARN, '--profile', 'SOME-AWS-PROFILE', '--no-source-code-integration'], context);
1455
- expect(code).toBe(0);
1456
- expect((_a = aws_sdk_1.config.credentials) === null || _a === void 0 ? void 0 : _a.accessKeyId).toBe(fixtures_1.mockAwsAccessKeyId);
1457
- }));
1458
- test('prints error when updating aws profile credentials fails', () => __awaiter(void 0, void 0, void 0, function* () {
1459
- ;
1460
- aws_sdk_1.SharedIniFileCredentials.mockImplementation(() => {
1461
- throw Error('Update failed!');
1462
- });
1463
- const cli = fixtures_1.makeCli();
1464
- const context = fixtures_1.createMockContext();
1465
- const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
1466
- const code = yield cli.run(['lambda', 'instrument', '-f', functionARN, '--profile', 'SOME-AWS-PROFILE'], context);
1467
- const output = context.stdout.toString();
1468
- expect(code).toBe(1);
1469
- expect(output).toMatchInlineSnapshot(`
1470
- "\n🐶 Instrumenting Lambda function
1471
- [Error] Error: Couldn't set AWS profile credentials. Update failed!
1472
- "
1473
- `);
1474
- }));
1475
- });
1476
- describe('getSettings', () => {
1477
- test('uses config file settings', () => {
1478
- process.env = {};
1479
- const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
1480
- command['config']['flushMetricsToLogs'] = 'false';
1481
- command['config']['forwarder'] = 'my-forwarder';
1482
- command['config']['layerVersion'] = '2';
1483
- command['config']['extensionVersion'] = '6';
1484
- command['config']['layerAWSAccount'] = 'another-account';
1485
- command['config']['mergeXrayTraces'] = 'false';
1486
- command['config']['tracing'] = 'false';
1487
- command['config']['logLevel'] = 'debug';
1488
- expect(command['getSettings']()).toEqual({
1489
- captureLambdaPayload: false,
1490
- environment: undefined,
1491
- extensionVersion: 6,
1492
- extraTags: undefined,
1493
- flushMetricsToLogs: false,
1494
- forwarderARN: 'my-forwarder',
1495
- interactive: false,
1496
- layerAWSAccount: 'another-account',
1497
- layerVersion: 2,
1498
- logLevel: 'debug',
1499
- mergeXrayTraces: false,
1500
- service: undefined,
1501
- tracingEnabled: false,
1502
- version: undefined,
1503
- });
1504
- });
1505
- test('prefers command line arguments over config file', () => {
1506
- process.env = {};
1507
- const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
1508
- command['forwarder'] = 'my-forwarder';
1509
- command['config']['forwarder'] = 'another-forwarder';
1510
- command['layerVersion'] = '1';
1511
- command['config']['layerVersion'] = '2';
1512
- command['layerAWSAccount'] = 'my-account';
1513
- command['config']['layerAWSAccount'] = 'another-account';
1514
- command['mergeXrayTraces'] = 'true';
1515
- command['config']['mergeXrayTraces'] = 'false';
1516
- command['flushMetricsToLogs'] = 'false';
1517
- command['config']['flushMetricsToLogs'] = 'true';
1518
- command['tracing'] = 'true';
1519
- command['config']['tracing'] = 'false';
1520
- command['logLevel'] = 'debug';
1521
- command['config']['logLevel'] = 'info';
1522
- expect(command['getSettings']()).toEqual({
1523
- captureLambdaPayload: false,
1524
- flushMetricsToLogs: false,
1525
- forwarderARN: 'my-forwarder',
1526
- interactive: false,
1527
- layerAWSAccount: 'my-account',
1528
- layerVersion: 1,
1529
- logLevel: 'debug',
1530
- mergeXrayTraces: true,
1531
- tracingEnabled: true,
1532
- });
1533
- });
1534
- test("returns undefined when layer version can't be parsed", () => {
1535
- process.env = {};
1536
- const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
1537
- command.context = {
1538
- stdout: { write: jest.fn() },
1539
- };
1540
- command['layerVersion'] = 'abd';
1541
- expect(command['getSettings']()).toBeUndefined();
1542
- });
1543
- test("returns undefined when extension version can't be parsed", () => {
1544
- process.env = {};
1545
- const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
1546
- command.context = {
1547
- stdout: { write: jest.fn() },
1548
- };
1549
- command['extensionVersion'] = 'abd';
1550
- expect(command['getSettings']()).toBeUndefined();
1551
- });
1552
- test('converts string boolean from command line and config file correctly', () => {
1553
- process.env = {};
1554
- const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
1555
- const validSettings = {
1556
- captureLambdaPayload: true,
1557
- extensionVersion: undefined,
1558
- flushMetricsToLogs: false,
1559
- forwarderARN: undefined,
1560
- interactive: false,
1561
- layerAWSAccount: undefined,
1562
- layerVersion: undefined,
1563
- logLevel: undefined,
1564
- mergeXrayTraces: false,
1565
- tracingEnabled: true,
1566
- };
1567
- command['config']['captureLambdaPayload'] = 'truE';
1568
- command['config']['flushMetricsToLogs'] = 'False';
1569
- command['config']['mergeXrayTraces'] = 'falSE';
1570
- command['config']['tracing'] = 'TRUE';
1571
- expect(command['getSettings']()).toEqual(validSettings);
1572
- command['config']['captureLambdaPayload'] = 'true';
1573
- command['config']['flushMetricsToLogs'] = 'false';
1574
- command['config']['mergeXrayTraces'] = 'false';
1575
- command['config']['tracing'] = 'true';
1576
- expect(command['getSettings']()).toEqual(validSettings);
1577
- validSettings.captureLambdaPayload = false;
1578
- validSettings.flushMetricsToLogs = true;
1579
- validSettings.mergeXrayTraces = true;
1580
- validSettings.tracingEnabled = false;
1581
- command['captureLambdaPayload'] = 'faLSE';
1582
- command['flushMetricsToLogs'] = 'truE';
1583
- command['mergeXrayTraces'] = 'TRUe';
1584
- command['tracing'] = 'FALSE';
1585
- expect(command['getSettings']()).toEqual(validSettings);
1586
- command['captureLambdaPayload'] = 'false';
1587
- command['flushMetricsToLogs'] = 'true';
1588
- command['mergeXrayTraces'] = 'true';
1589
- command['tracing'] = 'false';
1590
- expect(command['getSettings']()).toEqual(validSettings);
1591
- });
1592
- test('aborts early if converting string boolean has an invalid value', () => {
1593
- process.env = {};
1594
- const stringBooleans = [
1595
- 'flushMetricsToLogs',
1596
- 'mergeXrayTraces',
1597
- 'tracing',
1598
- ];
1599
- for (const option of stringBooleans) {
1600
- let command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
1601
- command['config'][option] = 'NotBoolean';
1602
- command['getSettings']();
1603
- let output = command.context.stdout.toString();
1604
- expect(output).toMatch(`[Error] Invalid boolean specified for ${option}.\n`);
1605
- command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
1606
- command[option] = 'NotBoolean';
1607
- command['getSettings']();
1608
- output = command.context.stdout.toString();
1609
- expect(output).toMatch(`Invalid boolean specified for ${option}.\n`);
1610
- }
1611
- });
1612
- test('warns if any of environment, service or version tags are not set', () => __awaiter(void 0, void 0, void 0, function* () {
1613
- ;
1614
- fs.readFile.mockImplementation((a, b, callback) => callback({}));
1615
- process.env = {};
1616
- let command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
1617
- command['config']['region'] = 'ap-southeast-1';
1618
- command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
1619
- command['getSettings']();
1620
- let output = command.context.stdout.toString();
1621
- expect(output).toMatch('[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.\n');
1622
- command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
1623
- command['config']['region'] = 'ap-southeast-1';
1624
- command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
1625
- command['config']['environment'] = 'b';
1626
- command['config']['service'] = 'middletier';
1627
- command['getSettings']();
1628
- output = command.context.stdout.toString();
1629
- expect(output).toMatch('[Warning] The version tag has not been configured. Learn more about Datadog unified service tagging: https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/#serverless-environment.\n');
1630
- }));
1631
- test('aborts early if extraTags do not comply with expected key:value list', () => __awaiter(void 0, void 0, void 0, function* () {
1632
- ;
1633
- fs.readFile.mockImplementation((a, b, callback) => callback({}));
1634
- process.env = {};
1635
- const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
1636
- command['config']['region'] = 'ap-southeast-1';
1637
- command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
1638
- command['config']['service'] = 'middletier';
1639
- command['config']['environment'] = 'staging';
1640
- command['config']['version'] = '0.2';
1641
- command['config']['extraTags'] = 'not-complying:illegal-chars-in-key,complies:valid-pair';
1642
- command['getSettings']();
1643
- const output = command.context.stdout.toString();
1644
- expect(output).toMatch('[Error] Extra tags do not comply with the <key>:<value> array.\n');
1645
- }));
1646
- });
1647
- describe('printPlannedActions', () => {
1648
- test('prints no output when list is empty', () => {
1649
- process.env = {};
1650
- const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
1651
- command['printPlannedActions']([]);
1652
- const output = command.context.stdout.toString();
1653
- expect(output).toMatchInlineSnapshot(`
1654
- "
1655
- No updates will be applied.
1656
- "
1657
- `);
1658
- });
1659
- test('prints log group actions', () => {
1660
- process.env = {};
1661
- const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
1662
- command['printPlannedActions']([
1663
- {
1664
- functionARN: 'my-func',
1665
- lambdaConfig: {},
1666
- logGroupConfiguration: {
1667
- createLogGroupRequest: { logGroupName: 'my-log-group' },
1668
- deleteSubscriptionFilterRequest: { filterName: 'my-filter' },
1669
- logGroupName: 'my-log-group',
1670
- subscriptionFilterRequest: { filterName: 'my-filter' },
1671
- },
1672
- },
1673
- ]);
1674
- const output = command.context.stdout.toString();
1675
- expect(output).toMatchInlineSnapshot(`
1676
- "\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.
1677
- \n[!] Functions to be updated:
1678
- \t- my-func\n
1679
- Will apply the following updates:
1680
- CreateLogGroup -> my-log-group
1681
- {
1682
- \\"logGroupName\\": \\"my-log-group\\"
1683
- }
1684
- DeleteSubscriptionFilter -> my-log-group
1685
- {
1686
- \\"filterName\\": \\"my-filter\\"
1687
- }
1688
- PutSubscriptionFilter -> my-log-group
1689
- {
1690
- \\"filterName\\": \\"my-filter\\"
1691
- }
1692
- "
1693
- `);
1694
- });
1695
- });
1696
- });
1697
- });
1698
- //# sourceMappingURL=instrument.test.js.map