8000 add user agent wip · DataDog/datadog-lambda-python@aa56080 · GitHub
[go: up one dir, main page]

Skip to content

Commit aa56080

Browse files
committed
add user agent wip
1 parent 10638a8 commit aa56080

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

datadog_lambda/metric.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
import boto3
1313
from datadog import api
1414
from datadog.threadstats import ThreadStats
15+
from datadog.http_client import _get_user_agent_header
1516
from datadog_lambda.tags import get_enhanced_metrics_tags, tag_dd_lambda_layer
17+
from datadog_lambda import __version__
18+
19+
from platform import python_version_tuple
1620

1721

1822
ENHANCED_METRICS_NAMESPACE_PREFIX = "aws.lambda.enhanced"
@@ -41,6 +45,7 @@ def lambda_metric(metric_name, value, timestamp=None, tags=None):
4145
write_metric_point_to_stdout(metric_name, value, timestamp, tags)
4246
else:
4347
logger.debug("Sending metric %s to Datadog via lambda layer", metric_name)
48+
4449
lambda_stats.distribution(metric_name, value, timestamp=timestamp, tags=tags)
4550

4651

@@ -133,4 +138,11 @@ def submit_errors_metric(lambda_context):
133138
api._api_host = os.environ.get(
134139
"DATADOG_HOST", "https://api." + os.environ.get("DD_SITE", "datadoghq.com")
135140
)
141+
142+
http_client = api._get_http_client()
143+
144+
major_version, minor_version, _ = python_version_tuple()
145+
146+
http_client._session.headers.update({'User-Agent': 'datadog-lambda/{__version__} (runtime {runtime}) ' + _get_user_agent_header()})
147+
136148
logger.debug("Setting DATADOG_HOST to %s", api._api_host)

datadog_lambda/tags.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ def get_runtime_tag():
7777
major=major_version, minor=minor_version
7878
)
7979

80+
def get_library_version_tag():
81+
"""Get the runtime tag from the current Python version
82+
"""
83+
major_version, minor_version, _ = python_version_tuple()
84+
85+
return "datadog_lambda:python{major}.{minor}".format(
86+
major=major_version, minor=minor_version
87+
)
88+
8089

8190
def get_enhanced_metrics_tags(lambda_context):
8291
"""Get the list of tags to apply to enhanced metrics
@@ -86,6 +95,7 @@ def get_enhanced_metrics_tags(lambda_context):
8695
"memorysize:{}".format(lambda_context.memory_limit_in_mb),
8796
get_runtime_tag(),
8897
_format_dd_lambda_layer_tag(),
98+
8999
]
90100

91101

0 commit comments

Comments
 (0)
0