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

Prefer arrays of name value pairs over objects #115

Merged
merged 7 commits into from
Sep 19, 2024
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ SCHEMA_FILES := $(shell find . -path './schema/*.json' -exec basename {} \; | so
EXAMPLE_FILES := $(shell find . -path './examples/*.yaml' -exec basename {} \; | sort)
$(shell mkdir -p out)

include validator/Makefile

.PHONY: all
all: install-tools compile-schema validate-examples

Expand Down
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ The [examples](./examples) repository contains a variety of sample configuration
- [sdk-migration-config.yaml](./examples/sdk-migration-config.yaml): Includes env var substitution references to all [standard env vars](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md) which map cleanly to file configuration (see notes in the example for the set of env vars which are not referenced). Note, SDKs parsing configuration files ignore all env vars besides those referenced via [env var substitution][]. This is a great starting point for transitioning from env var based configuration to file based configuration.
- [sdk-config.yaml](./examples/sdk-config.yaml): Represents the typical default configuration. This is a good starting point if you are not using env var based configuration or wish to transition fully to file based configuration. Note, SDKs parsing configuration files ignore all env vars besides those referenced via [env var substitution][].

[env var substitution]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/file-configuration.md#environment-variable-substitution

## Code generation

There are [several tools](https://json-schema.org/implementations.html) available to generate code from a JSON schema. The following shows an example for generating code from the JSON schema in Go:
Expand Down Expand Up @@ -70,6 +68,24 @@ Properties should be modeled using the most appropriate data structures and type

In instances where there is a type mismatch between the JSON schema and equivalent standard env var, an alternative version of the property may be provided to resolve the mismatch. For example, resource attributes are configured at `.resource.attributes`, but `.resource.attributes_list` is available with a format matching that of `OTEL_RESOURCE_ATTRIBUTES`. Alternative properties are reserved for cases where there is a demonstrated need for platforms to be able to participate in configuration and there is no reasonable alternative.

### Name-value pairs

When a type requires a configurable list of name-value pairs (i.e. resource attributes, HTTP headers), model using an array of objects, each with `name` and `value` properties. While an arrays of name-value objects is slightly more verbose an object where each key-value is an entry, it is preferred because:
jack-berg marked this conversation as resolved.
Show resolved Hide resolved

* Avoids user input as keys, which ensures conformity with the [snake_case properties](#property-name-case) rule.
* Allows both the names and the values to be targets for [env var substitution]. For example:

```yaml
tracer_provider:
processors:
- batch:
exporter:
otlp:
headers:
- name: ${AUTHORIZATION_HEADER_NAME:-api-key}
value: ${AUTHORIZATION_HEADER_VALUE}
```
marcalff marked this conversation as resolved.
Show resolved Hide resolved

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md)
Expand All @@ -89,3 +105,6 @@ Maintainers ([@open-telemetry/configuration-maintainers](https://github.com/orgs
- [Tyler Yahn](https://github.com/tsloughter), Splunk

*Find more about the maintainer role in [community repository](https://github.com/open-telemetry/community/blob/main/guides/contributor/membership.md#maintainer).*

[env var substitution]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/file-configuration.md#environment-variable-substitution

3 changes: 2 additions & 1 deletion examples/anchors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ exporters:
client_key: /app/cert.pem
client_certificate: /app/cert.pem
headers:
api-key: !!str 1234
- name: api-key
value: "1234"
compression: gzip
timeout: 10000

Expand Down
27 changes: 23 additions & 4 deletions examples/kitchen-sink.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ logger_provider:
#
# Environment variable: OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_LOGS_HEADERS
headers:
api-key: "1234"
- name: api-key
value: "1234"
# Configure compression.
#
# Environment variable: OTEL_EXPORTER_OTLP_COMPRESSION, OTEL_EXPORTER_OTLP_LOGS_COMPRESSION
Expand Down Expand Up @@ -186,7 +187,8 @@ meter_provider:
#
# Environment variable: OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_METRICS_HEADERS
headers:
api-key: !!str 1234
- name: api-key
value: "1234"
# Configure compression.
#
# Environment variable: OTEL_EXPORTER_OTLP_COMPRESSION, OTEL_EXPORTER_OTLP_METRICS_COMPRESSION
Expand Down Expand Up @@ -313,7 +315,8 @@ tracer_provider:
#
# Environment variable: OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_TRACES_HEADERS
headers:
api-key: !!str 1234
- name: api-key
value: "1234"
# Configure compression.
#
# Environment variable: OTEL_EXPORTER_OTLP_COMPRESSION, OTEL_EXPORTER_OTLP_TRACES_COMPRESSION
Expand Down Expand Up @@ -416,7 +419,23 @@ resource:
# Configure `service.name` resource attribute
#
# Environment variable: OTEL_SERVICE_NAME
service.name: !!str "unknown_service"
- name: service-name
jack-berg marked this conversation as resolved.
Show resolved Hide resolved
string_value: "unknown_service"
# Configure other resource attributes with explicit types.
- name: bool_key
bool_value: true
- name: int_key
int_value: 1
jack-berg marked this conversation as resolved.
Show resolved Hide resolved
- name: double_key
double_value: 1.1
- name: string_array_key
string_array_value: ["value1", "value2"]
- name: bool_array_key
bool_array_value: [ true, false ]
- name: int_array_key
int_array_value: [ 1, 2 ]
- name: double_array_key
double_array_value: [ 1.1, 2.2 ]
# Configure resource attributes. Entries have lower priority than entries from .resource.attributes.
#
# The value is a list of comma separated key-value pairs, matching the format of OTEL_RESOURCE_ATTRIBUTES. See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#general-sdk-configuration for details.
Expand Down
9 changes: 5 additions & 4 deletions examples/sdk-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ resource:
# Configure resource attributes.
attributes:
# Configure `service.name` resource attribute
service.name: unknown_service
- name: service.name
string_value: unknown_service

# Configure general attribute limits. See also tracer_provider.limits, logger_provider.limits.
attribute_limits:
Expand Down Expand Up @@ -62,7 +63,7 @@ tracer_provider:
# Configure max time (in milliseconds) to wait for each export.
timeout: 10000
# Configure headers:
headers: {}
headers: []
# Configure span limits. See also attribute_limits.
limits:
# Configure max span attribute value size. Overrides attribute_limits.attribute_value_length_limit.
Expand Down Expand Up @@ -131,7 +132,7 @@ meter_provider:
# Configure max time (in milliseconds) to wait for each export.
timeout: 10000
# Configure headers:
headers: {}
headers: []
# Configure temporality preference.
temporality_preference: cumulative
# Configure default histogram aggregation.
Expand Down Expand Up @@ -170,7 +171,7 @@ logger_provider:
# Configure max time (in milliseconds) to wait for each export.
timeout: 10000
# Configure headers:
headers: {}
headers: []
# Configure log record limits. See also attribute_limits.
limits:
# Configure max log record attribute value size. Overrides attribute_limits.attribute_value_length_limit.
Expand Down
9 changes: 5 additions & 4 deletions examples/sdk-migration-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ resource:
# Configure resource attributes. Entries have higher priority than entries from .resource.attributes_list.
attributes:
# Configure `service.name` resource attribute
service.name: ${OTEL_SERVICE_NAME:-unknown_service}
- name: service.name
string_value: ${OTEL_SERVICE_NAME:-unknown_service}
# Configure resource attributes. Entries have lower priority than entries from .resource.attributes.
#
# The value is a list of comma separated key-value pairs, matching the format of OTEL_RESOURCE_ATTRIBUTES. See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#general-sdk-configuration for details.
Expand Down Expand Up @@ -97,7 +98,7 @@ tracer_provider:
# Configure max time (in milliseconds) to wait for each export.
timeout: ${OTEL_EXPORTER_OTLP_TRACES_TIMEOUT:-10000}
# Configure headers:
headers: {}
headers: []
# Configure span limits. See also attribute_limits.
limits:
# Configure max span attribute value size. Overrides attribute_limits.attribute_value_length_limit.
Expand Down Expand Up @@ -166,7 +167,7 @@ meter_provider:
# Configure max time (in milliseconds) to wait for each export.
timeout: ${OTEL_EXPORTER_OTLP_METRICS_TIMEOUT:-10000}
# Configure headers:
headers: {}
headers: []
# Configure temporality preference.
temporality_preference: ${OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE:-cumulative}
# Configure default histogram aggregation.
Expand Down Expand Up @@ -205,7 +206,7 @@ logger_provider:
# Configure max time (in milliseconds) to wait for each export.
timeout: ${OTEL_EXPORTER_OTLP_LOGS_TIMEOUT:-10000}
# Configure headers:
headers: {}
headers: []
# Configure log record limits. See also attribute_limits.
limits:
# Configure max log record attribute value size. Overrides attribute_limits.attribute_value_length_limit.
Expand Down
29 changes: 19 additions & 10 deletions schema/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@
"title": "Common",
"type": ["object", "null"],
"$defs": {
"Headers": {
"type": ["object", "null"],
"title": "Headers",
"patternProperties": {
".*": {
"type": ["string", "null"]
}
}
},
"IncludeExclude": {
"type": "object",
"additionalProperties": false,
Expand Down Expand Up @@ -43,6 +34,21 @@
}
}
},
"NameStringValuePair": {
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"type": "string"
},
"value": {
"type": ["string", "null"]
}
},
"required": [
"name", "value"
]
},
"Otlp": {
"type": ["object", "null"],
"additionalProperties": false,
Expand All @@ -64,7 +70,10 @@
"type": ["string", "null"]
},
"headers": {
"$ref": "#/$defs/Headers"
"type": "array",
"items": {
"$ref": "common.json#/$defs/NameStringValuePair"
}
},
"compression": {
"type": ["string", "null"]
Expand Down
5 changes: 4 additions & 1 deletion schema/meter_provider.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@
"type": ["string", "null"]
},
"headers": {
"$ref": "common.json#/$defs/Headers"
"type": "array",
"items": {
"$ref": "common.json#/$defs/NameStringValuePair"
}
},
"compression": {
"type": ["string", "null"]
Expand Down
59 changes: 54 additions & 5 deletions schema/resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"additionalProperties": false,
"properties": {
"attributes": {
"$ref": "#/$defs/Attributes"
"type": "array",
"items": {
"$ref": "#/$defs/AttributeNameValue"
}
},
"detectors": {
"$ref": "#/$defs/Detectors"
Expand All @@ -19,10 +22,56 @@
}
},
"$defs": {
"Attributes": {
"title": "Attributes",
"type": ["object", "null"],
"additionalProperties": true
"AttributeNameValue": {
"title": "AttributeNameValue",
"type": "object",
"additionalProperties": false,
"minProperties": 2,
"maxProperties": 2,
"properties": {
"name": {
"type": "string"
},
"string_value": {
"type": "string"
},
"bool_value": {
"type": "boolean"
},
"int_value": {
"type": "integer"
},
"double_value": {
"type": "number"
},
"string_array_value": {
"type": "array",
"items": {
"type": "string"
}
},
"bool_array_value": {
"type": "array",
"items": {
"type": "boolean"
}
},
"int_array_value": {
"type": "array",
"items": {
"type": "integer"
}
},
"double_array_value": {
"type": "array",
"items": {
"type": "number"
}
}
},
"required": [
"name"
]
},
"Detectors": {
"title": "Detectors",
Expand Down
Loading