awslabs/aws-embedded-metrics-python

MAX_DIMENSIONS should be 9, not 10

dlenski opened this issue · 2 comments

Per the upstream docs:

A DimensionSet MUST NOT contain more than 9 dimension keys.

Currently, you're setting MAX_DIMENSIONS to 10:

… and then using that to truncate the dimension set to 10 entries when serializing, e.g.:

def serialize(context: MetricsContext) -> str:
dimension_keys = []
dimensions_properties: Dict[str, str] = {}
for dimension_set in context.get_dimensions():
keys = list(dimension_set.keys())
dimension_keys.append(keys[0:MAX_DIMENSIONS])
dimensions_properties = {**dimensions_properties, **dimension_set}

I'm not sure that “silently truncating the dimension set” to an acceptable size is the best solution, but in any case the MAX_DIMENSIONS should be reduced to 9.

Thanks for reporting this! Definitely open to proposals on how to treat this. I've considered adding a configuration parameter that would throw exceptions or to log and silently move on in these kinds of cases.

Based on the Zen of Python (“Explicit is better than implicit”, “Errors should never pass silently unless explicitly silenced”, and all that) I would say that throwing an exception is probably the right default behavior.