2021-10-15 18:44:13 +02:00
|
|
|
# Telemetry Schema Files
|
|
|
|
|
|
|
|
The `schema` module contains packages that help to parse and validate
|
|
|
|
[schema files](https://github.com/open-telemetry/oteps/blob/main/text/0152-telemetry-schemas.md).
|
|
|
|
|
|
|
|
Each `major.minor` schema file format version is implemented as a separate package, with
|
|
|
|
the name of the package in the `vmajor.minor` form.
|
|
|
|
|
|
|
|
To parse a schema file, first decide what file format version you want to parse,
|
|
|
|
then import the corresponding package and use the `Parse` or `ParseFile` functions
|
|
|
|
like this:
|
|
|
|
|
|
|
|
```go
|
2022-07-25 17:30:23 +02:00
|
|
|
import schema "go.opentelemetry.io/otel/schema/v1.1"
|
2021-10-15 18:44:13 +02:00
|
|
|
|
2022-07-25 17:30:23 +02:00
|
|
|
// Load the schema from a file in v1.1.x file format.
|
2021-10-15 18:44:13 +02:00
|
|
|
func loadSchemaFromFile() error {
|
|
|
|
telSchema, err := schema.ParseFile("schema-file.yaml")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Use telSchema struct here.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Alternatively use schema.Parse to read the schema file from io.Reader.
|
|
|
|
func loadSchemaFromReader(r io.Reader) error {
|
|
|
|
telSchema, err := schema.Parse(r)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Use telSchema struct here.
|
|
|
|
}
|
|
|
|
```
|