Skip to content

Commit

Permalink
Unified service tagging for AWS Lambda (DataDog#9374)
Browse files Browse the repository at this point in the history
* Unified service tagging for AWS Lambda

* AWS SAM

* AWS CDK

* Custom

* Link to unified service tagging from installation instructions

* Apply suggestions from code review

Co-authored-by: Kaylyn <kaylyn.sigler@datadoghq.com>

Co-authored-by: Kaylyn <kaylyn.sigler@datadoghq.com>
  • Loading branch information
tianchu and Kaylyn authored Dec 28, 2020
1 parent 822a8fe commit aa2ec69
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 72 deletions.
116 changes: 116 additions & 0 deletions content/en/getting_started/tagging/unified_service_tagging.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,122 @@ to configure the `service` tag only in the configuration of the process check.
{{% /tab %}}
{{< /tabs >}}

### Serverless environment

#### AWS Lambda Functions

Depending on how you build and deploy your AWS Lambda-based serverless applications, you may have several options available for applying the `env`, `service` and `version` tags to metrics, traces and logs.

*Note*: These tags are specified through AWS resource tags instead of environment variables. Specifically, the `DD_ENV`, `DD_SERVICE` and `DD_VERSION` environment variables are not supported.

{{< tabs >}}

{{% tab "Serverless Framework" %}}

Tag your Lambda functions using the [tags][1] option:

```yaml
# serverless.yml
service: service-name
provider:
name: aws
# to apply the tags to all functions
tags:
env: "<ENV>"
service: "<SERVICE>"
version: "<VERSION>"
functions:
hello:
# this function will inherit the service level tags config above
handler: handler.hello
world:
# this function will overwrite the tags
handler: handler.users
tags:
env: "<ENV>"
service: "<SERVICE>"
version: "<VERSION>"
```

If you have installed the [Datadog serverless plugin][2], the plugin automatically tags the Lambda functions with the `service` and `env` tags using the `service` and `stage` values from the serverless application definition, unless a `service` or `env` tag already exists.

[1]: https://www.serverless.com/framework/docs/providers/aws/guide/functions#tags
[2]: https://docs.datadoghq.com/serverless/serverless_integrations/plugin
{{% /tab %}}

{{% tab "AWS SAM" %}}

Tag your Lambda functions using the [Tags][1] option:

```yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
MyLambdaFunction:
Type: AWS::Serverless::Function
Properties:
Tags:
env: "<ENV>"
service: "<SERVICE>"
version: "<VERSION>"
```

If you have installed the [Datadog serverless macro][2], you can also specify a `service` and `env` tag as parameters:

```yaml
Transform:
- AWS::Serverless-2016-10-31
- Name: DatadogServerless
Parameters:
service: "<SERVICE>"
env: "<ENV>"
```

[1]: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html#sam-function-tags
[2]: https://docs.datadoghq.com/serverless/serverless_integrations/macro

{{% /tab %}}

{{% tab "AWS CDK" %}}

Tag your app, stack or individual Lambda functions using the [Tags class][1]. If you have installed the [Datadog serverless macro][2], you can also specify a `service` and `env` tag as parameters:

```javascript
import * as cdk from "@aws-cdk/core";
class CdkStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
this.addTransform("DatadogServerless");
new cdk.CfnMapping(this, "Datadog", {
mapping: {
Parameters: {
service: "<SERVICE>",
env: "<ENV>",
},
},
});
}
}
```

[1]: https://docs.aws.amazon.com/cdk/latest/guide/tagging.html
[2]: https://docs.datadoghq.com/serverless/serverless_integrations/macro

{{% /tab %}}

{{% tab "Custom" %}}

Apply the `env`, `service` and `version` tags following the AWS instructions for [Tagging Lambda Functions][1].

[1]: https://docs.aws.amazon.com/lambda/latest/dg/configuration-tags.html

{{% /tab %}}

{{< /tabs >}}

## Further Reading

{{< partial name="whats-next/whats-next.html" >}}
Expand Down
15 changes: 10 additions & 5 deletions content/en/serverless/installation/dotnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ You need to subscribe the Datadog Forwarder Lambda function to each of your func
1. [Install the Datadog Forwarder if you haven't][2].
2. [Subscribe the Datadog Forwarder to your function's log groups][5].

### Unified Service Tagging

Although it's optional, Datadog highly recommends tagging you serverless applications with the `env`, `service`, and `version` tags following the [unified service tagging documentation][6].

## Explore Datadog Serverless Monitoring

After you have configured your function following the steps above, you should be able to view metrics, logs and traces on the [Serverless homepage][6].
After you have configured your function following the steps above, you should be able to view metrics, logs and traces on the [Serverless homepage][7].

### Monitor Custom Business Logic
## Monitor Custom Business Logic

If you would like to submit a custom metric, see the sample code below:

Expand All @@ -53,7 +57,7 @@ myMetric.Add("t", new string[] {"product:latte", "order:online"});
LambdaLogger.Log(JsonConvert.SerializeObject(myMetric));
```

For more information on custom metric submission, see [here][7].
For more information on custom metric submission, see [here][8].

## Further Reading

Expand All @@ -64,5 +68,6 @@ For more information on custom metric submission, see [here][7].
[3]: https://docs.aws.amazon.com/xray/latest/devguide/xray-services-lambda.html
[4]: https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-dotnet.html
[5]: /logs/guide/send-aws-services-logs-with-the-datadog-lambda-function/#collecting-logs-from-cloudwatch-log-group
[6]: https://app.datadoghq.com/functions
[7]: /serverless/custom_metrics?tab=otherruntimes
[6]: /getting_started/tagging/unified_service_tagging/#aws-lambda-functions
[7]: https://app.datadoghq.com/functions
[8]: /serverless/custom_metrics?tab=otherruntimes
15 changes: 10 additions & 5 deletions content/en/serverless/installation/go.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ You need to subscribe the Datadog Forwarder Lambda function to each of your func
1. [Install the Datadog Forwarder if you haven't][2].
2. [Subscribe the Datadog Forwarder to your function's log groups][5].

### Unified Service Tagging

Although it's optional, Datadog highly recommends tagging you serverless applications with the `env`, `service`, and `version` tags following the [unified service tagging documentation][6].
## Explore Datadog Serverless Monitoring
After you have configured your function following the steps above, you should be able to view metrics, logs and traces on the [Serverless Homepage][6].
After you have configured your function following the steps above, you should be able to view metrics, logs and traces on the [Serverless Homepage][7].
### Monitor Custom Business Logic
## Monitor Custom Business Logic
If you would like to submit a custom metric, see the sample code below:
Expand Down Expand Up @@ -115,7 +119,7 @@ func myHandler(ctx context.Context, event MyEvent) (string, error) {
}
```
For more information on custom metric submission, see [here][7].
For more information on custom metric submission, see [here][8].
## Further Reading
Expand All @@ -126,5 +130,6 @@ For more information on custom metric submission, see [here][7].
[3]: https://github.com/DataDog/datadog-lambda-go
[4]: https://docs.aws.amazon.com/xray/latest/devguide/xray-services-lambda.html
[5]: /logs/guide/send-aws-services-logs-with-the-datadog-lambda-function/#collecting-logs-from-cloudwatch-log-group
[6]: https://app.datadoghq.com/functions
[7]: /serverless/custom_metrics?tab=go
[6]: /getting_started/tagging/unified_service_tagging/#aws-lambda-functions
[7]: https://app.datadoghq.com/functions
[8]: /serverless/custom_metrics?tab=go
15 changes: 10 additions & 5 deletions content/en/serverless/installation/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,15 @@ You need to subscribe the Datadog Forwarder Lambda function to each of your func
1. [Install the Datadog Forwarder if you haven't][2].
2. [Subscribe the Datadog Forwarder to your function's log groups][5].

### Unified Service Tagging

Although it's optional, Datadog highly recommends tagging you serverless applications with the `env`, `service`, and `version` tags following the [unified service tagging documentation][6].
## Explore Datadog Serverless Monitoring
After you have configured your function following the steps above, you should be able to view metrics, logs and traces on the [Serverless Homepage][6].
After you have configured your function following the steps above, you should be able to view metrics, logs and traces on the [Serverless Homepage][7].
### Monitor Custom Business Logic
## Monitor Custom Business Logic
If you would like to submit a custom metric, see the sample code below:
Expand Down Expand Up @@ -118,7 +122,7 @@ public class Handler implements RequestHandler<APIGatewayV2ProxyRequestEvent, AP
}
```
For more information on custom metric submission, see [here][7].
For more information on custom metric submission, see [here][8].
## Further Reading
Expand All @@ -129,5 +133,6 @@ For more information on custom metric submission, see [here][7].
[3]: https://img.shields.io/bintray/v/datadog/datadog-maven/datadog-lambda-java
[4]: https://docs.aws.amazon.com/xray/latest/devguide/xray-services-lambda.html
[5]: /logs/guide/send-aws-services-logs-with-the-datadog-lambda-function/#collecting-logs-from-cloudwatch-log-group
[6]: https://app.datadoghq.com/functions
[7]: /serverless/custom_metrics?tab=java
[6]: /getting_started/tagging/unified_service_tagging/#aws-lambda-functions
[7]: https://app.datadoghq.com/functions
[8]: /serverless/custom_metrics?tab=java
43 changes: 24 additions & 19 deletions content/en/serverless/installation/nodejs.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,15 @@ For example:
datadog-ci lambda instrument -f my-function -f another-function -r us-east-1 -v 26 --forwarder arn:aws:lambda:us-east-1:000000000000:function:datadog-forwarder
```

If your Lambda function is configured to use code signing, you must add Datadog's Signing Profile ARN (`arn:aws:signer:us-east-1:464622532012:/signing-profiles/DatadogLambdaSigningProfile/9vMI9ZAGLc`) to your function's [Code Signing Configuration][5] before you can instrument it with the Datadog CLI.
If your Lambda function is configured to use code signing, you must add Datadog's Signing Profile ARN (`arn:aws:signer:us-east-1:464622532012:/signing-profiles/DatadogLambdaSigningProfile/9vMI9ZAGLc`) to your function's [Code Signing Configuration][4] before you can instrument it with the Datadog CLI.

More information and additional parameters can be found in the [CLI documentation][4].
More information and additional parameters can be found in the [CLI documentation][5].

[1]: https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-node.html
[2]: https://github.com/DataDog/datadog-lambda-js/releases
[3]: https://docs.datadoghq.com/serverless/forwarder/
[4]: https://docs.datadoghq.com/serverless/serverless_integrations/cli
[5]: https://docs.aws.amazon.com/lambda/latest/dg/configuration-codesigning.html#config-codesigning-config-update
[4]: https://docs.aws.amazon.com/lambda/latest/dg/configuration-codesigning.html#config-codesigning-config-update
[5]: https://docs.datadoghq.com/serverless/serverless_integrations/cli
{{% /tab %}}
{{% tab "Container Image" %}}

Expand Down Expand Up @@ -244,9 +244,9 @@ You need to subscribe the Datadog Forwarder Lambda function to each of your func
1. [Install the Datadog Forwarder if you haven't][1].
2. [Subscribe the Datadog Forwarder to your function's log groups][2].


[1]: https://docs.datadoghq.com/serverless/forwarder/
[2]: https://docs.datadoghq.com/logs/guide/send-aws-services-logs-with-the-datadog-lambda-function/#collecting-logs-from-cloudwatch-log-group

{{% /tab %}}
{{% tab "Custom" %}}

Expand Down Expand Up @@ -274,7 +274,7 @@ The available `RUNTIME` options are `Node10-x` and `Node12-x`. For `VERSION`, se
arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Node12-x:25
```
If your Lambda function is configured to use code signing, you must add Datadog's Signing Profile ARN (`arn:aws:signer:us-east-1:464622532012:/signing-profiles/DatadogLambdaSigningProfile/9vMI9ZAGLc`) to your function's [Code Signing Configuration][6] before you can add the Datadog Lambda library as a layer.
If your Lambda function is configured to use code signing, you must add Datadog's Signing Profile ARN (`arn:aws:signer:us-east-1:464622532012:/signing-profiles/DatadogLambdaSigningProfile/9vMI9ZAGLc`) to your function's [Code Signing Configuration][3] before you can add the Datadog Lambda library as a layer.
#### Using the Package
Expand All @@ -290,7 +290,7 @@ npm install --save datadog-lambda-js
yarn add datadog-lambda-js
```
See the [latest release][3].
See the [latest release][4].
### Configure the Function
Expand All @@ -304,24 +304,28 @@ See the [latest release][3].
You need to subscribe the Datadog Forwarder Lambda function to each of your function’s log groups, in order to send metrics, traces, and logs to Datadog.
1. [Install the Datadog Forwarder if you haven't][4].
2. [Subscribe the Datadog Forwarder to your function's log groups][5].
1. [Install the Datadog Forwarder if you haven't][5].
2. [Subscribe the Datadog Forwarder to your function's log groups][6].
[1]: https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html
[2]: https://github.com/DataDog/datadog-lambda-layer-js/releases
[3]: https://www.npmjs.com/package/datadog-lambda-js
[4]: https://docs.datadoghq.com/serverless/forwarder/
[5]: https://docs.datadoghq.com/logs/guide/send-aws-services-logs-with-the-datadog-lambda-function/#collecting-logs-from-cloudwatch-log-group
[6]: https://docs.aws.amazon.com/lambda/latest/dg/configuration-codesigning.html#config-codesigning-config-update
[3]: https://docs.aws.amazon.com/lambda/latest/dg/configuration-codesigning.html#config-codesigning-config-update
[4]: https://www.npmjs.com/package/datadog-lambda-js
[5]: https://docs.datadoghq.com/serverless/forwarder/
[6]: https://docs.datadoghq.com/logs/guide/send-aws-services-logs-with-the-datadog-lambda-function/#collecting-logs-from-cloudwatch-log-group
{{% /tab %}}
{{< /tabs >}}
### Unified Service Tagging
Although it's optional, Datadog highly recommends tagging you serverless applications with the `env`, `service`, and `version` tags following the [unified service tagging documentation][3].
## Explore Datadog Serverless Monitoring
After you have configured your function following the steps above, you can view metrics, logs and traces on the [Serverless Homepage][3].
After you have configured your function following the steps above, you can view metrics, logs and traces on the [Serverless Homepage][4].
### Monitor Custom Business Logic
## Monitor Custom Business Logic
If you would like to submit a custom metric or span, see the sample code below:
Expand Down Expand Up @@ -372,14 +376,15 @@ exports.handler = async (event) => {
};
```

For more information on custom metric submission, see [here][4]. For additional details on custom instrumentation, see the Datadog APM documentation for [custom instrumentation][5].
For more information on custom metric submission, see [here][5]. For additional details on custom instrumentation, see the Datadog APM documentation for [custom instrumentation][6].

## Further Reading

{{< partial name="whats-next/whats-next.html" >}}

[1]: /integrations/amazon_web_services/
[2]: /serverless/forwarder
[3]: https://app.datadoghq.com/functions
[4]: /serverless/custom_metrics?tab=nodejs
[5]: /tracing/custom_instrumentation/nodejs/
[3]: /getting_started/tagging/unified_service_tagging/#aws-lambda-functions
[4]: https://app.datadoghq.com/functions
[5]: /serverless/custom_metrics?tab=nodejs
[6]: /tracing/custom_instrumentation/nodejs/
Loading

0 comments on commit aa2ec69

Please sign in to comment.