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

Add ability to parse Schema files according to OTEP 0152 #2267

Merged
merged 14 commits into from
Oct 15, 2021
Merged
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,14 @@ updates:
schedule:
day: sunday
interval: weekly

-
package-ecosystem: gomod
directory: /schema
labels:
- dependencies
- go
- "Skip Changelog"
schedule:
day: sunday
interval: weekly
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Added

- Adds `otlptracegrpc.WithGRPCConn` and `otlpmetricgrpc.WithGRPCConn` for reusing existing gRPC connection. (#2002)
- Added a new `schema` module to help parse Schema Files in OTEP 0152 format. (#2267)

## [1.0.1] - 2021-10-01

Expand Down
2 changes: 2 additions & 0 deletions bridge/opencensus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ./test

replace go.opentelemetry.io/otel/example/fib => ../../example/fib

replace go.opentelemetry.io/otel/schema => ../../schema
2 changes: 2 additions & 0 deletions bridge/opencensus/test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ replace go.opentelemetry.io/otel/sdk/metric => ../../../sdk/metric
replace go.opentelemetry.io/otel/trace => ../../../trace

replace go.opentelemetry.io/otel/example/fib => ../../../example/fib

replace go.opentelemetry.io/otel/schema => ../../../schema
2 changes: 2 additions & 0 deletions bridge/opentracing/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../../example/fib

replace go.opentelemetry.io/otel/schema => ../../schema
2 changes: 2 additions & 0 deletions example/fib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ replace go.opentelemetry.io/otel/sdk/metric => ../../sdk/metric
replace go.opentelemetry.io/otel/trace => ../../trace

replace go.opentelemetry.io/otel/example/fib => ./

replace go.opentelemetry.io/otel/schema => ../../schema
2 changes: 2 additions & 0 deletions example/jaeger/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../fib

replace go.opentelemetry.io/otel/schema => ../../schema
2 changes: 2 additions & 0 deletions example/namedtracer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../fib

replace go.opentelemetry.io/otel/schema => ../../schema
2 changes: 2 additions & 0 deletions example/opencensus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../fib

replace go.opentelemetry.io/otel/schema => ../../schema
2 changes: 2 additions & 0 deletions example/otel-collector/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../fib

replace go.opentelemetry.io/otel/schema => ../../schema
2 changes: 2 additions & 0 deletions example/passthrough/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../fib

replace go.opentelemetry.io/otel/schema => ../../schema
2 changes: 2 additions & 0 deletions example/prometheus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../fib

replace go.opentelemetry.io/otel/schema => ../../schema
2 changes: 2 additions & 0 deletions example/zipkin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../fib

replace go.opentelemetry.io/otel/schema => ../../schema
2 changes: 2 additions & 0 deletions exporters/jaeger/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../../example/fib

replace go.opentelemetry.io/otel/schema => ../../schema
2 changes: 2 additions & 0 deletions exporters/otlp/otlpmetric/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ./o
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../../../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../../../example/fib

replace go.opentelemetry.io/otel/schema => ../../../schema
2 changes: 2 additions & 0 deletions exporters/otlp/otlpmetric/otlpmetricgrpc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../../../../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../../../../example/fib

replace go.opentelemetry.io/otel/schema => ../../../../schema
2 changes: 2 additions & 0 deletions exporters/otlp/otlpmetric/otlpmetrichttp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../../../../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../../../../example/fib

replace go.opentelemetry.io/otel/schema => ../../../../schema
2 changes: 2 additions & 0 deletions exporters/otlp/otlptrace/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../../../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../../../example/fib

replace go.opentelemetry.io/otel/schema => ../../../schema
2 changes: 2 additions & 0 deletions exporters/otlp/otlptrace/otlptracegrpc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../../../../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../../../../example/fib

replace go.opentelemetry.io/otel/schema => ../../../../schema
2 changes: 2 additions & 0 deletions exporters/otlp/otlptrace/otlptracehttp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../../../../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../../../../example/fib

replace go.opentelemetry.io/otel/schema => ../../../../schema
2 changes: 2 additions & 0 deletions exporters/prometheus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../../example/fib

replace go.opentelemetry.io/otel/schema => ../../schema
2 changes: 2 additions & 0 deletions exporters/stdout/stdoutmetric/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../../../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../../../example/fib

replace go.opentelemetry.io/otel/schema => ../../../schema
2 changes: 2 additions & 0 deletions exporters/stdout/stdouttrace/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../../../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../../../example/fib

replace go.opentelemetry.io/otel/schema => ../../../schema
2 changes: 2 additions & 0 deletions exporters/zipkin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../../example/fib

replace go.opentelemetry.io/otel/schema => ../../schema
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ./e
replace go.opentelemetry.io/otel/bridge/opencensus/test => ./bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ./example/fib

replace go.opentelemetry.io/otel/schema => ./schema
2 changes: 2 additions & 0 deletions internal/metric/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../../example/fib

replace go.opentelemetry.io/otel/schema => ../../schema
2 changes: 2 additions & 0 deletions internal/tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../../example/fib

replace go.opentelemetry.io/otel/schema => ../../schema
2 changes: 2 additions & 0 deletions metric/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../
replace go.opentelemetry.io/otel/bridge/opencensus/test => ../bridge/opencensus/test

replace go.opentelemetry.io/otel/example/fib => ../example/fib

replace go.opentelemetry.io/otel/schema => ../schema
31 changes: 31 additions & 0 deletions schema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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
import schema "go.opentelemetry.io/otel/schema/v1.0"

// Load the schema from a file in v1.0.x file format.
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.
}
```
71 changes: 71 additions & 0 deletions schema/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
module go.opentelemetry.io/otel/schema
tigrannajaryan marked this conversation as resolved.
Show resolved Hide resolved

go 1.15

require (
github.com/Masterminds/semver/v3 v3.1.1
github.com/stretchr/testify v1.7.0
gopkg.in/yaml.v2 v2.4.0
)

replace go.opentelemetry.io/otel => ../

replace go.opentelemetry.io/otel/bridge/opencensus => ../bridge/opencensus

replace go.opentelemetry.io/otel/bridge/opencensus/test => ../bridge/opencensus/test

replace go.opentelemetry.io/otel/bridge/opentracing => ../bridge/opentracing

replace go.opentelemetry.io/otel/example/fib => ../example/fib

replace go.opentelemetry.io/otel/example/jaeger => ../example/jaeger

replace go.opentelemetry.io/otel/example/namedtracer => ../example/namedtracer

replace go.opentelemetry.io/otel/example/opencensus => ../example/opencensus

replace go.opentelemetry.io/otel/example/otel-collector => ../example/otel-collector

replace go.opentelemetry.io/otel/example/passthrough => ../example/passthrough

replace go.opentelemetry.io/otel/example/prometheus => ../example/prometheus

replace go.opentelemetry.io/otel/example/zipkin => ../example/zipkin

replace go.opentelemetry.io/otel/exporters/jaeger => ../exporters/jaeger

replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../exporters/otlp/otlpmetric

replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../exporters/otlp/otlpmetric/otlpmetricgrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../exporters/otlp/otlpmetric/otlpmetrichttp

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../exporters/otlp/otlptrace

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/exporters/prometheus => ../exporters/prometheus

replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../exporters/stdout/stdoutmetric

replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../exporters/stdout/stdouttrace

replace go.opentelemetry.io/otel/exporters/zipkin => ../exporters/zipkin

replace go.opentelemetry.io/otel/internal/metric => ../internal/metric

replace go.opentelemetry.io/otel/internal/tools => ../internal/tools

replace go.opentelemetry.io/otel/metric => ../metric

replace go.opentelemetry.io/otel/schema => ./

replace go.opentelemetry.io/otel/sdk => ../sdk

replace go.opentelemetry.io/otel/sdk/export/metric => ../sdk/export/metric

replace go.opentelemetry.io/otel/sdk/metric => ../sdk/metric

replace go.opentelemetry.io/otel/trace => ../trace
15 changes: 15 additions & 0 deletions schema/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
56 changes: 56 additions & 0 deletions schema/v1.0/ast/ast_schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package ast // import "go.opentelemetry.io/otel/schema/v1.0/ast"

import "go.opentelemetry.io/otel/schema/v1.0/types"

// Schema represents a Schema file in FileFormat 1.0.0 as defined in
// https://github.com/open-telemetry/oteps/blob/main/text/0152-telemetry-schemas.md
type Schema struct {
// Schema file format. SHOULD be 1.0.0 for the current specification version.
// See https://github.com/open-telemetry/oteps/blob/main/text/0152-telemetry-schemas.md#schema-file-format-number
FileFormat string `yaml:"file_format"`

// Schema URL is an identifier of a Schema. The URL specifies a location of this
// Schema File that can be retrieved (so it is a URL and not just a URI) using HTTP
// or HTTPS protocol.
// See https://github.com/open-telemetry/oteps/blob/main/text/0152-telemetry-schemas.md#schema-url
SchemaURL string `yaml:"schema_url"`

// Versions section that lists changes that happened in each particular version.
Versions map[types.TelemetryVersion]VersionDef
}

// VersionDef corresponds to a section representing one version under the "versions"
// top-level key.
type VersionDef struct {
All Attributes
Resources Attributes
Spans Spans
SpanEvents SpanEvents `yaml:"span_events"`
Logs Logs
Metrics Metrics
}

// Attributes corresponds to a section representing a list of changes that
// happened in a particular version.
type Attributes struct {
Changes []AttributeChange
}

// AttributeChange corresponds to a section representing attribute changes.
type AttributeChange struct {
RenameAttributes *AttributeMap `yaml:"rename_attributes"`
}
25 changes: 25 additions & 0 deletions schema/v1.0/ast/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package ast // import "go.opentelemetry.io/otel/schema/v1.0/ast"

// RenameAttributes corresponds to a section that describes attribute renaming.
type RenameAttributes struct {
AttributeMap AttributeMap `yaml:"attribute_map"`
}

// AttributeMap corresponds to a section representing a mapping of attribute names.
// The keys are the old attribute name used in the previous version, the values are the
// new attribute name starting from this version.
type AttributeMap map[string]string
Loading