Skip to content

Commit 472bedb

Browse files
pyohanneslmolkova
andauthored
Sort attribute tables by requirement level and attribute name (#260)
Co-authored-by: Liudmila Molkova <[email protected]>
1 parent 3ff0eeb commit 472bedb

File tree

16 files changed

+118
-112
lines changed

16 files changed

+118
-112
lines changed

semantic-conventions/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Please update the changelog as part of any significant pull request.
1818
([#271](https://github.com/open-telemetry/build-tools/pull/271))
1919
- Add link to requirement levels definition from Markdown table title.
2020
([#222](https://github.com/open-telemetry/build-tools/pull/222))
21+
- Sort attribute tables by requirement level and attribute name
22+
([#260](https://github.com/open-telemetry/build-tools/pull/260))
2123

2224
## v0.23.0
2325

semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from opentelemetry.semconv.model.exceptions import ValidationError
2525
from opentelemetry.semconv.model.semantic_attribute import (
2626
AttributeType,
27+
RequirementLevel,
2728
SemanticAttribute,
2829
)
2930
from opentelemetry.semconv.model.unit_member import UnitMember
@@ -125,14 +126,19 @@ def _get_attributes(self, templates: Optional[bool]):
125126
if not hasattr(self, "attrs_by_name"):
126127
return []
127128

129+
def comparison_key(attr):
130+
if attr.requirement_level:
131+
return attr.requirement_level.value, attr.fqn
132+
return RequirementLevel.RECOMMENDED.value, attr.fqn
133+
128134
return sorted(
129135
[
130136
attr
131137
for attr in self.attrs_by_name.values()
132138
if templates is None
133139
or templates == AttributeType.is_template_type(attr.attr_type)
134140
],
135-
key=lambda attr: attr.fqn,
141+
key=comparison_key,
136142
)
137143

138144
def __init__(self, group, strict_validation=True):

semantic-conventions/src/tests/data/markdown/attribute_group/expected.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<!-- semconv span_attribute_group -->
44
| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
55
|---|---|---|---|---|---|
6-
| `foo.bar` | string | Attribute 1 | `baz` | `Recommended` if available | Experimental |
76
| `foo.qux` | int | Attribute 2 | `42` | `Conditionally Required` if available | Experimental |
7+
| `foo.bar` | string | Attribute 1 | `baz` | `Recommended` if available | Experimental |
88
<!-- endsemconv -->

semantic-conventions/src/tests/data/markdown/attribute_templates/expected.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<!-- semconv custom_http(full) -->
44
| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
55
|---|---|---|---|---|---|
6-
| `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` | Experimental |
76
| `custom_http.request.method` | string | HTTP request method. | `GET`; `POST`; `HEAD` | `Required` | Experimental |
7+
| `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` | Experimental |
88
| `general.some_general_attribute.<key>` | string | This is a general attribute. | ``some_general_attribute.some_key="abc"`` | `Recommended` | Experimental |
99
| `referenced_http.request.referenced.header.<key>` | string[] | This is a referenced attribute. | ``http.request.header.content_type=["application/json"]`` | `Recommended` | Experimental |
1010
<!-- endsemconv -->

semantic-conventions/src/tests/data/markdown/deprecated/expected.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
<!-- semconv http -->
55
| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
66
|---|---|---|---|---|---|
7+
| `http.method` | string | HTTP request method. | `GET`; `POST`; `HEAD` | `Required` | Experimental |
8+
| `http.status_code` | int | [HTTP response status code](https://tools.ietf.org/html/rfc7231#section-6). | `200` | `Conditionally Required` if and only if one was received/sent | Experimental |
79
| `http.flavor` | string | Kind of HTTP protocol used [1] | `1.0` | `Recommended` | Deprecated: Use attribute `flavor_new` instead. |
810
| `http.host` | string | The value of the [HTTP host header](https://tools.ietf.org/html/rfc7230#section-5.4). When the header is empty or not present, this attribute should be the same. | `www.example.org` | `Recommended` | Experimental |
9-
| `http.method` | string | HTTP request method. | `GET`; `POST`; `HEAD` | `Required` | Experimental |
1011
| `http.scheme` | string | The URI scheme identifying the used protocol. | `http`; `https` | `Recommended` | Experimental |
11-
| `http.status_code` | int | [HTTP response status code](https://tools.ietf.org/html/rfc7231#section-6). | `200` | `Conditionally Required` if and only if one was received/sent | Experimental |
1212
| `http.status_text` | string | [HTTP reason phrase](https://tools.ietf.org/html/rfc7230#section-3.1.2). | `OK` | `Recommended` | Deprecated: Use attribute `status_description` instead. |
1313
| `http.target` | string | The full request target as passed in a HTTP request line or equivalent. | `/path/12314/?q=ddds#123` | `Recommended` | Experimental |
1414
| `http.url` | string | Full HTTP request URL in the form `scheme://host[:port]/path?query[#fragment]`. Usually the fragment is not transmitted over HTTP, but if it is known, it should be included nevertheless. | `https://www.foo.bar/search?q=OpenTelemetry#SemConv` | `Recommended` | Experimental |

semantic-conventions/src/tests/data/markdown/extend_constraint/expected.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ Some database systems may allow a connection to switch to a different `db.user`,
3636
<!-- semconv db(tag=connection-level) -->
3737
| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
3838
|---|---|---|---|---|---|
39-
| `db.connection_string` | string | The connection string used to connect to the database. [1] | `Server=(localdb)\v11.0;Integrated Security=true;` | `Recommended` | Experimental |
4039
| `db.system` | string | An identifier for the database management system (DBMS) product being used. See below for a list of well-known identifiers. | `other_sql` | `Required` | Experimental |
40+
| `net.peer.port` | int | Remote port number. | `80`; `8080`; `443` | `Conditionally Required` [1] | Experimental |
41+
| `net.transport` | string | Transport protocol used. See note below. | `IP.TCP` | `Conditionally Required` [2] | Experimental |
42+
| `db.connection_string` | string | The connection string used to connect to the database. [3] | `Server=(localdb)\v11.0;Integrated Security=true;` | `Recommended` | Experimental |
4143
| `db.user` | string | Username for accessing the database. | `readonly_user`; `reporting_user` | `Recommended` | Experimental |
4244
| `net.peer.ip` | string | Remote address of the peer (dotted decimal for IPv4 or [RFC5952](https://tools.ietf.org/html/rfc5952) for IPv6) | `127.0.0.1` | See below | Experimental |
4345
| `net.peer.name` | string | Remote hostname or similar, see note below. | `example.com` | See below | Experimental |
44-
| `net.peer.port` | int | Remote port number. | `80`; `8080`; `443` | `Conditionally Required` [2] | Experimental |
45-
| `net.transport` | string | Transport protocol used. See note below. | `IP.TCP` | `Conditionally Required` [3] | Experimental |
4646

47-
**[1]:** It is recommended to remove embedded credentials.
47+
**[1]:** if using a port other than the default port for this DBMS.
4848

49-
**[2]:** if using a port other than the default port for this DBMS.
49+
**[2]:** Recommended in general, required for in-process databases (`"inproc"`).
5050

51-
**[3]:** Recommended in general, required for in-process databases (`"inproc"`).
51+
**[3]:** It is recommended to remove embedded credentials.
5252

5353
**Additional attribute requirements:** At least one of the following sets of attributes is required:
5454

semantic-conventions/src/tests/data/markdown/include/expected.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
<!-- semconv faas.http(full) -->
44
| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
55
|---|---|---|---|---|---|
6-
| `faas.execution` | string | The execution id of the current function execution. | `af9d5aa4-a685-4c5f-a22b-444f80b3cc28` | `Recommended` | Experimental |
76
| `faas.trigger` | string | Type of the trigger on which the function is executed. | `datasource` | `Required` | Experimental |
8-
| `http.host` | string | The value of the [HTTP host header](https://tools.ietf.org/html/rfc7230#section-5.4). When the header is empty or not present, this attribute should be the same. | `www.example.org` | See below | Experimental |
97
| `http.method` | string | HTTP request method. | `GET`; `POST`; `HEAD` | `Required` | Experimental |
8+
| [`http.server_name`](input_http.md) | string | The primary server name of the matched virtual host. [1] | `example.com` | `Conditionally Required` [2] | Experimental |
9+
| `http.status_code` | int | [HTTP response status code](https://tools.ietf.org/html/rfc7231#section-6). | `200` | `Conditionally Required` if and only if one was received/sent | Experimental |
10+
| `faas.execution` | string | The execution id of the current function execution. | `af9d5aa4-a685-4c5f-a22b-444f80b3cc28` | `Recommended` | Experimental |
11+
| `http.host` | string | The value of the [HTTP host header](https://tools.ietf.org/html/rfc7230#section-5.4). When the header is empty or not present, this attribute should be the same. | `www.example.org` | See below | Experimental |
1012
| `http.recommended_attribute` | string | brief | `foo` | `Recommended` short note | Experimental |
11-
| `http.recommended_attribute_long_note` | string | brief | `bar` | `Recommended` [1] | Experimental |
13+
| `http.recommended_attribute_long_note` | string | brief | `bar` | `Recommended` [3] | Experimental |
1214
| `http.scheme` | string | The URI scheme identifying the used protocol. | `http`; `https` | See below | Experimental |
13-
| [`http.server_name`](input_http.md) | string | The primary server name of the matched virtual host. [2] | `example.com` | `Conditionally Required` [3] | Experimental |
14-
| `http.status_code` | int | [HTTP response status code](https://tools.ietf.org/html/rfc7231#section-6). | `200` | `Conditionally Required` if and only if one was received/sent | Experimental |
1515
| `http.status_text` | string | [HTTP reason phrase](https://tools.ietf.org/html/rfc7230#section-3.1.2). | `OK` | `Recommended` | Experimental |
1616
| `http.target` | string | The full request target as passed in a HTTP request line or equivalent. | `/path/12314/?q=ddds#123` | See below | Experimental |
1717
| `http.url` | string | Full HTTP request URL in the form `scheme://host[:port]/path?query[#fragment]`. Usually the fragment is not transmitted over HTTP, but if it is known, it should be included nevertheless. | `https://www.foo.bar/search?q=OpenTelemetry#SemConv` | See below | Experimental |
1818
| `http.user_agent` | string | Value of the [HTTP User-Agent](https://tools.ietf.org/html/rfc7231#section-5.5.3) header sent by the client. | `CERN-LineMode/2.15 libwww/2.17b3` | `Recommended` | Experimental |
1919

20-
**[1]:** some very long note that should be written under the semconv table
21-
22-
**[2]:** This is an example
20+
**[1]:** This is an example
2321

2422
- of note
2523
- with list
2624

27-
**[3]:** This should be obtained via configuration. If this attribute can be obtained, this attribute MUST NOT be set ( `net.host.name` should be used instead).
25+
**[2]:** This should be obtained via configuration. If this attribute can be obtained, this attribute MUST NOT be set ( `net.host.name` should be used instead).
26+
27+
**[3]:** some very long note that should be written under the semconv table
2828

2929
**Additional attribute requirements:** At least one of the following sets of attributes is required:
3030

semantic-conventions/src/tests/data/markdown/multiple/expected.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
<!-- semconv http -->
55
| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
66
|---|---|---|---|---|---|
7-
| `http.host` | string | The value of the [HTTP host header](https://tools.ietf.org/html/rfc7230#section-5.4). When the header is empty or not present, this attribute should be the same. | `www.example.org` | `Recommended` | Experimental |
87
| `http.method` | string | HTTP request method. | `GET`; `POST`; `HEAD` | `Required` | Experimental |
9-
| `http.scheme` | string | The URI scheme identifying the used protocol. | `http`; `https` | `Recommended` | Experimental |
108
| `http.status_code` | int | [HTTP response status code](https://tools.ietf.org/html/rfc7231#section-6). | `200` | `Conditionally Required` if and only if one was received/sent | Experimental |
9+
| `http.host` | string | The value of the [HTTP host header](https://tools.ietf.org/html/rfc7230#section-5.4). When the header is empty or not present, this attribute should be the same. | `www.example.org` | `Recommended` | Experimental |
10+
| `http.scheme` | string | The URI scheme identifying the used protocol. | `http`; `https` | `Recommended` | Experimental |
1111
| `http.status_text` | string | [HTTP reason phrase](https://tools.ietf.org/html/rfc7230#section-3.1.2). | `OK` | `Recommended` | Experimental |
1212
| `http.target` | string | The full request target as passed in a HTTP request line or equivalent. | `/path/12314/?q=ddds#123` | `Recommended` | Experimental |
1313
| `http.url` | string | Full HTTP request URL in the form `scheme://host[:port]/path?query[#fragment]`. Usually the fragment is not transmitted over HTTP, but if it is known, it should be included nevertheless. | `https://www.foo.bar/search?q=OpenTelemetry#SemConv` | `Recommended` | Experimental |
@@ -17,10 +17,10 @@
1717
<!-- semconv http -->
1818
| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
1919
|---|---|---|---|---|---|
20-
| `http.host` | string | The value of the [HTTP host header](https://tools.ietf.org/html/rfc7230#section-5.4). When the header is empty or not present, this attribute should be the same. | `www.example.org` | `Recommended` | Experimental |
2120
| `http.method` | string | HTTP request method. | `GET`; `POST`; `HEAD` | `Required` | Experimental |
22-
| `http.scheme` | string | The URI scheme identifying the used protocol. | `http`; `https` | `Recommended` | Experimental |
2321
| `http.status_code` | int | [HTTP response status code](https://tools.ietf.org/html/rfc7231#section-6). | `200` | `Conditionally Required` if and only if one was received/sent | Experimental |
22+
| `http.host` | string | The value of the [HTTP host header](https://tools.ietf.org/html/rfc7230#section-5.4). When the header is empty or not present, this attribute should be the same. | `www.example.org` | `Recommended` | Experimental |
23+
| `http.scheme` | string | The URI scheme identifying the used protocol. | `http`; `https` | `Recommended` | Experimental |
2424
| `http.status_text` | string | [HTTP reason phrase](https://tools.ietf.org/html/rfc7230#section-3.1.2). | `OK` | `Recommended` | Experimental |
2525
| `http.target` | string | The full request target as passed in a HTTP request line or equivalent. | `/path/12314/?q=ddds#123` | `Recommended` | Experimental |
2626
| `http.url` | string | Full HTTP request URL in the form `scheme://host[:port]/path?query[#fragment]`. Usually the fragment is not transmitted over HTTP, but if it is known, it should be included nevertheless. | `https://www.foo.bar/search?q=OpenTelemetry#SemConv` | `Recommended` | Experimental |

semantic-conventions/src/tests/data/markdown/parameter_full/expected.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
<!-- semconv faas.http(full) -->
44
| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
55
|---|---|---|---|---|---|
6-
| `faas.execution` | string | The execution id of the current function execution. | `af9d5aa4-a685-4c5f-a22b-444f80b3cc28` | `Recommended` | Experimental |
76
| `faas.trigger` | string | Type of the trigger on which the function is executed. | `datasource` | `Required` | Experimental |
8-
| [`http.client_ip`](http.md) | string | The IP address of the original client behind all proxies, if known (e.g. from [X-Forwarded-For](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For)). [1] | `83.164.160.102` | `Recommended` | Experimental |
9-
| `http.host` | string | The value of the [HTTP host header](https://tools.ietf.org/html/rfc7230#section-5.4). When the header is empty or not present, this attribute should be the same. | `www.example.org` | `Conditionally Required` <condition> | Experimental |
107
| `http.method` | string | HTTP request method. | `GET`; `POST`; `HEAD` | `Required` | Experimental |
8+
| `http.host` | string | The value of the [HTTP host header](https://tools.ietf.org/html/rfc7230#section-5.4). When the header is empty or not present, this attribute should be the same. | `www.example.org` | `Conditionally Required` <condition> | Experimental |
9+
| [`http.server_name`](http.md) | string | The primary server name of the matched virtual host. [1] | `example.com` | `Conditionally Required` [2] | Experimental |
10+
| `http.status_code` | int | [HTTP response status code](https://tools.ietf.org/html/rfc7231#section-6). | `200` | `Conditionally Required` if and only if one was received/sent. | Experimental |
11+
| `faas.execution` | string | The execution id of the current function execution. | `af9d5aa4-a685-4c5f-a22b-444f80b3cc28` | `Recommended` | Experimental |
12+
| [`http.client_ip`](http.md) | string | The IP address of the original client behind all proxies, if known (e.g. from [X-Forwarded-For](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For)). [3] | `83.164.160.102` | `Recommended` | Experimental |
1113
| [`http.route`](http.md) | string | The matched route (path template). | `/users/:userID?` | `Recommended` | Experimental |
1214
| `http.scheme` | string | The URI scheme identifying the used protocol. | `http`; `https` | See below | Experimental |
13-
| [`http.server_name`](http.md) | string | The primary server name of the matched virtual host. [2] | `example.com` | `Conditionally Required` [3] | Experimental |
14-
| `http.status_code` | int | [HTTP response status code](https://tools.ietf.org/html/rfc7231#section-6). | `200` | `Conditionally Required` if and only if one was received/sent. | Experimental |
1515
| `http.status_text` | string | [HTTP reason phrase](https://tools.ietf.org/html/rfc7230#section-3.1.2). | `OK` | `Recommended` | Experimental |
1616
| `http.target` | string | The full request target as passed in a HTTP request line or equivalent. | `/path/12314/?q=ddds#123` | See below | Experimental |
1717
| `http.url` | string | Full HTTP request URL in the form `scheme://host[:port]/path?query[#fragment]`. Usually the fragment is not transmitted over HTTP, but if it is known, it should be included nevertheless. | `https://www.foo.bar/search?q=OpenTelemetry#SemConv` | See below | Experimental |
1818
| `http.user_agent` | string | Value of the [HTTP User-Agent](https://tools.ietf.org/html/rfc7231#section-5.5.3) header sent by the client. | `CERN-LineMode/2.15 libwww/2.17b3` | `Recommended` | Experimental |
1919

20-
**[1]:** This is not necessarily the same as `net.peer.ip`, which would identify the network-level peer, which may be a proxy.
20+
**[1]:** http.url is usually not readily available on the server side but would have to be assembled in a cumbersome and sometimes lossy process from other information (see e.g. open-telemetry/opentelemetry-python/pull/148). It is thus preferred to supply the raw data that is available.
2121

22-
**[2]:** http.url is usually not readily available on the server side but would have to be assembled in a cumbersome and sometimes lossy process from other information (see e.g. open-telemetry/opentelemetry-python/pull/148). It is thus preferred to supply the raw data that is available.
22+
**[2]:** This should be obtained via configuration. If this attribute can be obtained, this attribute MUST NOT be set ( `net.host.name` should be used instead).
2323

24-
**[3]:** This should be obtained via configuration. If this attribute can be obtained, this attribute MUST NOT be set ( `net.host.name` should be used instead).
24+
**[3]:** This is not necessarily the same as `net.peer.ip`, which would identify the network-level peer, which may be a proxy.
2525

2626
**Additional attribute requirements:** At least one of the following sets of attributes is required:
2727

0 commit comments

Comments
 (0)