From 7f704bfc06283357b795f27fb3fed60c03d49b4b Mon Sep 17 00:00:00 2001 From: Johannes Tax Date: Tue, 12 Mar 2024 10:06:48 +0100 Subject: [PATCH] extract logic to function --- .../semconv/model/semantic_convention.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py b/semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py index 7a8adf15..65f2865a 100644 --- a/semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py +++ b/semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py @@ -126,6 +126,12 @@ def _get_attributes(self, templates: Optional[bool]): if not hasattr(self, "attrs_by_name"): return [] + def comparison_key(attr): + if attr.requirement_level: + return attr.requirement_level.value, attr.fqn + else: + return RequirementLevel.RECOMMENDED.value, attr.fqn + return sorted( [ attr @@ -133,14 +139,7 @@ def _get_attributes(self, templates: Optional[bool]): if templates is None or templates == AttributeType.is_template_type(attr.attr_type) ], - key=lambda attr: ( - ( - attr.requirement_level.value - if attr.requirement_level - else RequirementLevel.RECOMMENDED.value - ), - attr.fqn, - ), + key=comparison_key ) def __init__(self, group, strict_validation=True):