Skip to content

Commit 4b27d6e

Browse files
authored
Merge pull request #5 from DataDog/compact-log-fmt-for-metric
Shorten the metric log keys
2 parents 9846c96 + 347176c commit 4b27d6e

File tree

7 files changed

+17
-13
lines changed

7 files changed

+17
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
CHANGELOG
22
=========
3+
# v3 / 2019-06-18
4+
5+
* Log metrics in a compact format
6+
37
# v2 / 2019-06-10
48

59
* Support submitting metrics through CloudWatch Logs

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Set the following Datadog environment variable to `datadoghq.eu` to send your da
2222

2323
If your Lambda function powers a performance-critical task (e.g., a consumer-facing API). You can avoid the added latencies of metric-submitting API calls, by setting the following Datadog environment variable to `True`. Custom metrics will be submitted asynchronously through CloudWatch Logs and [the Datadog log forwarder](https://github.com/DataDog/datadog-serverless-functions/tree/master/aws/logs_monitoring).
2424

25-
* DATADOG_FLUSH_TO_LOG
25+
* DD_FLUSH_TO_LOG
2626

2727
### The Serverless Framework
2828

datadog_lambda/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2"
1+
__version__ = "3"

datadog_lambda/metric.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def lambda_metric(metric_name, value, timestamp=None, tags=None):
4242
Submit a data point to Datadog distribution metrics.
4343
https://docs.datadoghq.com/graphing/metrics/distributions/
4444
45-
When DATADOG_LOG_FORWARDER is True, write metric to log, and
45+
When DD_FLUSH_TO_LOG is True, write metric to log, and
4646
wait for the Datadog Log Forwarder Lambda function to submit
4747
the metrics asynchronously.
4848
@@ -51,12 +51,12 @@ def lambda_metric(metric_name, value, timestamp=None, tags=None):
5151
background thread.
5252
"""
5353
tags = _tag_dd_lambda_layer(tags)
54-
if os.environ.get('DATADOG_FLUSH_TO_LOG') == 'True':
54+
if os.environ.get('DD_FLUSH_TO_LOG', '').lower() == 'true':
5555
print(json.dumps({
56-
'metric_name': metric_name,
57-
'value': value,
58-
'timestamp': timestamp or int(time.time()),
59-
'tags': tags
56+
'm': metric_name,
57+
'v': value,
58+
'e': timestamp or int(time.time()),
59+
't': tags
6060
}))
6161
else:
6262
lambda_stats.distribution(

datadog_lambda/wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class _LambdaDecorator(object):
3333

3434
def __init__(self, func):
3535
self.func = func
36-
self.flush_to_log = os.environ.get('DATADOG_FLUSH_TO_LOG') == 'True'
36+
self.flush_to_log = os.environ.get('DD_FLUSH_TO_LOG', '').lower() == 'true'
3737

3838
def _before(self, event, context):
3939
try:

tests/test_metric.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def test_lambda_metric_tagged_with_dd_lambda_layer(self):
3030
])
3131

3232
def test_lambda_metric_flush_to_log(self):
33-
os.environ["DATADOG_FLUSH_TO_LOG"] = 'True'
33+
os.environ["DD_FLUSH_TO_LOG"] = 'True'
3434

3535
lambda_metric('test', 1)
3636
self.mock_metric_lambda_stats.distribution.assert_not_called()
3737

38-
del os.environ["DATADOG_FLUSH_TO_LOG"]
38+
del os.environ["DD_FLUSH_TO_LOG"]

tests/test_wrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def lambda_handler(event, context):
4545
self.mock_patch_all.assert_called()
4646

4747
def test_datadog_lambda_wrapper_flush_to_log(self):
48-
os.environ["DATADOG_FLUSH_TO_LOG"] = 'True'
48+
os.environ["DD_FLUSH_TO_LOG"] = 'True'
4949

5050
@datadog_lambda_wrapper
5151
def lambda_handler(event, context):
@@ -60,4 +60,4 @@ def lambda_handler(event, context):
6060
self.mock_extract_dd_trace_context.assert_called_with(lambda_event)
6161
self.mock_patch_all.assert_called()
6262

63-
del os.environ["DATADOG_FLUSH_TO_LOG"]
63+
del os.environ["DD_FLUSH_TO_LOG"]

0 commit comments

Comments
 (0)