Skip to content

Commit

Permalink
oops
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed Mar 10, 2023
1 parent 43e722b commit d1f3b4d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
1 change: 0 additions & 1 deletion semantic-conventions/src/opentelemetry/semconv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def main():
args = parser.parse_args()
check_args(args, parser)
semconv = parse_semconv(args, parser)

filter_semconv(semconv, args.only)
if len(semconv.models) == 0:
parser.error("No semantic convention model found!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class MetricGroupSemanticConvention(BaseSemanticConvention):
GROUP_TYPE_NAME = "metric_group"


class gitMetricSemanticConvention(MetricGroupSemanticConvention):
class MetricSemanticConvention(MetricGroupSemanticConvention):
GROUP_TYPE_NAME = "metric"

allowed_keys: Tuple[str, ...] = BaseSemanticConvention.allowed_keys + (
Expand Down Expand Up @@ -300,9 +300,12 @@ class SemanticConventionSet:

debug: bool
models: typing.Dict[str, BaseSemanticConvention] = field(default_factory=dict)
extended_models: typing.Dict[str, BaseSemanticConvention] = field(
default_factory=dict
)
errors: bool = False

def parse(self, file):
def parse(self, file, ref_only=False):
with open(file, "r", encoding="utf-8") as yaml_file:
try:
semconv_models = parse_semantic_convention_groups(yaml_file)
Expand All @@ -314,7 +317,10 @@ def parse(self, file):
f"Semantic convention '{model.semconv_id}' is already defined.",
file=sys.stderr,
)
self.models[model.semconv_id] = model
if not ref_only:
self.models[model.semconv_id] = model

self.extended_models[model.semconv_id] = model
except ValidationError as e:
self.errors = True
print(f"Error parsing {file}\n", file=sys.stderr)
Expand All @@ -325,7 +331,7 @@ def has_error(self):

def check_unique_fqns(self):
group_by_fqn: typing.Dict[str, str] = {}
for model in self.models.values():
for model in self.extended_models.values():
for attr in model.attributes:
if not attr.ref:
if attr.fqn in group_by_fqn:
Expand All @@ -351,7 +357,7 @@ def finish(self):
fixpoint = True
if index > 0:
self.debug = False
for semconv in self.models.values():
for semconv in self.extended_models.values():
# Ref first, extends and includes after!
fixpoint_ref = self.resolve_ref(semconv)
fixpoint_inc = self.resolve_include(semconv)
Expand All @@ -370,7 +376,7 @@ def _populate_extends(self):
This internal method goes through every semantic convention to resolve parent/child relationships.
:return: None
"""
unprocessed = self.models.copy()
unprocessed = self.extended_models.copy()
# Iterate through the list and remove the semantic conventions that have been processed.
while len(unprocessed) > 0:
semconv = next(iter(unprocessed.values()))
Expand All @@ -386,7 +392,7 @@ def _populate_extends_single(self, semconv, unprocessed):
"""
# Resolve parent of current Semantic Convention
if semconv.extends:
extended = self.models.get(semconv.extends)
extended = self.extended_models.get(semconv.extends)
if extended is None:
raise ValidationError.from_yaml_pos(
semconv._position,
Expand All @@ -398,7 +404,7 @@ def _populate_extends_single(self, semconv, unprocessed):
not_yet_processed = extended.extends in unprocessed
if extended.extends and not_yet_processed:
# Recursion on parent if was not already processed
parent_extended = self.models.get(extended.extends)
parent_extended = self.extended_models.get(extended.extends)
self._populate_extends_single(parent_extended, unprocessed)

# inherit prefix and constraints
Expand Down Expand Up @@ -442,7 +448,7 @@ def _sort_attributes_dict(

def _populate_anyof_attributes(self):
any_of: AnyOf
for semconv in self.models.values():
for semconv in self.extended_models.values():
for any_of in semconv.constraints:
if not isinstance(any_of, AnyOf):
continue
Expand All @@ -461,10 +467,10 @@ def _populate_anyof_attributes(self):
any_of.add_attributes(constraint_attrs)

def _populate_events(self):
for semconv in self.models.values():
for semconv in self.extended_models.values():
events: typing.List[EventSemanticConvention] = []
for event_id in semconv.events:
event = self.models.get(event_id)
event = self.extended_models.get(event_id)
if event is None:
raise ValidationError.from_yaml_pos(
semconv._position,
Expand Down Expand Up @@ -511,7 +517,7 @@ def resolve_include(self, semconv):
fixpoint_inc = True
for constraint in semconv.constraints:
if isinstance(constraint, Include):
include_semconv = self.models.get(constraint.semconv_id)
include_semconv = self.extended_models.get(constraint.semconv_id)
# include required attributes and constraints
if include_semconv is None:
raise ValidationError.from_yaml_pos(
Expand Down Expand Up @@ -552,7 +558,7 @@ def _lookup_attribute(self, attr_id: str) -> Union[SemanticAttribute, None]:
return next(
(
attr
for model in self.models.values()
for model in self.extended_models.values()
for attr in model.attributes
if attr.fqn == attr_id and attr.ref is None
),
Expand Down

0 comments on commit d1f3b4d

Please sign in to comment.