Skip to content

Commit

Permalink
[docs-metrics] Add back SetMaxMetricPointsPerMetricStream example (#5493
Browse files Browse the repository at this point in the history
)
  • Loading branch information
CodeBlanch authored Mar 29, 2024
1 parent 39d960e commit e5ca93b
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions docs/metrics/customizing-the-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ Counter<long> MyFruitCounter = MyMeter.CreateCounter<long>("MyFruitCounter");
Counter<long> AnotherFruitCounter = MyMeter.CreateCounter<long>("AnotherFruitCounter");

using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter("*")
.AddMeter("MyCompany.MyProduct.MyLibrary")
.AddConsoleExporter()
.SetMaxMetricStreams(1) // The default value is 1000
.Build();
Expand All @@ -367,11 +367,31 @@ MyFruitCounter.Add(1, new("name", "apple"), new("color", "red"));
AnotherFruitCounter.Add(1, new("name", "apple"), new("color", "red"));
```

### Changing the cardinality limit for a MeterProvider

To set the default [cardinality limit](../README.md#cardinality-limits) for all
metrics managed by a given `MeterProvider`, use the
`MeterProviderBuilder.SetMaxMetricPointsPerMetricStream` extension:

> [!CAUTION]
> `MeterProviderBuilder.SetMaxMetricPointsPerMetricStream` is marked `Obsolete`
in pre-release builds and has been replaced by
`MetricStreamConfiguration.CardinalityLimit`. For details see:
[OTEL1003](../../diagnostics/experimental-apis/OTEL1003.md).

```csharp
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter("MyCompany.MyProduct.MyLibrary")
.SetMaxMetricPointsPerMetricStream(4000) // Note: The default value is 2000
.AddConsoleExporter()
.Build();
```

### Changing the cardinality limit for a Metric

To set the [cardinality limit](../README.md#cardinality-limits) for an
individual metric, use `MetricStreamConfiguration.CardinalityLimit` setting on
the View API:
individual metric, use the `MetricStreamConfiguration.CardinalityLimit` property
on the View API:

> [!NOTE]
> `MetricStreamConfiguration.CardinalityLimit` is an experimental API only
Expand Down

0 comments on commit e5ca93b

Please sign in to comment.