| 1 |
# Telemetry Schema Files |
| 2 |
|
| 3 |
The `schema` module contains packages that help to parse and validate |
| 4 |
[schema files](https://github.com/open-telemetry/oteps/blob/main/text/0152-telemetry-schemas.md). |
| 5 |
|
| 6 |
Each `major.minor` schema file format version is implemented as a separate package, with |
| 7 |
the name of the package in the `vmajor.minor` form. |
| 8 |
|
| 9 |
To parse a schema file, first decide what file format version you want to parse, |
| 10 |
then import the corresponding package and use the `Parse` or `ParseFile` functions |
| 11 |
like this: |
| 12 |
|
| 13 |
```go |
| 14 |
import schema "go.opentelemetry.io/otel/schema/v1.1" |
| 15 |
|
| 16 |
// Load the schema from a file in v1.1.x file format. |
| 17 |
func loadSchemaFromFile() error { |
| 18 |
telSchema, err := schema.ParseFile("schema-file.yaml") |
| 19 |
if err != nil { |
| 20 |
return err |
| 21 |
} |
| 22 |
// Use telSchema struct here. |
| 23 |
} |
| 24 |
|
| 25 |
// Alternatively use schema.Parse to read the schema file from io.Reader. |
| 26 |
func loadSchemaFromReader(r io.Reader) error { |
| 27 |
telSchema, err := schema.Parse(r) |
| 28 |
if err != nil { |
| 29 |
return err |
| 30 |
} |
| 31 |
// Use telSchema struct here. |
| 32 |
} |
| 33 |
``` |