Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions sdk/metric/internal/gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// Package internal provides internal functionality for the sdk/metric package.
package internal // import "go.opentelemetry.io/otel/sdk/metric/internal"

//go:generate gotmpl --body=../../../internal/shared/x/x.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/otel/sdk/metric\" }" --out=x/x.go
//go:generate gotmpl --body=../../../internal/shared/x/x_test.go.tmpl "--data={}" --out=x/x_test.go
15 changes: 15 additions & 0 deletions sdk/metric/internal/x/enabled_instrument.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package x // import "go.opentelemetry.io/otel/sdk/metric/internal/x"

import "context"

// EnabledInstrument interface is implemented by synchronous instruments.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// EnabledInstrument interface is implemented by synchronous instruments.
// EnabledInstrument informs whether the instrument is enabled.
//
// EnabledInstrument interface is implemented by synchronous instruments.

type EnabledInstrument interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep the original comments?

// Enabled reports whether the instrument will process measurements for the given context.
//
// This function can be used in places where measuring an instrument
// would result in computationally expensive operations.
Enabled(context.Context) bool
}
26 changes: 26 additions & 0 deletions sdk/metric/internal/x/enabled_instrument_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package x

import (
"context"
"testing"

"github.com/stretchr/testify/require"
)

type testInstrument struct{}

func (*testInstrument) Enabled(_ context.Context) bool {
return true
}

func TestEnabledInstrument(t *testing.T) {
var ei EnabledInstrument = &testInstrument{}

ctx := t.Context()
enabled := ei.Enabled(ctx)

require.True(t, enabled, "Enabled() should return true")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps using assert.Implements(....) would be more appropriate.

}
45 changes: 19 additions & 26 deletions sdk/metric/internal/x/x.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 29 additions & 5 deletions sdk/metric/internal/x/x_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.