Skip to content

Commit b4f6c81

Browse files
chore: wire up timestamp to StatsDWriter and fix tags=[] bug
1 parent 6c58173 commit b4f6c81

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

datadog_lambda/metric.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
# This product includes software developed at Datadog (https://www.datadoghq.com/).
44
# Copyright 2019 Datadog, Inc.
55

6+
import logging
67
import os
78
import time
8-
import logging
9-
import ujson as json
109
from datetime import datetime, timedelta
1110

11+
import ujson as json
12+
1213
from datadog_lambda.extension import should_use_extension
13-
from datadog_lambda.tags import get_enhanced_metrics_tags, dd_lambda_layer_tag
14+
from datadog_lambda.tags import dd_lambda_layer_tag, get_enhanced_metrics_tags
1415

1516
logger = logging.getLogger(__name__)
1617

@@ -28,8 +29,8 @@
2829
# and leads to data loss. When disabled, metrics are only flushed at the
2930
# end of invocation. To make metrics submitted from a long-running Lambda
3031
# function available sooner, consider using the Datadog Lambda extension.
31-
from datadog_lambda.thread_stats_writer import ThreadStatsWriter
3232
from datadog_lambda.api import init_api
33+
from datadog_lambda.thread_stats_writer import ThreadStatsWriter
3334

3435
init_api()
3536
lambda_stats = ThreadStatsWriter(flush_in_thread)
@@ -92,8 +93,8 @@ def lambda_metric(metric_name, value, timestamp=None, tags=None, force_async=Fal
9293
return
9394
global extension_thread_stats
9495
if extension_thread_stats is None:
95-
from datadog_lambda.thread_stats_writer import ThreadStatsWriter
9696
from datadog_lambda.api import init_api
97+
from datadog_lambda.thread_stats_writer import ThreadStatsWriter
9798

9899
init_api()
99100
extension_thread_stats = ThreadStatsWriter(flush_in_thread)
@@ -119,8 +120,10 @@ def lambda_metric(metric_name, value, timestamp=None, tags=None, force_async=Fal
119120
)
120121

121122

122-
def write_metric_point_to_stdout(metric_name, value, timestamp=None, tags=[]):
123+
def write_metric_point_to_stdout(metric_name, value, timestamp=None, tags=None):
123124
"""Writes the specified metric point to standard output"""
125+
tags = tags or []
126+
124127
logger.debug(
125128
"Sending metric %s value %s to Datadog via log forwarder", metric_name, value
126129
)

datadog_lambda/stats_writer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class StatsWriter:
2-
def distribution(self, metric_name, value, tags=[], timestamp=None):
2+
def distribution(self, metric_name, value, tags=None, timestamp=None):
33
raise NotImplementedError()
44

55
def flush(self):

datadog_lambda/statsd_writer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
from datadog_lambda.stats_writer import StatsWriter
21
from datadog_lambda.dogstatsd import statsd
2+
from datadog_lambda.stats_writer import StatsWriter
33

44

55
class StatsDWriter(StatsWriter):
66
"""
77
Writes distribution metrics using StatsD protocol
88
"""
99

10-
def distribution(self, metric_name, value, tags=[], timestamp=None):
11-
statsd.distribution(metric_name, value, tags=tags)
10+
def distribution(self, metric_name, value, tags=None, timestamp=None):
11+
statsd.distribution(metric_name, value, tags=tags, timestamp=timestamp)
1212

1313
def flush(self):
1414
pass

datadog_lambda/thread_stats_writer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Make sure that this package would always be lazy-loaded/outside from the critical path
44
# since underlying packages are quite heavy to load and useless when the extension is present
55
from datadog.threadstats import ThreadStats
6+
67
from datadog_lambda.stats_writer import StatsWriter
78

89
logger = logging.getLogger(__name__)
@@ -17,7 +18,7 @@ def __init__(self, flush_in_thread):
1718
self.thread_stats = ThreadStats(compress_payload=True)
1819
self.thread_stats.start(flush_in_thread=flush_in_thread)
1920

20-
def distribution(self, metric_name, value, tags=[], timestamp=None):
21+
def distribution(self, metric_name, value, tags=None, timestamp=None):
2122
self.thread_stats.distribution(
2223
metric_name, value, tags=tags, timestamp=timestamp
2324
)

0 commit comments

Comments
 (0)