serverless-plugin-datadog 5.1.1 → 5.1.2
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.
- package/dist/env.d.ts +17 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +63 -0
- package/dist/env.js.map +1 -0
- package/dist/forwarder.d.ts +14 -0
- package/dist/forwarder.d.ts.map +1 -0
- package/dist/forwarder.js +87 -0
- package/dist/forwarder.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +161 -0
- package/dist/index.js.map +1 -0
- package/dist/layer.d.ts +26 -0
- package/dist/layer.d.ts.map +1 -0
- package/dist/layer.js +65 -0
- package/dist/layer.js.map +1 -0
- package/dist/layers.json +156 -0
- package/dist/package.json +3 -3
- package/dist/src/env.d.ts +1 -0
- package/dist/src/env.d.ts.map +1 -1
- package/dist/src/env.js +1 -0
- package/dist/src/env.js.map +1 -1
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/layers-gov.json +4 -4
- package/dist/src/layers.json +42 -42
- package/dist/src/output.d.ts +2 -2
- package/dist/src/output.d.ts.map +1 -1
- package/dist/src/output.js +4 -4
- package/dist/src/output.js.map +1 -1
- package/dist/templates/node-es6-template.d.ts +2 -0
- package/dist/templates/node-es6-template.d.ts.map +1 -0
- package/dist/templates/node-es6-template.js +25 -0
- package/dist/templates/node-es6-template.js.map +1 -0
- package/dist/templates/node-js-template.d.ts +2 -0
- package/dist/templates/node-js-template.d.ts.map +1 -0
- package/dist/templates/node-js-template.js +24 -0
- package/dist/templates/node-js-template.js.map +1 -0
- package/dist/templates/node-ts-template.d.ts +2 -0
- package/dist/templates/node-ts-template.d.ts.map +1 -0
- package/dist/templates/node-ts-template.js +26 -0
- package/dist/templates/node-ts-template.js.map +1 -0
- package/dist/templates/python-template.d.ts +2 -0
- package/dist/templates/python-template.d.ts.map +1 -0
- package/dist/templates/python-template.js +25 -0
- package/dist/templates/python-template.js.map +1 -0
- package/dist/tracing.d.ts +9 -0
- package/dist/tracing.d.ts.map +1 -0
- package/dist/tracing.js +36 -0
- package/dist/tracing.js.map +1 -0
- package/dist/util.d.ts +9 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +72 -0
- package/dist/util.js.map +1 -0
- package/dist/wrapper.d.ts +11 -0
- package/dist/wrapper.d.ts.map +1 -0
- package/dist/wrapper.js +57 -0
- package/dist/wrapper.js.map +1 -0
- package/dist/yarn.lock +3703 -0
- package/package.json +3 -3
package/dist/env.d.ts
ADDED
@@ -0,0 +1,17 @@
|
|
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
|
@@ -0,0 +1 @@
|
|
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
ADDED
@@ -0,0 +1,63 @@
|
|
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
ADDED
@@ -0,0 +1 @@
|
|
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;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CAAC,eAAe,CAAC;KAC9D;AACH,CAAC;AAzBD,kDAyBC;AAED,SAAgB,SAAS,CAAC,OAAgB;IACxC,IAAI,MAAM,GAAG,OAAO,CAAC,MAAa,CAAC;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"}
|
@@ -0,0 +1,14 @@
|
|
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
|
@@ -0,0 +1 @@
|
|
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"}
|
@@ -0,0 +1,87 @@
|
|
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
|
@@ -0,0 +1 @@
|
|
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,CAAC;SACvF;QACD,MAAM,MAAM,GAAG,EAAE,CAAC;QAElB,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;YACxD,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,YAAY,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE;gBACzF,SAAS;aACV;YAED,MAAM,YAAY,GAAG,QAAQ,CAAC,UAAU,CAAC,YAAY,CAAC;YACtD,MAAM,aAAa,GAAG,GAAG,IAAI,cAAc,CAAC;YAE5C,IAAI,eAAe,GAAG,GAAG,OAAO,CAAC,cAAc,EAAE,IAAI,GAAG,CAAC,QAAQ,EAAE,IAAI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,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
ADDED
@@ -0,0 +1 @@
|
|
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
ADDED
@@ -0,0 +1,161 @@
|
|
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
|
@@ -0,0 +1 @@
|
|
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,IAA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+
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
|
@@ -0,0 +1 @@
|
|
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
ADDED
@@ -0,0 +1,65 @@
|
|
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
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"layer.js","sourceRoot":"","sources":["../src/layer.ts"],"names":[],"mappings":";;AAUA,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,6CAAI,CAAA;IACJ,iDAAM,CAAA;IACN,2DAAW,CAAA;AACb,CAAC,EAJW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAItB;AAmBY,QAAA,aAAa,GAAmC;IAC3D,YAAY,EAAE,WAAW,CAAC,IAAI;IAC9B,YAAY,EAAE,WAAW,CAAC,IAAI;IAC9B,YAAY,EAAE,WAAW,CAAC,IAAI;IAC9B,WAAW,EAAE,WAAW,CAAC,MAAM;IAC/B,WAAW,EAAE,WAAW,CAAC,MAAM;IAC/B,WAAW,EAAE,WAAW,CA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