diff --git a/semantic-conventions/CHANGELOG.md b/semantic-conventions/CHANGELOG.md index 1c48e69a..dd656f0e 100644 --- a/semantic-conventions/CHANGELOG.md +++ b/semantic-conventions/CHANGELOG.md @@ -4,7 +4,10 @@ Please update the changelog as part of any significant pull request. ## Unreleased -## 0.24.0 +- BREAKING: Remove unused semantic convention types: `UnitSemanticConvention`, `MetricGroupSemanticConvention` and `ScopeSemanticConvention` + ([#309](https://github.com/open-telemetry/build-tools/pull/309)) + +## v0.24.0 - BREAKING: Add `stability` (required) and `deprecated` (optional) properties to `EnumMember` ([#267](https://github.com/open-telemetry/build-tools/pull/267)) diff --git a/semantic-conventions/semconv.schema.json b/semantic-conventions/semconv.schema.json index 11871d89..a22365c8 100644 --- a/semantic-conventions/semconv.schema.json +++ b/semantic-conventions/semconv.schema.json @@ -54,9 +54,7 @@ "span", "resource", "metric", - "metric_group", "event", - "scope", "attribute_group" ], "description": "The (signal) type of the semantic convention" @@ -127,16 +125,6 @@ {"required": ["name"]} ] }, - "MetricGroupSemanticConvention": { - "allOf": [{ "$ref": "#/definitions/SemanticConventionBase" }], - "required": ["type"], - "properties": { - "type": { - "type": "string", - "const": "metric_group" - } - } - }, "MetricSemanticConvention": { "allOf": [{ "$ref": "#/definitions/SemanticConventionBase" }], "required": [ diff --git a/semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py b/semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py index dae2ed9e..360a9bb1 100644 --- a/semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py +++ b/semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py @@ -26,7 +26,6 @@ RequirementLevel, SemanticAttribute, ) -from opentelemetry.semconv.model.unit_member import UnitMember from opentelemetry.semconv.model.utils import ( ValidatableYamlNode, ValidationContext, @@ -185,10 +184,6 @@ class ResourceSemanticConvention(BaseSemanticConvention): GROUP_TYPE_NAME = "resource" -class ScopeSemanticConvention(BaseSemanticConvention): - GROUP_TYPE_NAME = "scope" - - class AttributeGroupConvention(BaseSemanticConvention): GROUP_TYPE_NAME = "attribute_group" @@ -226,26 +221,7 @@ def __init__(self, group, validation_ctx): ) -class UnitSemanticConvention(BaseSemanticConvention): - GROUP_TYPE_NAME = "units" - - allowed_keys = ( # We completely override base semantic keys here. - "id", - "type", - "brief", - "members", - ) - - def __init__(self, group, validation_ctx): - super().__init__(group, validation_ctx) - self.members = UnitMember.parse(group.get("members"), validation_ctx) - - -class MetricGroupSemanticConvention(BaseSemanticConvention): - GROUP_TYPE_NAME = "metric_group" - - -class MetricSemanticConvention(MetricGroupSemanticConvention): +class MetricSemanticConvention(BaseSemanticConvention): GROUP_TYPE_NAME = "metric" allowed_keys: Tuple[str, ...] = BaseSemanticConvention.allowed_keys + ( @@ -514,10 +490,7 @@ def attribute_templates(self): SpanSemanticConvention, ResourceSemanticConvention, EventSemanticConvention, - MetricGroupSemanticConvention, MetricSemanticConvention, - UnitSemanticConvention, - ScopeSemanticConvention, AttributeGroupConvention, ) } diff --git a/semantic-conventions/src/opentelemetry/semconv/model/unit_member.py b/semantic-conventions/src/opentelemetry/semconv/model/unit_member.py deleted file mode 100644 index 3068449b..00000000 --- a/semantic-conventions/src/opentelemetry/semconv/model/unit_member.py +++ /dev/null @@ -1,22 +0,0 @@ -from opentelemetry.semconv.model.utils import ValidatableYamlNode - - -class UnitMember(ValidatableYamlNode): - - allowed_keys = ("id", "brief", "value") - mandatory_keys = allowed_keys - - def __init__(self, node, validation_ctx): - super().__init__(node, validation_ctx) - self.value = node.get("value") - - @staticmethod - def parse(members, validation_ctx): - parsed_members = {} - for member in members: - UnitMember.validate_keys(member, validation_ctx) - unit_member = UnitMember(member, validation_ctx) - unit_member.validate_values() - parsed_members[unit_member.id] = unit_member - - return parsed_members diff --git a/semantic-conventions/src/opentelemetry/semconv/templating/markdown/__init__.py b/semantic-conventions/src/opentelemetry/semconv/templating/markdown/__init__.py index 78a1242a..7534d527 100644 --- a/semantic-conventions/src/opentelemetry/semconv/templating/markdown/__init__.py +++ b/semantic-conventions/src/opentelemetry/semconv/templating/markdown/__init__.py @@ -33,7 +33,6 @@ EventSemanticConvention, MetricSemanticConvention, SemanticConventionSet, - UnitSemanticConvention, ) from opentelemetry.semconv.model.utils import ID_RE from opentelemetry.semconv.templating.markdown.options import MarkdownOptions @@ -55,7 +54,6 @@ def __init__(self): self.group_key = "" self.enums = [] self.notes = [] - self.units = [] self.current_md = "" self.current_semconv = None @@ -277,17 +275,6 @@ def to_creation_time_attributes( for attr in sampling_relevant_attrs: output.write("* " + self.render_fqn_for_attribute(attr) + "\n") - @staticmethod - def to_markdown_unit_table(members, output: io.StringIO): - output.write("\n") - output.write( - "| Name | Kind of Quantity | Unit String |\n" - "| ------------| ---------------- | ----------- |" - ) - for member in members.values(): - output.write(f"\n| {member.id} | {member.brief} | `{member.value}` |") - output.write("\n") - def to_markdown_enum(self, output: io.StringIO): """Renders enum types after a Semantic Convention Table :return: @@ -490,9 +477,6 @@ def _render_group(self, semconv, parameters, output): self.to_markdown_enum(output) - if isinstance(semconv, UnitSemanticConvention): - self.to_markdown_unit_table(semconv.members, output) - output.write("") def _render_stability( diff --git a/semantic-conventions/src/tests/data/jinja/metrics/expected.java b/semantic-conventions/src/tests/data/jinja/metrics/expected.java deleted file mode 100644 index 46ec3069..00000000 --- a/semantic-conventions/src/tests/data/jinja/metrics/expected.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.opentelemetry.instrumentation.api.metric; - -class Units { - - /** - * Use this unit for Metric Instruments recording values - * representing fraction of a total. - **/ - public static final String PERCENT = "%"; - - /** - * Use this unit for Metric Instruments recording values - * representing time. - **/ - public static final String NANOSECOND = "NS"; - - /** - * Use this unit for Metric Instruments recording values - * representing connections. - **/ - public static final String CONNECTIONS = "{connections}"; - -} \ No newline at end of file diff --git a/semantic-conventions/src/tests/data/jinja/metrics/expected_trim_whitespace_enabled.java b/semantic-conventions/src/tests/data/jinja/metrics/expected_trim_whitespace_enabled.java index 4b4186ba..1bd77d9d 100644 --- a/semantic-conventions/src/tests/data/jinja/metrics/expected_trim_whitespace_enabled.java +++ b/semantic-conventions/src/tests/data/jinja/metrics/expected_trim_whitespace_enabled.java @@ -1,22 +1,19 @@ package io.opentelemetry.instrumentation.api.metric; -class Units { - - /** - * Use this unit for Metric Instruments recording values - * representing fraction of a total. - **/ - public static final String PERCENT = "%"; - +class AllMetrics { /** - * Use this unit for Metric Instruments recording values - * representing time. - **/ - public static final String NANOSECOND = "NS"; + * first metric description + * Unit: {one} + * Instrument: counter + * Experimental: False + */ + public static final String FIRST_METRIC = "first.metric"; /** - * Use this unit for Metric Instruments recording values - * representing connections. - **/ - public static final String CONNECTIONS = "{connections}"; -} + * second metric description + * Unit: s + * Instrument: histogram + * Experimental: True + */ + public static final String SECOND_GROUP_METRIC = "second_group.metric"; +} \ No newline at end of file diff --git a/semantic-conventions/src/tests/data/jinja/metrics/metrics_template_trim_whitespace_enabled b/semantic-conventions/src/tests/data/jinja/metrics/metrics_template_trim_whitespace_enabled new file mode 100644 index 00000000..7b751690 --- /dev/null +++ b/semantic-conventions/src/tests/data/jinja/metrics/metrics_template_trim_whitespace_enabled @@ -0,0 +1,14 @@ +package io.opentelemetry.instrumentation.api.metric; + +class AllMetrics { + {%- for metric in metrics %} + + /** + * {{metric.brief | to_doc_brief}} + * Unit: {{ metric.unit }} + * Instrument: {{ metric.instrument }} + * Experimental: {{ metric | is_experimental }} + */ + public static final String {{ metric.metric_name | to_const_name }} = "{{metric.metric_name}}"; +{% endfor %} +} diff --git a/semantic-conventions/src/tests/data/jinja/metrics/units_template b/semantic-conventions/src/tests/data/jinja/metrics/units_template deleted file mode 100644 index 47831ffa..00000000 --- a/semantic-conventions/src/tests/data/jinja/metrics/units_template +++ /dev/null @@ -1,11 +0,0 @@ -package io.opentelemetry.instrumentation.api.metric; - -class Units { -{% for member in semconvs['units'].members.values() %}{% set constant_name = member.id.upper() %} - /** - * Use this unit for Metric Instruments recording values - * representing {{member.brief}}. - **/ - public static final String {{constant_name}} = "{{member.value}}"; -{% endfor %} -} diff --git a/semantic-conventions/src/tests/data/jinja/metrics/units_template_trim_whitespace_enabled b/semantic-conventions/src/tests/data/jinja/metrics/units_template_trim_whitespace_enabled deleted file mode 100644 index c38ea68e..00000000 --- a/semantic-conventions/src/tests/data/jinja/metrics/units_template_trim_whitespace_enabled +++ /dev/null @@ -1,13 +0,0 @@ -package io.opentelemetry.instrumentation.api.metric; - -class Units { -{% for member in semconvs['units'].members.values() %}{% set constant_name = member.id.upper() %} - - /** - * Use this unit for Metric Instruments recording values - * representing {{member.brief}}. - **/ - public static final String {{constant_name}} = "{{member.value}}"; -{% endfor %} -} - diff --git a/semantic-conventions/src/tests/data/markdown/metrics_unit/expected.md b/semantic-conventions/src/tests/data/markdown/metrics_unit/expected.md deleted file mode 100644 index 3d1ab3af..00000000 --- a/semantic-conventions/src/tests/data/markdown/metrics_unit/expected.md +++ /dev/null @@ -1,10 +0,0 @@ -# Units - - - -| Name | Kind of Quantity | Unit String | -| ------------| ---------------- | ----------- | -| percent | fraction of a total | `%` | -| nanosecond | time | `NS` | -| connections | connections | `{connections}` | - diff --git a/semantic-conventions/src/tests/data/markdown/metrics_unit/input.md b/semantic-conventions/src/tests/data/markdown/metrics_unit/input.md deleted file mode 100644 index 75c93676..00000000 --- a/semantic-conventions/src/tests/data/markdown/metrics_unit/input.md +++ /dev/null @@ -1,4 +0,0 @@ -# Units - - - diff --git a/semantic-conventions/src/tests/data/markdown/scope/expected.md b/semantic-conventions/src/tests/data/markdown/scope/expected.md deleted file mode 100644 index 29209024..00000000 --- a/semantic-conventions/src/tests/data/markdown/scope/expected.md +++ /dev/null @@ -1,7 +0,0 @@ -# Instrumentation Scope Semantic Conventions - - -| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability | -|---|---|---|---|---|---| -| `short_name` | string | The single-word name for the instrumentation scope. | `mylibrary` | `Recommended` | Experimental | - diff --git a/semantic-conventions/src/tests/data/markdown/scope/input.md b/semantic-conventions/src/tests/data/markdown/scope/input.md deleted file mode 100644 index 94120116..00000000 --- a/semantic-conventions/src/tests/data/markdown/scope/input.md +++ /dev/null @@ -1,4 +0,0 @@ -# Instrumentation Scope Semantic Conventions - - - diff --git a/semantic-conventions/src/tests/data/markdown/scope/scope.yaml b/semantic-conventions/src/tests/data/markdown/scope/scope.yaml deleted file mode 100644 index ab0c8ce0..00000000 --- a/semantic-conventions/src/tests/data/markdown/scope/scope.yaml +++ /dev/null @@ -1,14 +0,0 @@ -groups: - - id: scope - prefix: "" - type: scope - brief: > - Instrumentation Scope attributes - attributes: - - id: short_name - stability: experimental - type: string - requirement_level: recommended - brief: > - The single-word name for the instrumentation scope. - examples: ['mylibrary'] \ No newline at end of file diff --git a/semantic-conventions/src/tests/data/yaml/metrics.yaml b/semantic-conventions/src/tests/data/yaml/metrics.yaml index 9ff2e70f..9ef78257 100644 --- a/semantic-conventions/src/tests/data/yaml/metrics.yaml +++ b/semantic-conventions/src/tests/data/yaml/metrics.yaml @@ -1,7 +1,7 @@ groups: - id: metric.foo prefix: bar - type: metric_group + type: attribute_group stability: experimental brief: "This document defines foo." note: > diff --git a/semantic-conventions/src/tests/data/yaml/metrics/units.yaml b/semantic-conventions/src/tests/data/yaml/metrics/units.yaml deleted file mode 100644 index cd5d189e..00000000 --- a/semantic-conventions/src/tests/data/yaml/metrics/units.yaml +++ /dev/null @@ -1,14 +0,0 @@ -groups: - - id: units - type: units - brief: Specification of commonly used units. - members: - - id: percent - brief: fraction of a total - value: "%" - - id: nanosecond - brief: time - value: NS - - id: connections - brief: connections - value: "{connections}" diff --git a/semantic-conventions/src/tests/data/yaml/metrics/units_bad_with_attributes.yaml b/semantic-conventions/src/tests/data/yaml/metrics/units_bad_with_attributes.yaml deleted file mode 100644 index 1a5b3b46..00000000 --- a/semantic-conventions/src/tests/data/yaml/metrics/units_bad_with_attributes.yaml +++ /dev/null @@ -1,12 +0,0 @@ -groups: - - id: units - type: units - brief: Specification of commonly used units. - members: - - id: percent - brief: fraction of a total - value: "%" - attributes: - - id: foo - brief: bar - type: int diff --git a/semantic-conventions/src/tests/data/yaml/scope.yaml b/semantic-conventions/src/tests/data/yaml/scope.yaml deleted file mode 100644 index a9bc8c36..00000000 --- a/semantic-conventions/src/tests/data/yaml/scope.yaml +++ /dev/null @@ -1,14 +0,0 @@ -groups: - - id: scope-id - prefix: "" - type: scope - brief: > - Instrumentation Scope attributes - attributes: - - id: short_name - stability: experimental - type: string - requirement_level: recommended - brief: > - The single-word name for the instrumentation scope. - examples: ['mylibrary'] \ No newline at end of file diff --git a/semantic-conventions/src/tests/semconv/model/test_correct_parse.py b/semantic-conventions/src/tests/semconv/model/test_correct_parse.py index 1ce672d3..1c4a4931 100644 --- a/semantic-conventions/src/tests/semconv/model/test_correct_parse.py +++ b/semantic-conventions/src/tests/semconv/model/test_correct_parse.py @@ -650,23 +650,6 @@ def semantic_convention_check(self, s, expected): self.assertEqual(len(expected["attributes"]), len(s.attributes)) self.assertEqual(expected["attributes"], [a.fqn for a in s.attributes]) - def test_scope_attribute(self): - semconv = SemanticConventionSet(debug=False) - semconv.parse(self.load_file("yaml/scope.yaml")) - self.assertEqual(len(semconv.models), 1) - - expected = { - "id": "scope-id", - "prefix": "", - "type": "scope", - "extends": "", - "brief": "Instrumentation Scope attributes", - "attributes": [ - "short_name", - ], - } - self.semantic_convention_check(list(semconv.models.values())[0], expected) - _TEST_DIR = os.path.dirname(__file__) def load_file(self, filename): diff --git a/semantic-conventions/src/tests/semconv/model/test_semantic_convention_units.py b/semantic-conventions/src/tests/semconv/model/test_semantic_convention_units.py deleted file mode 100644 index c2cdc880..00000000 --- a/semantic-conventions/src/tests/semconv/model/test_semantic_convention_units.py +++ /dev/null @@ -1,51 +0,0 @@ -import os - -import pytest - -from opentelemetry.semconv.model.exceptions import ValidationError -from opentelemetry.semconv.model.semantic_convention import ( - UnitSemanticConvention, - parse_semantic_convention_groups, -) -from opentelemetry.semconv.model.utils import ValidationContext - - -def test_build_units(open_test_file): - with open_test_file(os.path.join("yaml", "metrics", "units.yaml")) as yaml_file: - conventions = parse_semantic_convention_groups( - yaml_file, ValidationContext(open_test_file, True) - ) - - assert len(conventions) == 1 - convention = conventions[0] - - assert isinstance(convention, UnitSemanticConvention) - assert convention.id == "units" - assert convention.brief == "Specification of commonly used units." - - assert len(convention.members) == 3 - assert sorted(convention.members) == sorted( - ["percent", "nanosecond", "connections"] - ) - - assert convention.members["percent"].id == "percent" - assert convention.members["percent"].brief == "fraction of a total" - assert convention.members["percent"].value == "%" - - assert convention.members["nanosecond"].id == "nanosecond" - assert convention.members["nanosecond"].brief == "time" - assert convention.members["nanosecond"].value == "NS" - - assert convention.members["connections"].id == "connections" - assert convention.members["connections"].brief == "connections" - assert convention.members["connections"].value == "{connections}" - - -def test_build_units_bad(open_test_file): - with pytest.raises(ValidationError) as excinfo, open_test_file( - os.path.join("yaml", "metrics", "units_bad_with_attributes.yaml") - ) as yaml_file: - parse_semantic_convention_groups( - yaml_file, ValidationContext(open_test_file, True) - ) - assert "attributes" in str(excinfo.value) diff --git a/semantic-conventions/src/tests/semconv/templating/test_code.py b/semantic-conventions/src/tests/semconv/templating/test_code.py index 034d2b95..f0e28525 100644 --- a/semantic-conventions/src/tests/semconv/templating/test_code.py +++ b/semantic-conventions/src/tests/semconv/templating/test_code.py @@ -5,24 +5,6 @@ from opentelemetry.semconv.templating.code import CodeRenderer -def test_codegen_units(test_file_path, read_test_file): - semconv = SemanticConventionSet(debug=False) - semconv.parse(test_file_path("yaml", "metrics", "units.yaml")) - semconv.finish() - - template_path = test_file_path("jinja", "metrics", "units_template") - renderer = CodeRenderer({}, trim_whitespace=False) - - filename = os.path.join(tempfile.mkdtemp(), "Attributes.java") - renderer.render(semconv, template_path, filename, None) - with open(filename, "r", encoding="utf-8") as f: - result = f.read() - - expected = read_test_file("jinja", "metrics", "expected.java") - - assert result == expected - - def test_codegen_metrics_all(test_file_path, read_test_file): semconv = SemanticConventionSet(debug=False) semconv.parse(test_file_path("yaml", "metrics", "metrics.yaml")) @@ -44,11 +26,11 @@ def test_codegen_metrics_all(test_file_path, read_test_file): def test_strip_blocks_enabled(test_file_path, read_test_file): """Tests that the Jinja whitespace control params are fed to the Jinja environment""" semconv = SemanticConventionSet(debug=False) - semconv.parse(test_file_path("yaml", "metrics", "units.yaml")) + semconv.parse(test_file_path("yaml", "metrics", "metrics.yaml")) semconv.finish() template_path = test_file_path( - "jinja", "metrics", "units_template_trim_whitespace_enabled" + "jinja", "metrics", "metrics_template_trim_whitespace_enabled" ) renderer = CodeRenderer({}, trim_whitespace=True) @@ -61,6 +43,7 @@ def test_strip_blocks_enabled(test_file_path, read_test_file): "jinja", "metrics", "expected_trim_whitespace_enabled.java" ) + print(result) assert result == expected diff --git a/semantic-conventions/src/tests/semconv/templating/test_markdown.py b/semantic-conventions/src/tests/semconv/templating/test_markdown.py index 3e064e08..5d006535 100644 --- a/semantic-conventions/src/tests/semconv/templating/test_markdown.py +++ b/semantic-conventions/src/tests/semconv/templating/test_markdown.py @@ -117,9 +117,6 @@ def test_wrong_duplicate(self): self.assertIn("Parameter", msg) self.assertIn("already defined", msg) - def test_units(self): - self.check("markdown/metrics_unit/", extra_yaml_dirs=["yaml/metrics/"]) - def test_event(self): self.check("markdown/event/") @@ -145,9 +142,6 @@ def test_omit_requirement_level(self): def testSamplingRelevant(self): self.check("markdown/sampling_relevant/") - def test_scope(self): - self.check("markdown/scope/") - def test_attribute_group(self): self.check("markdown/attribute_group/") diff --git a/semantic-conventions/syntax.md b/semantic-conventions/syntax.md index 761ca796..15cdeb9b 100644 --- a/semantic-conventions/syntax.md +++ b/semantic-conventions/syntax.md @@ -48,8 +48,6 @@ convtype ::= "span" # Default if not specified | "resource" # see spanspecificfields | "event" # see eventspecificfields | "metric" # see metricfields - | "metric_group" - | "scope" | "attribute_group" # no specific fields defined brief ::= string