Skip to content

Commit 5a04620

Browse files
sdk/metric: Deprecate the sdk/metric/x Feature Supporting Cardinality Limits (#7166)
Fixes #6980 Towards #6887 ## What - Any references to sdk/metric/x in documentation, tests, or examples are updated to redirect users to use the cardinality limit feature in the SDK. --------- Co-authored-by: Robert Pająk <[email protected]>
1 parent 97343af commit 5a04620

File tree

4 files changed

+9
-59
lines changed

4 files changed

+9
-59
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
6060
- Change `SDKProcessorLogQueueCapacity`, `SDKProcessorLogQueueSize`, `SDKProcessorSpanQueueSize`, and `SDKProcessorSpanQueueCapacity` in `go.opentelemetry.io/otel/semconv/v1.36.0/otelconv` to use a `Int64ObservableUpDownCounter`. (#7041)
6161
- Change `DefaultExemplarReservoirProviderSelector` in `go.opentelemetry.io/otel/sdk/metric` to use `runtime.GOMAXPROCS(0)` instead of `runtime.NumCPU()` for the `FixedSizeReservoirProvider` default size. (#7094)
6262

63+
### Deprecated
64+
65+
- Deprecate support for `OTEL_GO_X_CARDINALITY_LIMIT` environment variable in `go.opentelemetry.io/otel/sdk/metric`. Use `WithCardinalityLimit` option instead. (#7166)
66+
6367
### Fixed
6468

6569
- Fix `go.opentelemetry.io/otel/exporters/prometheus` to deduplicate suffixes if already present in metric name when UTF8 is enabled. (#7088)

sdk/metric/internal/x/README.md

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,9 @@ See the [Compatibility and Stability](#compatibility-and-stability) section for
88

99
## Features
1010

11-
- [Cardinality Limit](#cardinality-limit)
1211
- [Exemplars](#exemplars)
1312
- [Instrument Enabled](#instrument-enabled)
1413

15-
### Cardinality Limit
16-
17-
The cardinality limit is the hard limit on the number of metric streams that can be collected for a single instrument.
18-
19-
This experimental feature can be enabled by setting the `OTEL_GO_X_CARDINALITY_LIMIT` environment value.
20-
The value must be an integer value.
21-
All other values are ignored.
22-
23-
If the value set is less than or equal to `0`, no limit will be applied.
24-
25-
#### Examples
26-
27-
Set the cardinality limit to 2000.
28-
29-
```console
30-
export OTEL_GO_X_CARDINALITY_LIMIT=2000
31-
```
32-
33-
Set an infinite cardinality limit (functionally equivalent to disabling the feature).
34-
35-
```console
36-
export OTEL_GO_X_CARDINALITY_LIMIT=-1
37-
```
38-
39-
Disable the cardinality limit.
40-
41-
```console
42-
unset OTEL_GO_X_CARDINALITY_LIMIT
43-
```
44-
4514
### Exemplars
4615

4716
A sample of measurements made may be exported directly as a set of exemplars.

sdk/metric/internal/x/x.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,16 @@ package x // import "go.opentelemetry.io/otel/sdk/metric/internal/x"
1010
import (
1111
"context"
1212
"os"
13-
"strconv"
1413
)
1514

16-
// CardinalityLimit is an experimental feature flag that defines if
17-
// cardinality limits should be applied to the recorded metric data-points.
18-
//
19-
// To enable this feature set the OTEL_GO_X_CARDINALITY_LIMIT environment
20-
// variable to the integer limit value you want to use.
21-
//
22-
// Setting OTEL_GO_X_CARDINALITY_LIMIT to a value less than or equal to 0
23-
// will disable the cardinality limits.
24-
var CardinalityLimit = newFeature("CARDINALITY_LIMIT", func(v string) (int, bool) {
25-
n, err := strconv.Atoi(v)
26-
if err != nil {
27-
return 0, false
28-
}
29-
return n, true
30-
})
31-
3215
// Feature is an experimental feature control flag. It provides a uniform way
3316
// to interact with these feature flags and parse their values.
3417
type Feature[T any] struct {
3518
key string
3619
parse func(v string) (T, bool)
3720
}
3821

22+
//nolint:unused
3923
func newFeature[T any](suffix string, parse func(string) (T, bool)) Feature[T] {
4024
const envKeyRoot = "OTEL_GO_X_"
4125
return Feature[T]{

sdk/metric/internal/x/x_test.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,9 @@ import (
77
"testing"
88

99
"github.com/stretchr/testify/assert"
10-
"github.com/stretchr/testify/require"
1110
)
1211

13-
func TestCardinalityLimit(t *testing.T) {
14-
const key = "OTEL_GO_X_CARDINALITY_LIMIT"
15-
require.Equal(t, key, CardinalityLimit.Key())
16-
17-
t.Run("100", run(setenv(key, "100"), assertEnabled(CardinalityLimit, 100)))
18-
t.Run("-1", run(setenv(key, "-1"), assertEnabled(CardinalityLimit, -1)))
19-
t.Run("false", run(setenv(key, "false"), assertDisabled(CardinalityLimit)))
20-
t.Run("empty", run(assertDisabled(CardinalityLimit)))
21-
}
22-
12+
//nolint:unused
2313
func run(steps ...func(*testing.T)) func(*testing.T) {
2414
return func(t *testing.T) {
2515
t.Helper()
@@ -29,10 +19,12 @@ func run(steps ...func(*testing.T)) func(*testing.T) {
2919
}
3020
}
3121

22+
//nolint:unused
3223
func setenv(k, v string) func(t *testing.T) {
3324
return func(t *testing.T) { t.Setenv(k, v) }
3425
}
3526

27+
//nolint:unused
3628
func assertEnabled[T any](f Feature[T], want T) func(*testing.T) {
3729
return func(t *testing.T) {
3830
t.Helper()
@@ -44,6 +36,7 @@ func assertEnabled[T any](f Feature[T], want T) func(*testing.T) {
4436
}
4537
}
4638

39+
//nolint:unused
4740
func assertDisabled[T any](f Feature[T]) func(*testing.T) {
4841
var zero T
4942
return func(t *testing.T) {

0 commit comments

Comments
 (0)