Skip to content

Commit

Permalink
Move experimental support to internal pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Aug 21, 2023
1 parent 99f6b14 commit 0486576
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
3 changes: 2 additions & 1 deletion sdk/metric/exemplar.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"os"

"go.opentelemetry.io/otel/sdk/metric/internal/exemplar"
"go.opentelemetry.io/otel/sdk/metric/internal/x"
)

// reservoirFunc returns the appropriately configured exemplar reservoir
Expand All @@ -27,7 +28,7 @@ import (
// Note: This will only return non-nil values when the experimental exemplar
// feature is enabled.
func reservoirFunc[N int64 | float64](agg Aggregation) func() exemplar.Reservoir[N] {
if !xEnabled(xExemplar) {
if !x.Enabled(x.Exemplars) {
return nil
}

Expand Down
34 changes: 18 additions & 16 deletions sdk/metric/experimental.go → sdk/metric/internal/x/x.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,43 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package metric // import "go.opentelemetry.io/otel/sdk/metric"
// Package x contains support for OTel metric SDK experimental features.
package x // import "go.opentelemetry.io/otel/sdk/metric/internal/x"

import (
"os"
"strings"
)

const xEnvKeyRoot = "OTEL_GO_X_"
const EnvKeyRoot = "OTEL_GO_X_"

var (
xExemplar = xFeature{
envKeySuffix: "EXEMPLAR",
enablementVals: []string{"true"},
Exemplars = Feature{
EnvKeySuffix: "EXEMPLAR",
EnablementVals: []string{"true"},
}
)

type xFeature struct {
// envKey is the environment variable key suffix the xFeature is stored at.
// It is assumed xEnvKeyRoot is the base of the environment variable key.
envKeySuffix string
// enablementVals are the case-insensitive comparison values that indicate
// the xFeature is enabled.
enablementVals []string
type Feature struct {
// EnvKeySuffix is the environment variable key suffix the xFeature is
// stored at. It is assumed EnvKeyRoot is the base of the environment
// variable key.
EnvKeySuffix string
// EnablementVals are the case-insensitive comparison values that indicate
// the Feature is enabled.
EnablementVals []string
}

// xEnabled returns if the xFeature is enabled.
func xEnabled(xf xFeature) bool {
key := xEnvKeyRoot + xf.envKeySuffix
// Enabled returns if the Feature is enabled.
func Enabled(f Feature) bool {
key := EnvKeyRoot + f.EnvKeySuffix
vRaw, present := os.LookupEnv(key)
if !present {
return false
}

v := strings.ToLower(vRaw)
for _, allowed := range xf.enablementVals {
for _, allowed := range f.EnablementVals {
if v == strings.ToLower(allowed) {
return true
}

Check warning on line 54 in sdk/metric/internal/x/x.go

View check run for this annotation

Codecov / codecov/patch

sdk/metric/internal/x/x.go#L50-L54

Added lines #L50 - L54 were not covered by tests
Expand Down

0 comments on commit 0486576

Please sign in to comment.