Skip to content

Commit a48c48e

Browse files
committed
chore: sdk/metric/internal/x - generate x package from x component template (#7386)
1 parent addcd63 commit a48c48e

File tree

5 files changed

+91
-31
lines changed

5 files changed

+91
-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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package x
2+
3+
import "context"
4+
5+
// EnabledInstrument interface is implemented by synchronous instruments.
6+
type EnabledInstrument interface {
7+
// Enabled reports whether the instrument will process measurements for the given context.
8+
//
9+
// This function can be used in places where measuring an instrument
10+
// would result in computationally expensive operations.
11+
Enabled(context.Context) bool
12+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package x
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
type testInstrument struct{}
11+
12+
func (t *testInstrument) Enabled(ctx context.Context) bool {
13+
return true
14+
}
15+
16+
func TestEnabledInstrument(t *testing.T) {
17+
var ei EnabledInstrument = &testInstrument{}
18+
19+
ctx := context.Background()
20+
enabled := ei.Enabled(ctx)
21+
22+
require.True(t, enabled, "Enabled() should return true")
23+
}

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)