def set_metric(self, key, value):
# This method sets a numeric tag value for the given key. It acts
# like `set_meta()` and it simply add a tag without further processing.
# FIXME[matt] we could push this check to serialization time as well.
# only permit types that are commonly serializable (don't use
# isinstance so that we convert unserializable types like numpy
# numbers)
if type(value) not in numeric_types:
try:
value = float(value)
except (ValueError, TypeError):
log.debug("ignoring not number metric %s:%s", key, value)
return
# don't allow nan or inf
if math.isnan(value) or math.isinf(value):
log.debug("ignoring not real metric %s:%s", key, value)
return
self.metrics[key] = value
评论列表
文章目录