OpsCanary
observabilityprometheusPractitioner

Dual-Exporting .NET Metrics: Mastering OTLP and Prometheus

5 min read OpenTelemetry BlogSep 18, 2026Reviewed for accuracy
Share
PractitionerHands-on experience recommended

In today's complex applications, observability is crucial. Dual-exporting metrics using OTLP and Prometheus in .NET allows you to capture a wide range of metrics seamlessly. This setup not only enhances your monitoring capabilities but also provides flexibility in how you analyze and visualize your data.

Using the OpenTelemetry Prometheus exporter, you can export metrics to both Prometheus and another exporter, such as the OTLP exporter. The Prometheus exporter implements the OpenTelemetry Prometheus specification and exposes an HTTP scrape endpoint in your application. By utilizing the Meter class along with instruments like Counter<T>, Gauge<T>, and Histogram<T>, you can collect metrics without needing a dedicated Prometheus client. For instance, you can set up your metrics collection with just a few lines of code, integrating it directly into your application logic.

In production, be aware of the limitations. Some Prometheus features, like summary data types and native histograms, do not have direct equivalents in the Meter APIs and are unsupported. This could lead to gaps in your metrics if you're relying on those specific features. Additionally, ensure your configuration is correct, particularly when setting up the OTLP exporter endpoint. The last modification was noted on September 18, 2026, so keep an eye on updates for any changes in functionality or best practices.

Key takeaways

  • Utilize the Meter class to collect metrics without needing a dedicated Prometheus client.
  • Expose metrics through an HTTP scrape endpoint using the Prometheus exporter.
  • Configure the OTLP exporter with the correct endpoint and protocol for optimal performance.
  • Be aware of unsupported Prometheus features like summary data types and native histograms.
  • Stay updated on changes, as the last modification was noted on September 18, 2026.

Why it matters

Implementing dual-exporting for metrics enhances your observability stack, allowing for richer insights and better monitoring of application performance. This can lead to quicker troubleshooting and improved system reliability.

Code examples

csharp
1public class BlogPostComments
2{
3private readonly Meter _meter;
4private readonly Counter<long> _likes;
5public BlogPostComments(IMeterFactory meterFactory)
6{
7_meter = meterFactory.Create("OpenTelemetry.Blog");
8_likes = _meter.CreateCounter<long>("blog_post_likes");
9}
10public void BlogPostLiked(long id) => _likes.Add(1, new KeyValuePair<string, object?>("post_id", id));
11}
csharp
1using OpenTelemetry;
2using OpenTelemetry.Exporter;
3using OpenTelemetry.Metrics;
4var meterProvider = Sdk.CreateMeterProviderBuilder()
5.SetResourceBuilder(CreateResourceBuilder())
6.AddMeter("OpenTelemetry.Blog")
7.AddOtlpExporter()
8.AddPrometheusExporter()
9.Build();
csharp
1var builder = WebApplication.CreateBuilder(args);
2// Configure services here
3var app = builder.Build();
4// Configure other middleware here
5app.MapPrometheusScrapingEndpoint();
6app.Run();

When NOT to use this

The official docs don't call out specific anti-patterns here. Use your judgment based on your scale and requirements.

Want the complete reference?

Read official docs

Test what you just learned

Quiz questions written from this article

Take the quiz →
DigitalOcean Serverless InferenceSponsor

OpenAI & Anthropic-compatible inference API — no GPU provisioning needed. 55+ models, pay-per-token with no minimums. VPC + zero data retention by default.

Try Serverless Inference →

Get the daily digest

One email. 5 articles. Every morning.

No spam. Unsubscribe anytime.