Skip to content

Commit cdf5378

Browse files
authored
docs: clarify MetricReaderOptions for metrics exporters (#6788)
1 parent 39cf140 commit cdf5378

File tree

2 files changed

+28
-2
lines changed
  • src
    • OpenTelemetry.Exporter.Console
    • OpenTelemetry.Exporter.OpenTelemetryProtocol

2 files changed

+28
-2
lines changed

src/OpenTelemetry.Exporter.Console/README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,33 @@ You can configure the `ConsoleExporter` through `Options` types properties
4040
and environment variables.
4141
The `Options` type setters take precedence over the environment variables.
4242

43+
### MetricReaderOptions (metrics)
44+
45+
For metrics, `AddConsoleExporter()` pairs the exporter with a
46+
`PeriodicExportingMetricReader`. Use `MetricReaderOptions` to configure
47+
temporality and export interval/timeout:
48+
49+
```csharp
50+
var meterProvider = Sdk.CreateMeterProviderBuilder()
51+
// rest of config not shown here.
52+
.AddConsoleExporter((_, metricReaderOptions) =>
53+
{
54+
metricReaderOptions.TemporalityPreference = MetricReaderTemporalityPreference.Delta;
55+
56+
metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 10_000;
57+
metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportTimeoutMilliseconds = 5_000;
58+
})
59+
.Build();
60+
```
61+
62+
See [`TestMetrics.cs`](../../examples/Console/TestMetrics.cs) for a runnable
63+
example.
64+
4365
## Environment Variables
4466

4567
The following environment variables can be used to override the default
4668
values of the `PeriodicExportingMetricReaderOptions`
47-
(following the [OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.12.0/specification/sdk-environment-variables.md#periodic-exporting-metricreader).
69+
(following the [OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#periodic-exporting-metricreader)).
4870

4971
| Environment variable | `PeriodicExportingMetricReaderOptions` property |
5072
| ------------------------------| ------------------------------------------------|

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,20 +394,24 @@ appBuilder.Services.Configure<LogRecordExportProcessorOptions>(
394394
### MetricReaderOptions
395395

396396
The `MetricReaderOptions` class may be used to configure reader settings for
397-
metrics:
397+
metrics (e.g. `TemporalityPreference` and `PeriodicExportingMetricReaderOptions`):
398398

399399
```csharp
400400
// Set via delegate using code:
401401
appBuilder.Services.AddOpenTelemetry()
402402
.WithMetrics(builder => builder.AddOtlpExporter((exporterOptions, readerOptions) =>
403403
{
404+
readerOptions.TemporalityPreference = MetricReaderTemporalityPreference.Delta;
404405
readerOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 10_000;
406+
readerOptions.PeriodicExportingMetricReaderOptions.ExportTimeoutMilliseconds = 5_000;
405407
}));
406408

407409
// Set via Options API using code:
408410
appBuilder.Services.Configure<MetricReaderOptions>(o =>
409411
{
412+
o.TemporalityPreference = MetricReaderTemporalityPreference.Delta;
410413
o.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 10_000;
414+
o.PeriodicExportingMetricReaderOptions.ExportTimeoutMilliseconds = 5_000;
411415
});
412416

413417
// Set via Options API using configuration:

0 commit comments

Comments
 (0)