serverless-plugin-datadog 3.4.0 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. package/README.md +31 -38
  2. package/dist/package.json +10 -2
  3. package/dist/src/env.d.ts +6 -3
  4. package/dist/src/env.d.ts.map +1 -1
  5. package/dist/src/env.js +25 -3
  6. package/dist/src/env.js.map +1 -1
  7. package/dist/src/git-metadata/interfaces.d.ts +10 -0
  8. package/dist/src/git-metadata/interfaces.d.ts.map +1 -0
  9. package/dist/src/git-metadata/interfaces.js +43 -0
  10. package/dist/src/git-metadata/interfaces.js.map +1 -0
  11. package/dist/src/git.d.ts +8 -0
  12. package/dist/src/git.d.ts.map +1 -0
  13. package/dist/src/git.js +115 -0
  14. package/dist/src/git.js.map +1 -0
  15. package/dist/src/helpers/apikey.d.ts +13 -0
  16. package/dist/src/helpers/apikey.d.ts.map +1 -0
  17. package/dist/src/helpers/apikey.js +74 -0
  18. package/dist/src/helpers/apikey.js.map +1 -0
  19. package/dist/src/helpers/errors.d.ts +3 -0
  20. package/dist/src/helpers/errors.d.ts.map +1 -0
  21. package/dist/src/helpers/errors.js +7 -0
  22. package/dist/src/helpers/errors.js.map +1 -0
  23. package/dist/src/helpers/interfaces.d.ts +20 -0
  24. package/dist/src/helpers/interfaces.d.ts.map +1 -0
  25. package/dist/src/helpers/interfaces.js +3 -0
  26. package/dist/src/helpers/interfaces.js.map +1 -0
  27. package/dist/src/helpers/retry.d.ts +3 -0
  28. package/dist/src/helpers/retry.d.ts.map +1 -0
  29. package/dist/src/helpers/retry.js +39 -0
  30. package/dist/src/helpers/retry.js.map +1 -0
  31. package/dist/src/helpers/tags.d.ts +29 -0
  32. package/dist/src/helpers/tags.d.ts.map +1 -0
  33. package/dist/src/helpers/tags.js +50 -0
  34. package/dist/src/helpers/tags.js.map +1 -0
  35. package/dist/src/helpers/upload.d.ts +45 -0
  36. package/dist/src/helpers/upload.d.ts.map +1 -0
  37. package/dist/src/helpers/upload.js +70 -0
  38. package/dist/src/helpers/upload.js.map +1 -0
  39. package/dist/src/helpers/utils.d.ts +31 -0
  40. package/dist/src/helpers/utils.d.ts.map +1 -0
  41. package/dist/src/helpers/utils.js +115 -0
  42. package/dist/src/helpers/utils.js.map +1 -0
  43. package/dist/src/index.d.ts +9 -1
  44. package/dist/src/index.d.ts.map +1 -1
  45. package/dist/src/index.js +56 -13
  46. package/dist/src/index.js.map +1 -1
  47. package/dist/src/layers-gov.json +8 -8
  48. package/dist/src/layers.json +84 -84
  49. package/dist/src/source-code-integration.d.ts +12 -0
  50. package/dist/src/source-code-integration.d.ts.map +1 -0
  51. package/dist/src/source-code-integration.js +76 -0
  52. package/dist/src/source-code-integration.js.map +1 -0
  53. package/package.json +10 -2
  54. package/dist/env.d.ts +0 -17
  55. package/dist/env.d.ts.map +0 -1
  56. package/dist/env.js +0 -63
  57. package/dist/env.js.map +0 -1
  58. package/dist/forwarder.d.ts +0 -14
  59. package/dist/forwarder.d.ts.map +0 -1
  60. package/dist/forwarder.js +0 -87
  61. package/dist/forwarder.js.map +0 -1
  62. package/dist/index.d.ts +0 -10
  63. package/dist/index.d.ts.map +0 -1
  64. package/dist/index.js +0 -161
  65. package/dist/index.js.map +0 -1
  66. package/dist/layer.d.ts +0 -26
  67. package/dist/layer.d.ts.map +0 -1
  68. package/dist/layer.js +0 -65
  69. package/dist/layer.js.map +0 -1
  70. package/dist/layers.json +0 -156
  71. package/dist/templates/node-es6-template.d.ts +0 -2
  72. package/dist/templates/node-es6-template.d.ts.map +0 -1
  73. package/dist/templates/node-es6-template.js +0 -25
  74. package/dist/templates/node-es6-template.js.map +0 -1
  75. package/dist/templates/node-js-template.d.ts +0 -2
  76. package/dist/templates/node-js-template.d.ts.map +0 -1
  77. package/dist/templates/node-js-template.js +0 -24
  78. package/dist/templates/node-js-template.js.map +0 -1
  79. package/dist/templates/node-ts-template.d.ts +0 -2
  80. package/dist/templates/node-ts-template.d.ts.map +0 -1
  81. package/dist/templates/node-ts-template.js +0 -26
  82. package/dist/templates/node-ts-template.js.map +0 -1
  83. package/dist/templates/python-template.d.ts +0 -2
  84. package/dist/templates/python-template.d.ts.map +0 -1
  85. package/dist/templates/python-template.js +0 -25
  86. package/dist/templates/python-template.js.map +0 -1
  87. package/dist/tracing.d.ts +0 -9
  88. package/dist/tracing.d.ts.map +0 -1
  89. package/dist/tracing.js +0 -36
  90. package/dist/tracing.js.map +0 -1
  91. package/dist/util.d.ts +0 -9
  92. package/dist/util.d.ts.map +0 -1
  93. package/dist/util.js +0 -72
  94. package/dist/util.js.map +0 -1
  95. package/dist/wrapper.d.ts +0 -11
  96. package/dist/wrapper.d.ts.map +0 -1
  97. package/dist/wrapper.js +0 -57
  98. package/dist/wrapper.js.map +0 -1
  99. package/dist/yarn.lock +0 -3703
@@ -0,0 +1,12 @@
1
+ import { SimpleGit } from "simple-git";
2
+ export declare class SourceCodeIntegration {
3
+ repositoryURL?: string;
4
+ private apiKey;
5
+ private datadogSite;
6
+ private simpleGit;
7
+ constructor(apiKey: string, datadogSite: string, simpleGit: SimpleGit, repositoryURL?: string);
8
+ uploadGitMetadata(): Promise<string>;
9
+ private getRequestBuilder;
10
+ private uploadRepository;
11
+ }
12
+ //# sourceMappingURL=source-code-integration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-code-integration.d.ts","sourceRoot":"","sources":["../../src/source-code-integration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAUvC,qBAAa,qBAAqB;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IAC9B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAY;gBAEjB,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,CAAC,EAAE,MAAM;IAOhF,iBAAiB;IAiC9B,OAAO,CAAC,iBAAiB;IAWzB,OAAO,CAAC,gBAAgB;CASzB"}
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SourceCodeIntegration = void 0;
13
+ const package_json_1 = require("../package.json");
14
+ const git_1 = require("./git");
15
+ const apikey_1 = require("./helpers/apikey");
16
+ const errors_1 = require("./helpers/errors");
17
+ const upload_1 = require("./helpers/upload");
18
+ const utils_1 = require("./helpers/utils");
19
+ class SourceCodeIntegration {
20
+ constructor(apiKey, datadogSite, simpleGit, repositoryURL) {
21
+ this.apiKey = apiKey;
22
+ this.datadogSite = datadogSite;
23
+ this.simpleGit = simpleGit;
24
+ this.repositoryURL = repositoryURL;
25
+ }
26
+ uploadGitMetadata() {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const apiKeyValidator = (0, apikey_1.newApiKeyValidator)({
29
+ apiKey: this.apiKey,
30
+ datadogSite: this.datadogSite,
31
+ });
32
+ const payload = yield (0, git_1.getCommitInfo)(this.simpleGit, this.repositoryURL);
33
+ if (payload === undefined) {
34
+ throw Error("Couldn't get git commit information.");
35
+ }
36
+ try {
37
+ const requestBuilder = this.getRequestBuilder();
38
+ const status = yield this.uploadRepository(requestBuilder)(payload, {
39
+ apiKeyValidator,
40
+ onError: (e) => {
41
+ throw e;
42
+ },
43
+ onRetry: (_) => { },
44
+ onUpload: () => {
45
+ return;
46
+ },
47
+ retries: 5,
48
+ });
49
+ if (status !== upload_1.UploadStatus.Success) {
50
+ throw new Error("Error uploading commit information.");
51
+ }
52
+ return payload.hash;
53
+ }
54
+ catch (error) {
55
+ throw error;
56
+ }
57
+ });
58
+ }
59
+ getRequestBuilder() {
60
+ if (!this.apiKey) {
61
+ throw new errors_1.InvalidConfigurationError("Missing DATADOG_API_KEY in your environment.");
62
+ }
63
+ return (0, utils_1.getRequestBuilder)({
64
+ apiKey: this.apiKey,
65
+ baseUrl: "https://sourcemap-intake." + this.datadogSite,
66
+ });
67
+ }
68
+ uploadRepository(requestBuilder) {
69
+ return (commitInfo, opts) => __awaiter(this, void 0, void 0, function* () {
70
+ const payload = commitInfo.asMultipartPayload(`serverless-plugin-datadog-${package_json_1.version}`);
71
+ return (0, upload_1.upload)(requestBuilder)(payload, opts);
72
+ });
73
+ }
74
+ }
75
+ exports.SourceCodeIntegration = SourceCodeIntegration;
76
+ //# sourceMappingURL=source-code-integration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-code-integration.js","sourceRoot":"","sources":["../../src/source-code-integration.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,kDAA0C;AAC1C,+BAAsC;AAEtC,6CAAsD;AACtD,6CAA6D;AAE7D,6CAAuE;AACvE,2CAAoD;AAEpD,MAAa,qBAAqB;IAMhC,YAAY,MAAc,EAAE,WAAmB,EAAE,SAAoB,EAAE,aAAsB;QAC3F,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAEY,iBAAiB;;YAC5B,MAAM,eAAe,GAAG,IAAA,2BAAkB,EAAC;gBACzC,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,WAAW,EAAE,IAAI,CAAC,WAAW;aAC9B,CAAC,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,IAAA,mBAAa,EAAC,IAAI,CAAC,SAAS,EAAE,IAA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CAAC,CAAC;QAC/C,CAAC,CAAA,CAAC;IACJ,CAAC;CACF;AAlED,sDAkEC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serverless-plugin-datadog",
3
- "version": "3.4.0",
3
+ "version": "3.5.0",
4
4
  "description": "Serverless plugin to automatically instrument python and node functions with datadog tracing",
5
5
  "main": "dist/src/index.js",
6
6
  "repository": "https://github.com/DataDog/serverless-plugin-datadog",
@@ -51,11 +51,19 @@
51
51
  "\\.snap$",
52
52
  "<rootDir>/node_modules/"
53
53
  ],
54
+ "testEnvironment": "<rootDir>/testEnvironment.js",
55
+ "clearMocks": true,
54
56
  "collectCoverageFrom": [
55
57
  "src/**/*.ts"
56
58
  ]
57
59
  },
58
60
  "dependencies": {
59
- "node-fetch": "^2.6.1"
61
+ "@datadog/datadog-ci": "^0.17.9",
62
+ "@types/async-retry": "^1.4.3",
63
+ "@types/datadog-metrics": "^0.6.2",
64
+ "@types/deep-extend": "^0.4.32",
65
+ "datadog-metrics": "^0.9.3",
66
+ "node-fetch": "^2.6.1",
67
+ "proxy": "^1.0.2"
60
68
  }
61
69
  }
package/dist/env.d.ts DELETED
@@ -1,17 +0,0 @@
1
- import Service from "serverless/classes/Service";
2
- export interface Configuration {
3
- addLayers: boolean;
4
- apiKey?: string;
5
- apiKMSKey?: string;
6
- site: string;
7
- logLevel: string;
8
- flushMetricsToLogs: boolean;
9
- enableXrayTracing: boolean;
10
- enableDDTracing: boolean;
11
- forwarder?: string;
12
- enableTags: boolean;
13
- }
14
- export declare const defaultConfiguration: Configuration;
15
- export declare function setEnvConfiguration(config: Configuration, service: Service): void;
16
- export declare function getConfig(service: Service): Configuration;
17
- //# sourceMappingURL=env.d.ts.map
package/dist/env.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAQA,OAAO,OAAO,MAAM,4BAA4B,CAAC;AAEjD,MAAM,WAAW,aAAa;IAE5B,SAAS,EAAE,OAAO,CAAC;IAEnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,IAAI,EAAE,MAAM,CAAC;IAEb,QAAQ,EAAE,MAAM,CAAC;IAEjB,kBAAkB,EAAE,OAAO,CAAC;IAE5B,iBAAiB,EAAE,OAAO,CAAC;IAE3B,eAAe,EAAE,OAAO,CAAC;IAGzB,SAAS,CAAC,EAAE,MAAM,CAAC;IAInB,UAAU,EAAE,OAAO,CAAC;CACrB;AASD,eAAO,MAAM,oBAAoB,EAAE,aAQlC,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,QAyB1E;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,aAAa,CAczD"}
package/dist/env.js DELETED
@@ -1,63 +0,0 @@
1
- "use strict";
2
- /*
3
- * Unless explicitly stated otherwise all files in this repository are licensed
4
- * under the Apache License Version 2.0.
5
- *
6
- * This product includes software developed at Datadog (https://www.datadoghq.com/).
7
- * Copyright 2019 Datadog, Inc.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- const apiKeyEnvVar = "DD_API_KEY";
11
- const apiKeyKMSEnvVar = "DD_KMS_API_KEY";
12
- const siteURLEnvVar = "DD_SITE";
13
- const logLevelEnvVar = "DD_LOG_LEVEL";
14
- const logForwardingEnvVar = "DD_FLUSH_TO_LOG";
15
- const ddTracingEnabledEnvVar = "DD_TRACE_ENABLED";
16
- exports.defaultConfiguration = {
17
- addLayers: true,
18
- flushMetricsToLogs: true,
19
- logLevel: "info",
20
- site: "datadoghq.com",
21
- enableXrayTracing: false,
22
- enableDDTracing: true,
23
- enableTags: true,
24
- };
25
- function setEnvConfiguration(config, service) {
26
- const provider = service.provider;
27
- if (provider.environment === undefined) {
28
- provider.environment = {};
29
- }
30
- const environment = provider.environment;
31
- if (config.apiKey !== undefined && environment[apiKeyEnvVar] === undefined) {
32
- environment[apiKeyEnvVar] = config.apiKey;
33
- }
34
- if (config.apiKMSKey !== undefined && environment[apiKeyKMSEnvVar] === undefined) {
35
- environment[apiKeyKMSEnvVar] = config.apiKMSKey;
36
- }
37
- if (environment[siteURLEnvVar] === undefined) {
38
- environment[siteURLEnvVar] = config.site;
39
- }
40
- if (environment[logLevelEnvVar] === undefined) {
41
- environment[logLevelEnvVar] = config.logLevel;
42
- }
43
- if (environment[logForwardingEnvVar] === undefined) {
44
- environment[logForwardingEnvVar] = config.flushMetricsToLogs;
45
- }
46
- if (config.enableDDTracing !== undefined && environment[ddTracingEnabledEnvVar] === undefined) {
47
- environment[ddTracingEnabledEnvVar] = config.enableDDTracing;
48
- }
49
- }
50
- exports.setEnvConfiguration = setEnvConfiguration;
51
- function getConfig(service) {
52
- let custom = service.custom;
53
- if (custom === undefined) {
54
- custom = {};
55
- }
56
- let datadog = custom.datadog;
57
- if (datadog === undefined) {
58
- datadog = {};
59
- }
60
- return Object.assign(Object.assign({}, exports.defaultConfiguration), datadog);
61
- }
62
- exports.getConfig = getConfig;
63
- //# sourceMappingURL=env.js.map
package/dist/env.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AA8BH,MAAM,YAAY,GAAG,YAAY,CAAC;AAClC,MAAM,eAAe,GAAG,gBAAgB,CAAC;AACzC,MAAM,aAAa,GAAG,SAAS,CAAC;AAChC,MAAM,cAAc,GAAG,cAAc,CAAC;AACtC,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AAC9C,MAAM,sBAAsB,GAAG,kBAAkB,CAAC;AAErC,QAAA,oBAAoB,GAAkB;IACjD,SAAS,EAAE,IAAI;IACf,kBAAkB,EAAE,IAAI;IACxB,QAAQ,EAAE,MAAM;IAChB,IAAI,EAAE,eAAe;IACrB,iBAAiB,EAAE,KAAK;IACxB,eAAe,EAAE,IAAI;I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AAC;IACnC,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,MAAM,GAAG,EAAE,CAAC;KACb;IAED,IAAI,OAAO,GAAG,MAAM,CAAC,OAA6C,CAAC;IACnE,IAAI,OAAO,KAAK,SAAS,EAAE;QACzB,OAAO,GAAG,EAAE,CAAC;KACd;IACD,uCACK,4BAAoB,GACpB,OAAO,EACV;AACJ,CAAC;AAdD,8BAcC"}
@@ -1,14 +0,0 @@
1
- import Service from "serverless/classes/Service";
2
- import Aws = require("serverless/plugins/aws/provider/awsProvider");
3
- export declare function addCloudWatchForwarderSubscriptions(service: Service, aws: Aws, functionArn: string): Promise<string[]>;
4
- export declare function canSubscribeLogGroup(aws: Aws, logGroupName: string, expectedSubName: string): Promise<boolean>;
5
- export declare function describeSubscriptionFilters(aws: Aws, logGroupName: string): Promise<{
6
- creationTime: number;
7
- destinationArn: string;
8
- distribution: string;
9
- filterName: string;
10
- filterPattern: string;
11
- logGroupName: string;
12
- roleArn: string;
13
- }[]>;
14
- //# sourceMappingURL=forwarder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"forwarder.d.ts","sourceRoot":"","sources":["../src/forwarder.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,4BAA4B,CAAC;AACjD,OAAO,GAAG,GAAG,QAAQ,6CAA6C,CAAC,CAAC;AA4BpE,wBAAsB,mCAAmC,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,qBAuCxG;AAED,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,oBAejG;AAED,wBAAsB,2BAA2B,CAAC,GAAG,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM;;;;;;;;KAc/E"}
package/dist/forwarder.js DELETED
@@ -1,87 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const logGroupKey = "AWS::Logs::LogGroup";
13
- const logGroupSubscriptionKey = "AWS::Logs::SubscriptionFilter";
14
- function isLogGroup(value) {
15
- return value.Type === logGroupKey;
16
- }
17
- function addCloudWatchForwarderSubscriptions(service, aws, functionArn) {
18
- var _a;
19
- return __awaiter(this, void 0, void 0, function* () {
20
- const resources = (_a = service.provider.compiledCloudFormationTemplate) === null || _a === void 0 ? void 0 : _a.Resources;
21
- if (resources === undefined) {
22
- return ["No cloudformation stack available. Skipping subscribing Datadog forwarder."];
23
- }
24
- const errors = [];
25
- for (const [name, resource] of Object.entries(resources)) {
26
- if (!isLogGroup(resource) || !resource.Properties.LogGroupName.startsWith("/aws/lambda/")) {
27
- continue;
28
- }
29
- const logGroupName = resource.Properties.LogGroupName;
30
- const scopedSubName = `${name}Subscription`;
31
- let expectedSubName = `${service.getServiceName()}-${aws.getStage()}-${scopedSubName}-`;
32
- const stackName = aws.naming.getStackName();
33
- if (stackName) {
34
- expectedSubName = `${stackName}-${scopedSubName}-`;
35
- }
36
- const canSub = yield canSubscribeLogGroup(aws, logGroupName, expectedSubName);
37
- if (!canSub) {
38
- errors.push(`Subscription already exists for log group ${logGroupName}. Skipping subscribing Datadog forwarder.`);
39
- continue;
40
- }
41
- const subscription = {
42
- Type: logGroupSubscriptionKey,
43
- Properties: {
44
- DestinationArn: functionArn,
45
- FilterPattern: "",
46
- LogGroupName: { Ref: name },
47
- },
48
- };
49
- resources[scopedSubName] = subscription;
50
- }
51
- return errors;
52
- });
53
- }
54
- exports.addCloudWatchForwarderSubscriptions = addCloudWatchForwarderSubscriptions;
55
- function canSubscribeLogGroup(aws, logGroupName, expectedSubName) {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- const subscriptionFilters = yield describeSubscriptionFilters(aws, logGroupName);
58
- let hasUnknownSubscriptions = false;
59
- for (const subscription of subscriptionFilters) {
60
- const filterName = subscription.filterName;
61
- if (filterName.startsWith(expectedSubName)) {
62
- return true;
63
- }
64
- // We don't own this log group. It might not be possible to set a forwarder
65
- hasUnknownSubscriptions = true;
66
- }
67
- // No log groups, so it's possible to subscribe.
68
- return !hasUnknownSubscriptions;
69
- });
70
- }
71
- exports.canSubscribeLogGroup = canSubscribeLogGroup;
72
- function describeSubscriptionFilters(aws, logGroupName) {
73
- return __awaiter(this, void 0, void 0, function* () {
74
- try {
75
- const result = yield aws.request("CloudWatchLogs", "describeSubscriptionFilters", {
76
- logGroupName,
77
- });
78
- return result.subscriptionFilters;
79
- }
80
- catch (err) {
81
- // An error will occur if the log group doesn't exist, so we swallow this and return an empty list.
82
- return [];
83
- }
84
- });
85
- }
86
- exports.describeSubscriptionFilters = describeSubscriptionFilters;
87
- //# sourceMappingURL=forwarder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"forwarder.js","sourceRoot":"","sources":["../src/forwarder.ts"],"names":[],"mappings":";;;;;;;;;;;AAGA,MAAM,WAAW,GAAG,qBAAqB,CAAC;AAC1C,MAAM,uBAAuB,GAAG,+BAA+B,CAAC;AAqBhE,SAAS,UAAU,CAAC,KAAU;IAC5B,OAAO,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC;AACpC,CAAC;AAED,SAAsB,mCAAmC,CAAC,OAAgB,EAAE,GAAQ,EAAE,WAAmB;;;QACvG,MAAM,SAAS,SAAG,OAAO,CAAC,QAAQ,CAAC,8BAA8B,0CAAE,SAAS,CAAC;QAC7E,IAAI,SAAS,KAAK,SAAS,EAAE;YAC3B,OAAO,CAAC,4EAA4E,CAAC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MAAM,2BAA2B,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;QAEjF,IAAI,uBAAuB,GAAG,KAAK,CAAC;QAEpC,KAAK,MAAM,YAAY,IAAI,mBAAmB,EAAE;YAC9C,MAAM,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC;YAC3C,IAAI,UAAU,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE;gBAC1C,OAAO,IAAI,CAAC;aACb;YACD,2EAA2E;YAC3E,uBAAuB,GAAG,IAAI,CAAC;SAChC;QACD,gDAAgD;QAChD,OAAO,CAAC,uBAAuB,CAAC;IAClC,CAAC;CAAA;AAfD,oDAeC;AAED,SAAsB,2BAA2B,CAAC,GAAQ,EAAE,YAAoB;;QAC9E,IAAI;YACF,MAAM,MAAM,GAAwC,MAAM,GAAG,CAAC,OAAO,CACnE,gBAAgB,EAChB,6BAA6B,EAC7B;gBACE,YAAY;aACb,CACF,CAAC;YACF,OAAO,MAAM,CAAC,mBAAmB,CAAC;SACnC;QAAC,OAAO,GAAG,EAAE;YACZ,mGAAmG;YACnG,OAAO,EAAE,CAAC;SACX;IACH,CAAC;CAAA;AAdD,kEAcC"}
package/dist/index.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { FunctionDefinition } from "serverless";
2
- export interface ExtendedFunctionDefinition extends FunctionDefinition {
3
- tags?: {
4
- [key: string]: string;
5
- };
6
- environment?: {
7
- [key: string]: string;
8
- };
9
- }
10
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGhD,MAAM,WAAW,0BAA2B,SAAQ,kBAAkB;IACpE,IAAI,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACjC,WAAW,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACzC"}
package/dist/index.js DELETED
@@ -1,161 +0,0 @@
1
- "use strict";
2
- /*
3
- * Unless explicitly stated otherwise all files in this repository are licensed
4
- * under the Apache License Version 2.0.
5
- *
6
- * This product includes software developed at Datadog (https://www.datadoghq.com/).
7
- * Copyright 2019 Datadog, Inc.
8
- */
9
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
10
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
11
- return new (P || (P = Promise))(function (resolve, reject) {
12
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
13
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
14
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
15
- step((generator = generator.apply(thisArg, _arguments || [])).next());
16
- });
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 (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
22
- result["default"] = mod;
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const layers = __importStar(require("./layers.json"));
27
- const env_1 = require("./env");
28
- const layer_1 = require("./layer");
29
- const tracing_1 = require("./tracing");
30
- const wrapper_1 = require("./wrapper");
31
- const forwarder_1 = require("./forwarder");
32
- var TagKeys;
33
- (function (TagKeys) {
34
- TagKeys["Service"] = "service";
35
- TagKeys["Env"] = "env";
36
- })(TagKeys || (TagKeys = {}));
37
- module.exports = class ServerlessPlugin {
38
- constructor(serverless, _) {
39
- this.serverless = serverless;
40
- this.hooks = {
41
- "after:datadog:clean:init": this.afterPackageFunction.bind(this),
42
- "after:datadog:generate:init": this.beforePackageFunction.bind(this),
43
- "after:deploy:function:packageFunction": this.afterPackageFunction.bind(this),
44
- "after:package:createDeploymentArtifacts": this.afterPackageFunction.bind(this),
45
- "after:package:initialize": this.beforePackageFunction.bind(this),
46
- "before:deploy:function:packageFunction": this.beforePackageFunction.bind(this),
47
- "before:offline:start:init": this.beforePackageFunction.bind(this),
48
- "before:step-functions-offline:start": this.beforePackageFunction.bind(this),
49
- };
50
- this.commands = {
51
- datadog: {
52
- commands: {
53
- clean: {
54
- lifecycleEvents: ["init"],
55
- usage: "Cleans up wrapper handler functions for DataDog, not necessary in most cases",
56
- },
57
- generate: {
58
- lifecycleEvents: ["init"],
59
- usage: "Generates wrapper handler functions for DataDog, not necessary in most cases",
60
- },
61
- },
62
- lifecycleEvents: ["clean", "generate"],
63
- usage: "Automatically instruments your lambdas with DataDog",
64
- },
65
- };
66
- }
67
- beforePackageFunction() {
68
- return __awaiter(this, void 0, void 0, function* () {
69
- this.serverless.cli.log("Auto instrumenting functions with Datadog");
70
- const config = env_1.getConfig(this.serverless.service);
71
- env_1.setEnvConfiguration(config, this.serverless.service);
72
- const defaultRuntime = this.serverless.service.provider.runtime;
73
- const handlers = layer_1.findHandlers(this.serverless.service, defaultRuntime);
74
- if (config.addLayers) {
75
- this.serverless.cli.log("Adding Lambda Layers to functions");
76
- this.debugLogHandlers(handlers);
77
- layer_1.applyLayers(this.serverless.service.provider.region, handlers, layers);
78
- }
79
- else {
80
- this.serverless.cli.log("Skipping adding Lambda Layers, make sure you are packaging them yourself");
81
- }
82
- let tracingMode = tracing_1.TracingMode.NONE;
83
- if (config.enableXrayTracing && config.enableDDTracing) {
84
- tracingMode = tracing_1.TracingMode.HYBRID;
85
- }
86
- else if (config.enableDDTracing) {
87
- tracingMode = tracing_1.TracingMode.DD_TRACE;
88
- }
89
- else if (config.enableXrayTracing) {
90
- tracingMode = tracing_1.TracingMode.XRAY;
91
- }
92
- tracing_1.enableTracing(this.serverless.service, tracingMode);
93
- });
94
- }
95
- afterPackageFunction() {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- const config = env_1.getConfig(this.serverless.service);
98
- if (config.forwarder) {
99
- const aws = this.serverless.getProvider("aws");
100
- const errors = yield forwarder_1.addCloudWatchForwarderSubscriptions(this.serverless.service, aws, config.forwarder);
101
- for (const error of errors) {
102
- this.serverless.cli.log(error);
103
- }
104
- }
105
- if (config.enableTags) {
106
- this.serverless.cli.log("Adding service and environment tags to functions");
107
- this.addServiceAndEnvTags();
108
- }
109
- const defaultRuntime = this.serverless.service.provider.runtime;
110
- const handlers = layer_1.findHandlers(this.serverless.service, defaultRuntime);
111
- wrapper_1.redirectHandlers(handlers, config.addLayers);
112
- });
113
- }
114
- debugLogHandlers(handlers) {
115
- for (const handler of handlers) {
116
- if (handler.type === layer_1.RuntimeType.UNSUPPORTED) {
117
- if (handler.runtime === undefined) {
118
- this.serverless.cli.log(`Unable to determine runtime for function ${handler.name}`);
119
- }
120
- else {
121
- this.serverless.cli.log(`Unable to add Lambda Layers to function ${handler.name} with runtime ${handler.runtime}`);
122
- }
123
- }
124
- }
125
- }
126
- /**
127
- * Check for service and env tags on provider level (under tags and stackTags),
128
- * as well as function level. Automatically create tags for service and env with
129
- * properties from deployment configurations if needed; does not override any existing values.
130
- */
131
- addServiceAndEnvTags() {
132
- let providerServiceTagExists = false;
133
- let providerEnvTagExists = false;
134
- const provider = this.serverless.service.provider;
135
- const providerTags = provider.tags;
136
- if (providerTags !== undefined) {
137
- providerServiceTagExists = providerTags[TagKeys.Service] !== undefined;
138
- providerEnvTagExists = providerTags[TagKeys.Env] !== undefined;
139
- }
140
- const providerStackTags = provider.stackTags;
141
- if (providerStackTags !== undefined) {
142
- providerServiceTagExists = providerServiceTagExists || providerStackTags[TagKeys.Service] !== undefined;
143
- providerEnvTagExists = providerEnvTagExists || providerStackTags[TagKeys.Env] !== undefined;
144
- }
145
- if (!providerServiceTagExists || !providerEnvTagExists) {
146
- this.serverless.service.getAllFunctions().forEach((functionName) => {
147
- const functionDefintion = this.serverless.service.getFunction(functionName);
148
- if (!functionDefintion.tags) {
149
- functionDefintion.tags = {};
150
- }
151
- if (!providerServiceTagExists && !functionDefintion.tags[TagKeys.Service]) {
152
- functionDefintion.tags[TagKeys.Service] = this.serverless.service.getServiceName();
153
- }
154
- if (!providerEnvTagExists && !functionDefintion.tags[TagKeys.Env]) {
155
- functionDefintion.tags[TagKeys.Env] = this.serverless.getProvider("aws").getStage();
156
- }
157
- });
158
- }
159
- }
160
- };
161
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;;AAGH,sDAAwC;AAExC,+BAAuD;AACvD,mCAA+E;AAC/E,uCAAuD;AACvD,uCAA6C;AAC7C,2CAAkE;AASlE,IAAK,OAGJ;AAHD,WAAK,OAAO;IACV,8BAAmB,CAAA;IACnB,sBAAW,CAAA;AACb,CAAC,EAHI,OAAO,KAAP,OAAO,QAGX;AAED,MAAM,CAAC,OAAO,GAAG,MAAM,gBAAgB;IA4BrC,YAAoB,UAAsB,EAAE,CAAqB;QAA7C,eAAU,GAAV,UAAU,CAAY;QA3BnC,UAAK,GAAG;YACb,0BAA0B,EAAE,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC;YAChE,6BAA6B,EAAE,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC;YACpE,uCAAuC,EAAE,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC;YAC7E,yCAAyC,EAAE,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC;YAC/E,0BAA0B,EAAE,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC;YACjE,wCAAwC,EAAE,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC;YAC/E,2BAA2B,EAAE,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC;YAClE,qCAAqC,EAAE,IAAI,CAAC,qBAAqB,CAAC,IAAI,CA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D,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,EAAE;gBACjE,MAAM,iBAAiB,GAA+B,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;gBACxG,IAAI,CAAC,iBAAiB,CAAC,IAAI,EAAE;oBAC3B,iBAAiB,CAAC,IAAI,GAAG,EAAE,CAAC;iBAC7B;gBACD,IAAI,CAAC,wBAAwB,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;oBACzE,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;iBACpF;gBACD,IAAI,CAAC,oBAAoB,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;oBACjE,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC;iBACrF;YACH,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF,CAAC"}
package/dist/layer.d.ts DELETED
@@ -1,26 +0,0 @@
1
- import { FunctionDefinition } from "serverless";
2
- import Service from "serverless/classes/Service";
3
- export declare enum RuntimeType {
4
- NODE = 0,
5
- PYTHON = 1,
6
- UNSUPPORTED = 2
7
- }
8
- export interface FunctionInfo {
9
- name: string;
10
- type: RuntimeType;
11
- handler: FunctionDefinition;
12
- runtime?: string;
13
- }
14
- export interface LayerJSON {
15
- regions: {
16
- [region: string]: {
17
- [runtime: string]: string | undefined;
18
- } | undefined;
19
- };
20
- }
21
- export declare const runtimeLookup: {
22
- [key: string]: RuntimeType;
23
- };
24
- export declare function findHandlers(service: Service, defaultRuntime?: string): FunctionInfo[];
25
- export declare function applyLayers(region: string, handlers: FunctionInfo[], layers: LayerJSON): void;
26
- //# sourceMappingURL=layer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"layer.d.ts","sourceRoot":"","sources":["../src/layer.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,OAAO,MAAM,4BAA4B,CAAC;AAEjD,oBAAY,WAAW;IACrB,IAAI,IAAA;IACJ,MAAM,IAAA;IACN,WAAW,IAAA;CACZ;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,kBAAkB,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE;QACP,CAAC,MAAM,EAAE,MAAM,GACX;YACE,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;SACvC,GACD,SAAS,CAAC;KACf,CAAC;CACH;AAED,eAAO,MAAM,aAAa,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAA;CAQvD,CAAC;AAEF,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,YAAY,EAAE,CAetF;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,MAAM,EAAE,SAAS,QAqBtF"}
package/dist/layer.js DELETED
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var RuntimeType;
4
- (function (RuntimeType) {
5
- RuntimeType[RuntimeType["NODE"] = 0] = "NODE";
6
- RuntimeType[RuntimeType["PYTHON"] = 1] = "PYTHON";
7
- RuntimeType[RuntimeType["UNSUPPORTED"] = 2] = "UNSUPPORTED";
8
- })(RuntimeType = exports.RuntimeType || (exports.RuntimeType = {}));
9
- exports.runtimeLookup = {
10
- "nodejs10.x": RuntimeType.NODE,
11
- "nodejs12.x": RuntimeType.NODE,
12
- "nodejs8.10": RuntimeType.NODE,
13
- "python2.7": RuntimeType.PYTHON,
14
- "python3.6": RuntimeType.PYTHON,
15
- "python3.7": RuntimeType.PYTHON,
16
- "python3.8": RuntimeType.PYTHON,
17
- };
18
- function findHandlers(service, defaultRuntime) {
19
- const funcs = service.functions;
20
- return Object.entries(funcs)
21
- .map(([name, handler]) => {
22
- let { runtime } = handler;
23
- if (runtime === undefined) {
24
- runtime = defaultRuntime;
25
- }
26
- if (runtime !== undefined && runtime in exports.runtimeLookup) {
27
- return { type: exports.runtimeLookup[runtime], runtime, name, handler };
28
- }
29
- return { type: RuntimeType.UNSUPPORTED, runtime, name, handler };
30
- })
31
- .filter((result) => result !== undefined);
32
- }
33
- exports.findHandlers = findHandlers;
34
- function applyLayers(region, handlers, layers) {
35
- const regionRuntimes = layers.regions[region];
36
- if (regionRuntimes === undefined) {
37
- return;
38
- }
39
- for (const handler of handlers) {
40
- if (handler.type === RuntimeType.UNSUPPORTED) {
41
- continue;
42
- }
43
- const { runtime } = handler;
44
- const layerARN = runtime !== undefined ? regionRuntimes[runtime] : undefined;
45
- if (layerARN !== undefined) {
46
- const currentLayers = getLayers(handler);
47
- if (!new Set(currentLayers).has(layerARN)) {
48
- currentLayers.push(layerARN);
49
- }
50
- setLayers(handler, currentLayers);
51
- }
52
- }
53
- }
54
- exports.applyLayers = applyLayers;
55
- function getLayers(handler) {
56
- const layersList = handler.handler.layers;
57
- if (layersList === undefined) {
58
- return [];
59
- }
60
- return layersList;
61
- }
62
- function setLayers(handler, layers) {
63
- handler.handler.layers = layers;
64
- }
65
- //# sourceMappingURL=layer.js.map
package/dist/layer.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"layer.js","sourceRoot":"","sources":["../src/layer.ts"],"names":[],"mappings":";;AAUA,IAAY,WAIX;AAJD,WAAY,WAAW;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