Add basic view to docs (#2460)

This commit is contained in:
Cijo Thomas 2021-10-06 16:57:57 -07:00 committed by GitHub
parent 7fc0cbb2ac
commit 0998eeddb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 3 deletions

View File

@ -40,9 +40,9 @@ public class Program
.AddView(instrumentName: "MyCounterCustomTags", new MetricStreamConfiguration() { TagKeys = new string[] { "tag1", "tag2" } })
// Drop the instrument "MyCounterDrop".
.AddView(instrumentName: "MyCounterDrop", new MetricStreamConfiguration() { Aggregation = Aggregation.Drop })
.AddView(instrumentName: "MyCounterDrop", MetricStreamConfiguration.Drop)
// Advanced selection criteria and config via Func<Instrument, AggregationConfig>
// Advanced selection criteria and config via Func<Instrument, MetricStreamConfiguration>
.AddView((instrument) =>
{
if (instrument.Meter.Name.Equals("CompanyA.ProductB.Library2") &&

View File

@ -98,7 +98,52 @@ the you can use `AddMeter("Abc.*")` to enable all meters whose name starts with
### View
// TODO
A
[View](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#view)
provides the ability to customize the metrics that are output by the SDK.
Following sections explains how to use this feature.
#### Rename an instrument
When SDK produces Metrics, the name of Metric is by default the name of the
instrument. View may be used to rename a metric to a different name. This is
particularly useful if there are conflicting instrument names, and you do not
own the instrument to create it with a different name.
```csharp
// Rename an instrument to new name.
.AddView(instrumentName: "MyCounter", name: "MyCounterRenamed")
```
See [Program.cs](./Program.cs) for a complete example.
#### Drop an instrument
When using `AddMeter` to add a Meter to the provider, all the instruments from
that `Meter` gets subscribed. Views can be used to selectively drop an
instrument from a Meter. If the goal is to drop every instrument from a `Meter`,
then it is recommended to simply not add that `Meter` using `AddMeter`.
```csharp
// Drop the instrument "MyCounterDrop".
.AddView(instrumentName: "MyCounterDrop", MetricStreamConfiguration.Drop)
```
```csharp
// Advanced selection criteria and config via Func<Instrument, MetricStreamConfiguration>
.AddView((instrument) =>
{
if (instrument.Meter.Name.Equals("CompanyA.ProductB.LibraryC") &&
instrument.Name.Equals("MyCounterDrop"))
{
return MetricStreamConfiguration.Drop;
}
return null;
})
```
See [Program.cs](./Program.cs) for a complete example.
### Instrumentation