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

Inherit overridden attribute properties #204

Merged
merged 5 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 6 additions & 2 deletions semantic-conventions/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Please update the changelog as part of any significant pull request.

## Unreleased

- Inherit referenced attribute properties from `extend`
hierarchy before falling back to original attribute definition.
lmolkova marked this conversation as resolved.
Show resolved Hide resolved
([#204](https://github.com/open-telemetry/build-tools/pull/204))

## v0.21.0

- Render template-type attributes from yaml files
Expand All @@ -27,7 +31,7 @@ Please update the changelog as part of any significant pull request.

- Allow multiple semconv in --only flag
([#157](https://github.com/open-telemetry/build-tools/pull/157))

## v0.17.0

- Rename Optional attribute requirement level to Opt-In
Expand All @@ -44,7 +48,7 @@ Please update the changelog as part of any significant pull request.

## v0.15.0

- Add a semantic convention type for Metrics ("metric" and "metric_group")
- Add a semantic convention type for Metrics ("metric" and "metric_group")
([#79](https://github.com/open-telemetry/build-tools/pull/79))
- Add a semantic convention type for generic attribute group ("attribute_group")
([#124](https://github.com/open-telemetry/build-tools/pull/124)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ def resolve_ref(self, semconv):
attr: SemanticAttribute
for attr in semconv.attributes:
if attr.ref is not None and attr.attr_id is None:
attr = self._fill_inherited_attribute(attr, semconv)
# There are changes
fixpoint_ref = False
ref_attr = self._lookup_attribute(attr.ref)
Expand All @@ -510,20 +511,34 @@ def resolve_ref(self, semconv):
semconv._position,
f"Semantic Convention {semconv.semconv_id} reference `{attr.ref}` but it cannot be found!",
)
attr.attr_type = ref_attr.attr_type
if not attr.brief:
attr.brief = ref_attr.brief
if not attr.requirement_level:
attr.requirement_level = ref_attr.requirement_level
if not attr.requirement_level_msg:
attr.requirement_level_msg = ref_attr.requirement_level_msg
if not attr.note:
attr.note = ref_attr.note
if attr.examples is None:
attr.examples = ref_attr.examples
attr.attr_id = attr.ref
attr = self._merge_attribute(attr, ref_attr)
return fixpoint_ref

def _fill_inherited_attribute(self, attr, semconv):
if attr.attr_id is not None:
return attr

if attr.ref in semconv.attrs_by_name.keys():
attr = self._merge_attribute(attr, semconv.attrs_by_name[attr.ref])
if semconv.extends in self.models:
attr = self._fill_inherited_attribute(attr, self.models[semconv.extends])
return attr

def _merge_attribute(self, child, parent):
child.attr_type = parent.attr_type
if not child.brief:
child.brief = parent.brief
if not child.requirement_level:
child.requirement_level = parent.requirement_level
if not child.requirement_level_msg:
child.requirement_level_msg = parent.requirement_level_msg
if not child.note:
child.note = parent.note
if child.examples is None:
child.examples = parent.examples
child.attr_id = parent.attr_id
return child

def resolve_include(self, semconv):
fixpoint_inc = True
for constraint in semconv.constraints:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Spans

<!-- semconv http.client.spans(full) -->
| Attribute | Type | Description | Examples | Requirement Level |
|---|---|---|---|---|
| [`server.address`](input_server.md) | string | Server component of Host header. (overridden brief) [1] | `foo.io` | Required |

**[1]:** Note on the overridden attribute definition.

Following attributes MUST be provided **at span creation time** (when provided at all), so they can be considered for sampling decisions:

* [`server.address`](input_server.md)
<!-- endsemconv -->

# Metrics

<!-- semconv http.client.request.duration.metric(metric_table) -->
| Name | Instrument Type | Unit (UCUM) | Description |
| -------- | --------------- | ----------- | -------------- |
| `http.client.request.duration` | Histogram | `s` | Measures request duration. |
<!-- endsemconv -->

<!-- semconv http.client.request.duration.metric(full) -->
| Attribute | Type | Description | Examples | Requirement Level |
|---|---|---|---|---|
| [`server.address`](input_server.md) | string | Server component of Host header. (overridden brief) [1] | `foo.io` | Required |

**[1]:** Note on the overridden attribute definition.
<!-- endsemconv -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
groups:
- id: http.client.attributes
type: attribute_group
brief: 'This document defines semantic conventions for HTTP client attributes.'
attributes:
- ref: server.address
requirement_level: required
brief: 'Server component of Host header. (overridden brief)'
note: 'Note on the overridden attribute definition.'
examples: ['foo.io']

- id: http.client.spans
type: span
brief: 'This document defines semantic conventions for HTTP client Spans.'
extends: http.client.attributes
attributes:
- ref: server.address
sampling_relevant: true

- id: http.client.request.duration.metric
type: metric
metric_name: http.client.request.duration
brief: "Measures request duration."
instrument: histogram
unit: "s"
extends: http.client.attributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Spans

<!-- semconv http.client.spans(full) -->
<!-- endsemconv -->

# Metrics

<!-- semconv http.client.request.duration.metric(metric_table) -->
<!-- endsemconv -->

<!-- semconv http.client.request.duration.metric(full) -->
<!-- endsemconv -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# General

<!-- semconv server -->
<!-- endsemconv -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
groups:
- id: server
type: attribute_group
prefix: server
brief: 'This document defines semantic conventions for common server attributes.'
attributes:
- id: address
type: string
brief: 'Domain name. (original brief)'
examples: 'foo'
note: 'Note on the original attribute definition.'
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class TestCorrectMarkdown(unittest.TestCase):
def testRef(self):
self.check("markdown/ref/")

def testRefExtends(self):
self.check("markdown/ref_extends/")

def testInclude(self):
self.check("markdown/include/")

Expand Down
Loading