DataDog
CLASS | DESCRIPTION |
---|---|
DatadogProvider |
DatadogProvider creates metrics asynchronously via Datadog extension or exporter. |
DatadogProvider ¶
DatadogProvider(
metric_set: list | None = None,
namespace: str | None = None,
flush_to_log: bool | None = None,
default_tags: dict[str, Any] | None = None,
)
Bases: BaseProvider
DatadogProvider creates metrics asynchronously via Datadog extension or exporter.
Use aws_lambda_powertools.DatadogMetrics
to create and metrics to Datadog.
Environment variables
POWERTOOLS_METRICS_NAMESPACE : str metric namespace to be set for all metrics
RAISES | DESCRIPTION |
---|---|
MetricValueError
|
When metric value isn't a number |
SchemaValidationError
|
When metric object fails EMF schema validation |
METHOD | DESCRIPTION |
---|---|
add_cold_start_metric |
Add cold start metric and function_name dimension |
add_metric |
The add_metrics function that will be used by metrics class. |
flush_metrics |
Manually flushes the metrics. This is normally not necessary, |
log_metrics |
Decorator to serialize and publish metrics at the end of a function execution. |
serialize_metric_set |
Serializes metrics |
set_default_tags |
Persist tags across Lambda invocations |
Source code in aws_lambda_powertools/metrics/provider/datadog/datadog.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
add_cold_start_metric ¶
add_cold_start_metric(context: LambdaContext) -> None
Add cold start metric and function_name dimension
PARAMETER | DESCRIPTION |
---|---|
context
|
Lambda context
TYPE:
|
Source code in aws_lambda_powertools/metrics/provider/datadog/datadog.py
215 216 217 218 219 220 221 222 223 224 |
|
add_metric ¶
add_metric(
name: str,
value: float,
timestamp: int | None = None,
**tags
) -> None
The add_metrics function that will be used by metrics class.
PARAMETER | DESCRIPTION |
---|---|
name
|
Name/Key for the metrics
TYPE:
|
value
|
Value for the metrics
TYPE:
|
timestamp
|
Timestamp in int for the metrics, default = time.time()
TYPE:
|
tags
|
In format like ["tag:value", "tag2:value2"]
DEFAULT:
|
Examples:
1 2 3 4 5 6 7 8 |
|
Source code in aws_lambda_powertools/metrics/provider/datadog/datadog.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
flush_metrics ¶
flush_metrics(raise_on_empty_metrics: bool = False) -> None
Manually flushes the metrics. This is normally not necessary, unless you're running on other runtimes besides Lambda, where the @log_metrics decorator already handles things for you.
PARAMETER | DESCRIPTION |
---|---|
raise_on_empty_metrics
|
raise exception if no metrics are emitted, by default False
TYPE:
|
Source code in aws_lambda_powertools/metrics/provider/datadog/datadog.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
log_metrics ¶
log_metrics(
lambda_handler: AnyCallableT | None = None,
capture_cold_start_metric: bool = False,
raise_on_empty_metrics: bool = False,
**kwargs
)
Decorator to serialize and publish metrics at the end of a function execution.
Be aware that the log_metrics *does call the decorated function (e.g. lambda_handler).
Example
Lambda function using tracer and metrics decorators
1 2 3 4 5 6 7 8 9 10 |
|
PARAMETER | DESCRIPTION |
---|---|
lambda_handler
|
lambda function handler, by default None |
capture_cold_start_metric
|
captures cold start metric, by default False
TYPE:
|
raise_on_empty_metrics
|
raise exception if no metrics are emitted, by default False
TYPE:
|
**kwargs
|
DEFAULT:
|
RAISES | DESCRIPTION |
---|---|
e
|
Propagate error received |
Source code in aws_lambda_powertools/metrics/provider/datadog/datadog.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
serialize_metric_set ¶
serialize_metric_set(metrics: list | None = None) -> list
Serializes metrics
Example
Serialize metrics into Datadog format
1 2 3 |
|
RETURNS | DESCRIPTION |
---|---|
list
|
Serialized metrics following Datadog specification |
RAISES | DESCRIPTION |
---|---|
SchemaValidationError
|
Raised when serialization fail schema validation |
Source code in aws_lambda_powertools/metrics/provider/datadog/datadog.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
|
set_default_tags ¶
set_default_tags(**tags) -> None
Persist tags across Lambda invocations
PARAMETER | DESCRIPTION |
---|---|
tags
|
tags as key=value
TYPE:
|
Example
Sets some default dimensions that will always be present across metrics and invocations
1 2 3 4 5 6 7 8 |
|
Source code in aws_lambda_powertools/metrics/provider/datadog/datadog.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
|