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 (45)

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 (2)

Showing the top 2 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.
Version Downloads Last updated
1.10.0-beta.1 5,504 11/12/2024
1.9.0-beta.2 1,242,275 6/24/2024
1.9.0-beta.1 133,997 6/14/2024
1.9.0-alpha.2 127,796 5/29/2024
1.9.0-alpha.1 34,730 5/20/2024
1.8.0-rc.1 1,527,034 3/27/2024
1.8.0-beta.1 106,625 3/14/2024
1.7.0-rc.1 2,134,618 11/30/2023
1.7.0-alpha.1 131,468 10/17/2023
1.6.0-rc.1 2,391,830 8/21/2023
1.6.0-alpha.1 195,911 7/12/2023
1.5.0-rc.1 1,179,611 5/26/2023
1.5.0-alpha.1 797,101 3/8/2023
1.4.0-rc.4 2,021,099 2/11/2023
1.4.0-rc.3 113,517 2/2/2023
1.4.0-rc.2 120,208 1/9/2023
1.4.0-rc.1 201,932 12/12/2022
1.4.0-beta.3 313,397 11/7/2022
1.4.0-beta.2 252,553 10/17/2022
1.4.0-beta.1 70,710 9/30/2022
1.4.0-alpha.2 112,304 8/18/2022