Skip to content

Commit

Permalink
Add scope semantic conventions as a type (#114)
Browse files Browse the repository at this point in the history
Co-authored-by: Joao Grassi <[email protected]>
  • Loading branch information
dashpole and joaopgrassi authored Aug 8, 2022
1 parent f871418 commit bbd48be
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 2 deletions.
3 changes: 2 additions & 1 deletion semantic-conventions/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Please update the changelog as part of any significant pull request.

## Unreleased

- ...
- Add a semantic convention type for Instrumentation Scope ("scope")
([#114](https://github.com/open-telemetry/build-tools/pull/114)).

## v0.13.0

Expand Down
3 changes: 2 additions & 1 deletion semantic-conventions/semconv.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"span",
"resource",
"metric",
"event"
"event",
"scope"
],
"description": "The (signal) type of the semantic convention"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ class ResourceSemanticConvention(BaseSemanticConvention):
GROUP_TYPE_NAME = "resource"


class ScopeSemanticConvention(BaseSemanticConvention):
GROUP_TYPE_NAME = "scope"


class SpanSemanticConvention(BaseSemanticConvention):
GROUP_TYPE_NAME = "span"

Expand Down Expand Up @@ -541,5 +545,6 @@ def attributes(self):
EventSemanticConvention,
MetricSemanticConvention,
UnitSemanticConvention,
ScopeSemanticConvention,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Instrumentation Scope Semantic Conventions

<!-- semconv scope -->
| Attribute | Type | Description | Examples | Requirement Level |
|---|---|---|---|---|
| `short_name` | string | The single-word name for the instrumentation scope. | `mylibrary` | Recommended |
<!-- endsemconv -->
4 changes: 4 additions & 0 deletions semantic-conventions/src/tests/data/markdown/scope/input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Instrumentation Scope Semantic Conventions

<!-- semconv scope -->
<!-- endsemconv -->
13 changes: 13 additions & 0 deletions semantic-conventions/src/tests/data/markdown/scope/scope.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
groups:
- id: scope
prefix: ""
type: scope
brief: >
Instrumentation Scope attributes
attributes:
- id: short_name
type: string
requirement_level: recommended
brief: >
The single-word name for the instrumentation scope.
examples: ['mylibrary']
13 changes: 13 additions & 0 deletions semantic-conventions/src/tests/data/yaml/scope.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
groups:
- id: scope-id
prefix: ""
type: scope
brief: >
Instrumentation Scope attributes
attributes:
- id: short_name
type: string
requirement_level: recommended
brief: >
The single-word name for the instrumentation scope.
examples: ['mylibrary']
18 changes: 18 additions & 0 deletions semantic-conventions/src/tests/semconv/model/test_correct_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,24 @@ def semantic_convention_check(self, s, expected):
self.assertEqual(expected["n_constraints"], len(s.constraints))
self.assertEqual(expected["attributes"], [a.fqn for a in s.attributes])

def test_scope_attribute(self):
semconv = SemanticConventionSet(debug=False)
semconv.parse(self.load_file("yaml/scope.yaml"))
self.assertEqual(len(semconv.models), 1)

expected = {
"id": "scope-id",
"prefix": "",
"type": "scope",
"extends": "",
"brief": "Instrumentation Scope attributes",
"n_constraints": 0,
"attributes": [
"short_name",
],
}
self.semantic_convention_check(list(semconv.models.values())[0], expected)

_TEST_DIR = os.path.dirname(__file__)

def load_file(self, filename):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ def test_event_renamed(self):
def testSamplingRelevant(self):
self.check("markdown/sampling_relevant/")

def test_scope(self):
self.check("markdown/scope/")

def check(
self,
input_dir: str,
Expand Down
1 change: 1 addition & 0 deletions semantic-conventions/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ convtype ::= "span" # Default if not specified
| "resource" # see spanspecificfields
| "event" # see eventspecificfields
| "metric" # (currently non-functional)
| "scope"
brief ::= string
note ::= string
Expand Down

0 comments on commit bbd48be

Please sign in to comment.