-
Notifications
You must be signed in to change notification settings - Fork 848
[sdk-metrics] Obsolete SetMaxMetricPointsPerMetricStream + standarize on "Cardinality Limit" name #5328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[sdk-metrics] Obsolete SetMaxMetricPointsPerMetricStream + standarize on "Cardinality Limit" name #5328
Changes from 13 commits
0e5c749
ce0afe2
5730d14
9bfe6cc
ae6d742
ea6aace
975b90e
d79ca7c
51674e6
8b91bf3
e3eb786
c2f8f88
4596cf1
bab53c9
856446f
6d05f7b
f3218a5
1b6c2a4
ae5c68d
73df3ec
695eb66
f1b62b0
9064b7a
454bd17
87d5875
5cfbf04
c24e42c
8a6d2c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -367,85 +367,18 @@ MyFruitCounter.Add(1, new("name", "apple"), new("color", "red")); | |
| AnotherFruitCounter.Add(1, new("name", "apple"), new("color", "red")); | ||
| ``` | ||
|
|
||
| ### Changing maximum MetricPoints per MetricStream | ||
|
|
||
| A Metric stream can contain as many Metric points as the number of unique | ||
| combination of keys and values. To protect the SDK from unbounded memory usage, | ||
| SDK limits the maximum number of metric points per metric stream, to a default | ||
| of 2000. Once the limit is hit, any new key/value combination for that metric is | ||
| ignored. The SDK chooses the key/value combinations in the order in which they | ||
| are emitted. `SetMaxMetricPointsPerMetricStream` can be used to override the | ||
| default. | ||
|
|
||
| > [!NOTE] | ||
| > One `MetricPoint` is reserved for every `MetricStream` for the | ||
| special case where there is no key/value pair associated with the metric. The | ||
| maximum number of `MetricPoint`s has to accommodate for this special case. | ||
|
|
||
| Consider the below example. Here we set the maximum number of `MetricPoint`s | ||
| allowed to be `3`. This means that for every `MetricStream`, the SDK will export | ||
| measurements for up to `3` distinct key/value combinations of the metric. There | ||
| are two instruments published here: `MyFruitCounter` and `AnotherFruitCounter`. | ||
| There are two total `MetricStream`s created one for each of these instruments. | ||
| SDK will limit the maximum number of distinct key/value combinations for each of | ||
| these `MetricStream`s to `3`. | ||
|
|
||
| ```csharp | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics.Metrics; | ||
| using OpenTelemetry; | ||
| using OpenTelemetry.Metrics; | ||
|
|
||
| Counter<long> MyFruitCounter = MyMeter.CreateCounter<long>("MyFruitCounter"); | ||
| Counter<long> AnotherFruitCounter = MyMeter.CreateCounter<long>("AnotherFruitCounter"); | ||
|
|
||
| using var meterProvider = Sdk.CreateMeterProviderBuilder() | ||
| .AddMeter("*") | ||
| .AddConsoleExporter() | ||
| .SetMaxMetricPointsPerMetricStream(3) // The default value is 2000 | ||
| .Build(); | ||
|
|
||
| // There are four distinct key/value combinations emitted for `MyFruitCounter`: | ||
| // 1. No key/value pair | ||
| // 2. (name:apple, color:red) | ||
| // 3. (name:lemon, color:yellow) | ||
| // 4. (name:apple, color:green) | ||
|
|
||
| // Since the maximum number of `MetricPoint`s allowed is `3`, the SDK will only export measurements for the following three combinations: | ||
| // 1. No key/value pair | ||
| // 2. (name:apple, color:red) | ||
| // 3. (name:lemon, color:yellow) | ||
|
|
||
| MyFruitCounter.Add(1); // Exported (No key/value pair) | ||
| MyFruitCounter.Add(1, new("name", "apple"), new("color", "red")); // Exported | ||
| MyFruitCounter.Add(2, new("name", "lemon"), new("color", "yellow")); // Exported | ||
| MyFruitCounter.Add(1, new("name", "lemon"), new("color", "yellow")); // Exported | ||
| MyFruitCounter.Add(2, new("name", "apple"), new("color", "green")); // Not exported | ||
| MyFruitCounter.Add(5, new("name", "apple"), new("color", "red")); // Exported | ||
| MyFruitCounter.Add(4, new("name", "lemon"), new("color", "yellow")); // Exported | ||
|
|
||
| // There are four distinct key/value combinations emitted for `AnotherFruitCounter`: | ||
| // 1. (name:kiwi) | ||
| // 2. (name:banana, color:yellow) | ||
| // 3. (name:mango, color:yellow) | ||
| // 4. (name:banana, color:green) | ||
|
|
||
| // Since the maximum number of `MetricPoint`s allowed is `3`, the SDK will only export measurements for the following three combinations: | ||
| // 1. No key/value pair (This is a special case. The SDK reserves a `MetricPoint` for it even if it's not explicitly emitted.) | ||
| // 2. (name:kiwi) | ||
| // 3. (name:banana, color:yellow) | ||
|
|
||
| AnotherFruitCounter.Add(4, new KeyValuePair<string, object>("name", "kiwi")); // Exported | ||
| AnotherFruitCounter.Add(1, new("name", "banana"), new("color", "yellow")); // Exported | ||
| AnotherFruitCounter.Add(2, new("name", "mango"), new("color", "yellow")); // Not exported | ||
| AnotherFruitCounter.Add(1, new("name", "mango"), new("color", "yellow")); // Not exported | ||
| AnotherFruitCounter.Add(2, new("name", "banana"), new("color", "green")); // Not exported | ||
| AnotherFruitCounter.Add(5, new("name", "banana"), new("color", "yellow")); // Exported | ||
| AnotherFruitCounter.Add(4, new("name", "mango"), new("color", "yellow")); // Not exported | ||
|
Comment on lines
-408
to
-444
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @reyang I might have been too aggressive removing all of this. Do you still want it in there just showing the view instead of the global mechanism? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No strong opinion here. @utpilla might have different ideas. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @CodeBlanch We should keep the example here. People have found it useful to understand how configuring the cardinality would affect the export. |
||
| ``` | ||
|
|
||
| To set the [cardinality limit](../README.md#cardinality-limits) at individual | ||
| metric level, use `MetricStreamConfiguration.CardinalityLimit`: | ||
| ### Changing the cardinality limit for a Metric | ||
|
|
||
| A Metric contains many Metric points which are the number of unique combinations | ||
| of key/values recorded by an instrument. To protect the SDK from unbounded | ||
CodeBlanch marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| memory usage, there is a default limit of 2000 metric points per metric which | ||
| will be maintained at any given time. Once the limit is hit, any new key/value | ||
CodeBlanch marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| combination for a metric will be ignored. The SDK chooses the key/value | ||
reyang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| combinations in the order in which they are emitted. | ||
|
|
||
| To set the [cardinality limit](../README.md#cardinality-limits) for an | ||
| individual metric, use `MetricStreamConfiguration.CardinalityLimit` setting on | ||
CodeBlanch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| the View API: | ||
|
|
||
| ```csharp | ||
| var meterProvider = Sdk.CreateMeterProviderBuilder() | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -238,6 +238,9 @@ public static MeterProviderBuilder SetMaxMetricStreams(this MeterProviderBuilder | |||||
| /// <param name="meterProviderBuilder"><see cref="MeterProviderBuilder"/>.</param> | ||||||
| /// <param name="maxMetricPointsPerMetricStream">Maximum number of metric points allowed per metric stream.</param> | ||||||
| /// <returns>The supplied <see cref="MeterProviderBuilder"/> for chaining.</returns> | ||||||
| #if EXPOSE_EXPERIMENTAL_FEATURES | ||||||
| [Obsolete("Use MetricStreamConfiguration.CardinalityLimit via the AddView API instead. This method will be removed in a future version.")] | ||||||
reyang marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or combine.. removed in a future version, along with major version bump of the package. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not going to do this here because we use similar a bunch of places but good thing for a follow-up! |
||||||
| #endif | ||||||
| public static MeterProviderBuilder SetMaxMetricPointsPerMetricStream(this MeterProviderBuilder meterProviderBuilder, int maxMetricPointsPerMetricStream) | ||||||
| { | ||||||
| Guard.ThrowIfOutOfRange(maxMetricPointsPerMetricStream, min: 1); | ||||||
|
|
@@ -246,7 +249,7 @@ public static MeterProviderBuilder SetMaxMetricPointsPerMetricStream(this MeterP | |||||
| { | ||||||
| if (builder is MeterProviderBuilderSdk meterProviderBuilderSdk) | ||||||
| { | ||||||
| meterProviderBuilderSdk.SetMaxMetricPointsPerMetricStream(maxMetricPointsPerMetricStream); | ||||||
| meterProviderBuilderSdk.SetDefaultCardinalityLimit(maxMetricPointsPerMetricStream); | ||||||
| } | ||||||
| }); | ||||||
|
|
||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.