INNER CODE UNIT · Python
save_sample
DataDog/dd-agent · checks/__init__.py:151
def save_sample(self, metric, value, timestamp=None, tags=None, hostname=None, device_name=None):
"""Save a simple sample, evict old values if needed
"""
from util import cast_metric_val
if timestamp is None:
timestamp = time.time()
if metric not in self._sample_store:
raise CheckException("Saving a sample for an undefined metric: %s" % metric)
try:
value = cast_metric_val(value)
except ValueError as ve:
raise NaN(ve)
# Sort and validate tags
if tags is not None:
if type(tags) not in [type([]), type(())]:
raise CheckException("Tags must be a list or tuple of strings")