serverless-plugin-datadog 5.0.1 → 5.1.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +39 -90
- 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 +7 -7
- package/dist/src/index.js.map +1 -1
- package/dist/src/layer.d.ts.map +1 -1
- package/dist/src/layer.js +1 -0
- package/dist/src/layer.js.map +1 -1
- package/dist/src/layers-gov.json +10 -8
- package/dist/src/layers.json +105 -84
- 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/src/tracing.d.ts.map +1 -1
- package/dist/src/tracing.js +4 -1
- package/dist/src/tracing.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/README.md
CHANGED
@@ -1,11 +1,3 @@
|
|
1
|
-
---
|
2
|
-
title: Datadog Serverless Plugin
|
3
|
-
kind: documentation
|
4
|
-
aliases:
|
5
|
-
- /serverless/serverless_integrations/plugin/
|
6
|
-
dependencies: ["https://github.com/DataDog/serverless-plugin-datadog/blob/master/README.md"]
|
7
|
-
---
|
8
|
-
|
9
1
|
![build](https://github.com/DataDog/serverless-plugin-datadog/workflows/build/badge.svg)
|
10
2
|
[![Code Coverage](https://img.shields.io/codecov/c/github/DataDog/serverless-plugin-datadog)](https://codecov.io/gh/DataDog/serverless-plugin-datadog)
|
11
3
|
[![NPM](https://img.shields.io/npm/v/serverless-plugin-datadog)](https://www.npmjs.com/package/serverless-plugin-datadog)
|
@@ -21,72 +13,71 @@ The plugin automatically enables instrumentation for applications to collect met
|
|
21
13
|
|
22
14
|
## Getting started
|
23
15
|
|
24
|
-
To quickly get started, follow the installation instructions for [Python][1], [Node.js][2], [Ruby][3], [Java][4], [Go][5], or [.NET][6] and view your function's enhanced metrics, traces, and logs in Datadog.
|
16
|
+
To quickly get started, follow the installation instructions for [Python][1], [Node.js][2], [Ruby][3], [Java][4], [Go][5], or [.NET][6] and view your function's enhanced metrics, traces, and logs in Datadog.
|
17
|
+
|
18
|
+
After installation is complete, configure the [advanced options](https://docs.datadoghq.com/serverless/configuration) to suit your monitoring needs.
|
25
19
|
|
26
20
|
## Upgrade
|
27
21
|
|
28
22
|
Each version of the plugin is published with a [specific set of versions of the Datadog Lambda layers][15]. To pick up new features and bug fixes provided by the latest versions of Datadog Lambda layers, upgrade the serverless framework plugin. Test the new version before applying it on your production applications.
|
29
23
|
|
30
|
-
##
|
24
|
+
## Configuration parameters
|
31
25
|
|
32
26
|
To further configure your plugin, use the following custom parameters in your `serverless.yml`:
|
33
27
|
|
34
28
|
| Parameter | Description |
|
35
29
|
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
36
|
-
| `
|
37
|
-
| `
|
38
|
-
| `
|
39
|
-
| `
|
40
|
-
| `
|
41
|
-
| `
|
42
|
-
| `
|
43
|
-
| `
|
44
|
-
| `
|
45
|
-
| `
|
46
|
-
| `
|
47
|
-
| `
|
48
|
-
| `
|
49
|
-
| `
|
50
|
-
| `
|
51
|
-
| `
|
52
|
-
| `
|
53
|
-
| `
|
54
|
-
| `
|
55
|
-
| `
|
56
|
-
| `
|
57
|
-
| `exclude` | When set, this plugin ignores all specified functions. Use this parameter if you have any functions that should not include Datadog functionality. Defaults to `[]`.
|
58
|
-
| `enabled` | When set to `false`, the Datadog plugin stays inactive. Defaults to `true`. You can control this option using an environment variable. For example, use `enabled: ${strToBool(${env:DD_PLUGIN_ENABLED, true})}` to activate/deactivate the plugin during deployment. Alternatively, you can also use the value passed in through `--stage` to control this option—[see example](#disable-plugin-for-particular-environment).
|
59
|
-
| `
|
60
|
-
| `
|
61
|
-
| `
|
30
|
+
| `site` | Set which Datadog site to send data to, such as `datadoghq.com` (default), `datadoghq.eu`, `us3.datadoghq.com`, `us5.datadoghq.com`, or `ddog-gov.com`. This parameter is required when collecting telemtry using the Datadog Lambda Extension. |
|
31
|
+
| `apiKey` | [Datadog API key][7]. This parameter is required when collecting telemetry using the Datadog Lambda Extension. Alternatively, you can also set the `DATADOG_API_KEY` environment variable in your deployment environment. |
|
32
|
+
| `appKey` | Datadog app key. Only needed when the `monitors` field is defined. Alternatively, you can also set the `DATADOG_APP_KEY` environment variable in your deployment environment. |
|
33
|
+
| `apiKeySecretArn` | An alternative to using the `apiKey` field. The ARN of the secret that is storing the Datadog API key in AWS Secrets Manager. Remember to add the `secretsmanager:GetSecretValue` permission to the Lambda execution role. |
|
34
|
+
| `apiKMSKey` | An alternative to using the `apiKey` field. Datadog API key encrypted using KMS. Remember to add the `kms:Decrypt` permission to the Lambda execution role. |
|
35
|
+
| `env` | When set along with `addExtension`, a `DD_ENV` environment variable is added to all Lambda functions with the provided value. Otherwise, an `env` tag is added to all Lambda functions with the provided value. Defaults to the `stage` value of the serverless deployment. |
|
36
|
+
| `service` | When set along with `addExtension`, a `DD_SERVICE` environment variable is added to all Lambda functions with the provided value. Otherwise, a `service` tag is added to all Lambda functions with the provided value. Defaults to the `service` value of the serverless project.
|
37
|
+
| `version` | When set along with `addExtension`, a `DD_VERSION` environment variable is added to all Lambda functions with the provided value. When set along with `forwarderArn`, a `version` tag is added to all Lambda functions with the provided value. |
|
38
|
+
| `tags` | A comma separated list of `key`:`value` pairs as a single string. When set along with `extensionLayerVersion`, a `DD_TAGS` environment variable is added to all Lambda functions with the provided value. When set along with `forwarderArn`, the plugin parses the string and sets each `key`:`value` pair as a tag on all Lambda functions. |
|
39
|
+
| `enableXrayTracing` | Set `true` to enable X-Ray tracing on the Lambda functions and API Gateway integrations. Defaults to `false`. |
|
40
|
+
| `enableDDTracing` | Enable Datadog tracing on the Lambda function. Defaults to `true`. |
|
41
|
+
| `enableDDLogs` | Enable Datadog log collection using the Lambda Extension. Defaults to `true`. Note: This setting has no effect on logs sent by the Datadog Forwarder. |
|
42
|
+
| `monitors` | When defined, the Datadog plugin configures monitors for the deployed function. Requires setting `DATADOG_API_KEY` and `DATADOG_APP_KEY` in your environment. To learn how to define monitors, see [To Enable and Configure a Recommended Serverless Monitor](#to-enable-and-configure-a-recommended-serverless-monitor). |
|
43
|
+
| `captureLambdaPayload` | [Captures incoming and outgoing AWS Lambda payloads][17] in the Datadog APM spans for Lambda invocations. Defaults to `false`. |
|
44
|
+
| `enableSourceCodeIntegration` | Enable [Datadog source code integration][18] for the function. Defaults to `true`. |
|
45
|
+
| `subscribeToApiGatewayLogs` | Enable automatic subscription of the Datadog Forwarder to API Gateway log groups. Requires setting `forwarderArn`. Defaults to `true`. |
|
46
|
+
| `subscribeToHttpApiLogs` | Enable automatic subscription of the Datadog Forwarder to HTTP API log groups. Requires setting `forwarderArn`. Defaults to `true`. |
|
47
|
+
| `subscribeToWebsocketLogs` | Enable automatic subscription of the Datadog Forwarder to WebSocket log groups. Requires setting `forwarderArn`. Defaults to `true`. |
|
48
|
+
| `forwarderArn` | The ARN of the Datadog Forwarder to be subscribed to the Lambda or API Gateway log groups. |
|
49
|
+
| `addLayers` | Whether to install the Datadog Lambda library as a layer. Defaults to `true`. Set to `false` when you plan to package the Datadog Lambda library to your function's deployment package on your own so that you can install a specific version of the Datadog Lambda library ([Python][8] or [Node.js][9]). |
|
50
|
+
| `addExtension` | Whether to install the Datadog Lambda Extension as a layer. Defaults to `true`. When enabled, it's required to set the `apiKey` and `site`. |
|
51
|
+
| `exclude` | When set, this plugin ignores all specified functions. Use this parameter if you have any functions that should not include Datadog functionality. Defaults to `[]`. |
|
52
|
+
| `enabled` | When set to `false`, the Datadog plugin stays inactive. Defaults to `true`. You can control this option using an environment variable. For example, use `enabled: ${strToBool(${env:DD_PLUGIN_ENABLED, true})}` to activate/deactivate the plugin during deployment. Alternatively, you can also use the value passed in through `--stage` to control this option—[see example](#disable-plugin-for-particular-environment). |
|
53
|
+
| `customHandler` | When set, the specified handler is set as the handler for all the functions. |
|
54
|
+
| `failOnError` | When set, this plugin throws an error if any custom Datadog monitors fail to create or update. This occurs after deploy, but will cause the result of `serverless deploy` to return a nonzero exit code (to fail user CI). Defaults to `false`. |
|
55
|
+
| `integrationTesting` | Set `true` when running integration tests. This bypasses the validation of the Forwarder ARN and the addition of Datadog Monitor output links. Defaults to `false`. |
|
56
|
+
| `logLevel` | The log level, set to `DEBUG` for extended logging. |
|
62
57
|
|
63
58
|
To use any of these parameters, add a `custom` > `datadog` section to your `serverless.yml` similar to this example:
|
64
59
|
|
65
60
|
```yaml
|
66
61
|
custom:
|
67
62
|
datadog:
|
68
|
-
flushMetricsToLogs: true
|
69
63
|
apiKeySecretArn: "{Datadog_API_Key_Secret_ARN}"
|
70
|
-
apiKMSKey: "{Encrypted_Datadog_API_Key}"
|
71
|
-
addLayers: true
|
72
|
-
logLevel: "info"
|
73
64
|
enableXrayTracing: false
|
74
65
|
enableDDTracing: true
|
75
66
|
enableDDLogs: true
|
76
67
|
subscribeToAccessLogs: true
|
77
68
|
forwarderArn: arn:aws:lambda:us-east-1:000000000000:function:datadog-forwarder
|
78
|
-
enableTags: true
|
79
|
-
injectLogContext: true
|
80
69
|
exclude:
|
81
70
|
- dd-excluded-function
|
82
71
|
```
|
83
72
|
|
84
|
-
|
73
|
+
### Webpack
|
85
74
|
|
86
|
-
|
75
|
+
If you are using a bundler, such as webpack, see [Serverless Tracing and Webpack](https://docs.datadoghq.com/serverless/guide/serverless_tracing_and_webpack/).
|
87
76
|
|
88
77
|
### TypeScript
|
89
78
|
|
79
|
+
You may encounter the error of missing type definitions. To resolve the error, add `datadog-lambda-js` and `dd-trace` to the `devDependencies` list of your project's package.json.
|
80
|
+
|
90
81
|
If you are using serverless-typescript, make sure that `serverless-datadog` is above the `serverless-typescript` entry in your `serverless.yml`. The plugin will automatically detect `.ts` files.
|
91
82
|
|
92
83
|
```yaml
|
@@ -95,49 +86,6 @@ plugins:
|
|
95
86
|
- serverless-typescript
|
96
87
|
```
|
97
88
|
|
98
|
-
If you use TypeScript, you may encounter the error of missing type definitions. A missing type definition happens when you use the prebuilt layers (for example, set `addLayers` to `true`, which is the default) and need to import helper functions from the `datadog-lambda-js` and `dd-trace` packages to submit custom metrics or instrument a specific function. To resolve the error, add `datadog-lambda-js` and `dd-trace` to the `devDependencies` list of your project's package.json.
|
99
|
-
|
100
|
-
### Webpack
|
101
|
-
|
102
|
-
`dd-trace` is known to be not compatible with webpack due to the use of conditional import and other issues. If using webpack, make sure to mark `datadog-lambda-js` and `dd-trace` as [externals](https://webpack.js.org/configuration/externals/) for webpack, so webpack knows these dependencies will be available in the runtime. You should also remove `datadog-lambda-js` and `dd-trace` from `package.json` and the build process to ensure you're using the versions provided by the Datadog Lambda Layer.
|
103
|
-
|
104
|
-
#### serverless-webpack
|
105
|
-
|
106
|
-
If using `serverless-webpack`, make sure to also exclude `datadog-lambda-js` and `dd-trace` in your `serverless.yml` in addition to declaring them as external in your webpack config file.
|
107
|
-
|
108
|
-
**webpack.config.js**
|
109
|
-
|
110
|
-
```javascript
|
111
|
-
var nodeExternals = require("webpack-node-externals");
|
112
|
-
|
113
|
-
module.exports = {
|
114
|
-
// we use webpack-node-externals to excludes all node deps.
|
115
|
-
// You can manually set the externals too.
|
116
|
-
externals: [nodeExternals(), "dd-trace", "datadog-lambda-js"],
|
117
|
-
};
|
118
|
-
```
|
119
|
-
|
120
|
-
**serverless.yml**
|
121
|
-
|
122
|
-
```yaml
|
123
|
-
custom:
|
124
|
-
webpack:
|
125
|
-
includeModules:
|
126
|
-
forceExclude:
|
127
|
-
- dd-trace
|
128
|
-
- datadog-lambda-js
|
129
|
-
```
|
130
|
-
|
131
|
-
### Forwarder
|
132
|
-
|
133
|
-
The [Datadog Forwarder Lambda function][11] needs to be installed and subscribed to your Lambda functions' log groups. The plugin automatically creates the log subscriptions when the Forwarder's ARN is supplied via the `forwarderArn` option.
|
134
|
-
|
135
|
-
If you run into the following error, double check the supplied Forwarder ARN is correct and ensure it is from the same region and account where your serverless application is deployed.
|
136
|
-
|
137
|
-
```
|
138
|
-
An error occurred: GetaccountapiLogGroupSubscription - Could not execute the lambda function. Make sure you have given CloudWatch Logs permission to execute your function. (Service: AWSLogs; Status Code: 400; Error Code: InvalidParameterException).
|
139
|
-
```
|
140
|
-
|
141
89
|
### Disable Plugin for Particular Environment
|
142
90
|
|
143
91
|
If you'd like to turn off the plugin based on the environment (passed via `--stage`), you can use something similar to the example below.
|
@@ -246,9 +194,8 @@ custom:
|
|
246
194
|
|
247
195
|
### [v5.0.0](https://github.com/DataDog/serverless-plugin-datadog/releases/tag/v5.0.0)
|
248
196
|
|
249
|
-
-
|
250
|
-
|
251
|
-
v5.0 is compatible with v10+ of the Datadog Extension, and all version of the Datadog Forwarder.
|
197
|
+
- When used in conjunction with the Datadog Extension, this plugin sets `service` and `env` tags through environment variables instead of Lambda resource tags.
|
198
|
+
- The `enableTags` parameter was replaced by the new `service`, `env` parameters.
|
252
199
|
|
253
200
|
### [v4.0.0](https://github.com/DataDog/serverless-plugin-datadog/releases/tag/v4.0.0)
|
254
201
|
|
@@ -292,3 +239,5 @@ This product includes software developed at Datadog (<https://www.datadoghq.com/
|
|
292
239
|
[14]: https://github.com/DataDog/serverless-plugin-datadog/blob/master/CONTRIBUTING.md
|
293
240
|
[15]: https://github.com/DataDog/serverless-plugin-datadog/blob/master/src/layers.json
|
294
241
|
[16]: https://docs.datadoghq.com/tracing/setup_overview/configure_data_security/?tab=mongodb#replace-rules-for-tag-filtering
|
242
|
+
[17]: https://www.datadoghq.com/blog/troubleshoot-lambda-function-request-response-payloads/
|
243
|
+
[18]: https://docs.datadoghq.com/integrations/guide/source-code-integration
|
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;IACf,kBAAkB,EAAE,IAAI;IACxB,QAAQ,EAAE,MAAM;IAChB,IAAI,EAAE,eAAe;IACrB,iBAAiB,EAAE,KAAK;IACxB,eAAe,EAAE,IAAI;IACrB,UAAU,EAAE,IAAI;CACjB,CAAC;AAEF,SAAgB,mBAAmB,CAAC,MAAqB,EAAE,OAAgB;IACzE,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAe,CAAC;IAEzC,IAAI,QAAQ,CAAC,WAAW,KAAK,SAAS,EAAE;QACtC,QAAQ,CAAC,WAAW,GAAG,EAAE,CAAC;KAC3B;IACD,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAkB,CAAC;IAChD,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,IAAI,WAAW,CAAC,YAAY,CAAC,KAAK,SAAS,EAAE;QAC1E,WAAW,CAAC,YAAY,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;KAC3C;IACD,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS,IAAI,WAAW,CAAC,eAAe,CAAC,KAAK,SAAS,EAAE;QAChF,WAAW,CAAC,eAAe,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC;KACjD;IACD,IAAI,WAAW,CAAC,aAAa,CAAC,KAAK,SAAS,EAAE;QAC5C,WAAW,CAAC,aAAa,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC;KAC1C;IACD,IAAI,WAAW,CAAC,cAAc,CAAC,KAAK,SAAS,EAAE;QAC7C,WAAW,CAAC,cAAc,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC;KAC/C;IACD,IAAI,WAAW,CAAC,mBAAmB,CAAC,KAAK,SAAS,EAAE;QAClD,WAAW,CAAC,mBAAmB,CAAC,GAAG,MAAM,CAAC,kBAAkB,CAAC;KAC9D;IACD,IAAI,MAAM,CAAC,eAAe,KAAK,SAAS,IAAI,WAAW,CAAC,sBAAsB,CAAC,KAAK,SAAS,EAAE;QAC7F,WAAW,CAAC,sBAAsB,CAAC,GAAG,MAAM,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,0CA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
|
+
"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;;;;;;;;;;;;;;;;;;AA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