Skip to content

sdk/metric: Add WithCardinalityLimit option#6996

Merged
pellared merged 30 commits intoopen-telemetry:mainfrom
ysolomchenko:define-cardinality-limit-configuration-options
Jul 21, 2025
Merged

sdk/metric: Add WithCardinalityLimit option#6996
pellared merged 30 commits intoopen-telemetry:mainfrom
ysolomchenko:define-cardinality-limit-configuration-options

Conversation

@ysolomchenko
Copy link
Copy Markdown
Contributor

@ysolomchenko ysolomchenko commented Jul 11, 2025

Fixes #6976
Towards #6887

What

  • A new configuration field for cardinality limits is added to the SDK.
  • Users can set cardinality limits via code
  • Default value of 0(no limit) is applied if no value is provided.
  • Unit tests validate the configuration behavior.

Additional

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.8%. Comparing base (ac86022) to head (d34be5b).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #6996   +/-   ##
=====================================
  Coverage   82.7%   82.8%           
=====================================
  Files        261     261           
  Lines      24341   24361   +20     
=====================================
+ Hits       20154   20175   +21     
+ Misses      3812    3811    -1     
  Partials     375     375           
Files with missing lines Coverage Δ
sdk/metric/config.go 93.6% <100.0%> (+1.6%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread sdk/metric/config.go Outdated
Comment thread sdk/metric/config.go Outdated
Comment thread sdk/metric/config.go Outdated
Comment thread CHANGELOG.md Outdated
@pellared pellared changed the title Define Cardinality Limit Configuration Options sdk/metric: Add WithCardinalityLimit option Jul 11, 2025
Comment thread sdk/metric/config.go Outdated
Comment thread CHANGELOG.md Outdated
Comment thread sdk/metric/config.go Outdated
Comment thread sdk/metric/config.go Outdated
Co-authored-by: Robert Pająk <pellared@hotmail.com>
Comment thread sdk/metric/config_test.go Outdated
Copy link
Copy Markdown
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

Overall LGTM. Just a few nit comments that I would like to get addressed.

Probably we can consider improving the WithCardinalityLimit Go Doc, but it is not a blocker to me and the refinements could be scoped to a separate PR.

@ysolomchenko
Copy link
Copy Markdown
Contributor Author

My suggestion is to keep it no limit for now, mention that no limit will be deprecated, and in next releases change it to 2000.

@pellared
Copy link
Copy Markdown
Member

pellared commented Jul 14, 2025

My suggestion is to keep it no limit for now, mention that no limit will be deprecated, and in next releases change it to 2000.

In theory, this seems reasonable as it gives users time to configure the value higher than 2000 if needed. However, I’m not sure people would actually know they’re about to hit the 2000 cardinality limit. Because of that, I suspect it wouldn’t really help and might just add unnecessary complexity on us.

Personally, I’d try following the specification’s recommendation and set the default cardinality limit to 2000 right away. We should also include a prominent warning in the CHANGELOG.md, highlighting this as a behavioral breaking change that could impact some users. I think exceeding 2000 in cardinality is something ~99% of users don’t want anyway, and having this limit is an important safeguard to prevent issues like memory leaks from cardinality explosions.

One thing I haven’t checked yet: does setting a cardinality limit impact performance? If so, that could be a valid argument against making 2000 the default.

Given all this, I’d suggest creating a separate issue to discuss changing the default cardinality limit, so we can gather input and proceed carefully, while allowing other work to continue in parallel.

@ysolomchenko
Copy link
Copy Markdown
Contributor Author

ysolomchenko commented Jul 15, 2025

Here is benchstat no limit vs 2000 limit

goos: windows
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/metric
cpu: 13th Gen Intel(R) Core(TM) i9-13950HX
                                                                       │ 2000limit.txt │             nolimit.txt              │
                                                                       │    sec/op     │    sec/op     vs base                │
SyncMeasure/NoView/Int64Counter/Attributes/0-32                           55.98n ±  3%   45.06n ±  2%  -19.49% (p=0.000 n=10)
SyncMeasure/NoView/Int64Counter/Attributes/1-32                           156.0n ±  2%   116.3n ±  2%  -25.42% (p=0.000 n=10)
SyncMeasure/NoView/Int64Counter/Attributes/10-32                          966.2n ±  7%   650.6n ± 14%  -32.67% (p=0.000 n=10)
SyncMeasure/NoView/Float64Counter/Attributes/0-32                         57.24n ±  6%   48.90n ± 26%  -14.55% (p=0.022 n=10)
SyncMeasure/NoView/Float64Counter/Attributes/1-32                         166.2n ±  2%   121.0n ±  2%  -27.14% (p=0.000 n=10)
SyncMeasure/NoView/Float64Counter/Attributes/10-32                       1047.0n ±  6%   725.7n ±  9%  -30.69% (p=0.000 n=10)
SyncMeasure/NoView/Int64UpDownCounter/Attributes/0-32                     57.55n ±  1%   49.27n ±  2%  -14.39% (p=0.000 n=10)
SyncMeasure/NoView/Int64UpDownCounter/Attributes/1-32                     166.9n ±  2%   126.0n ±  2%  -24.56% (p=0.000 n=10)
SyncMeasure/NoView/Int64UpDownCounter/Attributes/10-32                   1028.0n ±  3%   702.4n ±  4%  -31.67% (p=0.000 n=10)
SyncMeasure/NoView/Float64UpDownCounter/Attributes/0-32                   57.66n ±  3%   49.69n ±  4%  -13.81% (p=0.000 n=10)
SyncMeasure/NoView/Float64UpDownCounter/Attributes/1-32                   162.9n ±  1%   123.5n ± 10%  -24.19% (p=0.000 n=10)
SyncMeasure/NoView/Float64UpDownCounter/Attributes/10-32                 1027.5n ±  3%   716.1n ±  2%  -30.31% (p=0.000 n=10)
SyncMeasure/NoView/Int64Histogram/Attributes/0-32                         47.75n ±  4%   38.53n ±  3%  -19.32% (p=0.000 n=10)
SyncMeasure/NoView/Int64Histogram/Attributes/1-32                        121.95n ±  2%   77.74n ±  1%  -36.25% (p=0.000 n=10)
SyncMeasure/NoView/Int64Histogram/Attributes/10-32                        707.8n ±  3%   365.1n ±  2%  -48.41% (p=0.000 n=10)
SyncMeasure/NoView/Float64Histogram/Attributes/0-32                       48.47n ±  4%   39.48n ±  1%  -18.54% (p=0.000 n=10)
SyncMeasure/NoView/Float64Histogram/Attributes/1-32                      123.65n ±  1%   77.46n ±  2%  -37.36% (p=0.000 n=10)
SyncMeasure/NoView/Float64Histogram/Attributes/10-32                      710.5n ±  3%   368.9n ±  2%  -48.07% (p=0.000 n=10)
SyncMeasure/DropView/Int64Counter/Attributes/0-32                         9.179n ±  2%   9.259n ±  2%        ~ (p=0.986 n=10)
SyncMeasure/DropView/Int64Counter/Attributes/1-32                         11.10n ±  2%   11.43n ±  1%   +2.93% (p=0.000 n=10)
SyncMeasure/DropView/Int64Counter/Attributes/10-32                        11.17n ±  1%   11.46n ±  3%   +2.60% (p=0.000 n=10)
SyncMeasure/DropView/Float64Counter/Attributes/0-32                       8.856n ±  2%   8.903n ±  3%        ~ (p=0.912 n=10)
SyncMeasure/DropView/Float64Counter/Attributes/1-32                       11.37n ±  2%   11.71n ±  2%   +2.95% (p=0.001 n=10)
SyncMeasure/DropView/Float64Counter/Attributes/10-32                      11.27n ±  1%   11.65n ±  1%   +3.37% (p=0.000 n=10)
SyncMeasure/DropView/Int64UpDownCounter/Attributes/0-32                   8.730n ±  2%   8.697n ±  2%        ~ (p=0.631 n=10)
SyncMeasure/DropView/Int64UpDownCounter/Attributes/1-32                   11.27n ±  2%   11.57n ±  1%   +2.71% (p=0.000 n=10)
SyncMeasure/DropView/Int64UpDownCounter/Attributes/10-32                  11.26n ±  1%   11.41n ±  3%   +1.38% (p=0.002 n=10)
SyncMeasure/DropView/Float64UpDownCounter/Attributes/0-32                 8.799n ±  3%   8.744n ±  2%        ~ (p=1.000 n=10)
SyncMeasure/DropView/Float64UpDownCounter/Attributes/1-32                 11.50n ±  2%   11.72n ±  3%   +1.91% (p=0.004 n=10)
SyncMeasure/DropView/Float64UpDownCounter/Attributes/10-32                11.01n ±  2%   11.44n ±  2%   +3.86% (p=0.000 n=10)
SyncMeasure/DropView/Int64Histogram/Attributes/0-32                       8.639n ±  5%   8.582n ±  1%        ~ (p=0.218 n=10)
SyncMeasure/DropView/Int64Histogram/Attributes/1-32                       11.67n ±  1%   12.23n ±  2%   +4.76% (p=0.000 n=10)
SyncMeasure/DropView/Int64Histogram/Attributes/10-32                      11.75n ±  3%   12.11n ±  4%   +3.02% (p=0.009 n=10)
SyncMeasure/DropView/Float64Histogram/Attributes/0-32                     8.518n ±  1%   8.581n ±  1%   +0.74% (p=0.024 n=10)
SyncMeasure/DropView/Float64Histogram/Attributes/1-32                     11.89n ±  2%   12.15n ±  2%   +2.19% (p=0.005 n=10)
SyncMeasure/DropView/Float64Histogram/Attributes/10-32                    11.71n ±  2%   11.88n ±  3%   +1.45% (p=0.041 n=10)
SyncMeasure/AttrFilterView/Int64Counter/Attributes/0-32                   63.51n ±  3%   52.95n ±  2%  -16.64% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Int64Counter/Attributes/1-32                   189.2n ±  2%   145.2n ±  1%  -23.26% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Int64Counter/Attributes/10-32                  675.8n ±  4%   637.9n ±  6%   -5.59% (p=0.005 n=10)
SyncMeasure/AttrFilterView/Float64Counter/Attributes/0-32                 63.33n ±  1%   54.08n ±  3%  -14.60% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Float64Counter/Attributes/1-32                 192.9n ±  1%   148.8n ±  2%  -22.86% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Float64Counter/Attributes/10-32                696.1n ±  7%   643.7n ±  5%   -7.52% (p=0.004 n=10)
SyncMeasure/AttrFilterView/Int64UpDownCounter/Attributes/0-32             63.72n ±  1%   53.31n ±  1%  -16.33% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Int64UpDownCounter/Attributes/1-32             195.8n ±  5%   149.0n ±  2%  -23.90% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Int64UpDownCounter/Attributes/10-32            690.9n ±  6%   630.3n ±  4%   -8.77% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Float64UpDownCounter/Attributes/0-32           63.16n ±  2%   53.27n ±  1%  -15.66% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Float64UpDownCounter/Attributes/1-32           192.7n ±  1%   146.2n ±  2%  -24.10% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Float64UpDownCounter/Attributes/10-32          690.1n ±  4%   642.5n ±  7%   -6.90% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Int64Histogram/Attributes/0-32                 53.53n ±  3%   43.33n ±  2%  -19.05% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Int64Histogram/Attributes/1-32                 147.8n ±  3%   102.5n ±  1%  -30.64% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Int64Histogram/Attributes/10-32                611.9n ±  3%   573.3n ±  3%   -6.29% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Float64Histogram/Attributes/0-32               55.70n ±  3%   43.82n ±  1%  -21.34% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Float64Histogram/Attributes/1-32               152.8n ±  2%   102.3n ±  1%  -33.05% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Float64Histogram/Attributes/10-32              632.9n ±  5%   565.4n ±  4%  -10.67% (p=0.000 n=10)
Collect/NoView/Int64Counter/1/Attributes/0-32                             359.1n ±  2%   362.0n ±  2%        ~ (p=0.247 n=10)
Collect/NoView/Int64Counter/1/Attributes/1-32                             356.4n ±  2%   358.6n ±  5%        ~ (p=0.529 n=10)
Collect/NoView/Int64Counter/1/Attributes/10-32                            366.5n ±  3%   355.8n ±  1%   -2.91% (p=0.029 n=10)
Collect/NoView/Int64Counter/10/Attributes/0-32                            356.2n ±  1%   350.1n ±  1%   -1.73% (p=0.011 n=10)
Collect/NoView/Int64Counter/10/Attributes/1-32                            355.1n ±  1%   354.6n ±  4%        ~ (p=0.927 n=10)
Collect/NoView/Int64Counter/10/Attributes/10-32                           360.8n ±  2%   366.2n ±  3%        ~ (p=0.123 n=10)
Collect/NoView/Float64Counter/1/Attributes/0-32                           358.9n ±  1%   377.9n ±  8%   +5.31% (p=0.000 n=10)
Collect/NoView/Float64Counter/1/Attributes/1-32                           358.1n ±  5%   368.3n ±  3%        ~ (p=0.055 n=10)
Collect/NoView/Float64Counter/1/Attributes/10-32                          370.6n ±  4%   360.0n ±  5%        ~ (p=0.271 n=10)
Collect/NoView/Float64Counter/10/Attributes/0-32                          361.1n ±  3%   365.2n ±  2%        ~ (p=0.225 n=10)
Collect/NoView/Float64Counter/10/Attributes/1-32                          372.9n ±  4%   368.9n ±  6%        ~ (p=0.796 n=10)
Collect/NoView/Float64Counter/10/Attributes/10-32                         357.8n ±  2%   357.8n ±  3%        ~ (p=0.684 n=10)
Collect/NoView/Int64UpDownCounter/1/Attributes/0-32                       359.9n ±  4%   383.2n ±  7%   +6.46% (p=0.000 n=10)
Collect/NoView/Int64UpDownCounter/1/Attributes/1-32                       367.1n ±  4%   371.3n ±  7%        ~ (p=0.393 n=10)
Collect/NoView/Int64UpDownCounter/1/Attributes/10-32                      360.8n ±  5%   365.8n ±  5%        ~ (p=0.912 n=10)
Collect/NoView/Int64UpDownCounter/10/Attributes/0-32                      362.9n ±  2%   359.3n ±  2%        ~ (p=0.631 n=10)
Collect/NoView/Int64UpDownCounter/10/Attributes/1-32                      355.2n ±  3%   357.6n ±  3%        ~ (p=0.725 n=10)
Collect/NoView/Int64UpDownCounter/10/Attributes/10-32                     356.8n ±  3%   360.0n ±  3%        ~ (p=0.631 n=10)
Collect/NoView/Float64UpDownCounter/1/Attributes/0-32                     355.1n ±  4%   361.6n ±  5%        ~ (p=0.128 n=10)
Collect/NoView/Float64UpDownCounter/1/Attributes/1-32                     373.5n ±  6%   369.8n ±  3%        ~ (p=0.853 n=10)
Collect/NoView/Float64UpDownCounter/1/Attributes/10-32                    358.1n ±  4%   371.3n ±  3%   +3.70% (p=0.011 n=10)
Collect/NoView/Float64UpDownCounter/10/Attributes/0-32                    359.1n ±  3%   419.8n ±  8%  +16.93% (p=0.000 n=10)
Collect/NoView/Float64UpDownCounter/10/Attributes/1-32                    363.9n ±  6%   410.6n ±  4%  +12.83% (p=0.000 n=10)
Collect/NoView/Float64UpDownCounter/10/Attributes/10-32                   360.1n ±  3%   394.2n ±  4%   +9.47% (p=0.000 n=10)
Collect/NoView/Int64Histogram/1/Attributes/0-32                           337.6n ±  6%   360.7n ±  8%        ~ (p=0.123 n=10)
Collect/NoView/Int64Histogram/1/Attributes/1-32                           348.6n ±  4%   352.3n ±  4%        ~ (p=0.305 n=10)
Collect/NoView/Int64Histogram/1/Attributes/10-32                          338.9n ±  2%   333.2n ±  3%        ~ (p=0.239 n=10)
Collect/NoView/Int64Histogram/10/Attributes/0-32                          344.6n ±  4%   346.8n ±  4%        ~ (p=1.000 n=10)
Collect/NoView/Int64Histogram/10/Attributes/1-32                          348.7n ±  6%   354.6n ±  4%        ~ (p=0.424 n=10)
Collect/NoView/Int64Histogram/10/Attributes/10-32                         348.2n ±  6%   357.0n ±  4%        ~ (p=0.315 n=10)
Collect/NoView/Float64Histogram/1/Attributes/0-32                         341.0n ±  7%   342.6n ±  5%        ~ (p=0.644 n=10)
Collect/NoView/Float64Histogram/1/Attributes/1-32                         349.8n ±  6%   340.1n ±  2%        ~ (p=0.190 n=10)
Collect/NoView/Float64Histogram/1/Attributes/10-32                        343.9n ±  6%   345.8n ±  5%        ~ (p=0.796 n=10)
Collect/NoView/Float64Histogram/10/Attributes/0-32                        337.4n ±  6%   332.4n ±  6%        ~ (p=0.075 n=10)
Collect/NoView/Float64Histogram/10/Attributes/1-32                        349.8n ±  4%   340.2n ±  9%        ~ (p=0.529 n=10)
Collect/NoView/Float64Histogram/10/Attributes/10-32                       343.8n ±  4%   335.3n ±  4%        ~ (p=0.165 n=10)
Collect/NoView/Int64ObservableCounter/Attributes/0-32                     1.732µ ±  3%   1.654µ ±  3%   -4.50% (p=0.002 n=10)
Collect/NoView/Int64ObservableCounter/Attributes/1-32                     1.793µ ±  4%   1.692µ ±  3%   -5.63% (p=0.001 n=10)
Collect/NoView/Int64ObservableCounter/Attributes/10-32                    2.379µ ±  4%   2.190µ ±  5%   -7.96% (p=0.000 n=10)
Collect/NoView/Float64ObservableCounter/Attributes/0-32                   1.710µ ±  5%   1.646µ ±  1%   -3.77% (p=0.000 n=10)
Collect/NoView/Float64ObservableCounter/Attributes/1-32                   1.936µ ±  9%   1.750µ ±  3%   -9.61% (p=0.002 n=10)
Collect/NoView/Float64ObservableCounter/Attributes/10-32                  2.385µ ±  3%   2.145µ ±  2%  -10.06% (p=0.000 n=10)
Collect/NoView/Int64ObservableUpDownCounter/Attributes/0-32               1.669µ ±  3%   1.687µ ±  2%        ~ (p=0.225 n=10)
Collect/NoView/Int64ObservableUpDownCounter/Attributes/1-32               1.811µ ±  2%   1.796µ ±  5%        ~ (p=0.644 n=10)
Collect/NoView/Int64ObservableUpDownCounter/Attributes/10-32              2.337µ ±  5%   2.226µ ±  8%   -4.73% (p=0.037 n=10)
Collect/NoView/Float64ObservableUpDownCounter/Attributes/0-32             1.702µ ±  3%   1.703µ ±  4%        ~ (p=0.725 n=10)
Collect/NoView/Float64ObservableUpDownCounter/Attributes/1-32             1.839µ ±  4%   1.722µ ±  2%   -6.39% (p=0.000 n=10)
Collect/NoView/Float64ObservableUpDownCounter/Attributes/10-32            2.401µ ±  4%   2.149µ ±  3%  -10.50% (p=0.000 n=10)
Collect/NoView/Int64ObservableGauge/Attributes/0-32                       1.702µ ±  5%   1.656µ ±  4%        ~ (p=0.075 n=10)
Collect/NoView/Int64ObservableGauge/Attributes/1-32                       1.847µ ±  5%   1.757µ ±  2%   -4.87% (p=0.000 n=10)
Collect/NoView/Int64ObservableGauge/Attributes/10-32                      2.438µ ±  4%   2.200µ ±  3%   -9.76% (p=0.000 n=10)
Collect/NoView/Float64ObservableGauge/Attributes/0-32                     1.753µ ±  6%   1.681µ ±  4%        ~ (p=0.138 n=10)
Collect/NoView/Float64ObservableGauge/Attributes/1-32                     1.808µ ±  3%   1.747µ ±  3%   -3.37% (p=0.011 n=10)
Collect/NoView/Float64ObservableGauge/Attributes/10-32                    2.365µ ±  7%   2.251µ ±  6%   -4.84% (p=0.035 n=10)
Collect/DropView/Int64Counter/1/Attributes/0-32                           41.35n ±  4%   42.08n ±  4%        ~ (p=0.075 n=10)
Collect/DropView/Int64Counter/1/Attributes/1-32                           40.80n ±  8%   42.81n ±  5%        ~ (p=0.247 n=10)
Collect/DropView/Int64Counter/1/Attributes/10-32                          40.37n ±  6%   43.97n ±  7%   +8.92% (p=0.007 n=10)
Collect/DropView/Int64Counter/10/Attributes/0-32                          40.80n ±  3%   43.60n ±  6%   +6.88% (p=0.000 n=10)
Collect/DropView/Int64Counter/10/Attributes/1-32                          41.67n ± 16%   42.91n ±  2%        ~ (p=0.353 n=10)
Collect/DropView/Int64Counter/10/Attributes/10-32                         41.80n ±  6%   40.89n ±  5%        ~ (p=0.315 n=10)
Collect/DropView/Float64Counter/1/Attributes/0-32                         44.37n ±  7%   40.29n ±  4%   -9.21% (p=0.000 n=10)
Collect/DropView/Float64Counter/1/Attributes/1-32                         41.23n ±  8%   40.89n ±  3%        ~ (p=0.670 n=10)
Collect/DropView/Float64Counter/1/Attributes/10-32                        42.00n ±  7%   41.31n ±  7%        ~ (p=0.481 n=10)
Collect/DropView/Float64Counter/10/Attributes/0-32                        44.02n ±  8%   40.05n ±  3%   -9.02% (p=0.001 n=10)
Collect/DropView/Float64Counter/10/Attributes/1-32                        44.88n ±  7%   41.66n ±  3%   -7.16% (p=0.009 n=10)
Collect/DropView/Float64Counter/10/Attributes/10-32                       42.01n ±  6%   40.42n ±  3%   -3.79% (p=0.009 n=10)
Collect/DropView/Int64UpDownCounter/1/Attributes/0-32                     41.64n ±  2%   40.36n ±  4%        ~ (p=0.075 n=10)
Collect/DropView/Int64UpDownCounter/1/Attributes/1-32                     41.10n ±  6%   41.88n ±  5%        ~ (p=0.436 n=10)
Collect/DropView/Int64UpDownCounter/1/Attributes/10-32                    45.99n ± 12%   42.09n ±  4%        ~ (p=0.123 n=10)
Collect/DropView/Int64UpDownCounter/10/Attributes/0-32                    40.27n ±  4%   43.81n ± 62%        ~ (p=0.247 n=10)
Collect/DropView/Int64UpDownCounter/10/Attributes/1-32                    41.73n ±  9%   37.91n ±  2%   -9.15% (p=0.000 n=10)
Collect/DropView/Int64UpDownCounter/10/Attributes/10-32                   41.48n ±  4%   38.14n ±  2%   -8.06% (p=0.000 n=10)
Collect/DropView/Float64UpDownCounter/1/Attributes/0-32                   40.91n ±  4%   37.53n ±  2%   -8.26% (p=0.000 n=10)
Collect/DropView/Float64UpDownCounter/1/Attributes/1-32                   40.65n ±  5%   39.25n ±  5%   -3.46% (p=0.005 n=10)
Collect/DropView/Float64UpDownCounter/1/Attributes/10-32                  40.86n ±  3%   40.16n ±  6%        ~ (p=0.592 n=10)
Collect/DropView/Float64UpDownCounter/10/Attributes/0-32                  40.29n ±  4%   40.32n ±  7%        ~ (p=0.754 n=10)
Collect/DropView/Float64UpDownCounter/10/Attributes/1-32                  39.74n ±  2%   41.26n ±  8%   +3.81% (p=0.004 n=10)
Collect/DropView/Float64UpDownCounter/10/Attributes/10-32                 40.10n ±  3%   40.16n ±  6%        ~ (p=0.739 n=10)
Collect/DropView/Int64Histogram/1/Attributes/0-32                         40.46n ±  4%   41.70n ±  6%   +3.04% (p=0.043 n=10)
Collect/DropView/Int64Histogram/1/Attributes/1-32                         40.96n ±  5%   41.42n ±  4%        ~ (p=0.255 n=10)
Collect/DropView/Int64Histogram/1/Attributes/10-32                        40.09n ±  3%   41.68n ±  3%   +3.97% (p=0.004 n=10)
Collect/DropView/Int64Histogram/10/Attributes/0-32                        40.13n ±  4%   39.95n ±  5%        ~ (p=0.579 n=10)
Collect/DropView/Int64Histogram/10/Attributes/1-32                        39.46n ±  2%   40.07n ±  7%        ~ (p=0.072 n=10)
Collect/DropView/Int64Histogram/10/Attributes/10-32                       39.55n ±  4%   40.43n ±  3%        ~ (p=0.247 n=10)
Collect/DropView/Float64Histogram/1/Attributes/0-32                       39.18n ±  4%   40.98n ±  3%   +4.58% (p=0.018 n=10)
Collect/DropView/Float64Histogram/1/Attributes/1-32                       42.26n ±  3%   44.50n ±  7%   +5.31% (p=0.029 n=10)
Collect/DropView/Float64Histogram/1/Attributes/10-32                      41.32n ±  5%   46.05n ±  8%  +11.45% (p=0.000 n=10)
Collect/DropView/Float64Histogram/10/Attributes/0-32                      43.52n ±  9%   47.48n ±  8%   +9.08% (p=0.029 n=10)
Collect/DropView/Float64Histogram/10/Attributes/1-32                      41.98n ±  5%   40.90n ±  3%        ~ (p=0.105 n=10)
Collect/DropView/Float64Histogram/10/Attributes/10-32                     41.73n ± 15%   41.01n ±  3%   -1.74% (p=0.012 n=10)
Collect/DropView/Int64ObservableCounter/Attributes/0-32                   40.68n ±  6%   42.02n ± 17%        ~ (p=0.063 n=10)
Collect/DropView/Int64ObservableCounter/Attributes/1-32                   39.40n ±  3%   40.62n ±  6%   +3.10% (p=0.043 n=10)
Collect/DropView/Int64ObservableCounter/Attributes/10-32                  40.43n ±  2%   44.67n ±  7%  +10.50% (p=0.000 n=10)
Collect/DropView/Float64ObservableCounter/Attributes/0-32                 40.26n ±  3%   43.34n ±  6%   +7.64% (p=0.000 n=10)
Collect/DropView/Float64ObservableCounter/Attributes/1-32                 42.61n ±  5%   41.40n ±  6%        ~ (p=0.105 n=10)
Collect/DropView/Float64ObservableCounter/Attributes/10-32                40.04n ±  8%   40.89n ±  4%        ~ (p=0.897 n=10)
Collect/DropView/Int64ObservableUpDownCounter/Attributes/0-32             40.62n ±  4%   40.62n ±  4%        ~ (p=0.839 n=10)
Collect/DropView/Int64ObservableUpDownCounter/Attributes/1-32             40.68n ±  5%   40.27n ±  6%        ~ (p=0.927 n=10)
Collect/DropView/Int64ObservableUpDownCounter/Attributes/10-32            40.48n ±  4%   41.49n ±  6%        ~ (p=0.190 n=10)
Collect/DropView/Float64ObservableUpDownCounter/Attributes/0-32           40.71n ±  3%   42.46n ±  6%   +4.31% (p=0.019 n=10)
Collect/DropView/Float64ObservableUpDownCounter/Attributes/1-32           40.69n ±  4%   39.65n ±  5%        ~ (p=0.123 n=10)
Collect/DropView/Float64ObservableUpDownCounter/Attributes/10-32          40.77n ± 11%   40.11n ±  2%        ~ (p=0.579 n=10)
Collect/DropView/Int64ObservableGauge/Attributes/0-32                     40.52n ±  4%   40.76n ±  3%        ~ (p=0.853 n=10)
Collect/DropView/Int64ObservableGauge/Attributes/1-32                     39.66n ±  7%   39.66n ±  5%        ~ (p=0.739 n=10)
Collect/DropView/Int64ObservableGauge/Attributes/10-32                    40.04n ±  6%   39.76n ±  7%        ~ (p=0.481 n=10)
Collect/DropView/Float64ObservableGauge/Attributes/0-32                   39.56n ±  2%   39.84n ±  3%        ~ (p=0.447 n=10)
Collect/DropView/Float64ObservableGauge/Attributes/1-32                   40.36n ±  3%   40.66n ±  4%        ~ (p=0.853 n=10)
Collect/DropView/Float64ObservableGauge/Attributes/10-32                  40.11n ±  8%   39.78n ±  3%        ~ (p=0.392 n=10)
Collect/AttrFilterView/Int64Counter/1/Attributes/0-32                     360.2n ±  3%   355.8n ±  3%        ~ (p=0.424 n=10)
Collect/AttrFilterView/Int64Counter/1/Attributes/1-32                     352.9n ±  2%   352.7n ±  3%        ~ (p=0.753 n=10)
Collect/AttrFilterView/Int64Counter/1/Attributes/10-32                    363.2n ±  4%   358.7n ±  2%        ~ (p=0.055 n=10)
Collect/AttrFilterView/Int64Counter/10/Attributes/0-32                    363.0n ±  3%   360.9n ±  4%        ~ (p=0.796 n=10)
Collect/AttrFilterView/Int64Counter/10/Attributes/1-32                    374.6n ±  5%   365.4n ±  5%        ~ (p=0.271 n=10)
Collect/AttrFilterView/Int64Counter/10/Attributes/10-32                   364.9n ±  1%   359.6n ±  6%        ~ (p=0.165 n=10)
Collect/AttrFilterView/Float64Counter/1/Attributes/0-32                   363.2n ±  3%   360.1n ±  4%        ~ (p=0.529 n=10)
Collect/AttrFilterView/Float64Counter/1/Attributes/1-32                   370.1n ±  1%   357.9n ±  4%   -3.28% (p=0.043 n=10)
Collect/AttrFilterView/Float64Counter/1/Attributes/10-32                  359.3n ±  2%   371.2n ±  8%        ~ (p=0.052 n=10)
Collect/AttrFilterView/Float64Counter/10/Attributes/0-32                  354.8n ±  2%   362.4n ±  3%        ~ (p=0.123 n=10)
Collect/AttrFilterView/Float64Counter/10/Attributes/1-32                  357.5n ±  2%   356.8n ±  3%        ~ (p=0.724 n=10)
Collect/AttrFilterView/Float64Counter/10/Attributes/10-32                 355.9n ±  3%   361.9n ± 51%        ~ (p=0.739 n=10)
Collect/AttrFilterView/Int64UpDownCounter/1/Attributes/0-32               356.5n ±  2%   333.0n ±  1%   -6.60% (p=0.000 n=10)
Collect/AttrFilterView/Int64UpDownCounter/1/Attributes/1-32               354.5n ±  3%   330.9n ±  1%   -6.66% (p=0.000 n=10)
Collect/AttrFilterView/Int64UpDownCounter/1/Attributes/10-32              353.5n ±  1%   332.0n ±  1%   -6.10% (p=0.000 n=10)
Collect/AttrFilterView/Int64UpDownCounter/10/Attributes/0-32              359.8n ±  1%   331.3n ±  2%   -7.89% (p=0.000 n=10)
Collect/AttrFilterView/Int64UpDownCounter/10/Attributes/1-32              366.9n ±  2%   331.3n ±  2%   -9.68% (p=0.000 n=10)
Collect/AttrFilterView/Int64UpDownCounter/10/Attributes/10-32             364.4n ±  3%   332.1n ±  2%   -8.89% (p=0.000 n=10)
Collect/AttrFilterView/Float64UpDownCounter/1/Attributes/0-32             353.4n ±  4%   331.1n ±  2%   -6.32% (p=0.000 n=10)
Collect/AttrFilterView/Float64UpDownCounter/1/Attributes/1-32             356.1n ±  2%   333.7n ±  2%   -6.30% (p=0.000 n=10)
Collect/AttrFilterView/Float64UpDownCounter/1/Attributes/10-32            352.9n ±  4%   333.8n ±  1%   -5.40% (p=0.000 n=10)
Collect/AttrFilterView/Float64UpDownCounter/10/Attributes/0-32            357.2n ±  4%   340.4n ±  4%   -4.68% (p=0.015 n=10)
Collect/AttrFilterView/Float64UpDownCounter/10/Attributes/1-32            361.4n ±  2%   361.1n ±  1%        ~ (p=0.853 n=10)
Collect/AttrFilterView/Float64UpDownCounter/10/Attributes/10-32           368.2n ±  3%   355.4n ±  2%   -3.48% (p=0.002 n=10)
Collect/AttrFilterView/Int64Histogram/1/Attributes/0-32                   344.2n ±  4%   333.7n ±  6%        ~ (p=0.593 n=10)
Collect/AttrFilterView/Int64Histogram/1/Attributes/1-32                   372.2n ±  7%   338.7n ±  8%   -9.00% (p=0.009 n=10)
Collect/AttrFilterView/Int64Histogram/1/Attributes/10-32                  350.9n ±  5%   346.8n ±  5%        ~ (p=0.853 n=10)
Collect/AttrFilterView/Int64Histogram/10/Attributes/0-32                  350.6n ±  4%   337.7n ±  5%        ~ (p=0.075 n=10)
Collect/AttrFilterView/Int64Histogram/10/Attributes/1-32                  346.8n ± 11%   340.9n ±  3%        ~ (p=0.093 n=10)
Collect/AttrFilterView/Int64Histogram/10/Attributes/10-32                 337.6n ±  3%   358.6n ±  5%   +6.24% (p=0.005 n=10)
Collect/AttrFilterView/Float64Histogram/1/Attributes/0-32                 344.9n ±  6%   338.3n ±  5%        ~ (p=0.184 n=10)
Collect/AttrFilterView/Float64Histogram/1/Attributes/1-32                 343.1n ±  5%   336.4n ±  3%        ~ (p=0.436 n=10)
Collect/AttrFilterView/Float64Histogram/1/Attributes/10-32                341.1n ± 12%   343.6n ±  2%        ~ (p=0.529 n=10)
Collect/AttrFilterView/Float64Histogram/10/Attributes/0-32                337.7n ±  5%   335.1n ±  5%        ~ (p=0.517 n=10)
Collect/AttrFilterView/Float64Histogram/10/Attributes/1-32                337.9n ±  4%   335.1n ±  4%        ~ (p=0.481 n=10)
Collect/AttrFilterView/Float64Histogram/10/Attributes/10-32               332.4n ±  2%   335.0n ±  4%        ~ (p=1.000 n=10)
Collect/AttrFilterView/Int64ObservableCounter/Attributes/0-32             1.759µ ±  5%   1.687µ ±  3%   -4.09% (p=0.029 n=10)
Collect/AttrFilterView/Int64ObservableCounter/Attributes/1-32             1.823µ ±  3%   1.861µ ± 21%        ~ (p=0.218 n=10)
Collect/AttrFilterView/Int64ObservableCounter/Attributes/10-32            2.336µ ±  2%   3.209µ ± 10%  +37.40% (p=0.000 n=10)
Collect/AttrFilterView/Float64ObservableCounter/Attributes/0-32           1.709µ ±  5%   2.041µ ±  6%  +19.46% (p=0.000 n=10)
Collect/AttrFilterView/Float64ObservableCounter/Attributes/1-32           1.858µ ±  4%   2.142µ ±  8%  +15.29% (p=0.000 n=10)
Collect/AttrFilterView/Float64ObservableCounter/Attributes/10-32          2.323µ ± 14%   2.804µ ± 14%  +20.68% (p=0.000 n=10)
Collect/AttrFilterView/Int64ObservableUpDownCounter/Attributes/0-32       1.708µ ±  6%   1.860µ ±  3%   +8.90% (p=0.001 n=10)
Collect/AttrFilterView/Int64ObservableUpDownCounter/Attributes/1-32       1.808µ ±  5%   2.118µ ± 22%  +17.18% (p=0.002 n=10)
Collect/AttrFilterView/Int64ObservableUpDownCounter/Attributes/10-32      2.437µ ±  5%   3.164µ ±  9%  +29.81% (p=0.000 n=10)
Collect/AttrFilterView/Float64ObservableUpDownCounter/Attributes/0-32     1.730µ ±  7%   2.474µ ±  8%  +43.02% (p=0.000 n=10)
Collect/AttrFilterView/Float64ObservableUpDownCounter/Attributes/1-32     1.983µ ± 13%   2.820µ ± 27%  +42.21% (p=0.000 n=10)
Collect/AttrFilterView/Float64ObservableUpDownCounter/Attributes/10-32    2.449µ ±  8%   2.906µ ± 12%  +18.66% (p=0.005 n=10)
Collect/AttrFilterView/Int64ObservableGauge/Attributes/0-32               1.742µ ±  5%   1.780µ ±  5%        ~ (p=0.314 n=10)
Collect/AttrFilterView/Int64ObservableGauge/Attributes/1-32               1.907µ ± 10%   1.854µ ±  5%        ~ (p=0.271 n=10)
Collect/AttrFilterView/Int64ObservableGauge/Attributes/10-32              2.436µ ±  5%   2.470µ ±  8%        ~ (p=0.739 n=10)
Collect/AttrFilterView/Float64ObservableGauge/Attributes/0-32             1.797µ ± 10%   1.748µ ±  6%        ~ (p=0.424 n=10)
Collect/AttrFilterView/Float64ObservableGauge/Attributes/1-32             1.882µ ±  3%   1.796µ ±  5%   -4.54% (p=0.007 n=10)
Collect/AttrFilterView/Float64ObservableGauge/Attributes/10-32            2.483µ ±  6%   2.306µ ±  5%   -7.13% (p=0.007 n=10)
Exemplars/Int64Counter/32-32                                              31.68µ ±  1%   26.79µ ±  3%  -15.44% (p=0.000 n=10)
Exemplars/Int64Histogram/32-32                                            23.64µ ±  3%   20.24µ ±  4%  -14.39% (p=0.000 n=10)
Instrument/instrumentImpl/aggregate-32                                    3.248µ ± 11%   2.947µ ±  6%   -9.27% (p=0.022 n=10)
Instrument/observable/observe-32                                          1.926µ ±  3%   2.049µ ±  1%   +6.39% (p=0.001 n=10)
ManualReader/Collect-32                                                   496.6n ±  1%   520.8n ±  1%   +4.86% (p=0.000 n=10)
InstrumentCreation-32                                                     1.323µ ±  5%   1.334µ ±  4%        ~ (p=0.424 n=10)
PeriodicReader/Collect-32                                                 522.9n ±  2%   524.6n ±  3%        ~ (p=0.927 n=10)
geomean                       

@ysolomchenko
Copy link
Copy Markdown
Contributor Author

updated Changelog entry for highlighting cardinality limit as a breaking change.
f3178f2

@pellared
Copy link
Copy Markdown
Member

pellared commented Jul 15, 2025

Given the performance overhead and the worry of breaking users I think it is reasonable to keep the "no limit" as default.

If there is still a will to change the default value, we can create a separate issue for tracking as proposed here.

Comment thread sdk/metric/config.go Outdated
@cijothomas
Copy link
Copy Markdown
Member

Given the performance overhead and the worry of breaking users I think it is reasonable to keep the "no limit" as default.

If there is still a will to change the default value, we can create a separate issue for tracking as proposed here.

SyncMeasure/NoView/Int64Counter/Attributes/0-32 55.98n ± 3% 45.06n ± 2% -19.49% (p=0.000 n=10)

Out of curiosity, what is the reason why enforcing cardinality limit causes a metric update to take additional 10ns? (Based on my experience implementing this in .NET, Rust there was no measurable overhead/no overhead at all. When a new attribute combination is seen, a check must be done to ensure if adding this would cross the limit. But for updating existing attributes, there is no change (i.e not even a single extra instruction)...)

Comment thread sdk/metric/config.go Outdated
@pellared
Copy link
Copy Markdown
Member

Given the performance overhead and the worry of breaking users I think it is reasonable to keep the "no limit" as default.
If there is still a will to change the default value, we can create a separate issue for tracking as proposed here.

SyncMeasure/NoView/Int64Counter/Attributes/0-32 55.98n ± 3% 45.06n ± 2% -19.49% (p=0.000 n=10)

Out of curiosity, what is the reason why enforcing cardinality limit causes a metric update to take additional 10ns? (Based on my experience implementing this in .NET, Rust there was no measurable overhead/no overhead at all. When a new attribute combination is seen, a check must be done to ensure if adding this would cross the limit. But for updating existing attributes, there is no change (i.e not even a single extra instruction)...)

I created #7035 for tracking as nobody responded so far.

@pellared pellared requested review from MrAlias and dashpole July 16, 2025 08:20
Comment thread sdk/metric/config.go Outdated
@MrAlias
Copy link
Copy Markdown
Contributor

MrAlias commented Jul 17, 2025

We are going to track the discussion about the default in a follow-up issue. Going to merge this to progress the work on adding this feature.

@pellared pellared merged commit c23a066 into open-telemetry:main Jul 21, 2025
33 checks passed
@MrAlias MrAlias added this to the v1.38.0 milestone Aug 20, 2025
@MrAlias MrAlias mentioned this pull request Aug 29, 2025
MrAlias added a commit that referenced this pull request Aug 29, 2025
This release is the last to support [Go 1.23].
The next release will require at least [Go 1.24].

### Added

- Add native histogram exemplar support in
`go.opentelemetry.io/otel/exporters/prometheus`. (#6772)
- Add template attribute functions to the
`go.opentelmetry.io/otel/semconv/v1.34.0` package. (#6939)
  - `ContainerLabel`
  - `DBOperationParameter`
  - `DBSystemParameter`
  - `HTTPRequestHeader`
  - `HTTPResponseHeader`
  - `K8SCronJobAnnotation`
  - `K8SCronJobLabel`
  - `K8SDaemonSetAnnotation`
  - `K8SDaemonSetLabel`
  - `K8SDeploymentAnnotation`
  - `K8SDeploymentLabel`
  - `K8SJobAnnotation`
  - `K8SJobLabel`
  - `K8SNamespaceAnnotation`
  - `K8SNamespaceLabel`
  - `K8SNodeAnnotation`
  - `K8SNodeLabel`
  - `K8SPodAnnotation`
  - `K8SPodLabel`
  - `K8SReplicaSetAnnotation`
  - `K8SReplicaSetLabel`
  - `K8SStatefulSetAnnotation`
  - `K8SStatefulSetLabel`
  - `ProcessEnvironmentVariable`
  - `RPCConnectRPCRequestMetadata`
  - `RPCConnectRPCResponseMetadata`
  - `RPCGRPCRequestMetadata`
  - `RPCGRPCResponseMetadata`
- Add `ErrorType` attribute helper function to the
`go.opentelmetry.io/otel/semconv/v1.34.0` package. (#6962)
- Add `WithAllowKeyDuplication` in `go.opentelemetry.io/otel/sdk/log`
which can be used to disable deduplication for log records. (#6968)
- Add `WithCardinalityLimit` option to configure the cardinality limit
in `go.opentelemetry.io/otel/sdk/metric`. (#6996, #7065, #7081, #7164,
#7165, #7179)
- Add `Clone` method to `Record` in `go.opentelemetry.io/otel/log` that
returns a copy of the record with no shared state. (#7001)
- Add experimental self-observability span and batch span processor
metrics in `go.opentelemetry.io/otel/sdk/trace`. Check the
`go.opentelemetry.io/otel/sdk/trace/internal/x` package documentation
for more information. (#7027, #6393, #7209)
- The `go.opentelemetry.io/otel/semconv/v1.36.0` package. The package
contains semantic conventions from the `v1.36.0` version of the
OpenTelemetry Semantic Conventions. See the [migration
documentation](./semconv/v1.36.0/MIGRATION.md) for information on how to
upgrade from `go.opentelemetry.io/otel/semconv/v1.34.0.`(#7032, #7041)
- Add support for configuring Prometheus name translation using
`WithTranslationStrategy` option in
`go.opentelemetry.io/otel/exporters/prometheus`. The current default
translation strategy when UTF-8 mode is enabled is
`NoUTF8EscapingWithSuffixes`, but a future release will change the
default strategy to `UnderscoreEscapingWithSuffixes` for compliance with
the specification. (#7111)
- Add experimental self-observability log metrics in
`go.opentelemetry.io/otel/sdk/log`. Check the
`go.opentelemetry.io/otel/sdk/log/internal/x` package documentation for
more information. (#7121)
- Add experimental self-observability trace exporter metrics in
`go.opentelemetry.io/otel/exporters/stdout/stdouttrace`. Check the
`go.opentelemetry.io/otel/exporters/stdout/stdouttrace/internal/x`
package documentation for more information. (#7133)
- Support testing of [Go 1.25]. (#7187)
- The `go.opentelemetry.io/otel/semconv/v1.37.0` package. The package
contains semantic conventions from the `v1.37.0` version of the
OpenTelemetry Semantic Conventions. See the [migration
documentation](./semconv/v1.37.0/MIGRATION.md) for information on how to
upgrade from `go.opentelemetry.io/otel/semconv/v1.36.0.`(#7254)

### Changed

- Optimize `TraceIDFromHex` and `SpanIDFromHex` in
`go.opentelemetry.io/otel/sdk/trace`. (#6791)
- Change `AssertEqual` in `go.opentelemetry.io/otel/log/logtest` to
accept `TestingT` in order to support benchmarks and fuzz tests. (#6908)
- Change `DefaultExemplarReservoirProviderSelector` in
`go.opentelemetry.io/otel/sdk/metric` to use `runtime.GOMAXPROCS(0)`
instead of `runtime.NumCPU()` for the `FixedSizeReservoirProvider`
default size. (#7094)

### Fixed

- `SetBody` method of `Record` in `go.opentelemetry.io/otel/sdk/log` now
deduplicates key-value collections (`log.Value` of `log.KindMap` from
`go.opentelemetry.io/otel/log`). (#7002)
- Fix `go.opentelemetry.io/otel/exporters/prometheus` to not append a
suffix if it's already present in metric name. (#7088)
- Fix the `go.opentelemetry.io/otel/exporters/stdout/stdouttrace`
self-observability component type and name. (#7195)
- Fix partial export count metric in
`go.opentelemetry.io/otel/exporters/stdout/stdouttrace`. (#7199)

### Deprecated

- Deprecate `WithoutUnits` and `WithoutCounterSuffixes` options,
preferring `WithTranslationStrategy` instead. (#7111)
- Deprecate support for `OTEL_GO_X_CARDINALITY_LIMIT` environment
variable in `go.opentelemetry.io/otel/sdk/metric`. Use
`WithCardinalityLimit` option instead. (#7166)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Define Cardinality Limit Configuration Options

6 participants