Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix referencing template attributes #206

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def __init__(self, group):
)

def contains_attribute(self, attr: "SemanticAttribute"):
for local_attr in self.attributes:
for local_attr in self.attributes_and_templates:
if local_attr.attr_id is not None:
if local_attr.fqn == attr.fqn:
return True
Expand Down Expand Up @@ -315,7 +315,7 @@ def has_error(self):
def check_unique_fqns(self):
group_by_fqn: typing.Dict[str, str] = {}
for model in self.models.values():
for attr in model.attributes:
for attr in model.attributes_and_templates:
if not attr.ref:
if attr.fqn in group_by_fqn:
self.errors = True
Expand Down Expand Up @@ -401,7 +401,7 @@ def _populate_extends_single(self, semconv, unprocessed):
semconv.constraints += (constraint.inherit_anyof(),)
# Attributes
parent_attributes = {}
for ext_attr in extended.attributes:
for ext_attr in extended.attributes_and_templates:
parent_attributes[ext_attr.fqn] = ext_attr.inherit_attribute()

parent_attributes.update(semconv.attrs_by_name)
Expand Down Expand Up @@ -509,7 +509,7 @@ def resolve_include(self, semconv):
include_semconv, {include_semconv.semconv_id: include_semconv}
)
attr: SemanticAttribute
for attr in include_semconv.attributes:
for attr in include_semconv.attributes_and_templates:
if semconv.contains_attribute(attr):
if self.debug:
print(
Expand Down Expand Up @@ -538,7 +538,7 @@ def _lookup_attribute(self, attr_id: str) -> Union[SemanticAttribute, None]:
(
attr
for model in self.models.values()
for attr in model.attributes
for attr in model.attributes_and_templates
if attr.fqn == attr_id and attr.ref is None
),
None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ groups:
note: >
These conventions can be used for http and https schemes
and various HTTP versions like 1.1, 2 and SPDY.
extends: general
attributes:
- id: request.header
type: template[string[]]
Expand All @@ -19,3 +20,24 @@ groups:
sampling_relevant: false
brief: 'HTTP request method.'
examples: ["GET", "POST", "HEAD"]
- ref: referenced_http.request.referenced.header
- id: referenced_http_id
type: span
prefix: referenced_http
brief: 'This document defines semantic conventions for HTTP client and server Spans.'
attributes:
- id: request.referenced.header
type: template[string[]]
brief: >
This is a referenced attribute.
examples: '`http.request.header.content_type=["application/json"]`'
- id: general
type: span
prefix: general
brief: 'This document defines general attributes.'
attributes:
- id: some_general_attribute
type: template[string]
brief: >
This is a general attribute.
examples: '`some_general_attribute.some_key="abc"`'
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Custom HTTP Semantic Conventions

<!-- semconv custom_http -->
<!-- semconv custom_http(full) -->
| Attribute | Type | Description | Examples | Requirement Level |
|---|---|---|---|---|
| `custom_http.request.header.<key>` | string[] | HTTP request headers, `<key>` being the normalized HTTP Header name (lowercase, with - characters replaced by _), the value being the header values. | ``http.request.header.content_type=["application/json"]`` | Recommended |
| `custom_http.request.method` | string | HTTP request method. | `GET`; `POST`; `HEAD` | Required |
| `general.some_general_attribute.<key>` | string | This is a general attribute. | ``some_general_attribute.some_key="abc"`` | Recommended |
| `referenced_http.request.referenced.header.<key>` | string[] | This is a referenced attribute. | ``http.request.header.content_type=["application/json"]`` | Recommended |
<!-- endsemconv -->
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Custom HTTP Semantic Conventions

<!-- semconv custom_http -->
<!-- semconv custom_http(full) -->
<!-- endsemconv -->
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def test_markdown_link(self):
semconv.finish()
self.assertEqual(len(semconv.models), 1)
s = list(semconv.models.values())[0]
for attr in s.attributes:
for attr in s.attributes_and_templates:
brief = attr.brief
self.assertEqual(brief.raw_text, str(brief))

Expand All @@ -348,6 +348,7 @@ def test_ref(self):

client = list(semconv.models.values())[1]
server = list(semconv.models.values())[2]

self.assertIsNotNone(client.attrs_by_name["net.peer.port"].ref)
self.assertIsNotNone(client.attrs_by_name["net.peer.port"].attr_type)

Expand Down Expand Up @@ -475,42 +476,42 @@ def test_stability(self):
self.assertEqual(len(semconv.models), 6)

model = list(semconv.models.values())[0]
self.assertEqual(len(model.attributes), 4)
self.assertEqual(len(model.attributes_and_templates), 4)
self.assertEqual(model.stability, None)

attr = model.attributes[0]
attr = model.attributes_and_templates[0]
self.assertEqual(attr.attr_id, "def_stability")
self.assertEqual(attr.stability, StabilityLevel.EXPERIMENTAL)

attr = model.attributes[1]
attr = model.attributes_and_templates[1]
self.assertEqual(attr.attr_id, "deprecated_attr")
self.assertEqual(attr.stability, StabilityLevel.DEPRECATED)

attr = model.attributes[2]
attr = model.attributes_and_templates[2]
self.assertEqual(attr.attr_id, "exp_attr")
self.assertEqual(attr.stability, StabilityLevel.EXPERIMENTAL)

attr = model.attributes[3]
attr = model.attributes_and_templates[3]
self.assertEqual(attr.attr_id, "stable_attr")
self.assertEqual(attr.stability, StabilityLevel.STABLE)

model = list(semconv.models.values())[1]
self.assertEqual(len(model.attributes), 2)
self.assertEqual(len(model.attributes_and_templates), 2)
self.assertEqual(model.stability, StabilityLevel.EXPERIMENTAL)

attr = model.attributes[0]
attr = model.attributes_and_templates[0]
self.assertEqual(attr.attr_id, "dep")
self.assertEqual(attr.stability, StabilityLevel.DEPRECATED)

attr = model.attributes[1]
attr = model.attributes_and_templates[1]
self.assertEqual(attr.attr_id, "test_attr")
self.assertEqual(attr.stability, StabilityLevel.EXPERIMENTAL)

model = list(semconv.models.values())[2]
self.assertEqual(len(model.attributes), 1)
self.assertEqual(len(model.attributes_and_templates), 1)
self.assertEqual(model.stability, StabilityLevel.DEPRECATED)

attr = model.attributes[0]
attr = model.attributes_and_templates[0]
self.assertEqual(attr.attr_id, "test_attr")
self.assertEqual(attr.stability, StabilityLevel.DEPRECATED)

Expand Down Expand Up @@ -549,7 +550,7 @@ def test_inherited_imported(self):
models = sorted(semconv.models.values(), key=lambda m: m.semconv_id)
self.assertEqual(len(models), 6)
# HTTP
attrs = models[0].attributes
attrs = models[0].attributes_and_templates
self.assertEqual(models[0].semconv_id, "http")
self.assertEqual(len(attrs), 2)

Expand All @@ -564,7 +565,7 @@ def test_inherited_imported(self):
self.assertEqual(attrs[1].ref, "net.peer.port")

# Network
attrs = models[1].attributes
attrs = models[1].attributes_and_templates
self.assertEqual(models[1].semconv_id, "network")
self.assertEqual(len(attrs), 3)

Expand All @@ -585,7 +586,7 @@ def test_inherited_imported(self):
self.assertEqual(attrs[2].note, "not override")

# Base - rpc
attrs = models[2].attributes
attrs = models[2].attributes_and_templates
self.assertEqual(models[2].semconv_id, "rpc")
self.assertEqual(len(attrs), 4)

Expand All @@ -611,7 +612,7 @@ def test_inherited_imported(self):
self.assertEqual(attrs[3].ref, None)

# Extended - rpc.client
attrs = models[3].attributes
attrs = models[3].attributes_and_templates
self.assertEqual(models[3].semconv_id, "rpc.client")
self.assertEqual(len(attrs), 6)

Expand Down Expand Up @@ -648,7 +649,7 @@ def test_inherited_imported(self):
self.assertEqual(attrs[5].ref, None)

# Include on Extended - zother
attrs = models[4].attributes
attrs = models[4].attributes_and_templates
self.assertEqual(models[4].semconv_id, "zother")
self.assertEqual(len(attrs), 1)

Expand All @@ -658,7 +659,7 @@ def test_inherited_imported(self):
self.assertEqual(attrs[0].ref, None)

# Include on Extended - zz.rpc.client
attrs = models[5].attributes
attrs = models[5].attributes_and_templates
self.assertEqual(models[5].semconv_id, "zz.rpc.client")
self.assertEqual(len(attrs), 8)

Expand Down