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

Object and enum types should be defined in $defs #155

Merged
merged 3 commits into from
Jan 15, 2025
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
60 changes: 58 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,75 @@ Another example:
]
},
"type": {
"type": ["string", "null"],
"enum": [null, "string", "bool", "int", "double", "string_array", "bool_array", "int_array", "double_array"]
"$ref": "#/$defs/AttributeType"
}
},
"required": [
"name", "value"
]
},
"AttributeType": {
"type": ["string", "null"],
"enum": [
null,
"string",
"bool",
"int",
"double",
"string_array",
"bool_array",
"int_array",
"double_array"
]
}
}
```

`oneOf` is used to specify that the `value` property matches the [standard attribute](https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/common#standard-attribute) definition, and is either a primitive or array of primitives. This type of use is acceptable but should be used judiciously.

## Schemas and subschemas

In JSON Schema, a [schema](https://json-schema.org/learn/glossary#schema) is a document, and a [subschema](https://json-schema.org/learn/glossary#subschema) is contained in surrounding parent schema. Subschemas can be nested in various ways:

A property can directly describe a complex set of requirements including nested structures:

```json
{
"properties": {
"shape": {
"type": "object",
"properties": {
"color": { "type": "string" },
"sides": { "type": "int" }
}
}
}
}
```

Or a property can reference a subschema residing in a schema document's [$defs](https://json-schema.org/understanding-json-schema/structuring#defs):

```json
{
"properties": {
"shape": {
"$ref": "#/$defs/Shape"
}
},
"$defs": {
"Shape": {
"type": "object",
"properties": {
"color": { "type": "string" },
"sides": { "type": "int" }
}
}
}
}
```

In order to promote stylistic consistency and allow for reuse of concepts, `object` and `enum` types should be defined in either as a top level schema document or as a subschema in a schema document's `$defs`.

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md)
Expand Down
15 changes: 9 additions & 6 deletions schema/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"headers": {
"type": "array",
"items": {
"$ref": "common.json#/$defs/NameStringValuePair"
"$ref": "#/$defs/NameStringValuePair"
}
},
"headers_list": {
Expand All @@ -70,14 +70,17 @@
"minimum": 0
},
"encoding": {
"type": ["string", "null"],
"enum": [
"protobuf",
"json"
]
"$ref": "#/$defs/OtlpHttpEncoding"
}
}
},
"OtlpHttpEncoding": {
"type": ["string", "null"],
"enum": [
"protobuf",
"json"
]
},
"OtlpGrpcExporter": {
"title": "OtlpGrpcExporter",
"type": ["object", "null"],
Expand Down
102 changes: 54 additions & 48 deletions schema/instrumentation.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,68 +53,74 @@
"additionalProperties": false,
"properties": {
"peer": {
"$ref": "#/$defs/PeerInstrumentation"
},
"http": {
"$ref": "#/$defs/HttpInstrumentation"
}
}
},
"PeerInstrumentation": {
"type": "object",
"additionalProperties": false,
"properties": {
"service_mapping": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"peer": {
"type": "string"
},
"service": {
"type": "string"
}
},
"required": [
"peer",
"service"
]
}
}
}
},
"HttpInstrumentation": {
"type": "object",
"additionalProperties": false,
"properties": {
"client": {
"type": "object",
"additionalProperties": false,
"properties": {
"service_mapping": {
"request_captured_headers": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"peer": {
"type": "string"
},
"service": {
"type": "string"
}
},
"required": [
"peer",
"service"
]
"type": "string"
}
},
"response_captured_headers": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"http": {
"server": {
"type": "object",
"additionalProperties": false,
"properties": {
"client": {
"type": "object",
"additionalProperties": false,
"properties": {
"request_captured_headers": {
"type": "array",
"items": {
"type": "string"
}
},
"response_captured_headers": {
"type": "array",
"items": {
"type": "string"
}
}
"request_captured_headers": {
"type": "array",
"items": {
"type": "string"
}
},
"server": {
"type": "object",
"additionalProperties": false,
"properties": {
"request_captured_headers": {
"type": "array",
"items": {
"type": "string"
}
},
"response_captured_headers": {
"type": "array",
"items": {
"type": "string"
}
}
"response_captured_headers": {
"type": "array",
"items": {
"type": "string"
}
}
}
Expand Down
Loading
Loading