OpenTelemetry.Instrumentation.EventCounters 1.20.1-alpha.1
EventCounters Instrumentation for OpenTelemetry .NET
| Status | |
|---|---|
| Stability | Alpha |
| Code Owners | @hananiel, @mic-max |
This is an Instrumentation Library , which republishes EventCounters using OpenTelemetry Metrics API.
Steps to enable OpenTelemetry.Instrumentation.EventCounters
You can view an example project using EventCounters at
/examples/event-counters/Examples.EventCounters.
Step 1: Install Package
Add a reference to the
OpenTelemetry.Instrumentation.EventCounters
package.
dotnet add package OpenTelemetry.Instrumentation.EventCounters --prerelease
Step 2: Enable EventCounters Instrumentation
EventCounters instrumentation should be enabled at application startup using the
AddEventCountersInstrumentation extension on the MeterProviderBuilder:
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddEventCountersInstrumentation(options => {
options.RefreshIntervalSecs = 1;
options.AddEventSources("MyEventSource");
})
.AddPrometheusHttpListener()
.Build();
Additionally, the above snippet sets up the OpenTelemetry Prometheus exporter, which
requires adding the package
OpenTelemetry.Exporter.Prometheus
to the application.
When using dependency injection (Microsoft.Extensions.DependencyInjection),
EventCounters instrumentation can be registered using
AddOpenTelemetry().WithMetrics():
services.AddOpenTelemetry()
.WithMetrics(builder => builder
.AddEventCountersInstrumentation(options =>
{
options.RefreshIntervalSecs = 1;
options.AddEventSources("MyEventSource");
}));
Options can also be bound to configuration via
services.Configure<EventCountersInstrumentationOptions>(...).
Step 3: Create EventCounters
Learn about EventCounters in .NET .
EventSource eventSource = new("MyEventSource");
EventCounter eventCounter = new("MyEventCounterName", eventSource);
eventCounter.WriteMetric(0);
eventCounter.WriteMetric(1000);
PollingCounter pollingCounter = new("MyPollingCounterName", eventSource, () => new Random().NextDouble());
Notes
The metrics will only be available after EventCounterIntervalSec seconds.
Before that nothing will be exported, if anything is present at the Prometheus
metrics endpoint it is from a prior execution. This is more evident when using
longer polling intervals.
References
No packages depend on OpenTelemetry.Instrumentation.EventCounters.
.NET Standard 2.0
- Microsoft.Extensions.Options (>= 10.0.0)
- OpenTelemetry.Api.ProviderBuilderExtensions (>= 1.20.1 && < 2.0.0)
| Version | Downloads | Last updated |
|---|---|---|
| 1.20.1-alpha.1 | 1 | 10/27/2026 |
| 1.20.0-alpha.2 | 2 | 10/19/2026 |
| 1.20.0-alpha.1 | 2 | 10/19/2026 |
| 1.19.0-alpha.1 | 2 | 09/28/2026 |
| 1.18.0-alpha.1 | 3 | 09/06/2026 |
| 1.17.0-alpha.1 | 2 | 07/29/2026 |
| 1.16.0-alpha.1 | 2 | 07/29/2026 |
| 1.15.1-alpha.1 | 4 | 04/21/2026 |
| 1.15.0-alpha.1 | 10 | 01/25/2026 |
| 1.14.0-alpha.1 | 13 | 11/23/2025 |
| 1.13.0-alpha.1 | 11 | 10/25/2025 |
| 1.5.1-alpha.1 | 30 | 04/16/2025 |
| 1.0.0-alpha.2 | 16 | 06/08/2025 |
| 1.0.0-alpha.1 | 16 | 06/08/2025 |
| 0.1.0-alpha.1 | 14 | 06/08/2025 |