From 3e4eee53ef9634ed52c62aacc33ce116931371d1 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Thu, 9 Nov 2023 09:57:10 -0600 Subject: [PATCH 1/2] [config] prepare package for release This PR does the following: - adds a section to versions.yaml, please review that the new section makes sense, it didn't seem to fit in any of the other groups. - adds doc.go - adds example Signed-off-by: Alex Boten --- config/doc.go | 7 +++++++ config/example_test.go | 34 ++++++++++++++++++++++++++++++++++ versions.yaml | 5 ++++- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 config/doc.go create mode 100644 config/example_test.go diff --git a/config/doc.go b/config/doc.go new file mode 100644 index 00000000000..293b43abb25 --- /dev/null +++ b/config/doc.go @@ -0,0 +1,7 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Package config can be used to parse a configuration file +// that follows the JSON Schema defined by the OpenTelemetry +// Configuration schema. +package config // import "go.opentelemetry.io/contrib/config" diff --git a/config/example_test.go b/config/example_test.go new file mode 100644 index 00000000000..f7fcb8036a3 --- /dev/null +++ b/config/example_test.go @@ -0,0 +1,34 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package config_test + +import ( + "context" + + "go.opentelemetry.io/contrib/config" + "go.opentelemetry.io/otel" +) + +func ExampleNewSDK() { + // NewSDK returns a configured SDK as configured + // per the options and any error that occurred during + // the initialization process. + configuredSDK, err := config.NewSDK( + config.WithContext(context.Background()), + config.WithOpenTelemetryConfiguration(config.OpenTelemetryConfiguration{ + TracerProvider: &config.TracerProvider{}, + MeterProvider: &config.MeterProvider{}, + }), + ) + + if err != nil { + // Handle error appropriately. + panic(err) + } + + // This SDK can then be used to get a TracerProvider and + // MeterProvider + otel.SetTracerProvider(configuredSDK.TracerProvider()) + otel.SetMeterProvider(configuredSDK.MeterProvider()) +} diff --git a/versions.yaml b/versions.yaml index 353af94b42b..85cf89a24de 100644 --- a/versions.yaml +++ b/versions.yaml @@ -83,8 +83,11 @@ module-sets: - go.opentelemetry.io/contrib/samplers/jaegerremote - go.opentelemetry.io/contrib/samplers/jaegerremote/example - go.opentelemetry.io/contrib/samplers/probability/consistent + experimental-config: + version: v0.1.0 + modules: + - go.opentelemetry.io/contrib/config excluded-modules: - - go.opentelemetry.io/contrib/config - go.opentelemetry.io/contrib/instrgen - go.opentelemetry.io/contrib/instrgen/driver - go.opentelemetry.io/contrib/instrgen/testdata/interface From df698a8945fb58bdc42d476ddf709b53b8b2de13 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Thu, 9 Nov 2023 11:46:40 -0600 Subject: [PATCH 2/2] remove readme/example for now. add todo in code Signed-off-by: Alex Boten --- config/README.md | 31 ------------------------------- config/config.go | 7 +++++++ config/example_test.go | 34 ---------------------------------- 3 files changed, 7 insertions(+), 65 deletions(-) delete mode 100644 config/README.md delete mode 100644 config/example_test.go diff --git a/config/README.md b/config/README.md deleted file mode 100644 index bc907dfaf1a..00000000000 --- a/config/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# Configuration Library - -This package can be used to parse a configuration file that follows the JSON -Schema defined by the [OpenTelemetry Configuration] schema. - -The package contains: - -- models generated via the JSON schema using the [go-jsonschema] library -- a `Create` function that interprets [configuration model] and return SDK components (TODO) -- a `Parse` function that parses and validates a [configuration file] (TODO) - -## Using the generate model code - -The `generated_config.go` code in versioned submodule can be used directly as-is to programmatically -produce a configuration model that can be then used as a parameter to the `Create` function. Note -that the package is versioned to match the release versioning of the opentelemetry-configuration -repository. - -## Using the `Create` function (TODO) - -## Using the `Parse` function (TODO) - -The original code from the package comes from the [OpenTelemetry Collector's service] telemetry -configuration code. The intent being to share this code across implementations and reduce -duplication where possible. - -[OpenTelemetry Configuration]: https://github.com/open-telemetry/opentelemetry-configuration/ -[go-jsonschema]: https://github.com/omissis/go-jsonschema -[configuration model]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/file-configuration.md#configuration-model -[configuration file]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/file-configuration.md#configuration-file -[OpenTelemetry Collector's service]: https://github.com/open-telemetry/opentelemetry-collector/blob/7c5ecef11dff4ce5501c9683b277a25a61ea0f1a/service/telemetry/generated_config.go diff --git a/config/config.go b/config/config.go index 8d77a783369..c49772a8e69 100644 --- a/config/config.go +++ b/config/config.go @@ -72,3 +72,10 @@ func WithOpenTelemetryConfiguration(cfg OpenTelemetryConfiguration) Configuratio return c }) } + +// TODO: implement parsing functionality: +// - https://github.com/open-telemetry/opentelemetry-go-contrib/issues/4373 +// - https://github.com/open-telemetry/opentelemetry-go-contrib/issues/4412 + +// TODO: create SDK from the model: +// - https://github.com/open-telemetry/opentelemetry-go-contrib/issues/4371 diff --git a/config/example_test.go b/config/example_test.go deleted file mode 100644 index f7fcb8036a3..00000000000 --- a/config/example_test.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package config_test - -import ( - "context" - - "go.opentelemetry.io/contrib/config" - "go.opentelemetry.io/otel" -) - -func ExampleNewSDK() { - // NewSDK returns a configured SDK as configured - // per the options and any error that occurred during - // the initialization process. - configuredSDK, err := config.NewSDK( - config.WithContext(context.Background()), - config.WithOpenTelemetryConfiguration(config.OpenTelemetryConfiguration{ - TracerProvider: &config.TracerProvider{}, - MeterProvider: &config.MeterProvider{}, - }), - ) - - if err != nil { - // Handle error appropriately. - panic(err) - } - - // This SDK can then be used to get a TracerProvider and - // MeterProvider - otel.SetTracerProvider(configuredSDK.TracerProvider()) - otel.SetMeterProvider(configuredSDK.MeterProvider()) -}