Skip to content

Commit

Permalink
Merge from main.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBlanch committed Oct 12, 2022
2 parents 305cfe5 + a6c3cac commit cff5bc7
Show file tree
Hide file tree
Showing 41 changed files with 319 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/apicompatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # fetching all
- uses: actions/setup-dotnet@v3.0.0
- uses: actions/setup-dotnet@v3.0.1
with:
dotnet-version: '7.0.x'
include-prerelease: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # fetching all
- uses: actions/setup-dotnet@v3.0.0
- uses: actions/setup-dotnet@v3.0.1
with:
dotnet-version: '7.0.x'
include-prerelease: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: actions/checkout@v3

- name: Setup .NET Core 7.0
uses: actions/setup-dotnet@v3.0.0
uses: actions/setup-dotnet@v3.0.1
with:
dotnet-version: '7.0.x'
include-prerelease: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/linux-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ jobs:
with:
fetch-depth: 0 # fetching all

- uses: actions/setup-dotnet@v3.0.0
- uses: actions/setup-dotnet@v3.0.1
with:
dotnet-version: '6.0.x'

- uses: actions/setup-dotnet@v3.0.0
- uses: actions/setup-dotnet@v3.0.1
with:
dotnet-version: '7.0.x'
include-prerelease: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-packages-1.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
fetch-depth: 0 # fetching all
ref: ${{ github.ref || 'main' }}

- uses: actions/setup-dotnet@v3.0.0
- uses: actions/setup-dotnet@v3.0.1
with:
dotnet-version: '7.0.x'
include-prerelease: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows-ci-md.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

strategy:
matrix:
version: [net462,net6.0]
version: [net462,net6.0,net7.0]

steps:
- run: 'echo "No build required"'
2 changes: 1 addition & 1 deletion .github/workflows/windows-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
with:
fetch-depth: 0 # fetching all

- uses: actions/setup-dotnet@v3.0.0
- uses: actions/setup-dotnet@v3.0.1
with:
dotnet-version: '7.0.x'
include-prerelease: true
Expand Down
11 changes: 6 additions & 5 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,15 @@ supported environment variables.

## OTLP Logs

This package currently only supports exporting traces and metrics. Once the
[OTLP log data model](https://github.com/open-telemetry/opentelemetry-proto#maturity-level)
is deemed stable, the OTLP log exporter will be folded into this package.

In the meantime, support for exporting logs is provided by installing the
This package currently only supports exporting traces and metrics. Support for
exporting logs is provided by installing the
[`OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs`](../OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/README.md)
package.

Once the OTLP log exporter is stable, it'll be folded into this package. Check
[this](https://github.com/open-telemetry/opentelemetry-dotnet/milestone/35)
milestone for tracking.

## Special case when using insecure channel

If your application is targeting .NET Core 3.1, and you are using an insecure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Microsoft.AspNetCore.Builder.PrometheusExporterApplicationBuilderExtensions
Microsoft.AspNetCore.Builder.PrometheusExporterEndpointRouteBuilderExtensions
OpenTelemetry.Exporter.PrometheusExporterOptions
OpenTelemetry.Exporter.PrometheusExporterOptions.PrometheusExporterOptions() -> void
OpenTelemetry.Exporter.PrometheusExporterOptions.ScrapeEndpointPath.get -> string
OpenTelemetry.Exporter.PrometheusExporterOptions.ScrapeEndpointPath.set -> void
OpenTelemetry.Exporter.PrometheusExporterOptions.ScrapeResponseCacheDurationMilliseconds.get -> int
OpenTelemetry.Exporter.PrometheusExporterOptions.ScrapeResponseCacheDurationMilliseconds.set -> void
OpenTelemetry.Exporter.PrometheusAspNetCoreOptions
OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.PrometheusAspNetCoreOptions() -> void
OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.ScrapeEndpointPath.get -> string
OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.ScrapeEndpointPath.set -> void
OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.ScrapeResponseCacheDurationMilliseconds.get -> int
OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.ScrapeResponseCacheDurationMilliseconds.set -> void
OpenTelemetry.Metrics.PrometheusExporterMeterProviderBuilderExtensions
static Microsoft.AspNetCore.Builder.PrometheusExporterApplicationBuilderExtensions.UseOpenTelemetryPrometheusScrapingEndpoint(this Microsoft.AspNetCore.Builder.IApplicationBuilder app) -> Microsoft.AspNetCore.Builder.IApplicationBuilder
static Microsoft.AspNetCore.Builder.PrometheusExporterApplicationBuilderExtensions.UseOpenTelemetryPrometheusScrapingEndpoint(this Microsoft.AspNetCore.Builder.IApplicationBuilder app, OpenTelemetry.Metrics.MeterProvider meterProvider, System.Func<Microsoft.AspNetCore.Http.HttpContext, bool> predicate, string path, System.Action<Microsoft.AspNetCore.Builder.IApplicationBuilder> configureBranchedPipeline) -> Microsoft.AspNetCore.Builder.IApplicationBuilder
Expand All @@ -15,5 +15,5 @@ static Microsoft.AspNetCore.Builder.PrometheusExporterEndpointRouteBuilderExtens
static Microsoft.AspNetCore.Builder.PrometheusExporterEndpointRouteBuilderExtensions.MapPrometheusScrapingEndpoint(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string path = null, OpenTelemetry.Metrics.MeterProvider meterProvider = null, System.Action<Microsoft.AspNetCore.Builder.IApplicationBuilder> configureBranchedPipeline = null) -> Microsoft.AspNetCore.Builder.IEndpointConventionBuilder
static Microsoft.AspNetCore.Builder.PrometheusExporterEndpointRouteBuilderExtensions.MapPrometheusScrapingEndpoint(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string path) -> Microsoft.AspNetCore.Builder.IEndpointConventionBuilder
static OpenTelemetry.Metrics.PrometheusExporterMeterProviderBuilderExtensions.AddPrometheusExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Metrics.PrometheusExporterMeterProviderBuilderExtensions.AddPrometheusExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action<OpenTelemetry.Exporter.PrometheusExporterOptions> configure) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Metrics.PrometheusExporterMeterProviderBuilderExtensions.AddPrometheusExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Exporter.PrometheusExporterOptions> configure) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Metrics.PrometheusExporterMeterProviderBuilderExtensions.AddPrometheusExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action<OpenTelemetry.Exporter.PrometheusAspNetCoreOptions> configure) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Metrics.PrometheusExporterMeterProviderBuilderExtensions.AddPrometheusExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Exporter.PrometheusAspNetCoreOptions> configure) -> OpenTelemetry.Metrics.MeterProviderBuilder
8 changes: 6 additions & 2 deletions src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

## Unreleased

* Changed configuration class name from `PrometheusExporterOptions`
to `PrometheusAspNetCoreOptions`
([#3717](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3717))

## 1.4.0-beta.1

Released 2022-Sep-29

* Bug fix for Prometheus Exporter reporting StatusCode 204
instead of 200, when no metrics are collected
([#3643](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3643))
instead of 200, when no metrics are collected
([#3643](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3643))
* Added overloads which accept a name to the `MeterProviderBuilder`
`AddPrometheusExporter` extension to allow for more fine-grained options
management
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Internal\PrometheusCollectionManager.cs" Link="Includes/PrometheusCollectionManager.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Internal\PrometheusExporter.cs" Link="Includes/PrometheusExporter.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Internal\PrometheusExporterEventSource.cs" Link="Includes/PrometheusExporterEventSource.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Internal\PrometheusExporterOptions.cs" Link="Includes/PrometheusExporterOptions.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Internal\PrometheusSerializer.cs" Link="Includes/PrometheusSerializer.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Internal\PrometheusSerializerExt.cs" Link="Includes/PrometheusSerializerExt.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// <copyright file="PrometheusAspNetCoreOptions.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using OpenTelemetry.Exporter.Prometheus;

namespace OpenTelemetry.Exporter
{
/// <summary>
/// Prometheus exporter options.
/// </summary>
public class PrometheusAspNetCoreOptions
{
internal const string DefaultScrapeEndpointPath = "/metrics";

/// <summary>
/// Gets or sets the path to use for the scraping endpoint. Default value: "/metrics".
/// </summary>
public string ScrapeEndpointPath { get; set; } = DefaultScrapeEndpointPath;

/// <summary>
/// Gets or sets the cache duration in milliseconds for scrape responses. Default value: 300.
/// </summary>
/// <remarks>
/// Note: Specify 0 to disable response caching.
/// </remarks>
public int ScrapeResponseCacheDurationMilliseconds
{
get => this.ExporterOptions.ScrapeResponseCacheDurationMilliseconds;
set => this.ExporterOptions.ScrapeResponseCacheDurationMilliseconds = value;
}

internal PrometheusExporterOptions ExporterOptions { get; } = new();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static class PrometheusExporterApplicationBuilderExtensions
/// </summary>
/// <remarks>Note: A branched pipeline is created for the route
/// specified by <see
/// cref="PrometheusExporterOptions.ScrapeEndpointPath"/>.</remarks>
/// cref="PrometheusAspNetCoreOptions.ScrapeEndpointPath"/>.</remarks>
/// <param name="app">The <see cref="IApplicationBuilder"/> to add
/// middleware to.</param>
/// <returns>A reference to the original <see
Expand Down Expand Up @@ -86,7 +86,7 @@ public static IApplicationBuilder UseOpenTelemetryPrometheusScrapingEndpoint(thi
/// <remarks>Note: A branched pipeline is created based on the <paramref
/// name="predicate"/> or <paramref name="path"/>. If neither <paramref
/// name="predicate"/> nor <paramref name="path"/> are provided then
/// <see cref="PrometheusExporterOptions.ScrapeEndpointPath"/> is
/// <see cref="PrometheusAspNetCoreOptions.ScrapeEndpointPath"/> is
/// used.</remarks>
/// <param name="app">The <see cref="IApplicationBuilder"/> to add
/// middleware to.</param>
Expand All @@ -111,18 +111,18 @@ public static IApplicationBuilder UseOpenTelemetryPrometheusScrapingEndpoint(
Action<IApplicationBuilder> configureBranchedPipeline)
{
// Note: Order is important here. MeterProvider is accessed before
// GetOptions<PrometheusExporterOptions> so that any changes made to
// PrometheusExporterOptions in deferred AddPrometheusExporter
// GetOptions<PrometheusAspNetCoreOptions> so that any changes made to
// PrometheusAspNetCoreOptions in deferred AddPrometheusExporter
// configure actions are reflected.
meterProvider ??= app.ApplicationServices.GetRequiredService<MeterProvider>();

if (predicate == null)
{
if (path == null)
{
var options = app.ApplicationServices.GetRequiredService<IOptions<PrometheusExporterOptions>>().Value;
var options = app.ApplicationServices.GetRequiredService<IOptions<PrometheusAspNetCoreOptions>>().Value;

path = options.ScrapeEndpointPath ?? PrometheusExporterOptions.DefaultScrapeEndpointPath;
path = options.ScrapeEndpointPath ?? PrometheusAspNetCoreOptions.DefaultScrapeEndpointPath;
}

if (!path.StartsWith("/"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static class PrometheusExporterEndpointRouteBuilderExtensions
/// </summary>
/// <remarks>Note: A branched pipeline is created for the route
/// specified by <see
/// cref="PrometheusExporterOptions.ScrapeEndpointPath"/>.</remarks>
/// cref="PrometheusAspNetCoreOptions.ScrapeEndpointPath"/>.</remarks>
/// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add
/// middleware to.</param>
/// <returns>A convention routes for the Prometheus scraping endpoint.</returns>
Expand Down Expand Up @@ -65,7 +65,7 @@ public static IEndpointConventionBuilder MapPrometheusScrapingEndpoint(this IEnd
/// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add
/// middleware to.</param>
/// <param name="path">Optional path to use for the branched pipeline.
/// If not provided then <see cref="PrometheusExporterOptions.ScrapeEndpointPath"/>
/// If not provided then <see cref="PrometheusAspNetCoreOptions.ScrapeEndpointPath"/>
/// is used.</param>
/// <param name="meterProvider">Optional <see cref="MeterProvider"/>
/// containing a Prometheus exporter otherwise the primary SDK provider
Expand All @@ -83,16 +83,16 @@ public static IEndpointConventionBuilder MapPrometheusScrapingEndpoint(
var builder = endpoints.CreateApplicationBuilder();

// Note: Order is important here. MeterProvider is accessed before
// GetOptions<PrometheusExporterOptions> so that any changes made to
// PrometheusExporterOptions in deferred AddPrometheusExporter
// GetOptions<PrometheusAspNetCoreOptions> so that any changes made to
// PrometheusAspNetCoreOptions in deferred AddPrometheusExporter
// configure actions are reflected.
meterProvider ??= endpoints.ServiceProvider.GetRequiredService<MeterProvider>();

if (path == null)
{
var options = endpoints.ServiceProvider.GetRequiredService<IOptions<PrometheusExporterOptions>>().Value;
var options = endpoints.ServiceProvider.GetRequiredService<IOptions<PrometheusAspNetCoreOptions>>().Value;

path = options.ScrapeEndpointPath ?? PrometheusExporterOptions.DefaultScrapeEndpointPath;
path = options.ScrapeEndpointPath ?? PrometheusAspNetCoreOptions.DefaultScrapeEndpointPath;
}

if (!path.StartsWith("/"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,24 @@ public static MeterProviderBuilder AddPrometheusExporter(this MeterProviderBuild
/// Adds <see cref="PrometheusExporter"/> to the <see cref="MeterProviderBuilder"/>.
/// </summary>
/// <param name="builder"><see cref="MeterProviderBuilder"/> builder to use.</param>
/// <param name="configure">Callback action for configuring <see cref="PrometheusExporterOptions"/>.</param>
/// <param name="configure">Callback action for configuring <see cref="PrometheusAspNetCoreOptions"/>.</param>
/// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns>
public static MeterProviderBuilder AddPrometheusExporter(
this MeterProviderBuilder builder,
Action<PrometheusExporterOptions> configure)
Action<PrometheusAspNetCoreOptions> configure)
=> AddPrometheusExporter(builder, name: null, configure);

/// <summary>
/// Adds <see cref="PrometheusExporter"/> to the <see cref="MeterProviderBuilder"/>.
/// </summary>
/// <param name="builder"><see cref="MeterProviderBuilder"/> builder to use.</param>
/// <param name="name">Name which is used when retrieving options.</param>
/// <param name="configure">Callback action for configuring <see cref="PrometheusExporterOptions"/>.</param>
/// <param name="configure">Callback action for configuring <see cref="PrometheusAspNetCoreOptions"/>.</param>
/// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns>
public static MeterProviderBuilder AddPrometheusExporter(
this MeterProviderBuilder builder,
string name,
Action<PrometheusExporterOptions> configure)
Action<PrometheusAspNetCoreOptions> configure)
{
Guard.ThrowIfNull(builder);

Expand All @@ -70,15 +70,15 @@ public static MeterProviderBuilder AddPrometheusExporter(

return builder.ConfigureBuilder((sp, builder) =>
{
var options = sp.GetRequiredService<IOptionsMonitor<PrometheusExporterOptions>>().Get(name);
var options = sp.GetRequiredService<IOptionsMonitor<PrometheusAspNetCoreOptions>>().Get(name);

AddPrometheusExporter(builder, options);
});
}

private static MeterProviderBuilder AddPrometheusExporter(MeterProviderBuilder builder, PrometheusExporterOptions options)
private static MeterProviderBuilder AddPrometheusExporter(MeterProviderBuilder builder, PrometheusAspNetCoreOptions options)
{
var exporter = new PrometheusExporter(scrapeResponseCacheDurationMilliseconds: options.ScrapeResponseCacheDurationMilliseconds);
var exporter = new PrometheusExporter(options.ExporterOptions);

var reader = new BaseExportingMetricReader(exporter)
{
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry.Exporter.Prometheus.AspNetCore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dotnet add package --prerelease OpenTelemetry.Exporter.Prometheus.AspNetCore

## Configuration

The `PrometheusExporter` can be configured using the `PrometheusExporterOptions`
The `PrometheusExporter` can be configured using the `PrometheusAspNetCoreOptions`
properties.

### ScrapeEndpointPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ internal sealed class PrometheusExporter : BaseExporter<Metric>, IPullMetricExpo
/// <summary>
/// Initializes a new instance of the <see cref="PrometheusExporter"/> class.
/// </summary>
/// <param name="scrapeResponseCacheDurationMilliseconds">
/// The cache duration in milliseconds for scrape responses. Default value: 0.
/// </param>
public PrometheusExporter(int scrapeResponseCacheDurationMilliseconds = 0)
/// <param name="options"><see cref="PrometheusExporterOptions"/>.</param>
public PrometheusExporter(PrometheusExporterOptions options)
{
Guard.ThrowIfOutOfRange(scrapeResponseCacheDurationMilliseconds, min: 0);
Guard.ThrowIfNull(options);

this.ScrapeResponseCacheDurationMilliseconds = options.ScrapeResponseCacheDurationMilliseconds;

this.ScrapeResponseCacheDurationMilliseconds = scrapeResponseCacheDurationMilliseconds;
this.CollectionManager = new PrometheusCollectionManager(this);
}

Expand Down
Loading

0 comments on commit cff5bc7

Please sign in to comment.