You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/serverless/custom_metrics/_index.md
+89-41Lines changed: 89 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,28 +58,94 @@ Datadog recommends using the [Datadog Lambda Extension][1] to submit custom metr
58
58
1. Follow the general [serverless installation instructions][8] appropriate for your Lambda runtime.
59
59
1. If you are not interested in collecting traces from your Lambda function, set the environment variable `DD_TRACE_ENABLED` to `false`.
60
60
1. If you are not interested in collecting logs from your Lambda function, set the environment variable `DD_SERVERLESS_LOGS_ENABLED` to `false`.
61
-
1.Import and use the helper function from the Datadog Lambda Library, such as `lambda_metric`or `sendDistributionMetric`, to submit your custom metrics following the [sample code](#custom-metrics-sample-code).
61
+
1.Follow the sample code or instructions belows to submit your custom metric.
62
62
63
-
If your Lambda function is running in a VPC, ensure that your function can reach Datadog API endpoints either through the public internet, [PrivateLink][9] or a [proxy][10].
Datadog recommends using the [Datadog Forwarder Lambda][11] to submit custom metrics from Lambda runtimes that are not yet supported by the Datadog Lambda Extension.
1. Follow the general [serverless installation instructions][8] to configure your Lambda function, install the Datadog Lambda Library and the Datadog Forwarder Lambda function, and subscribe the Forwarder to your function's log group.
70
-
1. If you are not interested in collecting traces from your Lambda function, set the environment variable `DD_TRACE_ENABLED` to `false` on your own Lambda function.
71
-
1. If you are not interested in collecting logs from your Lambda function, set the Forwarder's CloudFormation stack parameter `DdForwardLog` to `false`.
72
-
1. Import and use the helper function from the Datadog Lambda Library, such as `lambda_metric` or `sendDistributionMetric`, to submit your custom metrics following the [sample code](#custom-metrics-sample-code).
If the Datadog Lambda Library is not available for your runtime, you can print metrics to CloudWatch logs in the expected JSON format on your own. Select the "Other" tab from the [sample code](#custom-metrics-sample-code) section.
82
+
asyncfunctionmyHandler(event, context) {
83
+
sendDistributionMetric(
84
+
'coffee_house.order_value', // Metric name
85
+
12.45, // Metric value
86
+
'product:latte', // First tag
87
+
'order:online'// Second tag
88
+
);
89
+
}
90
+
```
91
+
{{< /programming-lang >}}
92
+
{{< programming-lang lang="go" >}}
75
93
76
-
## Custom metrics sample code
94
+
```go
95
+
package main
77
96
78
-
**Note:** The arguments to the custom metrics reporting methods have the following requirements:
97
+
import (
98
+
"github.com/aws/aws-lambda-go/lambda"
99
+
"github.com/DataDog/datadog-lambda-go"
100
+
)
79
101
80
-
-`<METRIC_NAME>` uniquely identifies your metric and follows the [metric naming policy][12].
81
-
-`<METRIC_VALUE>` MUST be a number (that is, integer or float).
82
-
-`<TAG_LIST>` is optional and formatted, for example: `['owner:Datadog', 'env:demo', 'cooltag']`.
[Install][14] the DogStatsD client for your runtime and follow the [sample code][15] to submit your custom metrics. Note: For accurate results, you must use [**distribution**](#understanding-distribution-metrics).
137
+
138
+
{{< /programming-lang >}}
139
+
{{< /programming-lang-wrapper >}}
140
+
141
+
## With the Datadog Forwarder
142
+
143
+
Datadog recommends using the [Datadog Forwarder Lambda][9] to submit custom metrics from Lambda runtimes that are not yet supported by the Datadog Lambda Extension.
144
+
145
+
1. Follow the general [serverless installation instructions][8] to instrument your Lambda function using the Datadog Forwarder Lambda function.
146
+
1. If you are not interested in collecting traces from your Lambda function, set the environment variable `DD_TRACE_ENABLED` to `false` on your own Lambda function.
147
+
1. If you are not interested in collecting logs from your Lambda function, set the Forwarder's CloudFormation stack parameter `DdForwardLog` to `false`.
148
+
1. Import and use the helper function from the Datadog Lambda Library, such as `lambda_metric` or `sendDistributionMetric`, to submit your custom metrics following the sample code below.
**Note**: If you are migrating to one of the recommended solutions, you'll need to start instrumenting your custom metrics under **new metric names** when submitting them to Datadog. The same metric name cannot simultaneously exist as both distribution and non-distribution metric types.
256
306
257
-
This requires the following AWS permissions in your [Datadog IAM policy][13].
307
+
This requires the following AWS permissions in your [Datadog IAM policy][10].
-`<UNIX_EPOCH_TIMESTAMP>` is in seconds, not milliseconds.
275
325
-`<METRIC_VALUE>` MUST be a number (that is, integer or float).
276
326
-`<METRIC_TYPE>` is `count`, `gauge`, `histogram`, or `check`.
277
-
-`<METRIC_NAME>` uniquely identifies your metric and follows the [metric naming policy][12].
327
+
-`<METRIC_NAME>` uniquely identifies your metric and follows the [metric naming policy][11].
278
328
-`<TAG_LIST>` is optional, comma separated, and must be preceded by `#`. The tag `function_name:<name_of_the_function>` is automatically applied to custom metrics.
279
329
280
330
**Note**: The sum for each timestamp is used for counts and the last value for a given timestamp is used for gauges. It is not recommended to print a log statement every time you increment a metric, as this increases the time it takes to parse your logs. Continually update the value of the metric in your code, and print one log statement for that metric before the function finishes.
0 commit comments