Skip to content

Commit 0afbbf1

Browse files
committed
chore: sdk/metric/internal/x - generate x package from x component template (#7386)
1 parent 643e735 commit 0afbbf1

File tree

5 files changed

+97
-31
lines changed

5 files changed

+97
-31
lines changed

sdk/metric/internal/gen.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// Package internal provides internal functionality for the sdk/metric package.
5+
package internal // import "go.opentelemetry.io/otel/sdk/metric/internal"
6+
7+
//go:generate gotmpl --body=../../../internal/shared/x/x.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/otel/sdk/metric\" }" --out=x/x.go
8+
//go:generate gotmpl --body=../../../internal/shared/x/x_test.go.tmpl "--data={}" --out=x/x_test.go
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package x
5+
6+
import "context"
7+
8+
// EnabledInstrument interface is implemented by synchronous instruments.
9+
type EnabledInstrument interface {
10+
// Enabled reports whether the instrument will process measurements for the given context.
11+
//
12+
// This function can be used in places where measuring an instrument
13+
// would result in computationally expensive operations.
14+
Enabled(context.Context) bool
15+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package x
5+
6+
import (
7+
"context"
8+
"testing"
9+
10+
"github.com/stretchr/testify/require"
11+
)
12+
13+
type testInstrument struct{}
14+
15+
func (*testInstrument) Enabled(_ context.Context) bool {
16+
return true
17+
}
18+
19+
func TestEnabledInstrument(t *testing.T) {
20+
var ei EnabledInstrument = &testInstrument{}
21+
22+
ctx := t.Context()
23+
enabled := ei.Enabled(ctx)
24+
25+
require.True(t, enabled, "Enabled() should return true")
26+
}

sdk/metric/internal/x/x.go

Lines changed: 19 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/metric/internal/x/x_test.go

Lines changed: 29 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)