Skip to content

Commit

Permalink
Add ability to parse Schema files according to OTEP 0152
Browse files Browse the repository at this point in the history
The parser and parsed representation (AST) are placed in a separate
Go module so that they are can be consumed independently without
the need to bring the rest of the SDK.

Ability to use the parsed representation for schema conversions
can be added later.
  • Loading branch information
tigrannajaryan committed Sep 28, 2021
1 parent 099df58 commit 4c60e21
Show file tree
Hide file tree
Showing 43 changed files with 664 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
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
2 changes: 2 additions & 0 deletions bridge/opencensus/go.mod
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 metric/go.mod
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
63 changes: 63 additions & 0 deletions schema/ast/ast_schema.go
@@ -0,0 +1,63 @@
// 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/ast"

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

const FileFormat = "1.0.0"

// 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 VersionOfAttributes
Resources VersionOfAttributes
Spans VersionOfSpans
SpanEvents VersionOfSpanEvents `yaml:"span_events"`
Logs VersionOfLogs
Metrics VersionOfMetrics
}

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

// AttributeChanges corresponds to a section representing attribute changes.
type AttributeChanges struct {
RenameAttributes *MappingOfAttributes `yaml:"rename_attributes"`
}

// MappingOfAttributes corresponds to a section representing a mapping of attribute names.
// The keys are the old attribute name used the previous version, the values are the
// new attribute name starting from this version.
type MappingOfAttributes map[string]string
30 changes: 30 additions & 0 deletions schema/ast/logs.go
@@ -0,0 +1,30 @@
// 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/ast"

// VersionOfLogs corresponds to a section representing a list of changes that happened
// to logs schema in a particular version.
type VersionOfLogs struct {
Changes []LogsChange
}

// LogsChange corresponds to a section representing logs change.
type LogsChange struct {
RenameAttributes *RenameLogAttributes `yaml:"rename_attributes"`
}

type RenameLogAttributes struct {
AttributeMap map[string]string `yaml:"attribute_map"`
}
34 changes: 34 additions & 0 deletions schema/ast/metrics.go
@@ -0,0 +1,34 @@
// 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/types"

// VersionOfMetrics corresponds to a section representing a list of changes that happened
// to metrics schema in a particular version.
type VersionOfMetrics struct {
Changes []MetricsChange
}

// MetricsChange corresponds to a section representing metrics change.
type MetricsChange struct {
RenameMetrics map[types.MetricName]types.MetricName `yaml:"rename_metrics"`
RenameLabels *LabelMapForMetrics `yaml:"rename_labels"`
}

type LabelMapForMetrics struct {
ApplyToMetrics []types.MetricName `yaml:"apply_to_metrics"`
LabelMap map[string]string `yaml:"label_map"`
}
54 changes: 54 additions & 0 deletions schema/ast/spans.go
@@ -0,0 +1,54 @@
// 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/ast"

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

// VersionOfSpans corresponds to a section representing a list of changes that happened
// to spans schema in a particular version.
type VersionOfSpans struct {
Changes []SpansChange
}

// VersionOfSpanEvents corresponds to a section representing a list of changes that happened
// to span events schema in a particular version.
type VersionOfSpanEvents struct {
Changes []SpanEventsChange
}

// SpansChange corresponds to a section representing spans change.
type SpansChange struct {
RenameAttributes *RenameSpanAttributes `yaml:"rename_attributes"`
}

// SpanEventsChange corresponds to a section representing span events change.
type SpanEventsChange struct {
RenameEvents *RenameSpanEvents `yaml:"rename_events"`
RenameAttributes *RenameSpanEventAttributes `yaml:"rename_attributes"`
}

type RenameSpanAttributes struct {
AttributeMap map[string]string `yaml:"attribute_map"`
}

type RenameSpanEvents struct {
EventNameMap map[string]string `yaml:"name_map"`
}

type RenameSpanEventAttributes struct {
ApplyToSpans []types.SpanName `yaml:"apply_to_spans"`
ApplyToEvents []types.EventName `yaml:"apply_to_events"`
AttributeMap map[string]string `yaml:"attribute_map"`
}

0 comments on commit 4c60e21

Please sign in to comment.