Skip to content

Commit 3cd63fa

Browse files
ysolomchenkopellaredMrAlias
authored
sdk/metric: Add Documentation for Cardinality Limits (#7179)
Fixes #6979 Towards #6887 ## What - Documentation includes a section on cardinality limits. - Adding guidance around what cardinality is, why it is important to consider, how to control it, and what defaults the SDK provides --------- Co-authored-by: Robert Pająk <[email protected]> Co-authored-by: Tyler Yahn <[email protected]>
1 parent 691b4b4 commit 3cd63fa

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The next release will require at least [Go 1.24].
4444
- `RPCGRPCResponseMetadata`
4545
- Add `ErrorType` attribute helper function to the `go.opentelmetry.io/otel/semconv/v1.34.0` package. (#6962)
4646
- Add `WithAllowKeyDuplication` in `go.opentelemetry.io/otel/sdk/log` which can be used to disable deduplication for log records. (#6968)
47-
- Add `WithCardinalityLimit` option to configure the cardinality limit in `go.opentelemetry.io/otel/sdk/metric`. (#6996, #7065, #7081, #7164, #7165)
47+
- Add `WithCardinalityLimit` option to configure the cardinality limit in `go.opentelemetry.io/otel/sdk/metric`. (#6996, #7065, #7081, #7164, #7165, #7179)
4848
- Add `Clone` method to `Record` in `go.opentelemetry.io/otel/log` that returns a copy of the record with no shared state. (#7001)
4949
- The `go.opentelemetry.io/otel/semconv/v1.36.0` package.
5050
The package contains semantic conventions from the `v1.36.0` version of the OpenTelemetry Semantic Conventions.

sdk/metric/doc.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,30 @@
3939
// Meter.RegisterCallback and Registration.Unregister to add and remove
4040
// callbacks without leaking memory.
4141
//
42+
// # Cardinality Limits
43+
//
44+
// Cardinality refers to the number of unique attributes collected. High cardinality can lead to
45+
// excessive memory usage, increased storage costs, and backend performance issues.
46+
//
47+
// Currently, the OpenTelemetry Go Metric SDK does not enforce a cardinality limit by default
48+
// (note that this may change in a future release). Use [WithCardinalityLimit] to set the
49+
// cardinality limit as desired.
50+
//
51+
// New attribute sets are dropped when the cardinality limit is reached. The measurement of
52+
// these sets are aggregated into
53+
// a special attribute set containing "otel.metric.overflow" attribute with "true" value.
54+
// This ensures total metric values (e.g., Sum, Count) remain correct for the
55+
// collection cycle, but information about the specific dropped sets
56+
// is not preserved.
57+
//
58+
// Recommendations:
59+
//
60+
// - Set the limit based on the theoretical maximum combinations or expected
61+
// active combinations. The OpenTelemetry Specification recommends a default of 2000.
62+
// - A too high of a limit increases worst-case memory overhead in the SDK and may cause downstream
63+
// issues for databases that cannot handle high cardinality.
64+
// - A too low of a limit causes loss of attribute detail as more data falls into overflow.
65+
//
4266
// See [go.opentelemetry.io/otel/metric] for more information about
4367
// the metric API.
4468
//

0 commit comments

Comments
 (0)