OpenTelemetry.Exporter.Prometheus.AspNetCore 1.10.0-beta.1

Prefix Reserved
This is a prerelease version of OpenTelemetry.Exporter.Prometheus.AspNetCore.
dotnet add package OpenTelemetry.Exporter.Prometheus.AspNetCore --version 1.10.0-beta.1                
NuGet\Install-Package OpenTelemetry.Exporter.Prometheus.AspNetCore -Version 1.10.0-beta.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.10.0-beta.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OpenTelemetry.Exporter.Prometheus.AspNetCore --version 1.10.0-beta.1                
#r "nuget: OpenTelemetry.Exporter.Prometheus.AspNetCore, 1.10.0-beta.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install OpenTelemetry.Exporter.Prometheus.AspNetCore as a Cake Addin
#addin nuget:?package=OpenTelemetry.Exporter.Prometheus.AspNetCore&version=1.10.0-beta.1&prerelease

// Install OpenTelemetry.Exporter.Prometheus.AspNetCore as a Cake Tool
#tool nuget:?package=OpenTelemetry.Exporter.Prometheus.AspNetCore&version=1.10.0-beta.1&prerelease                

Prometheus Exporter AspNetCore for OpenTelemetry .NET

NuGet NuGet

An OpenTelemetry Prometheus exporter for configuring an ASP.NET Core application with an endpoint for Prometheus to scrape.

[!WARNING] This component is still under development due to a dependency on the experimental Prometheus and OpenMetrics Compatibility specification and can undergo breaking changes before stable release. Production environments should consider using OpenTelemetry.Exporter.OpenTelemetryProtocol. Refer to the Getting Started with Prometheus and Grafana tutorial for more information.

[!NOTE] This exporter does not support Exemplars. For using Exemplars, use the OTLP Exporter and use a component like OTel Collector to expose metrics (with exemplars) to Prometheus. This tutorial shows one way how to do that.

Prerequisite

Steps to enable OpenTelemetry.Exporter.Prometheus.AspNetCore

Step 1: Install Package

dotnet add package --prerelease OpenTelemetry.Exporter.Prometheus.AspNetCore

Step 2: Configure OpenTelemetry MeterProvider

  • When using OpenTelemetry.Extensions.Hosting package on .NET 6.0+:

    services.AddOpenTelemetry()
        .WithMetrics(builder => builder
            .AddPrometheusExporter());
    
  • Or configure directly:

    Call the MeterProviderBuilder.AddPrometheusExporter extension to register the Prometheus exporter.

    var meterProvider = Sdk.CreateMeterProviderBuilder()
        .AddPrometheusExporter()
        .Build();
    builder.Services.AddSingleton(meterProvider);
    

Step 3: Configure Prometheus Scraping Endpoint

  • Register Prometheus scraping middleware using the UseOpenTelemetryPrometheusScrapingEndpoint extension method on IApplicationBuilder :

    var builder = WebApplication.CreateBuilder(args);
    var app = builder.Build();
    app.UseOpenTelemetryPrometheusScrapingEndpoint();
    

    Overloads of the UseOpenTelemetryPrometheusScrapingEndpoint extension are provided to change the path or for more advanced configuration a predicate function can be used:

    app.UseOpenTelemetryPrometheusScrapingEndpoint(
            context => context.Request.Path == "/internal/metrics"
                && context.Connection.LocalPort == 5067);
    

    This can be used in combination with configuring multiple ports on the ASP.NET application to expose the scraping endpoint on a different port.

Configuration

The PrometheusExporter can be configured using the PrometheusAspNetCoreOptions properties.

ScrapeEndpointPath

Defines the path for the Prometheus scrape endpoint for the middleware registered by UseOpenTelemetryPrometheusScrapingEndpoint. Default value: "/metrics".

ScrapeResponseCacheDurationMilliseconds

Configures scrape endpoint response caching. Multiple scrape requests within the cache duration time period will receive the same previously generated response. The default value is 300. Set to 0 to disable response caching.

Troubleshooting

This component uses an EventSource with the name "OpenTelemetry-Exporter-Prometheus" for its internal logging. Please refer to SDK troubleshooting for instructions on seeing these internal logs.

References

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (48)

Showing the top 5 NuGet packages that depend on OpenTelemetry.Exporter.Prometheus.AspNetCore:

Package Downloads
SharpAbp.Abp.OpenTelemetry.Exporter.Prometheus.AspNetCore

SharpAbp OpenTelemetry Module

ShtrihM.Wattle3.OpenTelemetry

Framework for creating high-performance servers with domain object models.

Packs.Template.BaseApi

Basis for any Packs API

Jakar.Database

Package Description

Aguacongas.TheIdServer

OpenID/Connect , OAuth and WS-Federation server base on Duende IdentityServer.

GitHub repositories (30)

Showing the top 5 popular GitHub repositories that depend on OpenTelemetry.Exporter.Prometheus.AspNetCore:

Repository Stars
dotnet/AspNetCore.Docs
Documentation for ASP.NET Core
JustArchiNET/ArchiSteamFarm
C# application with primary purpose of farming Steam cards from multiple accounts simultaneously.
fullstackhero/dotnet-starter-kit
Production Grade Cloud-Ready .NET 9 Starter Kit (Web API + Blazor Client) with Multitenancy Support, and Clean/Modular Architecture that saves roughly 200+ Development Hours! All Batteries Included.
EventStore/EventStore
EventStoreDB, the event-native database. Designed for Event Sourcing, Event-Driven, and Microservices architectures
dotnet/samples
Sample code referenced by the .NET documentation
Version Downloads Last updated
1.10.0-beta.1 56,057 11/12/2024
1.9.0-beta.2 1,699,735 6/24/2024
1.9.0-beta.1 164,180 6/14/2024
1.9.0-alpha.2 149,658 5/29/2024
1.9.0-alpha.1 37,766 5/20/2024
1.8.0-rc.1 1,750,988 3/27/2024
1.8.0-beta.1 121,979 3/14/2024
1.7.0-rc.1 2,316,926 11/30/2023
1.7.0-alpha.1 144,856 10/17/2023
1.6.0-rc.1 2,485,590 8/21/2023
1.6.0-alpha.1 209,479 7/12/2023
1.5.0-rc.1 1,228,086 5/26/2023
1.5.0-alpha.1 809,750 3/8/2023
1.4.0-rc.4 2,084,159 2/11/2023
1.4.0-rc.3 114,892 2/2/2023
1.4.0-rc.2 121,603 1/9/2023
1.4.0-rc.1 204,236 12/12/2022
1.4.0-beta.3 318,074 11/7/2022
1.4.0-beta.2 257,645 10/17/2022
1.4.0-beta.1 70,890 9/30/2022
1.4.0-alpha.2 112,535 8/18/2022