Skip to content

Commit

Permalink
Add attribute processing to metric identity
Browse files Browse the repository at this point in the history
  • Loading branch information
TimPansino committed May 11, 2023
1 parent 6caf71e commit ed33957
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions newrelic/common/metric_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,22 @@
This module implements functions for creating a unique identity from a name and set of tags for use in dimensional metrics.
"""

from newrelic.packages import six
from newrelic.core.attribute import process_user_attribute


def create_metric_identity(name, tags=None):
if tags:
# Convert dicts to an iterable of tuples, other iterables should already be in this form
if isinstance(tags, dict):
tags = frozenset(six.iteritems(tags)) if tags is not None else None
elif not isinstance(tags, frozenset):
tags = frozenset(tags)
elif tags is not None:
tags = None # Set empty iterables to None
tags = tags.items()

# Apply attribute system sanitization.
# process_user_attribute returns (None, None) for results that fail sanitization.
# The filter removes these results fromt he iterable before creating the frozenset.
tags = frozenset(filter(lambda args: args[0] is not None, map(lambda args: process_user_attribute(*args), tags)))

# Set empty iterables after filtering to None
if not tags and tags is not None:
tags = None

return (name, tags)

0 comments on commit ed33957

Please sign in to comment.