From bbd48be9be46234fb3c971de426f9bb388e25f63 Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Mon, 8 Aug 2022 12:17:19 -0400 Subject: [PATCH] Add scope semantic conventions as a type (#114) Co-authored-by: Joao Grassi --- semantic-conventions/CHANGELOG.md | 3 ++- semantic-conventions/semconv.schema.json | 3 ++- .../semconv/model/semantic_convention.py | 5 +++++ .../src/tests/data/markdown/scope/expected.md | 7 +++++++ .../src/tests/data/markdown/scope/input.md | 4 ++++ .../src/tests/data/markdown/scope/scope.yaml | 13 +++++++++++++ .../src/tests/data/yaml/scope.yaml | 13 +++++++++++++ .../tests/semconv/model/test_correct_parse.py | 18 ++++++++++++++++++ .../tests/semconv/templating/test_markdown.py | 3 +++ semantic-conventions/syntax.md | 1 + 10 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 semantic-conventions/src/tests/data/markdown/scope/expected.md create mode 100644 semantic-conventions/src/tests/data/markdown/scope/input.md create mode 100644 semantic-conventions/src/tests/data/markdown/scope/scope.yaml create mode 100644 semantic-conventions/src/tests/data/yaml/scope.yaml diff --git a/semantic-conventions/CHANGELOG.md b/semantic-conventions/CHANGELOG.md index 2911b9b0..c6ea3901 100644 --- a/semantic-conventions/CHANGELOG.md +++ b/semantic-conventions/CHANGELOG.md @@ -4,7 +4,8 @@ Please update the changelog as part of any significant pull request. ## Unreleased -- ... +- Add a semantic convention type for Instrumentation Scope ("scope") + ([#114](https://github.com/open-telemetry/build-tools/pull/114)). ## v0.13.0 diff --git a/semantic-conventions/semconv.schema.json b/semantic-conventions/semconv.schema.json index 7bc4613d..9c9dd991 100644 --- a/semantic-conventions/semconv.schema.json +++ b/semantic-conventions/semconv.schema.json @@ -51,7 +51,8 @@ "span", "resource", "metric", - "event" + "event", + "scope" ], "description": "The (signal) type of the semantic convention" }, diff --git a/semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py b/semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py index 7da6cc4f..08894cb0 100644 --- a/semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py +++ b/semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py @@ -194,6 +194,10 @@ class ResourceSemanticConvention(BaseSemanticConvention): GROUP_TYPE_NAME = "resource" +class ScopeSemanticConvention(BaseSemanticConvention): + GROUP_TYPE_NAME = "scope" + + class SpanSemanticConvention(BaseSemanticConvention): GROUP_TYPE_NAME = "span" @@ -541,5 +545,6 @@ def attributes(self): EventSemanticConvention, MetricSemanticConvention, UnitSemanticConvention, + ScopeSemanticConvention, ) } diff --git a/semantic-conventions/src/tests/data/markdown/scope/expected.md b/semantic-conventions/src/tests/data/markdown/scope/expected.md new file mode 100644 index 00000000..9707b860 --- /dev/null +++ b/semantic-conventions/src/tests/data/markdown/scope/expected.md @@ -0,0 +1,7 @@ +# Instrumentation Scope Semantic Conventions + + +| Attribute | Type | Description | Examples | Requirement Level | +|---|---|---|---|---| +| `short_name` | string | The single-word name for the instrumentation scope. | `mylibrary` | Recommended | + diff --git a/semantic-conventions/src/tests/data/markdown/scope/input.md b/semantic-conventions/src/tests/data/markdown/scope/input.md new file mode 100644 index 00000000..94120116 --- /dev/null +++ b/semantic-conventions/src/tests/data/markdown/scope/input.md @@ -0,0 +1,4 @@ +# 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 new file mode 100644 index 00000000..12036dbf --- /dev/null +++ b/semantic-conventions/src/tests/data/markdown/scope/scope.yaml @@ -0,0 +1,13 @@ +groups: + - id: scope + prefix: "" + type: scope + brief: > + Instrumentation Scope attributes + attributes: + - id: short_name + 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/scope.yaml b/semantic-conventions/src/tests/data/yaml/scope.yaml new file mode 100644 index 00000000..ac691c9f --- /dev/null +++ b/semantic-conventions/src/tests/data/yaml/scope.yaml @@ -0,0 +1,13 @@ +groups: + - id: scope-id + prefix: "" + type: scope + brief: > + Instrumentation Scope attributes + attributes: + - id: short_name + 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 bad3ed68..245f6b27 100644 --- a/semantic-conventions/src/tests/semconv/model/test_correct_parse.py +++ b/semantic-conventions/src/tests/semconv/model/test_correct_parse.py @@ -669,6 +669,24 @@ def semantic_convention_check(self, s, expected): self.assertEqual(expected["n_constraints"], len(s.constraints)) 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", + "n_constraints": 0, + "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/templating/test_markdown.py b/semantic-conventions/src/tests/semconv/templating/test_markdown.py index 996fd043..618f08e8 100644 --- a/semantic-conventions/src/tests/semconv/templating/test_markdown.py +++ b/semantic-conventions/src/tests/semconv/templating/test_markdown.py @@ -126,6 +126,9 @@ def test_event_renamed(self): def testSamplingRelevant(self): self.check("markdown/sampling_relevant/") + def test_scope(self): + self.check("markdown/scope/") + def check( self, input_dir: str, diff --git a/semantic-conventions/syntax.md b/semantic-conventions/syntax.md index f99dee09..abc746c6 100644 --- a/semantic-conventions/syntax.md +++ b/semantic-conventions/syntax.md @@ -48,6 +48,7 @@ convtype ::= "span" # Default if not specified | "resource" # see spanspecificfields | "event" # see eventspecificfields | "metric" # (currently non-functional) + | "scope" brief ::= string note ::= string