Skip to content

Commit 1b74e42

Browse files
thisthatarminru
andauthored
YAML Model for Semantic Conventions (open-telemetry#571)
* First model draft * Fix checkstyle * Generate network table from YAML * HTTP semantic convention tables * Fix requirements order * Add code and basic documentation * Missing \n * Remove tool * Add General and HTTP semantic convention * Update table style * yaml->semantic_conventions * Fix small errors * Fix docfx errors * Update Makefile to use otel Docker repo Co-authored-by: Armin Ruech <[email protected]>
1 parent 87d7dd3 commit 1b74e42

File tree

8 files changed

+584
-69
lines changed

8 files changed

+584
-69
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Semantic Conventions Check
2+
on:
3+
push:
4+
tags: [ '**' ]
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
paths:
9+
- .github/workflows/semantic-convention-check.yml
10+
- '**/semantic_conventions/**'
11+
12+
jobs:
13+
test-markdown:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v1
17+
- name: Verify that semantic convention tables are up-to-date
18+
run: docker run --rm -v $(pwd)/semantic_conventions:/source -v $(pwd)/specification:/spec otel/semconvgen -f /source markdown -md /spec --md-check

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# All documents to be used in spell check.
22
ALL_DOCS := $(shell find . -name '*.md' -not -path './.github/*' -type f | grep -v ^./node_modules | sort)
3+
PWD := $(shell pwd)
34

45
TOOLS_DIR := ./.tools
56
MISSPELL_BINARY=$(TOOLS_DIR)/misspell
67
MARKDOWN_LINK_CHECK=markdown-link-check
78
MARKDOWN_LINT=markdownlint
89

10+
911
.PHONY: install-misspell
1012
install-misspell:
1113
go build -o $(MISSPELL_BINARY) github.com/client9/misspell/cmd/misspell
@@ -34,3 +36,7 @@ install-markdown-lint:
3436
markdown-lint:
3537
@echo $(ALL_DOCS)
3638
@for f in $(ALL_DOCS); do echo $$f; $(MARKDOWN_LINT) -c .markdownlint.yaml $$f || exit 1; done
39+
40+
.PHONY: table-generation
41+
table-generation:
42+
docker run --rm -v $(PWD)/semantic_conventions:/source -v $(PWD)/specification:/spec otel/semconvgen -f /source markdown -md /spec

semantic_conventions/syntax.md

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
# Semantic Convention YAML Language
2+
3+
First, the syntax with a pseudo [EBNF](https://en.wikipedia.org/wiki/Extended_Backus-Naur_form) grammar is presented.
4+
Then, the semantic of each field is described.
5+
6+
## Syntax
7+
8+
All attributes are lower case.
9+
10+
```bnf
11+
groups ::= semconv
12+
| semconv groups
13+
14+
semconv ::= id brief [note] [prefix] [extends] [span_kind] attributes [constraints]
15+
16+
id ::= string
17+
brief ::= string
18+
note ::= string
19+
20+
prefix ::= string
21+
22+
# extends MUST point to an existing semconv id
23+
extends ::= string
24+
25+
span_kind ::= "client"
26+
| "server"
27+
| "producer"
28+
| "consumer"
29+
| "internal"
30+
31+
attributes ::= (id type brief examples | ref [brief] [examples]) [required] [note]
32+
33+
# ref MUST point to an existing attribute id
34+
ref ::= id
35+
36+
type ::= "string"
37+
| "number"
38+
| "boolean"
39+
| "string[]"
40+
| "number[]"
41+
| "boolean[]"
42+
| enum
43+
44+
enum ::= [allow_custom_values] members
45+
46+
allow_custom_values := boolean
47+
48+
members ::= member {member}
49+
50+
member ::= id value [brief] [note]
51+
52+
required ::= "always"
53+
| "conditional" <condition>
54+
55+
examples ::= <example_value> {<example_value>}
56+
57+
constraints ::= constraint {constraint}
58+
59+
constraint ::= any_of
60+
| include
61+
62+
any_of ::= id {id}
63+
64+
include ::= id
65+
66+
```
67+
68+
## Semantics
69+
70+
### Groups
71+
72+
Groups contain the list of semantic conventions and it is the root node of each yaml file.
73+
74+
### Semantic Convention
75+
76+
The field `semconv` represents a semantic convention and it is made by:
77+
78+
- `id`, string that uniquely identifies the semantic convention.
79+
- `brief`, string, a brief description of the semantic convention.
80+
- `note`, optional string, a more elaborate description of the semantic convention.
81+
It defaults to an empty string.
82+
- `prefix`, optional string, prefix for the attributes for this semantic convention.
83+
It defaults to an empty string.
84+
- `extends`, optional string, reference another semantic convention `id`.
85+
It inherits the prefix, constraints, and all attributes defined in the specified semantic convention.
86+
- `span_kind`, optional enum, specifies the kind of the span.
87+
- `attributes`, list of attributes that belong to the semantic convention.
88+
- `constraints`, optional list, additional constraints (See later). It defaults to an empty list.
89+
90+
### Attributes
91+
92+
An attribute is defined by:
93+
94+
- `id`, string that uniquely identifies the attribute.
95+
- `type`, either a string literal denoting the type or an enum definition (See later).
96+
The accepted strings literals are:
97+
* "string": String attributes.
98+
* "number": Numeric attributes.
99+
* "boolean": Boolean attributes.
100+
* "string[]": Array of strings attributes.
101+
* "number[]": Array of numbers attributes.
102+
* "boolean[]": Array of booleans attributes.
103+
- `ref`, optional string, reference an existing attribute, see later.
104+
- `required`, optional, specifies if the attribute is mandatory.
105+
Can be "always", or "conditional". When omitted, the attribute is not required.
106+
When set to "conditional",the string provided as `<condition>` MUST specify
107+
the conditions under which the attribute is required.
108+
- `brief`, string, brief description of the attribute.
109+
- `note`, optional string, additional notes to the attribute. It defaults to an empty string.
110+
- `examples`, sequence/dictionary of example values for the attribute.
111+
They are optional for boolean and enum attributes.
112+
Example values must be of the same type of the attribute.
113+
If only a single example is provided, it can directly be reported without encapsulating it into a sequence/dictionary.
114+
115+
Examples for setting the `examples` field:
116+
117+
A single example value for a string attribute. All the following three representations are equivalent:
118+
119+
```yaml
120+
examples: 'this is a single string'
121+
```
122+
123+
or
124+
125+
```yaml
126+
examples: ['this is a single string']
127+
```
128+
129+
or
130+
131+
```yaml
132+
examples:
133+
- 'this is a single string'
134+
```
135+
136+
Attention, the following will throw a type mismatch error because a string type as example value is expected and not an array of string:
137+
138+
```yaml
139+
examples:
140+
- ['this is an error']
141+
142+
examples: [['this is an error']]
143+
```
144+
145+
Multiple example values for a string attribute:
146+
147+
```yaml
148+
examples: ['this is a single string', 'this is another one']
149+
```
150+
151+
or
152+
153+
```yaml
154+
examples:
155+
- 'this is a single string'
156+
- 'this is another one'
157+
```
158+
159+
A single example value for an array of strings attribute:
160+
161+
```yaml
162+
examples: ['first element of first array', 'second element of first array']
163+
```
164+
165+
or
166+
167+
```yaml
168+
examples:
169+
- ['first element of first array', 'second element of first array']
170+
```
171+
172+
Attention, the following will throw a type mismatch error because an array of strings as type for the example values is expected and not a string:
173+
174+
```yaml
175+
examples: 'this is an error'
176+
```
177+
178+
Multiple example values for an array of string attribute:
179+
180+
```yaml
181+
examples: [ ['first element of first array', 'second element of first array'], ['first element of second array', 'second element of second array'] ]
182+
```
183+
184+
or
185+
186+
```yaml
187+
examples:
188+
- ['first element of first array', 'second element of first array']
189+
- ['first element of second array', 'second element of second array']
190+
```
191+
192+
### Ref
193+
194+
`ref` MUST have an id of an existing attribute. When it is set, `id` and `type` MUST not be present.
195+
`ref` is useful for specifying that an existing attribute of another semantic convention is part of
196+
the current semantic convention and inherit its `brief`, `note`, and `example` values. However, if these
197+
fields are present in the current attribute definition, they override the inherited values.
198+
199+
### Type
200+
201+
An attribute type can either be a string, number, boolean, array of strings, array of numbers,
202+
array of booleans, or an enumeration. If it is an enumeration, additional fields are required:
203+
204+
- `allow_custom_values`, optional boolean, set to false to not accept values
205+
other than the specified members. It defaults to `true`.
206+
- `members`, list of enum entries.
207+
208+
An enum entry has the following fields:
209+
210+
- `id`, string that uniquely identifies the enum entry.
211+
- `value`, string, number, or boolean, value of the enum entry.
212+
- `brief`, optional string, brief description of the enum entry value. It defaults to the value of `id`.
213+
- `note`, optional string, longer description. It defaults to an empty string.
214+
215+
### Constraints
216+
217+
Allow to define additional requirements on the semantic convention.
218+
Currently, it supports `any_of` and `include`.
219+
220+
#### Any Of
221+
222+
`any_of` accepts a list of sequences. Each sequence contains a list of attribute ids that are required.
223+
`any_of` enforces that all attributes of at least one of the sequences are set.
224+
225+
#### Include
226+
227+
`include` accepts a semantic conventions `id`. It includes as part of this semantic convention all constraints
228+
and required attributes that are not already defined in the current semantic convention.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
groups:
2+
- id: network
3+
prefix: net
4+
brief: >
5+
These attributes may be used for any network related operation.
6+
attributes:
7+
- id: transport
8+
type:
9+
allow_custom_values: false
10+
members:
11+
- id: IP.TCP
12+
value: "IP.TCP"
13+
- id: IP.UDP
14+
value: "IP.UDP"
15+
- id: IP
16+
value: "IP"
17+
brief: 'Another IP-based protocol'
18+
- id: Unix
19+
value: "Unix"
20+
brief: 'Unix Domain socket. See below.'
21+
- id: pipe
22+
value: "pipe"
23+
brief: 'Named or anonymous pipe. See note below.'
24+
- id: inproc
25+
value: "inproc"
26+
brief: 'In-process communication.'
27+
note: >
28+
Signals that there is only in-process communication not using a "real" network protocol
29+
in cases where network attributes would normally be expected. Usually all other network
30+
attributes can be left out in that case.
31+
- id: other
32+
value: "other"
33+
brief: 'Something else (non IP-based).'
34+
brief: >
35+
Transport protocol used. See note below.
36+
examples: 'IP.TCP'
37+
- id: peer.ip
38+
type: string
39+
brief: >
40+
Remote address of the peer (dotted decimal for IPv4 or
41+
[RFC5952](https://tools.ietf.org/html/rfc5952) for IPv6)
42+
examples: '127.0.0.1'
43+
- id: peer.port
44+
type: number
45+
brief: 'Remote port number.'
46+
examples: [80, 8080, 443]
47+
- id: peer.name
48+
type: string
49+
brief: 'Remote hostname or similar, see note below.'
50+
examples: 'example.com'
51+
- id: host.ip
52+
type: string
53+
brief: 'Like `net.peer.ip` but for the host IP. Useful in case of a multi-IP host.'
54+
examples: '192.168.0.1'
55+
- id: host.port
56+
type: number
57+
brief: 'Like `net.peer.port` but for the host port.'
58+
examples: 35555
59+
- id: host.name
60+
type: string
61+
brief: 'Local hostname or similar, see note below.'
62+
examples: 'localhost'
63+
- id: peer
64+
prefix: peer
65+
brief: "Operations that access some remote service."
66+
attributes:
67+
- id: service
68+
type: string
69+
brief: >
70+
The [`service.name`](../../resource/semantic_conventions/README.md#service)
71+
of the remote service. SHOULD be equal to the actual `service.name`
72+
resource attribute of the remote service if any.
73+
examples: "AuthTokenCache"
74+
- id: identity
75+
prefix: enduser
76+
brief: >
77+
These attributes may be used for any operation with an authenticated and/or authorized enduser.
78+
attributes:
79+
- id: id
80+
type: string
81+
brief: >
82+
Username or client_id extracted from the access token or
83+
[Authorization](https://tools.ietf.org/html/rfc7235#section-4.2)
84+
header in the inbound request from outside the system.
85+
examples: 'username'
86+
- id: role
87+
type: string
88+
brief: 'Actual/assumed role the client is making the request under extracted from token or application security context.'
89+
examples: 'admin'
90+
- id: scope
91+
type: string
92+
brief: >
93+
Scopes or granted authorities the client currently possesses extracted from token
94+
or application security context. The value would come from the scope associated
95+
with an [OAuth 2.0 Access Token](https://tools.ietf.org/html/rfc6749#section-3.3)
96+
or an attribute value in a [SAML 2.0 Assertion](http://docs.oasis-open.org/security/saml/Post2.0/sstc-saml-tech-overview-2.0.html).
97+
examples: 'read:message, write:files'

0 commit comments

Comments
 (0)