@datadog/datadog-ci 2.48.0 → 3.0.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 (399) hide show
  1. package/README.md +9 -2
  2. package/dist/__tests__/cli.test.d.ts +1 -0
  3. package/dist/__tests__/cli.test.js +92 -0
  4. package/dist/__tests__/cli.test.js.map +1 -0
  5. package/dist/cli.js +1 -1
  6. package/dist/cli.js.map +1 -1
  7. package/dist/commands/cloud-run/__tests__/fixtures.d.ts +2 -0
  8. package/dist/commands/cloud-run/__tests__/fixtures.js +12 -0
  9. package/dist/commands/cloud-run/__tests__/fixtures.js.map +1 -0
  10. package/dist/commands/cloud-run/__tests__/flare.test.d.ts +1 -0
  11. package/dist/commands/cloud-run/__tests__/flare.test.js +557 -0
  12. package/dist/commands/cloud-run/__tests__/flare.test.js.map +1 -0
  13. package/dist/commands/coverage/__tests__/upload.test.d.ts +1 -0
  14. package/dist/commands/coverage/__tests__/upload.test.js +323 -0
  15. package/dist/commands/coverage/__tests__/upload.test.js.map +1 -0
  16. package/dist/commands/coverage/__tests__/utils.test.d.ts +1 -0
  17. package/dist/commands/coverage/__tests__/utils.test.js +57 -0
  18. package/dist/commands/coverage/__tests__/utils.test.js.map +1 -0
  19. package/dist/commands/coverage/api.d.ts +9 -0
  20. package/dist/commands/coverage/api.js +52 -0
  21. package/dist/commands/coverage/api.js.map +1 -0
  22. package/dist/commands/coverage/cli.d.ts +1 -0
  23. package/dist/commands/coverage/cli.js +5 -0
  24. package/dist/commands/coverage/cli.js.map +1 -0
  25. package/dist/commands/coverage/interfaces.d.ts +13 -0
  26. package/dist/commands/coverage/interfaces.js +3 -0
  27. package/dist/commands/coverage/interfaces.js.map +1 -0
  28. package/dist/commands/coverage/renderer.d.ts +12 -0
  29. package/dist/commands/coverage/renderer.js +83 -0
  30. package/dist/commands/coverage/renderer.js.map +1 -0
  31. package/dist/commands/coverage/upload.d.ts +27 -0
  32. package/dist/commands/coverage/upload.js +329 -0
  33. package/dist/commands/coverage/upload.js.map +1 -0
  34. package/dist/commands/coverage/utils.d.ts +3 -0
  35. package/dist/commands/coverage/utils.js +83 -0
  36. package/dist/commands/coverage/utils.js.map +1 -0
  37. package/dist/commands/deployment/__tests__/correlate.test.d.ts +1 -0
  38. package/dist/commands/deployment/__tests__/correlate.test.js +106 -0
  39. package/dist/commands/deployment/__tests__/correlate.test.js.map +1 -0
  40. package/dist/commands/deployment/__tests__/mark.test.d.ts +1 -0
  41. package/dist/commands/deployment/__tests__/mark.test.js +97 -0
  42. package/dist/commands/deployment/__tests__/mark.test.js.map +1 -0
  43. package/dist/commands/dora/__tests__/deployment.test.d.ts +1 -0
  44. package/dist/commands/dora/__tests__/deployment.test.js +201 -0
  45. package/dist/commands/dora/__tests__/deployment.test.js.map +1 -0
  46. package/dist/commands/dsyms/__tests__/upload.test.d.ts +1 -0
  47. package/dist/commands/dsyms/__tests__/upload.test.js +346 -0
  48. package/dist/commands/dsyms/__tests__/upload.test.js.map +1 -0
  49. package/dist/commands/dsyms/__tests__/utils.test.d.ts +1 -0
  50. package/dist/commands/dsyms/__tests__/utils.test.js +100 -0
  51. package/dist/commands/dsyms/__tests__/utils.test.js.map +1 -0
  52. package/dist/commands/dsyms/upload.js +3 -3
  53. package/dist/commands/dsyms/upload.js.map +1 -1
  54. package/dist/commands/dsyms/utils.js +7 -6
  55. package/dist/commands/dsyms/utils.js.map +1 -1
  56. package/dist/commands/elf-symbols/__tests__/elf.test.d.ts +1 -0
  57. package/dist/commands/elf-symbols/__tests__/elf.test.js +819 -0
  58. package/dist/commands/elf-symbols/__tests__/elf.test.js.map +1 -0
  59. package/dist/commands/elf-symbols/__tests__/upload.test.d.ts +1 -0
  60. package/dist/commands/elf-symbols/__tests__/upload.test.js +224 -0
  61. package/dist/commands/elf-symbols/__tests__/upload.test.js.map +1 -0
  62. package/dist/commands/elf-symbols/elf.d.ts +1 -0
  63. package/dist/commands/elf-symbols/upload.js +2 -3
  64. package/dist/commands/elf-symbols/upload.js.map +1 -1
  65. package/dist/commands/flutter-symbols/__tests__/upload.test.d.ts +1 -0
  66. package/dist/commands/flutter-symbols/__tests__/upload.test.js +617 -0
  67. package/dist/commands/flutter-symbols/__tests__/upload.test.js.map +1 -0
  68. package/dist/commands/flutter-symbols/upload.js +2 -2
  69. package/dist/commands/flutter-symbols/upload.js.map +1 -1
  70. package/dist/commands/gate/__tests__/evaluate.test.d.ts +1 -0
  71. package/dist/commands/gate/__tests__/evaluate.test.js +398 -0
  72. package/dist/commands/gate/__tests__/evaluate.test.js.map +1 -0
  73. package/dist/commands/gate/__tests__/scope.test.d.ts +1 -0
  74. package/dist/commands/gate/__tests__/scope.test.js +29 -0
  75. package/dist/commands/gate/__tests__/scope.test.js.map +1 -0
  76. package/dist/commands/git-metadata/__tests__/git.test.d.ts +1 -0
  77. package/dist/commands/git-metadata/__tests__/git.test.js +132 -0
  78. package/dist/commands/git-metadata/__tests__/git.test.js.map +1 -0
  79. package/dist/commands/git-metadata/__tests__/gitdb.test.d.ts +1 -0
  80. package/dist/commands/git-metadata/__tests__/gitdb.test.js +1386 -0
  81. package/dist/commands/git-metadata/__tests__/gitdb.test.js.map +1 -0
  82. package/dist/commands/git-metadata/__tests__/library.test.d.ts +1 -0
  83. package/dist/commands/git-metadata/__tests__/library.test.js +118 -0
  84. package/dist/commands/git-metadata/__tests__/library.test.js.map +1 -0
  85. package/dist/commands/git-metadata/__tests__/upload.test.d.ts +1 -0
  86. package/dist/commands/git-metadata/__tests__/upload.test.js +52 -0
  87. package/dist/commands/git-metadata/__tests__/upload.test.js.map +1 -0
  88. package/dist/commands/git-metadata/upload.d.ts +0 -1
  89. package/dist/commands/git-metadata/upload.js +0 -6
  90. package/dist/commands/git-metadata/upload.js.map +1 -1
  91. package/dist/commands/junit/__tests__/upload.test.d.ts +1 -0
  92. package/dist/commands/junit/__tests__/upload.test.js +446 -0
  93. package/dist/commands/junit/__tests__/upload.test.js.map +1 -0
  94. package/dist/commands/junit/renderer.d.ts +0 -1
  95. package/dist/commands/junit/renderer.js +1 -5
  96. package/dist/commands/junit/renderer.js.map +1 -1
  97. package/dist/commands/junit/upload.d.ts +0 -2
  98. package/dist/commands/junit/upload.js +8 -21
  99. package/dist/commands/junit/upload.js.map +1 -1
  100. package/dist/commands/lambda/__tests__/fixtures.d.ts +51 -0
  101. package/dist/commands/lambda/__tests__/fixtures.js +146 -0
  102. package/dist/commands/lambda/__tests__/fixtures.js.map +1 -0
  103. package/dist/commands/lambda/__tests__/flare.test.d.ts +1 -0
  104. package/dist/commands/lambda/__tests__/flare.test.js +730 -0
  105. package/dist/commands/lambda/__tests__/flare.test.js.map +1 -0
  106. package/dist/commands/lambda/__tests__/functions/commons.test.d.ts +1 -0
  107. package/dist/commands/lambda/__tests__/functions/commons.test.js +791 -0
  108. package/dist/commands/lambda/__tests__/functions/commons.test.js.map +1 -0
  109. package/dist/commands/lambda/__tests__/functions/instrument.part1.test.d.ts +1 -0
  110. package/dist/commands/lambda/__tests__/functions/instrument.part1.test.js +386 -0
  111. package/dist/commands/lambda/__tests__/functions/instrument.part1.test.js.map +1 -0
  112. package/dist/commands/lambda/__tests__/functions/instrument.part2.test.d.ts +1 -0
  113. package/dist/commands/lambda/__tests__/functions/instrument.part2.test.js +721 -0
  114. package/dist/commands/lambda/__tests__/functions/instrument.part2.test.js.map +1 -0
  115. package/dist/commands/lambda/__tests__/functions/uninstrument.test.d.ts +1 -0
  116. package/dist/commands/lambda/__tests__/functions/uninstrument.test.js +513 -0
  117. package/dist/commands/lambda/__tests__/functions/uninstrument.test.js.map +1 -0
  118. package/dist/commands/lambda/__tests__/functions/versionChecker.test.d.ts +1 -0
  119. package/dist/commands/lambda/__tests__/functions/versionChecker.test.js +33 -0
  120. package/dist/commands/lambda/__tests__/functions/versionChecker.test.js.map +1 -0
  121. package/dist/commands/lambda/__tests__/instrument.test.d.ts +1 -0
  122. package/dist/commands/lambda/__tests__/instrument.test.js +1537 -0
  123. package/dist/commands/lambda/__tests__/instrument.test.js.map +1 -0
  124. package/dist/commands/lambda/__tests__/loggroup.test.d.ts +1 -0
  125. package/dist/commands/lambda/__tests__/loggroup.test.js +340 -0
  126. package/dist/commands/lambda/__tests__/loggroup.test.js.map +1 -0
  127. package/dist/commands/lambda/__tests__/prompt.test.d.ts +1 -0
  128. package/dist/commands/lambda/__tests__/prompt.test.js +206 -0
  129. package/dist/commands/lambda/__tests__/prompt.test.js.map +1 -0
  130. package/dist/commands/lambda/__tests__/tags.test.d.ts +1 -0
  131. package/dist/commands/lambda/__tests__/tags.test.js +305 -0
  132. package/dist/commands/lambda/__tests__/tags.test.js.map +1 -0
  133. package/dist/commands/lambda/__tests__/uninstrument.test.d.ts +1 -0
  134. package/dist/commands/lambda/__tests__/uninstrument.test.js +722 -0
  135. package/dist/commands/lambda/__tests__/uninstrument.test.js.map +1 -0
  136. package/dist/commands/lambda/constants.d.ts +2 -0
  137. package/dist/commands/lambda/constants.js +4 -0
  138. package/dist/commands/lambda/constants.js.map +1 -1
  139. package/dist/commands/lambda/functions/commons.d.ts +1 -1
  140. package/dist/commands/measure/__tests__/measure.test.d.ts +1 -0
  141. package/dist/commands/measure/__tests__/measure.test.js +102 -0
  142. package/dist/commands/measure/__tests__/measure.test.js.map +1 -0
  143. package/dist/commands/measure/measure.d.ts +0 -1
  144. package/dist/commands/measure/measure.js +2 -9
  145. package/dist/commands/measure/measure.js.map +1 -1
  146. package/dist/commands/react-native/__tests__/codepush.test.d.ts +1 -0
  147. package/dist/commands/react-native/__tests__/codepush.test.js +161 -0
  148. package/dist/commands/react-native/__tests__/codepush.test.js.map +1 -0
  149. package/dist/commands/react-native/__tests__/interfaces.test.d.ts +1 -0
  150. package/dist/commands/react-native/__tests__/interfaces.test.js +33 -0
  151. package/dist/commands/react-native/__tests__/interfaces.test.js.map +1 -0
  152. package/dist/commands/react-native/__tests__/upload.test.d.ts +1 -0
  153. package/dist/commands/react-native/__tests__/upload.test.js +238 -0
  154. package/dist/commands/react-native/__tests__/upload.test.js.map +1 -0
  155. package/dist/commands/react-native/__tests__/utils.test.d.ts +1 -0
  156. package/dist/commands/react-native/__tests__/utils.test.js +27 -0
  157. package/dist/commands/react-native/__tests__/utils.test.js.map +1 -0
  158. package/dist/commands/react-native/__tests__/xcode.test.d.ts +1 -0
  159. package/dist/commands/react-native/__tests__/xcode.test.js +465 -0
  160. package/dist/commands/react-native/__tests__/xcode.test.js.map +1 -0
  161. package/dist/commands/sarif/__tests__/upload.test.d.ts +1 -0
  162. package/dist/commands/sarif/__tests__/upload.test.js +218 -0
  163. package/dist/commands/sarif/__tests__/upload.test.js.map +1 -0
  164. package/dist/commands/sarif/__tests__/validation.test.d.ts +1 -0
  165. package/dist/commands/sarif/__tests__/validation.test.js +19 -0
  166. package/dist/commands/sarif/__tests__/validation.test.js.map +1 -0
  167. package/dist/commands/sarif/api.js +1 -1
  168. package/dist/commands/sarif/api.js.map +1 -1
  169. package/dist/commands/sarif/interfaces.d.ts +0 -1
  170. package/dist/commands/sarif/renderer.d.ts +2 -2
  171. package/dist/commands/sarif/renderer.js +5 -5
  172. package/dist/commands/sarif/renderer.js.map +1 -1
  173. package/dist/commands/sarif/upload.d.ts +1 -1
  174. package/dist/commands/sarif/upload.js +15 -10
  175. package/dist/commands/sarif/upload.js.map +1 -1
  176. package/dist/commands/sbom/__tests__/payload.test.d.ts +1 -0
  177. package/dist/commands/sbom/__tests__/payload.test.js +306 -0
  178. package/dist/commands/sbom/__tests__/payload.test.js.map +1 -0
  179. package/dist/commands/sbom/__tests__/validation.test.d.ts +1 -0
  180. package/dist/commands/sbom/__tests__/validation.test.js +141 -0
  181. package/dist/commands/sbom/__tests__/validation.test.js.map +1 -0
  182. package/dist/commands/sbom/upload.d.ts +1 -1
  183. package/dist/commands/sbom/upload.js +9 -3
  184. package/dist/commands/sbom/upload.js.map +1 -1
  185. package/dist/commands/sourcemaps/__tests__/upload.test.d.ts +1 -0
  186. package/dist/commands/sourcemaps/__tests__/upload.test.js +270 -0
  187. package/dist/commands/sourcemaps/__tests__/upload.test.js.map +1 -0
  188. package/dist/commands/sourcemaps/__tests__/utils.test.d.ts +1 -0
  189. package/dist/commands/sourcemaps/__tests__/utils.test.js +31 -0
  190. package/dist/commands/sourcemaps/__tests__/utils.test.js.map +1 -0
  191. package/dist/commands/sourcemaps/upload.d.ts +1 -0
  192. package/dist/commands/sourcemaps/upload.js +6 -2
  193. package/dist/commands/sourcemaps/upload.js.map +1 -1
  194. package/dist/commands/stepfunctions/__tests__/awsCommands.test.d.ts +1 -0
  195. package/dist/commands/stepfunctions/__tests__/awsCommands.test.js +210 -0
  196. package/dist/commands/stepfunctions/__tests__/awsCommands.test.js.map +1 -0
  197. package/dist/commands/stepfunctions/__tests__/fixtures/aws-resources.d.ts +6 -0
  198. package/dist/commands/stepfunctions/__tests__/fixtures/aws-resources.js +45 -0
  199. package/dist/commands/stepfunctions/__tests__/fixtures/aws-resources.js.map +1 -0
  200. package/dist/commands/stepfunctions/__tests__/fixtures/cli.d.ts +5 -0
  201. package/dist/commands/stepfunctions/__tests__/fixtures/cli.js +19 -0
  202. package/dist/commands/stepfunctions/__tests__/fixtures/cli.js.map +1 -0
  203. package/dist/commands/stepfunctions/__tests__/helpers.test.d.ts +1 -0
  204. package/dist/commands/stepfunctions/__tests__/helpers.test.js +501 -0
  205. package/dist/commands/stepfunctions/__tests__/helpers.test.js.map +1 -0
  206. package/dist/commands/stepfunctions/__tests__/instrument.test.d.ts +1 -0
  207. package/dist/commands/stepfunctions/__tests__/instrument.test.js +431 -0
  208. package/dist/commands/stepfunctions/__tests__/instrument.test.js.map +1 -0
  209. package/dist/commands/stepfunctions/__tests__/uninstrument.test.d.ts +1 -0
  210. package/dist/commands/stepfunctions/__tests__/uninstrument.test.js +166 -0
  211. package/dist/commands/stepfunctions/__tests__/uninstrument.test.js.map +1 -0
  212. package/dist/commands/synthetics/__tests__/api.test.d.ts +1 -0
  213. package/dist/commands/synthetics/__tests__/api.test.js +416 -0
  214. package/dist/commands/synthetics/__tests__/api.test.js.map +1 -0
  215. package/dist/commands/synthetics/__tests__/batch.test.d.ts +1 -0
  216. package/dist/commands/synthetics/__tests__/batch.test.js +906 -0
  217. package/dist/commands/synthetics/__tests__/batch.test.js.map +1 -0
  218. package/dist/commands/synthetics/__tests__/cli.test.d.ts +1 -0
  219. package/dist/commands/synthetics/__tests__/cli.test.js +1371 -0
  220. package/dist/commands/synthetics/__tests__/cli.test.js.map +1 -0
  221. package/dist/commands/synthetics/__tests__/deploy-tests-lib.test.d.ts +1 -0
  222. package/dist/commands/synthetics/__tests__/deploy-tests-lib.test.js +112 -0
  223. package/dist/commands/synthetics/__tests__/deploy-tests-lib.test.js.map +1 -0
  224. package/dist/commands/synthetics/__tests__/fixtures.d.ts +123 -0
  225. package/dist/commands/synthetics/__tests__/fixtures.js +493 -0
  226. package/dist/commands/synthetics/__tests__/fixtures.js.map +1 -0
  227. package/dist/commands/synthetics/__tests__/import-tests-lib.test.d.ts +1 -0
  228. package/dist/commands/synthetics/__tests__/import-tests-lib.test.js +186 -0
  229. package/dist/commands/synthetics/__tests__/import-tests-lib.test.js.map +1 -0
  230. package/dist/commands/synthetics/__tests__/mobile.test.d.ts +1 -0
  231. package/dist/commands/synthetics/__tests__/mobile.test.js +376 -0
  232. package/dist/commands/synthetics/__tests__/mobile.test.js.map +1 -0
  233. package/dist/commands/synthetics/__tests__/multilocator.test.d.ts +1 -0
  234. package/dist/commands/synthetics/__tests__/multilocator.test.js +132 -0
  235. package/dist/commands/synthetics/__tests__/multilocator.test.js.map +1 -0
  236. package/dist/commands/synthetics/__tests__/reporters/default.test.d.ts +1 -0
  237. package/dist/commands/synthetics/__tests__/reporters/default.test.js +410 -0
  238. package/dist/commands/synthetics/__tests__/reporters/default.test.js.map +1 -0
  239. package/dist/commands/synthetics/__tests__/reporters/junit.test.d.ts +1 -0
  240. package/dist/commands/synthetics/__tests__/reporters/junit.test.js +354 -0
  241. package/dist/commands/synthetics/__tests__/reporters/junit.test.js.map +1 -0
  242. package/dist/commands/synthetics/__tests__/reporters/mobile/app-upload.test.d.ts +1 -0
  243. package/dist/commands/synthetics/__tests__/reporters/mobile/app-upload.test.js +232 -0
  244. package/dist/commands/synthetics/__tests__/reporters/mobile/app-upload.test.js.map +1 -0
  245. package/dist/commands/synthetics/__tests__/run-tests-lib.test.d.ts +1 -0
  246. package/dist/commands/synthetics/__tests__/run-tests-lib.test.js +698 -0
  247. package/dist/commands/synthetics/__tests__/run-tests-lib.test.js.map +1 -0
  248. package/dist/commands/synthetics/__tests__/test.test.d.ts +1 -0
  249. package/dist/commands/synthetics/__tests__/test.test.js +269 -0
  250. package/dist/commands/synthetics/__tests__/test.test.js.map +1 -0
  251. package/dist/commands/synthetics/__tests__/tunnel/crypto.test.d.ts +1 -0
  252. package/dist/commands/synthetics/__tests__/tunnel/crypto.test.js +21 -0
  253. package/dist/commands/synthetics/__tests__/tunnel/crypto.test.js.map +1 -0
  254. package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.d.ts +1 -0
  255. package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.js +80 -0
  256. package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.js.map +1 -0
  257. package/dist/commands/synthetics/__tests__/tunnel/websocket.test.d.ts +1 -0
  258. package/dist/commands/synthetics/__tests__/tunnel/websocket.test.js +109 -0
  259. package/dist/commands/synthetics/__tests__/tunnel/websocket.test.js.map +1 -0
  260. package/dist/commands/synthetics/__tests__/utils/internal.test.d.ts +1 -0
  261. package/dist/commands/synthetics/__tests__/utils/internal.test.js +161 -0
  262. package/dist/commands/synthetics/__tests__/utils/internal.test.js.map +1 -0
  263. package/dist/commands/synthetics/__tests__/utils/public.test.d.ts +1 -0
  264. package/dist/commands/synthetics/__tests__/utils/public.test.js +575 -0
  265. package/dist/commands/synthetics/__tests__/utils/public.test.js.map +1 -0
  266. package/dist/commands/synthetics/api.d.ts +4 -2
  267. package/dist/commands/synthetics/api.js +20 -1
  268. package/dist/commands/synthetics/api.js.map +1 -1
  269. package/dist/commands/synthetics/batch.d.ts +4 -2
  270. package/dist/commands/synthetics/batch.js +65 -7
  271. package/dist/commands/synthetics/batch.js.map +1 -1
  272. package/dist/commands/synthetics/cli.js +3 -1
  273. package/dist/commands/synthetics/cli.js.map +1 -1
  274. package/dist/commands/synthetics/deploy-tests-command.d.ts +22 -0
  275. package/dist/commands/synthetics/deploy-tests-command.js +150 -0
  276. package/dist/commands/synthetics/deploy-tests-command.js.map +1 -0
  277. package/dist/commands/synthetics/deploy-tests-lib.d.ts +2 -0
  278. package/dist/commands/synthetics/deploy-tests-lib.js +72 -0
  279. package/dist/commands/synthetics/deploy-tests-lib.js.map +1 -0
  280. package/dist/commands/synthetics/errors.d.ts +1 -1
  281. package/dist/commands/synthetics/errors.js +1 -0
  282. package/dist/commands/synthetics/errors.js.map +1 -1
  283. package/dist/commands/synthetics/import-tests-command.d.ts +22 -0
  284. package/dist/commands/synthetics/import-tests-command.js +142 -0
  285. package/dist/commands/synthetics/import-tests-command.js.map +1 -0
  286. package/dist/commands/synthetics/import-tests-lib.d.ts +2 -0
  287. package/dist/commands/synthetics/import-tests-lib.js +71 -0
  288. package/dist/commands/synthetics/import-tests-lib.js.map +1 -0
  289. package/dist/commands/synthetics/interfaces.d.ts +74 -28
  290. package/dist/commands/synthetics/interfaces.js.map +1 -1
  291. package/dist/commands/synthetics/local-test-definition.d.ts +2 -0
  292. package/dist/commands/synthetics/local-test-definition.js +16 -0
  293. package/dist/commands/synthetics/local-test-definition.js.map +1 -0
  294. package/dist/commands/synthetics/mobile.js +2 -2
  295. package/dist/commands/synthetics/mobile.js.map +1 -1
  296. package/dist/commands/synthetics/multilocator.d.ts +3 -0
  297. package/dist/commands/synthetics/multilocator.js +98 -0
  298. package/dist/commands/synthetics/multilocator.js.map +1 -0
  299. package/dist/commands/synthetics/reporters/junit.d.ts +1 -2
  300. package/dist/commands/synthetics/reporters/junit.js +5 -6
  301. package/dist/commands/synthetics/reporters/junit.js.map +1 -1
  302. package/dist/commands/synthetics/run-tests-command.d.ts +0 -9
  303. package/dist/commands/synthetics/run-tests-command.js +22 -64
  304. package/dist/commands/synthetics/run-tests-command.js.map +1 -1
  305. package/dist/commands/synthetics/run-tests-lib.js +24 -12
  306. package/dist/commands/synthetics/run-tests-lib.js.map +1 -1
  307. package/dist/commands/synthetics/test.d.ts +10 -19
  308. package/dist/commands/synthetics/test.js +93 -13
  309. package/dist/commands/synthetics/test.js.map +1 -1
  310. package/dist/commands/synthetics/tunnel/tunnel.js +2 -2
  311. package/dist/commands/synthetics/tunnel/tunnel.js.map +1 -1
  312. package/dist/commands/synthetics/utils/internal.d.ts +3 -1
  313. package/dist/commands/synthetics/utils/internal.js +18 -8
  314. package/dist/commands/synthetics/utils/internal.js.map +1 -1
  315. package/dist/commands/synthetics/utils/public.d.ts +5 -26
  316. package/dist/commands/synthetics/utils/public.js +13 -248
  317. package/dist/commands/synthetics/utils/public.js.map +1 -1
  318. package/dist/commands/tag/__tests__/tag.test.d.ts +1 -0
  319. package/dist/commands/tag/__tests__/tag.test.js +85 -0
  320. package/dist/commands/tag/__tests__/tag.test.js.map +1 -0
  321. package/dist/commands/trace/__tests__/trace.test.d.ts +1 -0
  322. package/dist/commands/trace/__tests__/trace.test.js +145 -0
  323. package/dist/commands/trace/__tests__/trace.test.js.map +1 -0
  324. package/dist/commands/unity-symbols/__tests__/upload.test.d.ts +1 -0
  325. package/dist/commands/unity-symbols/__tests__/upload.test.js +369 -0
  326. package/dist/commands/unity-symbols/__tests__/upload.test.js.map +1 -0
  327. package/dist/commands/unity-symbols/upload.js +2 -2
  328. package/dist/commands/unity-symbols/upload.js.map +1 -1
  329. package/dist/helpers/__tests__/app.test.d.ts +1 -0
  330. package/dist/helpers/__tests__/app.test.js +31 -0
  331. package/dist/helpers/__tests__/app.test.js.map +1 -0
  332. package/dist/helpers/__tests__/ci.test.d.ts +1 -0
  333. package/dist/helpers/__tests__/ci.test.js +295 -0
  334. package/dist/helpers/__tests__/ci.test.js.map +1 -0
  335. package/dist/helpers/__tests__/env.test.d.ts +1 -0
  336. package/dist/helpers/__tests__/env.test.js +74 -0
  337. package/dist/helpers/__tests__/env.test.js.map +1 -0
  338. package/dist/helpers/__tests__/fips.test.d.ts +1 -0
  339. package/dist/helpers/__tests__/fips.test.js +30 -0
  340. package/dist/helpers/__tests__/fips.test.js.map +1 -0
  341. package/dist/helpers/__tests__/fixtures.d.ts +41 -0
  342. package/dist/helpers/__tests__/fixtures.js +80 -0
  343. package/dist/helpers/__tests__/fixtures.js.map +1 -0
  344. package/dist/helpers/__tests__/flare.test.d.ts +1 -0
  345. package/dist/helpers/__tests__/flare.test.js +226 -0
  346. package/dist/helpers/__tests__/flare.test.js.map +1 -0
  347. package/dist/helpers/__tests__/fs.test.d.ts +1 -0
  348. package/dist/helpers/__tests__/fs.test.js +189 -0
  349. package/dist/helpers/__tests__/fs.test.js.map +1 -0
  350. package/dist/helpers/__tests__/id.test.d.ts +1 -0
  351. package/dist/helpers/__tests__/id.test.js +24 -0
  352. package/dist/helpers/__tests__/id.test.js.map +1 -0
  353. package/dist/helpers/__tests__/plist.test.d.ts +1 -0
  354. package/dist/helpers/__tests__/plist.test.js +43 -0
  355. package/dist/helpers/__tests__/plist.test.js.map +1 -0
  356. package/dist/helpers/__tests__/prompt.test.d.ts +1 -0
  357. package/dist/helpers/__tests__/prompt.test.js +71 -0
  358. package/dist/helpers/__tests__/prompt.test.js.map +1 -0
  359. package/dist/helpers/__tests__/retry.test.d.ts +1 -0
  360. package/dist/helpers/__tests__/retry.test.js +99 -0
  361. package/dist/helpers/__tests__/retry.test.js.map +1 -0
  362. package/dist/helpers/__tests__/tags.test.d.ts +1 -0
  363. package/dist/helpers/__tests__/tags.test.js +303 -0
  364. package/dist/helpers/__tests__/tags.test.js.map +1 -0
  365. package/dist/helpers/__tests__/upload.test.d.ts +1 -0
  366. package/dist/helpers/__tests__/upload.test.js +231 -0
  367. package/dist/helpers/__tests__/upload.test.js.map +1 -0
  368. package/dist/helpers/__tests__/user-provided-git.test.d.ts +1 -0
  369. package/dist/helpers/__tests__/user-provided-git.test.js +119 -0
  370. package/dist/helpers/__tests__/user-provided-git.test.js.map +1 -0
  371. package/dist/helpers/__tests__/utils.test.d.ts +1 -0
  372. package/dist/helpers/__tests__/utils.test.js +429 -0
  373. package/dist/helpers/__tests__/utils.test.js.map +1 -0
  374. package/dist/helpers/__tests__/validation.test.d.ts +1 -0
  375. package/dist/helpers/__tests__/validation.test.js +25 -0
  376. package/dist/helpers/__tests__/validation.test.js.map +1 -0
  377. package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.d.ts +1 -0
  378. package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.js +103 -0
  379. package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.js.map +1 -0
  380. package/dist/helpers/git/__tests__/format-git-span-data.test.d.ts +1 -0
  381. package/dist/helpers/git/__tests__/format-git-span-data.test.js +121 -0
  382. package/dist/helpers/git/__tests__/format-git-span-data.test.js.map +1 -0
  383. package/dist/helpers/git/__tests__/get-git-data.test.d.ts +1 -0
  384. package/dist/helpers/git/__tests__/get-git-data.test.js +72 -0
  385. package/dist/helpers/git/__tests__/get-git-data.test.js.map +1 -0
  386. package/dist/helpers/id.js.map +1 -0
  387. package/dist/helpers/tags.d.ts +1 -4
  388. package/dist/helpers/tags.js +2 -6
  389. package/dist/helpers/tags.js.map +1 -1
  390. package/dist/helpers/utils.d.ts +0 -4
  391. package/dist/helpers/utils.js +1 -21
  392. package/dist/helpers/utils.js.map +1 -1
  393. package/package.json +16 -17
  394. package/dist/commands/junit/id.js.map +0 -1
  395. package/dist/commands/synthetics/compatibility.d.ts +0 -7
  396. package/dist/commands/synthetics/compatibility.js +0 -83
  397. package/dist/commands/synthetics/compatibility.js.map +0 -1
  398. /package/dist/{commands/junit → helpers}/id.d.ts +0 -0
  399. /package/dist/{commands/junit → helpers}/id.js +0 -0
@@ -0,0 +1,1537 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ jest.mock('fs');
36
+ jest.mock('@aws-sdk/credential-providers', () => (Object.assign(Object.assign({}, jest.requireActual('@aws-sdk/credential-providers')), { fromIni: jest.fn() })));
37
+ jest.mock('../prompt');
38
+ jest.mock('../renderers/instrument-uninstrument-renderer');
39
+ jest.mock('../../../helpers/prompt');
40
+ jest.mock('../../../../package.json', () => ({ version: 'XXXX' }));
41
+ const fs = __importStar(require("fs"));
42
+ const client_lambda_1 = require("@aws-sdk/client-lambda");
43
+ const credential_providers_1 = require("@aws-sdk/credential-providers");
44
+ const aws_sdk_client_mock_1 = require("aws-sdk-client-mock");
45
+ require("aws-sdk-client-mock-jest");
46
+ const advanced_1 = require("clipanion/lib/advanced");
47
+ const constants_1 = require("../../../constants");
48
+ const fixtures_1 = require("../../../helpers/__tests__/fixtures");
49
+ const prompt_1 = require("../../../helpers/prompt");
50
+ const constants_2 = require("../constants");
51
+ const instrument_1 = require("../instrument");
52
+ const prompt_2 = require("../prompt");
53
+ const fixtures_2 = require("./fixtures");
54
+ describe('lambda', () => {
55
+ const lambdaClientMock = (0, aws_sdk_client_mock_1.mockClient)(client_lambda_1.LambdaClient);
56
+ describe('instrument', () => {
57
+ describe('execute', () => {
58
+ const OLD_ENV = process.env;
59
+ beforeEach(() => {
60
+ lambdaClientMock.reset();
61
+ jest.resetModules();
62
+ process.env = {};
63
+ (0, fixtures_2.mockLambdaClientCommands)(lambdaClientMock);
64
+ });
65
+ afterAll(() => {
66
+ process.env = OLD_ENV;
67
+ });
68
+ test('prints dry run data for lambda library layer', () => __awaiter(void 0, void 0, void 0, function* () {
69
+ ;
70
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
71
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
72
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
73
+ config: {
74
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
75
+ Handler: 'index.handler',
76
+ Runtime: 'nodejs22.x',
77
+ },
78
+ },
79
+ });
80
+ const cli = (0, fixtures_2.makeCli)();
81
+ const context = (0, fixtures_1.createMockContext)();
82
+ const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
83
+ const code = yield cli.run([
84
+ 'lambda',
85
+ 'instrument',
86
+ '-f',
87
+ functionARN,
88
+ '--dry-run',
89
+ '--layerVersion',
90
+ '10',
91
+ '--logLevel',
92
+ 'debug',
93
+ '--service',
94
+ 'middletier',
95
+ '--env',
96
+ 'staging',
97
+ '--version',
98
+ '0.2',
99
+ '--extra-tags',
100
+ 'layer:api,team:intake',
101
+ '--no-source-code-integration',
102
+ ], context);
103
+ const output = context.stdout.toString();
104
+ expect(code).toBe(0);
105
+ expect(output).toMatchSnapshot();
106
+ }));
107
+ test('prints dry run data for lambda library and extension layers using kebab case args', () => __awaiter(void 0, void 0, void 0, function* () {
108
+ ;
109
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
110
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
111
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
112
+ config: {
113
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
114
+ Handler: 'index.handler',
115
+ Runtime: 'nodejs22.x',
116
+ },
117
+ },
118
+ });
119
+ const cli = (0, fixtures_2.makeCli)();
120
+ const context = (0, fixtures_1.createMockContext)();
121
+ const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
122
+ process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
123
+ const code = yield cli.run([
124
+ 'lambda',
125
+ 'instrument',
126
+ '-f',
127
+ functionARN,
128
+ '--dry-run',
129
+ '--service',
130
+ 'middletier',
131
+ '--env',
132
+ 'staging',
133
+ '--version',
134
+ '0.2',
135
+ '--extra-tags',
136
+ 'layer:api,team:intake',
137
+ '--layer-version',
138
+ '10',
139
+ '--extension-version',
140
+ '5',
141
+ '--merge-xray-traces',
142
+ 'true',
143
+ '--flush-metrics-to-logs',
144
+ 'false',
145
+ '--log-level',
146
+ 'debug',
147
+ '--no-source-code-integration',
148
+ ], context);
149
+ const output = context.stdout.toString();
150
+ expect(code).toBe(0);
151
+ expect(output).toMatchSnapshot();
152
+ }));
153
+ test('prints dry run data for lambda extension layer', () => __awaiter(void 0, void 0, void 0, function* () {
154
+ ;
155
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
156
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
157
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
158
+ config: {
159
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
160
+ Handler: 'index.handler',
161
+ Runtime: 'nodejs22.x',
162
+ },
163
+ },
164
+ });
165
+ const cli = (0, fixtures_2.makeCli)();
166
+ const context = (0, fixtures_1.createMockContext)();
167
+ const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
168
+ process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
169
+ const code = yield cli.run([
170
+ 'lambda',
171
+ 'instrument',
172
+ '-f',
173
+ functionARN,
174
+ '--dry-run',
175
+ '--extensionVersion',
176
+ '6',
177
+ '--service',
178
+ 'middletier',
179
+ '--env',
180
+ 'staging',
181
+ '--version',
182
+ '0.2',
183
+ '--extra-tags',
184
+ 'layer:api,team:intake',
185
+ '--no-source-code-integration',
186
+ ], context);
187
+ const output = context.stdout.toString();
188
+ expect(code).toBe(0);
189
+ expect(output).toMatchSnapshot();
190
+ }));
191
+ test('prints dry run data for lambda .NET layer', () => __awaiter(void 0, void 0, void 0, function* () {
192
+ ;
193
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
194
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
195
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
196
+ config: {
197
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
198
+ Runtime: 'dotnet8',
199
+ },
200
+ },
201
+ });
202
+ const cli = (0, fixtures_2.makeCli)();
203
+ const context = (0, fixtures_1.createMockContext)();
204
+ const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
205
+ process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
206
+ const code = yield cli.run([
207
+ 'lambda',
208
+ 'instrument',
209
+ '-f',
210
+ functionARN,
211
+ '--dry-run',
212
+ '-v',
213
+ '129',
214
+ '--extra-tags',
215
+ 'layer:api,team:intake',
216
+ '--service',
217
+ 'middletier',
218
+ '--env',
219
+ 'staging',
220
+ '--version',
221
+ '0.2',
222
+ '--no-source-code-integration',
223
+ ], context);
224
+ const output = context.stdout.toString();
225
+ expect(code).toBe(0);
226
+ expect(output).toMatchSnapshot();
227
+ }));
228
+ test('instrumenting with source code integrations fails if not run within a git repo', () => __awaiter(void 0, void 0, void 0, function* () {
229
+ ;
230
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
231
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
232
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
233
+ config: {
234
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
235
+ Handler: 'index.handler',
236
+ Runtime: 'nodejs22.x',
237
+ },
238
+ },
239
+ });
240
+ process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
241
+ const cli = (0, fixtures_2.makeCli)();
242
+ const context = (0, fixtures_1.createMockContext)();
243
+ yield cli.run([
244
+ 'lambda',
245
+ 'instrument',
246
+ '--function',
247
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
248
+ '--layerVersion',
249
+ '10',
250
+ '-s',
251
+ '--service',
252
+ 'dummy',
253
+ '--env',
254
+ 'dummy',
255
+ '--version',
256
+ '0.1',
257
+ ], context);
258
+ const output = context.stdout.toString();
259
+ expect(output.replace('\n', '')).toMatch(/.*Error: Couldn't get local git status.*/);
260
+ }));
261
+ test('ensure the instrument command ran from a dirty git repo fails', () => __awaiter(void 0, void 0, void 0, function* () {
262
+ ;
263
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
264
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
265
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
266
+ config: {
267
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
268
+ Handler: 'index.handler',
269
+ Runtime: 'nodejs22.x',
270
+ },
271
+ },
272
+ });
273
+ process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
274
+ const context = (0, fixtures_1.createMockContext)();
275
+ const instrumentCommand = instrument_1.InstrumentCommand;
276
+ const mockGitStatus = jest.spyOn(instrumentCommand.prototype, 'getCurrentGitStatus');
277
+ mockGitStatus.mockImplementation(() => ({
278
+ ahead: 0,
279
+ isClean: false,
280
+ }));
281
+ const cli = new advanced_1.Cli();
282
+ cli.register(instrumentCommand);
283
+ yield cli.run([
284
+ 'lambda',
285
+ 'instrument',
286
+ '--function',
287
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
288
+ '--layerVersion',
289
+ '10',
290
+ '-s',
291
+ '--service',
292
+ 'dummy',
293
+ '--env',
294
+ 'dummy',
295
+ '--version',
296
+ '0.1',
297
+ ], context);
298
+ const output = context.stdout.toString();
299
+ expect(output).toMatch('Error: Local git repository is dirty');
300
+ }));
301
+ test('ensure source code integration flag works from a clean repo', () => __awaiter(void 0, void 0, void 0, function* () {
302
+ ;
303
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
304
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
305
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
306
+ config: {
307
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
308
+ Handler: 'index.handler',
309
+ Runtime: 'nodejs22.x',
310
+ },
311
+ },
312
+ });
313
+ process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
314
+ const context = (0, fixtures_1.createMockContext)();
315
+ const instrumentCommand = instrument_1.InstrumentCommand;
316
+ const mockGitStatus = jest.spyOn(instrumentCommand.prototype, 'getCurrentGitStatus');
317
+ mockGitStatus.mockImplementation(() => ({
318
+ ahead: 0,
319
+ hash: '1be168ff837f043bde17c0314341c84271047b31',
320
+ remote: 'git.repository_url:git@github.com:datadog/test.git',
321
+ isClean: true,
322
+ }));
323
+ const mockUploadFunction = jest.spyOn(instrumentCommand.prototype, 'uploadGitData');
324
+ mockUploadFunction.mockImplementation(() => {
325
+ return;
326
+ });
327
+ const cli = new advanced_1.Cli();
328
+ cli.register(instrumentCommand);
329
+ yield cli.run([
330
+ 'lambda',
331
+ 'instrument',
332
+ '--function',
333
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
334
+ '--layerVersion',
335
+ '10',
336
+ '-s',
337
+ '--service',
338
+ 'dummy',
339
+ '--env',
340
+ 'dummy',
341
+ '--version',
342
+ '0.1',
343
+ ], context);
344
+ const output = context.stdout.toString();
345
+ expect(output).toMatchSnapshot();
346
+ expect(mockUploadFunction).toHaveBeenCalledTimes(1);
347
+ }));
348
+ test('ensure no git metadata upload flag works', () => __awaiter(void 0, void 0, void 0, function* () {
349
+ ;
350
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
351
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
352
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
353
+ config: {
354
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
355
+ Handler: 'index.handler',
356
+ Runtime: 'nodejs22.x',
357
+ },
358
+ },
359
+ });
360
+ process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
361
+ const context = (0, fixtures_1.createMockContext)();
362
+ const instrumentCommand = instrument_1.InstrumentCommand;
363
+ const mockGitStatus = jest.spyOn(instrumentCommand.prototype, 'getCurrentGitStatus');
364
+ mockGitStatus.mockImplementation(() => ({
365
+ ahead: 0,
366
+ hash: '1be168ff837f043bde17c0314341c84271047b31',
367
+ remote: 'git.repository_url:git@github.com:datadog/test.git',
368
+ isClean: true,
369
+ }));
370
+ const mockUploadFunction = jest.spyOn(instrumentCommand.prototype, 'uploadGitData');
371
+ mockUploadFunction.mockImplementation(() => {
372
+ return;
373
+ });
374
+ const cli = new advanced_1.Cli();
375
+ cli.register(instrumentCommand);
376
+ yield cli.run([
377
+ 'lambda',
378
+ 'instrument',
379
+ '--function',
380
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
381
+ '--layerVersion',
382
+ '10',
383
+ '--no-upload-git-metadata',
384
+ '--service',
385
+ 'dummy',
386
+ '--env',
387
+ 'dummy',
388
+ '--version',
389
+ '0.1',
390
+ ], context);
391
+ const output = context.stdout.toString();
392
+ expect(mockUploadFunction).toHaveBeenCalledTimes(0);
393
+ expect(output).toMatchSnapshot();
394
+ }));
395
+ test('ensure the instrument command ran from a local git repo ahead of the origin fails', () => __awaiter(void 0, void 0, void 0, function* () {
396
+ ;
397
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
398
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
399
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
400
+ config: {
401
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
402
+ Handler: 'index.handler',
403
+ Runtime: 'nodejs22.x',
404
+ },
405
+ },
406
+ });
407
+ process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
408
+ const context = (0, fixtures_1.createMockContext)();
409
+ const instrumentCommand = instrument_1.InstrumentCommand;
410
+ const mockGitStatus = jest.spyOn(instrumentCommand.prototype, 'getCurrentGitStatus');
411
+ mockGitStatus.mockImplementation(() => ({
412
+ ahead: 1,
413
+ isClean: true,
414
+ }));
415
+ const cli = new advanced_1.Cli();
416
+ cli.register(instrumentCommand);
417
+ yield cli.run([
418
+ 'lambda',
419
+ 'instrument',
420
+ '--function',
421
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
422
+ '--layerVersion',
423
+ '10',
424
+ '-s',
425
+ '--service',
426
+ 'dummy',
427
+ '--env',
428
+ 'dummy',
429
+ '--version',
430
+ '0.1',
431
+ ], context);
432
+ const output = context.stdout.toString();
433
+ expect(output).toMatch('Error: Local changes have not been pushed remotely. Aborting git data tagging.');
434
+ }));
435
+ test('runs function update command for lambda library layer', () => __awaiter(void 0, void 0, void 0, function* () {
436
+ ;
437
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
438
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
439
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
440
+ config: {
441
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
442
+ Handler: 'index.handler',
443
+ Runtime: 'nodejs22.x',
444
+ },
445
+ },
446
+ });
447
+ const cli = (0, fixtures_2.makeCli)();
448
+ const context = (0, fixtures_1.createMockContext)();
449
+ yield cli.run([
450
+ 'lambda',
451
+ 'instrument',
452
+ '--function',
453
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
454
+ '--layerVersion',
455
+ '10',
456
+ '--no-source-code-integration',
457
+ ], context);
458
+ expect(lambdaClientMock).toHaveReceivedCommand(client_lambda_1.UpdateFunctionConfigurationCommand);
459
+ }));
460
+ test('runs function update command for lambda extension layer', () => __awaiter(void 0, void 0, void 0, function* () {
461
+ ;
462
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
463
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
464
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
465
+ config: {
466
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
467
+ Handler: 'index.handler',
468
+ Runtime: 'nodejs22.x',
469
+ },
470
+ },
471
+ });
472
+ const cli = (0, fixtures_2.makeCli)();
473
+ const context = (0, fixtures_1.createMockContext)();
474
+ process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
475
+ yield cli.run([
476
+ 'lambda',
477
+ 'instrument',
478
+ '--function',
479
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
480
+ '--extensionVersion',
481
+ '6',
482
+ '--no-source-code-integration',
483
+ ], context);
484
+ expect(lambdaClientMock).toHaveReceivedCommand(client_lambda_1.UpdateFunctionConfigurationCommand);
485
+ }));
486
+ test('aborts early when no functions are specified', () => __awaiter(void 0, void 0, void 0, function* () {
487
+ ;
488
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
489
+ const cli = (0, fixtures_2.makeCli)();
490
+ const context = (0, fixtures_1.createMockContext)();
491
+ const code = yield cli.run([
492
+ 'lambda',
493
+ 'instrument',
494
+ '--layerVersion',
495
+ '10',
496
+ '--service',
497
+ 'middletier',
498
+ '--env',
499
+ 'staging',
500
+ '--version',
501
+ '0.2',
502
+ ], context);
503
+ const output = context.stdout.toString();
504
+ expect(code).toBe(1);
505
+ expect(output).toMatchInlineSnapshot(`
506
+ "
507
+ 🐶 Instrumenting Lambda function
508
+ [Error] No functions specified to instrument.
509
+ "
510
+ `);
511
+ }));
512
+ test('aborts early when no functions are specified while using config file', () => __awaiter(void 0, void 0, void 0, function* () {
513
+ ;
514
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
515
+ process.env = {};
516
+ const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
517
+ command['config']['layerVersion'] = '60';
518
+ command['config']['extensionVersion'] = '10';
519
+ command['config']['region'] = 'ap-southeast-1';
520
+ command['config']['service'] = 'middletier';
521
+ command['config']['environment'] = 'staging';
522
+ command['config']['version'] = '0.2';
523
+ yield command['execute']();
524
+ const output = command.context.stdout.toString();
525
+ expect(output).toMatchInlineSnapshot(`
526
+ "
527
+ 🐶 Instrumenting Lambda function
528
+ [Error] No functions specified to instrument.
529
+ "
530
+ `);
531
+ }));
532
+ test("aborts early when function regions can't be found", () => __awaiter(void 0, void 0, void 0, function* () {
533
+ ;
534
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
535
+ const cli = (0, fixtures_2.makeCli)();
536
+ const context = (0, fixtures_1.createMockContext)();
537
+ const code = yield cli.run([
538
+ 'lambda',
539
+ 'instrument',
540
+ '--function',
541
+ 'my-func',
542
+ '--layerVersion',
543
+ '10',
544
+ '--service',
545
+ 'middletier',
546
+ '--env',
547
+ 'staging',
548
+ '--version',
549
+ '0.2',
550
+ '--no-source-code-integration',
551
+ ], context);
552
+ const output = context.stdout.toString();
553
+ expect(code).toBe(1);
554
+ expect(output).toMatch(`Couldn't group functions. Error: No default region specified for ["my-func"]. Use -r, --region, or use a full functionARN\n`);
555
+ }));
556
+ test('aborts early when extensionVersion and forwarder are set', () => __awaiter(void 0, void 0, void 0, function* () {
557
+ ;
558
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
559
+ const cli = (0, fixtures_2.makeCli)();
560
+ const context = (0, fixtures_1.createMockContext)();
561
+ const code = yield cli.run([
562
+ 'lambda',
563
+ 'instrument',
564
+ '--function',
565
+ 'test-function-arn',
566
+ '--forwarder',
567
+ 'arn:aws:lambda:sa-east-1:000000000000:function:datadog-forwarder',
568
+ '--extensionVersion',
569
+ '6',
570
+ '--region',
571
+ 'us-east-1',
572
+ '--service',
573
+ 'middletier',
574
+ '--env',
575
+ 'staging',
576
+ '--version',
577
+ '0.2',
578
+ ], context);
579
+ const output = context.stdout.toString();
580
+ expect(code).toBe(1);
581
+ expect(output).toMatchInlineSnapshot(`
582
+ "
583
+ 🐶 Instrumenting Lambda function
584
+ [Error] "extensionVersion" and "forwarder" should not be used at the same time.
585
+ "
586
+ `);
587
+ }));
588
+ test('check if functions are not empty while using config file', () => __awaiter(void 0, void 0, void 0, function* () {
589
+ ;
590
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
591
+ process.env = {};
592
+ const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
593
+ command['config']['layerVersion'] = '60';
594
+ command['config']['extensionVersion'] = '10';
595
+ command['config']['region'] = 'ap-southeast-1';
596
+ command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
597
+ yield command['execute']();
598
+ expect(command['config']['functions']).toHaveLength(1);
599
+ }));
600
+ test('aborts if functions and a pattern are set at the same time', () => __awaiter(void 0, void 0, void 0, function* () {
601
+ ;
602
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
603
+ process.env = {};
604
+ let command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
605
+ command['config']['environment'] = 'staging';
606
+ command['config']['service'] = 'middletier';
607
+ command['config']['version'] = '2';
608
+ command['config']['region'] = 'ap-southeast-1';
609
+ command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
610
+ command['regExPattern'] = 'valid-pattern';
611
+ command['sourceCodeIntegration'] = false;
612
+ yield command['execute']();
613
+ let output = command.context.stdout.toString();
614
+ expect(output).toMatch('Functions in config file and "--functions-regex" should not be used at the same time.\n');
615
+ command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
616
+ command['environment'] = 'staging';
617
+ command['service'] = 'middletier';
618
+ command['version'] = '2';
619
+ command['region'] = 'ap-southeast-1';
620
+ command['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
621
+ command['regExPattern'] = 'valid-pattern';
622
+ command['sourceCodeIntegration'] = false;
623
+ yield command['execute']();
624
+ output = command.context.stdout.toString();
625
+ expect(output).toMatch('"--functions" and "--functions-regex" should not be used at the same time.\n');
626
+ }));
627
+ test('aborts if pattern is set and no default region is specified', () => __awaiter(void 0, void 0, void 0, function* () {
628
+ ;
629
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
630
+ process.env = {};
631
+ const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
632
+ command['environment'] = 'staging';
633
+ command['service'] = 'middletier';
634
+ command['version'] = '2';
635
+ command['regExPattern'] = 'valid-pattern';
636
+ command['sourceCodeIntegration'] = false;
637
+ yield command['execute']();
638
+ const output = command.context.stdout.toString();
639
+ expect(output).toMatch('[Error] No default region specified. [-r,--region]\n');
640
+ }));
641
+ test('aborts if the regEx pattern is an ARN', () => __awaiter(void 0, void 0, void 0, function* () {
642
+ ;
643
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
644
+ process.env = {};
645
+ const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
646
+ command['environment'] = 'staging';
647
+ command['service'] = 'middletier';
648
+ command['version'] = '2';
649
+ command['region'] = 'ap-southeast-1';
650
+ command['regExPattern'] = 'arn:aws:lambda:ap-southeast-1:123456789012:function:*';
651
+ command['sourceCodeIntegration'] = false;
652
+ yield command['execute']();
653
+ const output = command.context.stdout.toString();
654
+ expect(output).toMatch(`"--functions-regex" isn't meant to be used with ARNs.\n`);
655
+ }));
656
+ test('instrument multiple functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
657
+ ;
658
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
659
+ const node22LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node22-x`;
660
+ const node20LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node20-x`;
661
+ const node18LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node18-x`;
662
+ const node16LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node16-x`;
663
+ const extensionLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension`;
664
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
665
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
666
+ config: {
667
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
668
+ FunctionName: 'lambda-hello-world',
669
+ Handler: 'index.handler',
670
+ Runtime: 'nodejs16.x',
671
+ },
672
+ },
673
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2': {
674
+ config: {
675
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
676
+ FunctionName: 'lambda-hello-world-2',
677
+ Handler: 'index.handler',
678
+ Runtime: 'nodejs18.x',
679
+ },
680
+ },
681
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-3': {
682
+ config: {
683
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-3',
684
+ FunctionName: 'lambda-hello-world-3',
685
+ Handler: 'index.handler',
686
+ Runtime: 'nodejs20.x',
687
+ },
688
+ },
689
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-4': {
690
+ config: {
691
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-4',
692
+ FunctionName: 'lambda-hello-world-4',
693
+ Handler: 'index.handler',
694
+ Runtime: 'nodejs22.x',
695
+ },
696
+ },
697
+ });
698
+ (0, fixtures_2.mockLambdaLayers)(lambdaClientMock, {
699
+ [`${node16LibraryLayer}:1`]: {
700
+ LayerName: `${node16LibraryLayer}`,
701
+ VersionNumber: 1,
702
+ },
703
+ [`${node18LibraryLayer}:1`]: {
704
+ LayerName: `${node18LibraryLayer}`,
705
+ VersionNumber: 1,
706
+ },
707
+ [`${node20LibraryLayer}:1`]: {
708
+ LayerName: `${node20LibraryLayer}`,
709
+ VersionNumber: 1,
710
+ },
711
+ [`${node22LibraryLayer}:1`]: {
712
+ LayerName: `${node22LibraryLayer}`,
713
+ VersionNumber: 1,
714
+ },
715
+ [`${extensionLayer}:1`]: {
716
+ LayerName: `${extensionLayer}`,
717
+ VersionNumber: 1,
718
+ },
719
+ });
720
+ prompt_2.requestAWSCredentials.mockImplementation(() => {
721
+ process.env[constants_2.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_2.mockAwsAccessKeyId;
722
+ process.env[constants_2.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_2.mockAwsSecretAccessKey;
723
+ process.env[constants_2.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
724
+ });
725
+ prompt_2.requestDatadogEnvVars.mockImplementation(() => {
726
+ process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
727
+ process.env[constants_1.CI_API_KEY_ENV_VAR] = fixtures_1.MOCK_DATADOG_API_KEY;
728
+ });
729
+ prompt_2.requestFunctionSelection.mockImplementation(() => [
730
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
731
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
732
+ ]);
733
+ prompt_1.requestConfirmation.mockImplementation(() => true);
734
+ const cli = (0, fixtures_2.makeCli)();
735
+ const context = (0, fixtures_1.createMockContext)();
736
+ const code = yield cli.run(['lambda', 'instrument', '-i', '--no-source-code-integration'], context);
737
+ const output = context.stdout.toString();
738
+ expect(code).toBe(0);
739
+ expect(output).toMatchSnapshot();
740
+ }));
741
+ test('instrument multiple specified functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
742
+ ;
743
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
744
+ const node16LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node16-x`;
745
+ const node18LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node18-x`;
746
+ const node20LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node20-x`;
747
+ const node22LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node22-x`;
748
+ const extensionLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension`;
749
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
750
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
751
+ config: {
752
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
753
+ FunctionName: 'lambda-hello-world',
754
+ Handler: 'index.handler',
755
+ Runtime: 'nodejs16.x',
756
+ },
757
+ },
758
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2': {
759
+ config: {
760
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
761
+ FunctionName: 'lambda-hello-world-2',
762
+ Handler: 'index.handler',
763
+ Runtime: 'nodejs18.x',
764
+ },
765
+ },
766
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-3': {
767
+ config: {
768
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-3',
769
+ FunctionName: 'lambda-hello-world-3',
770
+ Handler: 'index.handler',
771
+ Runtime: 'nodejs20.x',
772
+ },
773
+ },
774
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-4': {
775
+ config: {
776
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-4',
777
+ FunctionName: 'lambda-hello-world-4',
778
+ Handler: 'index.handler',
779
+ Runtime: 'nodejs22.x',
780
+ },
781
+ },
782
+ });
783
+ (0, fixtures_2.mockLambdaLayers)(lambdaClientMock, {
784
+ [`${node16LibraryLayer}:1`]: {
785
+ LayerName: `${node16LibraryLayer}`,
786
+ VersionNumber: 1,
787
+ },
788
+ [`${node18LibraryLayer}:1`]: {
789
+ LayerName: `${node18LibraryLayer}`,
790
+ VersionNumber: 1,
791
+ },
792
+ [`${node20LibraryLayer}:1`]: {
793
+ LayerName: `${node20LibraryLayer}`,
794
+ VersionNumber: 1,
795
+ },
796
+ [`${node22LibraryLayer}:1`]: {
797
+ LayerName: `${node22LibraryLayer}`,
798
+ VersionNumber: 1,
799
+ },
800
+ [`${extensionLayer}:1`]: {
801
+ LayerName: `${extensionLayer}`,
802
+ VersionNumber: 1,
803
+ },
804
+ });
805
+ prompt_2.requestAWSCredentials.mockImplementation(() => {
806
+ process.env[constants_2.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_2.mockAwsAccessKeyId;
807
+ process.env[constants_2.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_2.mockAwsSecretAccessKey;
808
+ process.env[constants_2.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
809
+ process.env[constants_2.AWS_SESSION_TOKEN_ENV_VAR] = 'some-session-token';
810
+ });
811
+ prompt_2.requestDatadogEnvVars.mockImplementation(() => {
812
+ process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
813
+ process.env[constants_1.CI_API_KEY_ENV_VAR] = fixtures_1.MOCK_DATADOG_API_KEY;
814
+ });
815
+ prompt_1.requestConfirmation.mockImplementation(() => true);
816
+ const cli = (0, fixtures_2.makeCli)();
817
+ const context = (0, fixtures_1.createMockContext)();
818
+ const code = yield cli.run([
819
+ 'lambda',
820
+ 'instrument',
821
+ '-i',
822
+ '-f',
823
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
824
+ '-f',
825
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
826
+ '--no-source-code-integration',
827
+ ], context);
828
+ const output = context.stdout.toString();
829
+ expect(code).toBe(0);
830
+ expect(output).toMatchSnapshot();
831
+ }));
832
+ test('aborts if a problem occurs while setting the AWS credentials interactively', () => __awaiter(void 0, void 0, void 0, function* () {
833
+ ;
834
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
835
+ prompt_2.requestAWSCredentials.mockImplementation(() => Promise.reject('Unexpected error'));
836
+ const cli = (0, fixtures_2.makeCli)();
837
+ const context = (0, fixtures_1.createMockContext)();
838
+ const code = yield cli.run(['lambda', 'instrument', '-i'], context);
839
+ const output = context.stdout.toString();
840
+ expect(code).toBe(1);
841
+ expect(output).toMatchInlineSnapshot(`
842
+ "
843
+ 🐶 Instrumenting Lambda function
844
+ [!] 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.
845
+ [Error] Unexpected error
846
+ "
847
+ `);
848
+ }));
849
+ test('aborts if a problem occurs while setting the Datadog Environment Variables interactively', () => __awaiter(void 0, void 0, void 0, function* () {
850
+ ;
851
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
852
+ process.env = {
853
+ [constants_2.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_2.mockAwsAccessKeyId,
854
+ [constants_2.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_2.mockAwsSecretAccessKey,
855
+ [constants_2.AWS_DEFAULT_REGION_ENV_VAR]: 'sa,-east-1',
856
+ };
857
+ prompt_2.requestDatadogEnvVars.mockImplementation(() => Promise.reject('Unexpected error'));
858
+ const cli = (0, fixtures_2.makeCli)();
859
+ const context = (0, fixtures_1.createMockContext)();
860
+ const code = yield cli.run(['lambda', 'instrument', '-i'], context);
861
+ const output = context.stdout.toString();
862
+ expect(code).toBe(1);
863
+ expect(output).toMatchInlineSnapshot(`
864
+ "
865
+ 🐶 Instrumenting Lambda function
866
+
867
+ [!] Configure AWS region.
868
+
869
+ [!] Configure Datadog settings.
870
+ [Error] Unexpected error
871
+ "
872
+ `);
873
+ }));
874
+ 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* () {
875
+ ;
876
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
877
+ const node22LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node22-x`;
878
+ const extensionLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension`;
879
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
880
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
881
+ config: {
882
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
883
+ FunctionName: 'lambda-hello-world',
884
+ Handler: 'index.handler',
885
+ Runtime: 'nodejs22.x',
886
+ },
887
+ },
888
+ });
889
+ (0, fixtures_2.mockLambdaLayers)(lambdaClientMock, {
890
+ [`${node22LibraryLayer}:1`]: {
891
+ LayerName: `${node22LibraryLayer}`,
892
+ VersionNumber: 1,
893
+ },
894
+ [`${extensionLayer}:1`]: {
895
+ LayerName: `${extensionLayer}`,
896
+ VersionNumber: 1,
897
+ },
898
+ });
899
+ prompt_2.requestAWSCredentials.mockImplementation(() => {
900
+ process.env[constants_2.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_2.mockAwsAccessKeyId;
901
+ process.env[constants_2.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_2.mockAwsSecretAccessKey;
902
+ process.env[constants_2.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
903
+ });
904
+ prompt_2.requestDatadogEnvVars.mockImplementation(() => {
905
+ process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
906
+ process.env[constants_1.CI_API_KEY_ENV_VAR] = fixtures_1.MOCK_DATADOG_API_KEY;
907
+ });
908
+ prompt_2.requestFunctionSelection.mockImplementation(() => [
909
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
910
+ ]);
911
+ prompt_1.requestConfirmation.mockImplementation(() => true);
912
+ prompt_2.requestEnvServiceVersion.mockImplementation(() => {
913
+ process.env[constants_1.ENVIRONMENT_ENV_VAR] = fixtures_2.mockDatadogEnv;
914
+ process.env[constants_1.SERVICE_ENV_VAR] = fixtures_2.mockDatadogService;
915
+ process.env[constants_1.VERSION_ENV_VAR] = fixtures_2.mockDatadogVersion;
916
+ });
917
+ const cli = (0, fixtures_2.makeCli)();
918
+ const context = (0, fixtures_1.createMockContext)();
919
+ const code = yield cli.run(['lambda', 'instrument', '-i', '--no-source-code-integration'], context);
920
+ const output = context.stdout.toString();
921
+ expect(code).toBe(0);
922
+ expect(output).toMatchSnapshot();
923
+ }));
924
+ 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* () {
925
+ ;
926
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
927
+ const node22LibraryLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node22-x`;
928
+ const extensionLayer = `arn:aws:lambda:sa-east-1:${constants_2.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension`;
929
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
930
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
931
+ config: {
932
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
933
+ FunctionName: 'lambda-hello-world',
934
+ Handler: 'index.handler',
935
+ Runtime: 'nodejs22.x',
936
+ },
937
+ },
938
+ });
939
+ (0, fixtures_2.mockLambdaLayers)(lambdaClientMock, {
940
+ [`${node22LibraryLayer}:1`]: {
941
+ LayerName: `${node22LibraryLayer}`,
942
+ VersionNumber: 1,
943
+ },
944
+ [`${extensionLayer}:1`]: {
945
+ LayerName: `${extensionLayer}`,
946
+ VersionNumber: 1,
947
+ },
948
+ });
949
+ prompt_2.requestAWSCredentials.mockImplementation(() => {
950
+ process.env[constants_2.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_2.mockAwsAccessKeyId;
951
+ process.env[constants_2.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_2.mockAwsSecretAccessKey;
952
+ process.env[constants_2.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
953
+ });
954
+ prompt_2.requestDatadogEnvVars.mockImplementation(() => {
955
+ process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
956
+ process.env[constants_1.CI_API_KEY_ENV_VAR] = fixtures_1.MOCK_DATADOG_API_KEY;
957
+ });
958
+ prompt_2.requestFunctionSelection.mockImplementation(() => [
959
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
960
+ ]);
961
+ prompt_1.requestConfirmation.mockImplementation(() => true);
962
+ prompt_2.requestEnvServiceVersion.mockImplementation(() => {
963
+ process.env[constants_1.ENVIRONMENT_ENV_VAR] = undefined;
964
+ process.env[constants_1.SERVICE_ENV_VAR] = undefined;
965
+ process.env[constants_1.VERSION_ENV_VAR] = undefined;
966
+ });
967
+ const cli = (0, fixtures_2.makeCli)();
968
+ const context = (0, fixtures_1.createMockContext)();
969
+ const code = yield cli.run(['lambda', 'instrument', '-i', '--no-source-code-integration'], context);
970
+ const output = context.stdout.toString();
971
+ expect(code).toBe(0);
972
+ expect(output).toMatchSnapshot();
973
+ }));
974
+ test('aborts if there are no functions to instrument in the user AWS account', () => __awaiter(void 0, void 0, void 0, function* () {
975
+ ;
976
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
977
+ process.env = {
978
+ [constants_2.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_2.mockAwsAccessKeyId,
979
+ [constants_2.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_2.mockAwsSecretAccessKey,
980
+ [constants_2.AWS_DEFAULT_REGION_ENV_VAR]: 'sa-east-1',
981
+ [constants_1.CI_SITE_ENV_VAR]: 'datadoghq.com',
982
+ [constants_1.CI_API_KEY_ENV_VAR]: fixtures_1.MOCK_DATADOG_API_KEY,
983
+ };
984
+ const cli = (0, fixtures_2.makeCli)();
985
+ const context = (0, fixtures_1.createMockContext)();
986
+ const code = yield cli.run(['lambda', 'instrument', '-i'], context);
987
+ const output = context.stdout.toString();
988
+ expect(code).toBe(1);
989
+ expect(output).toMatchInlineSnapshot(`
990
+ "
991
+ 🐶 Instrumenting Lambda function
992
+
993
+ [!] Configure AWS region.
994
+ [Error] Couldn't find any Lambda functions in the specified region.
995
+ "
996
+ `);
997
+ }));
998
+ test('aborts early when the aws-sdk throws an error while instrumenting interactively', () => __awaiter(void 0, void 0, void 0, function* () {
999
+ ;
1000
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1001
+ process.env = {
1002
+ [constants_2.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_2.mockAwsAccessKeyId,
1003
+ [constants_2.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_2.mockAwsSecretAccessKey,
1004
+ [constants_2.AWS_DEFAULT_REGION_ENV_VAR]: 'sa-east-1',
1005
+ [constants_1.CI_SITE_ENV_VAR]: 'datadoghq.com',
1006
+ [constants_1.CI_API_KEY_ENV_VAR]: fixtures_1.MOCK_DATADOG_API_KEY,
1007
+ };
1008
+ lambdaClientMock.on(client_lambda_1.ListFunctionsCommand).rejects('ListFunctionsError');
1009
+ const cli = (0, fixtures_2.makeCli)();
1010
+ const context = (0, fixtures_1.createMockContext)();
1011
+ const code = yield cli.run(['lambda', 'instrument', '-i'], context);
1012
+ const output = context.stdout.toString();
1013
+ expect(code).toBe(1);
1014
+ expect(output).toMatchInlineSnapshot(`
1015
+ "
1016
+ 🐶 Instrumenting Lambda function
1017
+
1018
+ [!] Configure AWS region.
1019
+ [Error] Couldn't fetch Lambda functions. Error: ListFunctionsError
1020
+ "
1021
+ `);
1022
+ }));
1023
+ test('instruments Ruby application properly', () => __awaiter(void 0, void 0, void 0, function* () {
1024
+ ;
1025
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1026
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
1027
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
1028
+ config: {
1029
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
1030
+ Runtime: 'ruby3.2',
1031
+ },
1032
+ },
1033
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world-2': {
1034
+ config: {
1035
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world-2',
1036
+ Runtime: 'ruby3.2',
1037
+ Architectures: ['arm64'],
1038
+ },
1039
+ },
1040
+ });
1041
+ const cli = (0, fixtures_2.makeCli)();
1042
+ const context = (0, fixtures_1.createMockContext)();
1043
+ process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
1044
+ const code = yield cli.run([
1045
+ 'lambda',
1046
+ 'instrument',
1047
+ '-f',
1048
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
1049
+ '-f',
1050
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world-2',
1051
+ '--dry-run',
1052
+ '-e',
1053
+ '40',
1054
+ '-v',
1055
+ '19',
1056
+ '--extra-tags',
1057
+ 'layer:api,team:intake',
1058
+ '--service',
1059
+ 'middletier',
1060
+ '--env',
1061
+ 'staging',
1062
+ '--version',
1063
+ '0.2',
1064
+ '--no-source-code-integration',
1065
+ ], context);
1066
+ const output = context.stdout.toString();
1067
+ expect(code).toBe(0);
1068
+ expect(output).toMatchSnapshot();
1069
+ }));
1070
+ test('aborts early when a layer version is set for a Custom runtime', () => __awaiter(void 0, void 0, void 0, function* () {
1071
+ ;
1072
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1073
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
1074
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
1075
+ config: {
1076
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
1077
+ Runtime: 'provided.al2',
1078
+ },
1079
+ },
1080
+ });
1081
+ const cli = (0, fixtures_2.makeCli)();
1082
+ const context = (0, fixtures_1.createMockContext)();
1083
+ const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
1084
+ process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
1085
+ const code = yield cli.run([
1086
+ 'lambda',
1087
+ 'instrument',
1088
+ '-f',
1089
+ functionARN,
1090
+ '--dry-run',
1091
+ '-v',
1092
+ '6',
1093
+ '--extra-tags',
1094
+ 'layer:api,team:intake',
1095
+ '--service',
1096
+ 'middletier',
1097
+ '--env',
1098
+ 'staging',
1099
+ '--version',
1100
+ '0.2',
1101
+ '--no-source-code-integration',
1102
+ ], context);
1103
+ const output = context.stdout.toString();
1104
+ expect(code).toBe(1);
1105
+ expect(output).toMatchInlineSnapshot(`
1106
+ "
1107
+ [Dry Run] 🐶 Instrumenting Lambda function
1108
+ [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.
1109
+ "
1110
+ `);
1111
+ }));
1112
+ test('aborts early when .NET is using ARM64 architecture', () => __awaiter(void 0, void 0, void 0, function* () {
1113
+ ;
1114
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1115
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
1116
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
1117
+ config: {
1118
+ Architectures: ['arm64'],
1119
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
1120
+ Runtime: 'dotnet6',
1121
+ },
1122
+ },
1123
+ });
1124
+ const cli = (0, fixtures_2.makeCli)();
1125
+ const context = (0, fixtures_1.createMockContext)();
1126
+ const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
1127
+ process.env.DATADOG_API_KEY = fixtures_1.MOCK_DATADOG_API_KEY;
1128
+ const code = yield cli.run([
1129
+ 'lambda',
1130
+ 'instrument',
1131
+ '-f',
1132
+ functionARN,
1133
+ '--dry-run',
1134
+ '-v',
1135
+ '6',
1136
+ '--extra-tags',
1137
+ 'layer:api,team:intake',
1138
+ '--service',
1139
+ 'middletier',
1140
+ '--env',
1141
+ 'staging',
1142
+ '--version',
1143
+ '0.2',
1144
+ '--no-source-code-integration',
1145
+ ], context);
1146
+ const output = context.stdout.toString();
1147
+ expect(code).toBe(1);
1148
+ expect(output).toMatchInlineSnapshot(`
1149
+ "
1150
+ [Dry Run] 🐶 Instrumenting Lambda function
1151
+ [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.
1152
+ "
1153
+ `);
1154
+ }));
1155
+ test('instruments correctly with profile when provided', () => __awaiter(void 0, void 0, void 0, function* () {
1156
+ const credentials = fixtures_2.mockAwsCredentials;
1157
+ credential_providers_1.fromIni.mockImplementation((_init) => () => __awaiter(void 0, void 0, void 0, function* () { return Promise.resolve(credentials); }));
1158
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
1159
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world': {
1160
+ config: {
1161
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
1162
+ Handler: 'index.handler',
1163
+ Runtime: 'nodejs22.x',
1164
+ },
1165
+ },
1166
+ });
1167
+ const cli = (0, fixtures_2.makeCli)();
1168
+ const context = (0, fixtures_1.createMockContext)();
1169
+ const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
1170
+ const code = yield cli.run(['lambda', 'instrument', '-f', functionARN, '--profile', 'SOME-AWS-PROFILE', '--no-source-code-integration'], context);
1171
+ expect(code).toBe(0);
1172
+ }));
1173
+ test('prints error when updating aws profile credentials fails', () => __awaiter(void 0, void 0, void 0, function* () {
1174
+ ;
1175
+ credential_providers_1.fromIni.mockImplementation(() => {
1176
+ throw Error('Update failed!');
1177
+ });
1178
+ const cli = (0, fixtures_2.makeCli)();
1179
+ const context = (0, fixtures_1.createMockContext)();
1180
+ const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
1181
+ const code = yield cli.run(['lambda', 'instrument', '-f', functionARN, '--profile', 'SOME-AWS-PROFILE'], context);
1182
+ const output = context.stdout.toString();
1183
+ expect(code).toBe(1);
1184
+ expect(output).toMatchInlineSnapshot(`
1185
+ "
1186
+ 🐶 Instrumenting Lambda function
1187
+ [Error] Error: Couldn't set AWS profile credentials. Update failed!
1188
+ "
1189
+ `);
1190
+ }));
1191
+ 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* () {
1192
+ const failingLambdas = [
1193
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
1194
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-2-us-east-1',
1195
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
1196
+ ];
1197
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1198
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
1199
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1': {
1200
+ config: {
1201
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
1202
+ FunctionName: 'lambda-1-us-east-1',
1203
+ Handler: 'index.handler',
1204
+ Runtime: 'nodejs22.x',
1205
+ },
1206
+ },
1207
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-2-us-east-1': {
1208
+ config: {
1209
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-2-us-east-1',
1210
+ FunctionName: 'lambda-2-us-east-1',
1211
+ Handler: 'index.handler',
1212
+ Runtime: 'nodejs22.x',
1213
+ },
1214
+ },
1215
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-3-us-east-1': {
1216
+ config: {
1217
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-3-us-east-1',
1218
+ FunctionName: 'lambda-3-us-east-1',
1219
+ Handler: 'index.handler',
1220
+ Runtime: 'nodejs22.x',
1221
+ },
1222
+ },
1223
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2': {
1224
+ config: {
1225
+ FunctionArn: 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
1226
+ FunctionName: 'lambda-1-us-east-2',
1227
+ Handler: 'index.handler',
1228
+ Runtime: 'nodejs16.x',
1229
+ },
1230
+ },
1231
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-2-us-east-2': {
1232
+ config: {
1233
+ FunctionArn: 'arn:aws:lambda:us-east-2:123456789012:function:lambda-2-us-east-2',
1234
+ FunctionName: 'lambda-2-us-east-2',
1235
+ Handler: 'index.handler',
1236
+ Runtime: 'nodejs18.x',
1237
+ },
1238
+ },
1239
+ });
1240
+ for (const failingLambda of failingLambdas) {
1241
+ lambdaClientMock
1242
+ .on(client_lambda_1.UpdateFunctionConfigurationCommand, { FunctionName: failingLambda })
1243
+ .rejects('Unexpected error updating request');
1244
+ }
1245
+ const cli = (0, fixtures_2.makeCli)();
1246
+ const context = (0, fixtures_1.createMockContext)();
1247
+ const code = yield cli.run([
1248
+ 'lambda',
1249
+ 'instrument',
1250
+ '-f',
1251
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
1252
+ '-f',
1253
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-2-us-east-1',
1254
+ '-f',
1255
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-3-us-east-1',
1256
+ '-f',
1257
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
1258
+ '-f',
1259
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-2-us-east-2',
1260
+ ], context);
1261
+ const output = context.stdout.toString();
1262
+ expect(code).toBe(0);
1263
+ expect(output).toMatchSnapshot();
1264
+ }));
1265
+ test('aborts when every lambda function fails to update on instrument', () => __awaiter(void 0, void 0, void 0, function* () {
1266
+ ;
1267
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1268
+ (0, fixtures_2.mockLambdaConfigurations)(lambdaClientMock, {
1269
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1': {
1270
+ config: {
1271
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
1272
+ FunctionName: 'lambda-1-us-east-1',
1273
+ Handler: 'index.handler',
1274
+ Runtime: 'nodejs22.x',
1275
+ },
1276
+ },
1277
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2': {
1278
+ config: {
1279
+ FunctionArn: 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
1280
+ FunctionName: 'lambda-1-us-east-2',
1281
+ Handler: 'index.handler',
1282
+ Runtime: 'nodejs18.x',
1283
+ },
1284
+ },
1285
+ });
1286
+ lambdaClientMock.on(client_lambda_1.UpdateFunctionConfigurationCommand).rejects('Unexpected error updating request');
1287
+ const cli = (0, fixtures_2.makeCli)();
1288
+ const context = (0, fixtures_1.createMockContext)();
1289
+ const code = yield cli.run([
1290
+ 'lambda',
1291
+ 'instrument',
1292
+ '-f',
1293
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
1294
+ '-f',
1295
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
1296
+ ], context);
1297
+ const output = context.stdout.toString();
1298
+ expect(code).toBe(1);
1299
+ expect(output).toMatchSnapshot();
1300
+ }));
1301
+ });
1302
+ describe('getSettings', () => {
1303
+ beforeEach(() => {
1304
+ lambdaClientMock.reset();
1305
+ });
1306
+ test('uses config file settings', () => {
1307
+ process.env = {};
1308
+ const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
1309
+ command['config']['flushMetricsToLogs'] = 'false';
1310
+ command['config']['forwarder'] = 'my-forwarder';
1311
+ command['config']['layerVersion'] = '2';
1312
+ command['config']['extensionVersion'] = '6';
1313
+ command['config']['layerAWSAccount'] = 'another-account';
1314
+ command['config']['mergeXrayTraces'] = 'false';
1315
+ command['config']['tracing'] = 'false';
1316
+ command['config']['logLevel'] = 'debug';
1317
+ expect(command['getSettings']()).toEqual({
1318
+ appsecEnabled: false,
1319
+ apmFlushDeadline: undefined,
1320
+ captureLambdaPayload: false,
1321
+ environment: undefined,
1322
+ extensionVersion: 6,
1323
+ extraTags: undefined,
1324
+ flushMetricsToLogs: false,
1325
+ forwarderARN: 'my-forwarder',
1326
+ interactive: false,
1327
+ layerAWSAccount: 'another-account',
1328
+ layerVersion: 2,
1329
+ logLevel: 'debug',
1330
+ mergeXrayTraces: false,
1331
+ service: undefined,
1332
+ tracingEnabled: false,
1333
+ version: undefined,
1334
+ });
1335
+ });
1336
+ test('prefers command line arguments over config file', () => {
1337
+ process.env = {};
1338
+ const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
1339
+ command['forwarder'] = 'my-forwarder';
1340
+ command['config']['forwarder'] = 'another-forwarder';
1341
+ command['layerVersion'] = '1';
1342
+ command['config']['layerVersion'] = '2';
1343
+ command['layerAWSAccount'] = 'my-account';
1344
+ command['config']['layerAWSAccount'] = 'another-account';
1345
+ command['mergeXrayTraces'] = 'true';
1346
+ command['config']['mergeXrayTraces'] = 'false';
1347
+ command['flushMetricsToLogs'] = 'false';
1348
+ command['config']['flushMetricsToLogs'] = 'true';
1349
+ command['tracing'] = 'true';
1350
+ command['config']['tracing'] = 'false';
1351
+ command['logLevel'] = 'debug';
1352
+ command['config']['logLevel'] = 'info';
1353
+ command['apmFlushDeadline'] = '20';
1354
+ command['config']['apmFlushDeadline'] = '50';
1355
+ expect(command['getSettings']()).toEqual({
1356
+ appsecEnabled: false,
1357
+ apmFlushDeadline: '20',
1358
+ captureLambdaPayload: false,
1359
+ flushMetricsToLogs: false,
1360
+ forwarderARN: 'my-forwarder',
1361
+ interactive: false,
1362
+ layerAWSAccount: 'my-account',
1363
+ layerVersion: 1,
1364
+ logLevel: 'debug',
1365
+ mergeXrayTraces: true,
1366
+ tracingEnabled: true,
1367
+ });
1368
+ });
1369
+ test("returns undefined when layer version can't be parsed", () => {
1370
+ process.env = {};
1371
+ const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
1372
+ command.context = {
1373
+ stdout: { write: jest.fn() },
1374
+ };
1375
+ command['layerVersion'] = 'abd';
1376
+ expect(command['getSettings']()).toBeUndefined();
1377
+ });
1378
+ test("returns undefined when extension version can't be parsed", () => {
1379
+ process.env = {};
1380
+ const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
1381
+ command.context = {
1382
+ stdout: { write: jest.fn() },
1383
+ };
1384
+ command['extensionVersion'] = 'abd';
1385
+ expect(command['getSettings']()).toBeUndefined();
1386
+ });
1387
+ test('converts string boolean from command line and config file correctly', () => {
1388
+ process.env = {};
1389
+ const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
1390
+ const validSettings = {
1391
+ appsecEnabled: false,
1392
+ captureLambdaPayload: true,
1393
+ extensionVersion: undefined,
1394
+ flushMetricsToLogs: false,
1395
+ forwarderARN: undefined,
1396
+ interactive: false,
1397
+ layerAWSAccount: undefined,
1398
+ layerVersion: undefined,
1399
+ logLevel: undefined,
1400
+ mergeXrayTraces: false,
1401
+ tracingEnabled: true,
1402
+ };
1403
+ command['config']['captureLambdaPayload'] = 'truE';
1404
+ command['config']['flushMetricsToLogs'] = 'False';
1405
+ command['config']['mergeXrayTraces'] = 'falSE';
1406
+ command['config']['tracing'] = 'TRUE';
1407
+ expect(command['getSettings']()).toEqual(validSettings);
1408
+ command['config']['captureLambdaPayload'] = 'true';
1409
+ command['config']['flushMetricsToLogs'] = 'false';
1410
+ command['config']['mergeXrayTraces'] = 'false';
1411
+ command['config']['tracing'] = 'true';
1412
+ expect(command['getSettings']()).toEqual(validSettings);
1413
+ validSettings.captureLambdaPayload = false;
1414
+ validSettings.flushMetricsToLogs = true;
1415
+ validSettings.mergeXrayTraces = true;
1416
+ validSettings.tracingEnabled = false;
1417
+ command['captureLambdaPayload'] = 'faLSE';
1418
+ command['flushMetricsToLogs'] = 'truE';
1419
+ command['mergeXrayTraces'] = 'TRUe';
1420
+ command['tracing'] = 'FALSE';
1421
+ expect(command['getSettings']()).toEqual(validSettings);
1422
+ command['captureLambdaPayload'] = 'false';
1423
+ command['flushMetricsToLogs'] = 'true';
1424
+ command['mergeXrayTraces'] = 'true';
1425
+ command['tracing'] = 'false';
1426
+ expect(command['getSettings']()).toEqual(validSettings);
1427
+ });
1428
+ test('aborts early if converting string boolean has an invalid value', () => {
1429
+ process.env = {};
1430
+ const stringBooleans = [
1431
+ 'flushMetricsToLogs',
1432
+ 'mergeXrayTraces',
1433
+ 'tracing',
1434
+ ];
1435
+ for (const option of stringBooleans) {
1436
+ let command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
1437
+ command['config'][option] = 'NotBoolean';
1438
+ command['getSettings']();
1439
+ let output = command.context.stdout.toString();
1440
+ expect(output).toMatch(`[Error] Invalid boolean specified for ${option}.\n`);
1441
+ command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
1442
+ command[option] = 'NotBoolean';
1443
+ command['getSettings']();
1444
+ output = command.context.stdout.toString();
1445
+ expect(output).toMatch(`Invalid boolean specified for ${option}.\n`);
1446
+ }
1447
+ });
1448
+ test('warns if any of environment, service or version tags are not set', () => __awaiter(void 0, void 0, void 0, function* () {
1449
+ ;
1450
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1451
+ process.env = {};
1452
+ let command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
1453
+ command['config']['region'] = 'ap-southeast-1';
1454
+ command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
1455
+ command['getSettings']();
1456
+ let output = command.context.stdout.toString();
1457
+ 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');
1458
+ command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
1459
+ command['config']['region'] = 'ap-southeast-1';
1460
+ command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
1461
+ command['config']['environment'] = 'b';
1462
+ command['config']['service'] = 'middletier';
1463
+ command['getSettings']();
1464
+ output = command.context.stdout.toString();
1465
+ 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');
1466
+ }));
1467
+ test('aborts early if extraTags do not comply with expected key:value list', () => __awaiter(void 0, void 0, void 0, function* () {
1468
+ ;
1469
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
1470
+ process.env = {};
1471
+ const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
1472
+ command['config']['region'] = 'ap-southeast-1';
1473
+ command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
1474
+ command['config']['service'] = 'middletier';
1475
+ command['config']['environment'] = 'staging';
1476
+ command['config']['version'] = '0.2';
1477
+ command['config']['extraTags'] = 'not@complying:illegal-chars-in-key,complies:valid-pair';
1478
+ command['getSettings']();
1479
+ const output = command.context.stdout.toString();
1480
+ expect(output).toMatch('[Error] Extra tags do not comply with the <key>:<value> array.\n');
1481
+ }));
1482
+ });
1483
+ describe('printPlannedActions', () => {
1484
+ test('prints no output when list is empty', () => {
1485
+ process.env = {};
1486
+ const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
1487
+ command['printPlannedActions']([]);
1488
+ const output = command.context.stdout.toString();
1489
+ expect(output).toMatchInlineSnapshot(`
1490
+ "
1491
+ No updates will be applied.
1492
+ "
1493
+ `);
1494
+ });
1495
+ test('prints log group actions', () => {
1496
+ process.env = {};
1497
+ const command = (0, fixtures_1.createCommand)(instrument_1.InstrumentCommand);
1498
+ command['printPlannedActions']([
1499
+ {
1500
+ functionARN: 'my-func',
1501
+ lambdaConfig: {},
1502
+ logGroupConfiguration: {
1503
+ createLogGroupCommandInput: { logGroupName: 'my-log-group' },
1504
+ deleteSubscriptionFilterCommandInput: { filterName: 'my-filter' },
1505
+ logGroupName: 'my-log-group',
1506
+ putSubscriptionFilterCommandInput: { filterName: 'my-filter' },
1507
+ },
1508
+ },
1509
+ ]);
1510
+ const output = command.context.stdout.toString();
1511
+ expect(output).toMatchInlineSnapshot(`
1512
+ "
1513
+ [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.
1514
+
1515
+ [!] Functions to be updated:
1516
+ - my-func
1517
+
1518
+ Will apply the following updates:
1519
+ CreateLogGroup -> my-log-group
1520
+ {
1521
+ "logGroupName": "my-log-group"
1522
+ }
1523
+ DeleteSubscriptionFilter -> my-log-group
1524
+ {
1525
+ "filterName": "my-filter"
1526
+ }
1527
+ PutSubscriptionFilter -> my-log-group
1528
+ {
1529
+ "filterName": "my-filter"
1530
+ }
1531
+ "
1532
+ `);
1533
+ });
1534
+ });
1535
+ });
1536
+ });
1537
+ //# sourceMappingURL=instrument.test.js.map