From 863357206b2fc1743b5df9a19f2a639a21430df7 Mon Sep 17 00:00:00 2001 From: Alexandra Konrad Date: Wed, 3 Jul 2024 15:12:57 +0200 Subject: [PATCH] update build tools to support embedding of attribute implemented in weaver --- semantic-conventions/semconv.schema.json | 5 ++++ .../semconv/model/semantic_attribute.py | 7 +++++- .../tests/data/markdown/ref_embed/expected.md | 17 +++++++++++++ .../tests/data/markdown/ref_embed/geo.yaml | 24 +++++++++++++++++++ .../tests/data/markdown/ref_embed/input.md | 8 +++++++ .../tests/data/markdown/ref_embed/server.yaml | 15 ++++++++++++ .../tests/semconv/templating/test_markdown.py | 4 ++++ 7 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 semantic-conventions/src/tests/data/markdown/ref_embed/expected.md create mode 100644 semantic-conventions/src/tests/data/markdown/ref_embed/geo.yaml create mode 100644 semantic-conventions/src/tests/data/markdown/ref_embed/input.md create mode 100644 semantic-conventions/src/tests/data/markdown/ref_embed/server.yaml diff --git a/semantic-conventions/semconv.schema.json b/semantic-conventions/semconv.schema.json index a22365c8..b0f61ce5 100644 --- a/semantic-conventions/semconv.schema.json +++ b/semantic-conventions/semconv.schema.json @@ -268,6 +268,11 @@ "tag": { "type": "string", "description": "associates a tag to the attribute" + }, + "prefix": { + "type": "boolean", + "description": "specifies if it is embedded attribute from other namespace. It defaults to false.", + "default": false } } }, diff --git a/semantic-conventions/src/opentelemetry/semconv/model/semantic_attribute.py b/semantic-conventions/src/opentelemetry/semconv/model/semantic_attribute.py index 233e2e64..5c4afa9b 100644 --- a/semantic-conventions/src/opentelemetry/semconv/model/semantic_attribute.py +++ b/semantic-conventions/src/opentelemetry/semconv/model/semantic_attribute.py @@ -100,6 +100,7 @@ def parse( "requirement_level", "sampling_relevant", "note", + "prefix", ) if not yaml_attributes: return attributes @@ -136,8 +137,12 @@ def parse( validation_ctx.raise_or_warn(position, msg, ref) brief = attribute.get("brief") examples = attribute.get("examples") + ref_prefix = attribute.get("prefix", False) ref = ref.strip() - fqn = ref + if ref_prefix: + fqn = f"{prefix}.{ref}" + else: + fqn = ref required_value_map = { "required": RequirementLevel.REQUIRED, diff --git a/semantic-conventions/src/tests/data/markdown/ref_embed/expected.md b/semantic-conventions/src/tests/data/markdown/ref_embed/expected.md new file mode 100644 index 00000000..b96e69e9 --- /dev/null +++ b/semantic-conventions/src/tests/data/markdown/ref_embed/expected.md @@ -0,0 +1,17 @@ +# Server + + +| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability | +|---|---|---|---|---|---| +| `geo.country` | string | country of the geo coordinates. | `US` | `Recommended` | Experimental | +| `geo.lat` | string | latitude of the geo coordinates. | `123.456` | `Recommended` | Experimental | +| `geo.lon` | string | longitude of the geo coordinates. | `234.456` | `Recommended` | Experimental | + + + + +| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability | +|---|---|---|---|---|---| +| `server.geo.lat` | string | My own latitude | `123.456` | `Recommended` | Experimental | +| `server.id` | string | some server id | `123` | `Recommended` | Experimental | + diff --git a/semantic-conventions/src/tests/data/markdown/ref_embed/geo.yaml b/semantic-conventions/src/tests/data/markdown/ref_embed/geo.yaml new file mode 100644 index 00000000..51693c48 --- /dev/null +++ b/semantic-conventions/src/tests/data/markdown/ref_embed/geo.yaml @@ -0,0 +1,24 @@ +groups: + - id: registry.geo + brief: Attributes describing geo. + type: attribute_group + prefix: geo + attributes: + - id: lat + type: string + stability: experimental + brief: > + latitude of the geo coordinates. + examples: ["123.456"] + - id: lon + type: string + stability: experimental + brief: > + longitude of the geo coordinates. + examples: [ "234.456" ] + - id: country + type: string + stability: experimental + brief: > + country of the geo coordinates. + examples: [ "US" ] diff --git a/semantic-conventions/src/tests/data/markdown/ref_embed/input.md b/semantic-conventions/src/tests/data/markdown/ref_embed/input.md new file mode 100644 index 00000000..c5deb310 --- /dev/null +++ b/semantic-conventions/src/tests/data/markdown/ref_embed/input.md @@ -0,0 +1,8 @@ +# Server + + + + + + + diff --git a/semantic-conventions/src/tests/data/markdown/ref_embed/server.yaml b/semantic-conventions/src/tests/data/markdown/ref_embed/server.yaml new file mode 100644 index 00000000..ec0dc888 --- /dev/null +++ b/semantic-conventions/src/tests/data/markdown/ref_embed/server.yaml @@ -0,0 +1,15 @@ +groups: + - id: registry.server + prefix: server + type: attribute_group + brief: "Describes information about the server." + attributes: + - id: id + type: string + stability: experimental + brief: > + some server id + examples: ['123'] + - ref: geo.lat + prefix: true + brief: My own latitude \ No newline at end of file diff --git a/semantic-conventions/src/tests/semconv/templating/test_markdown.py b/semantic-conventions/src/tests/semconv/templating/test_markdown.py index 5d006535..3c63214d 100644 --- a/semantic-conventions/src/tests/semconv/templating/test_markdown.py +++ b/semantic-conventions/src/tests/semconv/templating/test_markdown.py @@ -31,6 +31,10 @@ def testRef(self): def testRefExtends(self): self.check("markdown/ref_extends/") + def testRefEmbed(self): + self.check("markdown/ref_embed/") + + def testDeprecated(self): self.check("markdown/deprecated/")