Merge branch 'main-before-scope-fix' into main-logs

This commit is contained in:
Mikel Blanchard 2022-10-05 13:58:21 -07:00
commit 9c3f53f4c7
45 changed files with 304 additions and 97 deletions

View File

@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # fetching all
- uses: actions/setup-dotnet@v2
- uses: actions/setup-dotnet@v3.0.1
with:
dotnet-version: '7.0.x'
include-prerelease: true

View File

@ -27,7 +27,7 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # fetching all
- uses: actions/setup-dotnet@v2
- uses: actions/setup-dotnet@v3.0.1
with:
dotnet-version: '7.0.x'
include-prerelease: true

View File

@ -21,7 +21,7 @@ jobs:
uses: actions/checkout@v3
- name: Setup .NET Core 7.0
uses: actions/setup-dotnet@v2
uses: actions/setup-dotnet@v3.0.1
with:
dotnet-version: '7.0.x'
include-prerelease: true

View File

@ -23,11 +23,11 @@ jobs:
with:
fetch-depth: 0 # fetching all
- uses: actions/setup-dotnet@v2
- uses: actions/setup-dotnet@v3.0.1
with:
dotnet-version: '6.0.x'
- uses: actions/setup-dotnet@v2
- uses: actions/setup-dotnet@v3.0.1
with:
dotnet-version: '7.0.x'
include-prerelease: true

View File

@ -23,7 +23,7 @@ jobs:
fetch-depth: 0 # fetching all
ref: ${{ github.ref || 'main' }}
- uses: actions/setup-dotnet@v2
- uses: actions/setup-dotnet@v3.0.1
with:
dotnet-version: '7.0.x'
include-prerelease: true
@ -40,7 +40,7 @@ jobs:
- name: Publish Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ github.ref || 'main' }}-packages
name: ${{ github.ref_name }}-packages
path: '**/bin/**/*.*nupkg'
- name: Publish MyGet

View File

@ -26,7 +26,7 @@ jobs:
with:
fetch-depth: 0 # fetching all
- uses: actions/setup-dotnet@v2
- uses: actions/setup-dotnet@v3.0.1
with:
dotnet-version: '7.0.x'
include-prerelease: true

View File

@ -7,6 +7,10 @@
## Unreleased
## 1.4.0-beta.1
Released 2022-Sep-29
* Updated to System.Diagnostics.DiagnosticSource version `7.0.0-rc.1.22426.10`.
([#3698](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3698))

View File

@ -9,6 +9,10 @@
## Unreleased
## 1.4.0-beta.1
Released 2022-Sep-29
* Changed the behavior of `ConsoleExporter`, the exporter will stop outputting
the data if it is disposed.
([#3578](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3578))

View File

@ -7,6 +7,10 @@
## Unreleased
## 1.4.0-beta.1
Released 2022-Sep-29
* Changed error handling, `InMemoryExporter` will now throw
`ObjectDisposedException` if `Export` is invoked after the exporter is
disposed.

View File

@ -2,6 +2,10 @@
## Unreleased
## 1.4.0-beta.1
Released 2022-Sep-29
* Added overloads which accept a name to the `TracerProviderBuilder`
`AddJaegerExporter` extension to allow for more fine-grained options
management

View File

@ -9,6 +9,10 @@
## Unreleased
## 1.4.0-beta.1
Released 2022-Sep-29
* `OtlpExporterOptions` can now be bound to `IConfiguation` and
`HttpClientFactory` may be used to manage the `HttpClient` instance used when
`HttpProtobuf` is configured

View File

@ -2,6 +2,10 @@
## Unreleased
## 1.4.0-beta.1
Released 2022-Sep-29
* Added overloads which accept a name to the `MeterProviderBuilder`
`AddOtlpExporter` extension to allow for more fine-grained options management
([#3648](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3648))

View File

@ -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
@ -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

View File

@ -2,9 +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

View File

@ -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>

View File

@ -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();
}
}

View File

@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Builder
/// </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
@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Builder
/// <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>
@ -111,8 +111,8 @@ namespace Microsoft.AspNetCore.Builder
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>();
@ -120,9 +120,9 @@ namespace Microsoft.AspNetCore.Builder
{
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("/"))

View File

@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Builder
/// </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>
@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Builder
/// <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
@ -83,16 +83,16 @@ namespace Microsoft.AspNetCore.Builder
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("/"))

View File

@ -40,11 +40,11 @@ namespace OpenTelemetry.Metrics
/// 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>
@ -52,12 +52,12 @@ namespace OpenTelemetry.Metrics
/// </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);
@ -70,15 +70,15 @@ namespace OpenTelemetry.Metrics
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)
{

View File

@ -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

View File

@ -2,6 +2,10 @@
## Unreleased
## 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))

View File

@ -33,14 +33,13 @@ namespace OpenTelemetry.Exporter.Prometheus
/// <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);
}

View File

@ -16,22 +16,15 @@
using OpenTelemetry.Internal;
namespace OpenTelemetry.Exporter
namespace OpenTelemetry.Exporter.Prometheus
{
/// <summary>
/// Prometheus exporter options.
/// </summary>
public class PrometheusExporterOptions
internal sealed class PrometheusExporterOptions
{
internal const string DefaultScrapeEndpointPath = "/metrics";
private int scrapeResponseCacheDurationMilliseconds = 300;
/// <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>

View File

@ -21,6 +21,7 @@
<ItemGroup>
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\ExceptionExtensions.cs" Link="Includes\ExceptionExtensions.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\Guard.cs" Link="Includes\Guard.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry\Internal\MathHelper.cs" Link="Includes\MathHelper.cs" />
</ItemGroup>
</Project>

View File

@ -80,7 +80,7 @@ namespace OpenTelemetry.Metrics
MeterProviderBuilder builder,
PrometheusHttpListenerOptions options)
{
var exporter = new PrometheusExporter();
var exporter = new PrometheusExporter(new PrometheusExporterOptions { ScrapeResponseCacheDurationMilliseconds = 0 });
var reader = new BaseExportingMetricReader(exporter)
{

View File

@ -25,7 +25,7 @@ namespace OpenTelemetry.Exporter
/// </summary>
public class PrometheusHttpListenerOptions
{
private IReadOnlyCollection<string> uriPrefixes = new string[] { "http://localhost:9464/" };
private IReadOnlyCollection<string> uriPrefixes = new[] { "http://localhost:9464/" };
/// <summary>
/// Gets or sets the path to use for the scraping endpoint. Default value: "/metrics".

View File

@ -2,6 +2,10 @@
## Unreleased
## 1.0.0-rc9.7
Released 2022-Sep-29
## 1.0.0-rc9.6
Released 2022-Aug-18

View File

@ -2,6 +2,10 @@
## Unreleased
## 1.4.0-beta.1
Released 2022-Sep-29
* Added overloads which accept a name to the `TracerProviderBuilder`
`AddZipkinExporter` extension to allow for more fine-grained options
management

View File

@ -2,6 +2,10 @@
## Unreleased
## 1.0.0-rc9.7
Released 2022-Sep-29
* Dependency injection support when configuring
`TracerProvider` has been moved into the SDK.
([#3533](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3533))

View File

@ -36,9 +36,20 @@ namespace Microsoft.Extensions.DependencyInjection
/// cref="IServiceCollection" />.
/// </summary>
/// <remarks>
/// Note: This is safe to be called multiple times and by library
/// authors. Only a single <see cref="TracerProvider"/> will be created
/// for a given <see cref="IServiceCollection"/>.
/// Notes:
/// <list type="bullet">
/// <item>
/// This is safe to be called multiple times. Only a single <see
/// cref="TracerProvider"/> will be created for a given <see
/// cref="IServiceCollection"/>.
/// </item>
/// <item>
/// This method should be called by application host code. Library
/// authors should call <see
/// cref="TracerProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryTracing(IServiceCollection)"/>
/// instead.
/// </item>
/// </list>
/// </remarks>
/// <param name="services"><see cref="IServiceCollection"/>.</param>
/// <returns>Supplied <see cref="IServiceCollection"/> for chaining
@ -76,9 +87,20 @@ namespace Microsoft.Extensions.DependencyInjection
/// cref="IServiceCollection" />.
/// </summary>
/// <remarks>
/// Note: This is safe to be called multiple times and by library
/// authors. Only a single <see cref="MeterProvider"/> will be created
/// for a given <see cref="IServiceCollection"/>.
/// Notes:
/// <list type="bullet">
/// <item>
/// This is safe to be called multiple times. Only a single <see
/// cref="MeterProvider"/> will be created for a given <see
/// cref="IServiceCollection"/>.
/// </item>
/// <item>
/// This method should be called by application host code. Library
/// authors should call <see
/// cref="MeterProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryMetrics(IServiceCollection)"/>
/// instead.
/// </item>
/// </list>
/// </remarks>
/// <param name="services"><see cref="IServiceCollection"/>.</param>
/// <returns>Supplied <see cref="IServiceCollection"/> for chaining

View File

@ -2,6 +2,10 @@
## Unreleased
## 1.4.0-beta.1
Released 2022-Sep-29
## 1.4.0-alpha.2
Released 2022-Aug-18

View File

@ -26,6 +26,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore
{
private static readonly HashSet<string> DiagnosticSourceEvents = new()
{
"Microsoft.AspNetCore.Hosting.HttpRequestIn",
"Microsoft.AspNetCore.Hosting.HttpRequestIn.Start",
"Microsoft.AspNetCore.Hosting.HttpRequestIn.Stop",
"Microsoft.AspNetCore.Mvc.BeforeAction",

View File

@ -2,6 +2,10 @@
## Unreleased
## 1.0.0-rc9.7
Released 2022-Sep-29
* Performance improvement (Reduced memory allocation) - Updated DiagnosticSource
event subscription to specific set of events.
([#3519](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3519))

View File

@ -2,6 +2,10 @@
## Unreleased
## 1.0.0-rc9.7
Released 2022-Sep-29
* Added overloads which accept a name to the `TracerProviderBuilder`
`AddGrpcClientInstrumentation` extension to allow for more fine-grained
options management

View File

@ -2,6 +2,10 @@
## Unreleased
## 1.0.0-rc9.7
Released 2022-Sep-29
* Dropped `netstandard2.0` target and added `net6.0`. .NET 5 reached EOL
in May 2022 and .NET Core 3.1 reaches EOL in December 2022. End of support
dates for .NET are published

View File

@ -2,6 +2,10 @@
## Unreleased
## 1.0.0-rc9.7
Released 2022-Sep-29
## 1.0.0-rc9.6
Released 2022-Aug-18

View File

@ -2,6 +2,10 @@
## Unreleased
## 1.0.0-rc9.7
Released 2022-Sep-29
## 1.0.0-rc9.6
Released 2022-Aug-18

View File

@ -18,10 +18,8 @@ using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("OpenTelemetry.Tests" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.InMemory" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.Prometheus.Shared" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.Prometheus.AspNetCore" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.Prometheus.HttpListener" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.Prometheus.HttpListener.Tests" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Extensions.Hosting.Tests" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2" + AssemblyInfo.MoqPublicKey)]

View File

@ -7,6 +7,10 @@
## Unreleased
## 1.4.0-beta.1
Released 2022-Sep-29
* Use binary search for histograms with 50 or more supplied boundaries.
([#3252](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3252))

View File

@ -31,9 +31,9 @@ public sealed class PrometheusExporterMeterProviderBuilderExtensionsTests
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.ConfigureServices(services =>
{
services.Configure<PrometheusExporterOptions>(o => defaultExporterOptionsConfigureOptionsInvocations++);
services.Configure<PrometheusAspNetCoreOptions>(o => defaultExporterOptionsConfigureOptionsInvocations++);
services.Configure<PrometheusExporterOptions>("Exporter2", o => namedExporterOptionsConfigureOptionsInvocations++);
services.Configure<PrometheusAspNetCoreOptions>("Exporter2", o => namedExporterOptionsConfigureOptionsInvocations++);
})
.AddPrometheusExporter()
.AddPrometheusExporter("Exporter2", o => { })

View File

@ -52,7 +52,7 @@ namespace OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests
return RunPrometheusExporterMiddlewareIntegrationTest(
"/metrics_options",
app => app.UseOpenTelemetryPrometheusScrapingEndpoint(),
services => services.Configure<PrometheusExporterOptions>(o => o.ScrapeEndpointPath = "metrics_options"));
services => services.Configure<PrometheusAspNetCoreOptions>(o => o.ScrapeEndpointPath = "metrics_options"));
}
[Fact]
@ -61,7 +61,7 @@ namespace OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests
return RunPrometheusExporterMiddlewareIntegrationTest(
"/metrics",
app => app.UseOpenTelemetryPrometheusScrapingEndpoint(),
services => services.Configure<PrometheusExporterOptions>(o => o.ScrapeEndpointPath = null));
services => services.Configure<PrometheusAspNetCoreOptions>(o => o.ScrapeEndpointPath = null));
}
[Fact]
@ -103,7 +103,7 @@ namespace OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests
context.Response.Headers.Add("X-MiddlewareExecuted", "true");
return next();
})),
services => services.Configure<PrometheusExporterOptions>(o => o.ScrapeEndpointPath = "/metrics_options"),
services => services.Configure<PrometheusAspNetCoreOptions>(o => o.ScrapeEndpointPath = "/metrics_options"),
validateResponse: rsp =>
{
if (!rsp.Headers.TryGetValues("X-MiddlewareExecuted", out IEnumerable<string> headers))
@ -129,7 +129,7 @@ namespace OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests
context.Response.Headers.Add("X-MiddlewareExecuted", "true");
return next();
})),
services => services.Configure<PrometheusExporterOptions>(o => o.ScrapeEndpointPath = "/metrics_options"),
services => services.Configure<PrometheusAspNetCoreOptions>(o => o.ScrapeEndpointPath = "/metrics_options"),
validateResponse: rsp =>
{
if (!rsp.Headers.TryGetValues("X-MiddlewareExecuted", out IEnumerable<string> headers))
@ -210,7 +210,7 @@ namespace OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests
Action<IServiceCollection> configureServices = null,
Action<HttpResponseMessage> validateResponse = null,
bool registerMeterProvider = true,
Action<PrometheusExporterOptions> configureOptions = null,
Action<PrometheusAspNetCoreOptions> configureOptions = null,
bool skipMetrics = false)
{
using var host = await new HostBuilder()

View File

@ -29,13 +29,14 @@ namespace OpenTelemetry.Exporter.Prometheus.Tests
{
public sealed class PrometheusCollectionManagerTests
{
#if PROMETHEUS_HTTP_LISTENER
[Fact(Skip = "Might be flaky. Might be a bug. See: https://github.com/open-telemetry/opentelemetry-dotnet/issues/3679")]
#else
[Fact]
[Theory]
[InlineData(0)] // disable cache, default value for HttpListener
#if PROMETHEUS_ASPNETCORE
[InlineData(300)] // default value for AspNetCore, no possibility to set on HttpListener
#endif
public async Task EnterExitCollectTest()
public async Task EnterExitCollectTest(int scrapeResponseCacheDurationMilliseconds)
{
bool cacheEnabled = scrapeResponseCacheDurationMilliseconds != 0;
using var meter = new Meter(Utils.GetCurrentMethodName());
using (var provider = Sdk.CreateMeterProviderBuilder()
@ -43,7 +44,7 @@ namespace OpenTelemetry.Exporter.Prometheus.Tests
#if PROMETHEUS_HTTP_LISTENER
.AddPrometheusHttpListener()
#elif PROMETHEUS_ASPNETCORE
.AddPrometheusExporter()
.AddPrometheusExporter(x => x.ScrapeResponseCacheDurationMilliseconds = scrapeResponseCacheDurationMilliseconds)
#endif
.Build())
{
@ -108,9 +109,18 @@ namespace OpenTelemetry.Exporter.Prometheus.Tests
var response = await task.ConfigureAwait(false);
try
{
Assert.Equal(1, runningCollectCount);
Assert.True(response.FromCache);
Assert.Equal(firstResponse.CollectionResponse.GeneratedAtUtc, response.GeneratedAtUtc);
if (cacheEnabled)
{
Assert.Equal(1, runningCollectCount);
Assert.True(response.FromCache);
Assert.Equal(firstResponse.CollectionResponse.GeneratedAtUtc, response.GeneratedAtUtc);
}
else
{
Assert.Equal(2, runningCollectCount);
Assert.False(response.FromCache);
Assert.True(firstResponse.CollectionResponse.GeneratedAtUtc < response.GeneratedAtUtc);
}
}
finally
{
@ -143,7 +153,7 @@ namespace OpenTelemetry.Exporter.Prometheus.Tests
await Task.WhenAll(collectTasks).ConfigureAwait(false);
Assert.Equal(2, runningCollectCount);
Assert.Equal(cacheEnabled ? 2 : 3, runningCollectCount);
Assert.NotEqual(firstResponse.ViewPayload, collectTasks[0].Result.ViewPayload);
Assert.NotEqual(firstResponse.CollectionResponse.GeneratedAtUtc, collectTasks[0].Result.CollectionResponse.GeneratedAtUtc);

View File

@ -189,7 +189,7 @@ namespace OpenTelemetry.Exporter.Prometheus.Tests
}
[Fact]
public void SumDoubleInfinites()
public void SumDoubleInfinities()
{
var buffer = new byte[85000];
var metrics = new List<Metric>();
@ -360,7 +360,7 @@ namespace OpenTelemetry.Exporter.Prometheus.Tests
}
[Fact]
public void HistogramInfinites()
public void HistogramInfinities()
{
var buffer = new byte[85000];
var metrics = new List<Metric>();

View File

@ -15,6 +15,7 @@
// </copyright>
#if !NETFRAMEWORK
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
@ -300,30 +301,36 @@ namespace OpenTelemetry.Instrumentation.Http.Tests
Assert.IsType<Activity>(processor.Invocations[1].Arguments[0]);
}
[Fact]
public async Task HttpClientInstrumentationBacksOffIfAlreadyInstrumented()
[Fact(Skip = "https://github.com/open-telemetry/opentelemetry-dotnet/issues/3729")]
public async Task HttpClientInstrumentationExportsSpansCreatedForRetries()
{
// TODO: Investigate why this feature is required.
var processor = new Mock<BaseProcessor<Activity>>();
var exportedItems = new List<Activity>();
var request = new HttpRequestMessage
{
RequestUri = new Uri(this.url),
Method = new HttpMethod("GET"),
};
request.Headers.Add("traceparent", "00-0123456789abcdef0123456789abcdef-0123456789abcdef-01");
using (Sdk.CreateTracerProviderBuilder()
using var traceprovider = Sdk.CreateTracerProviderBuilder()
.AddHttpClientInstrumentation()
.AddProcessor(processor.Object)
.Build())
{
using var c = new HttpClient();
await c.SendAsync(request);
}
.AddInMemoryExporter(exportedItems)
.Build();
Assert.Equal(4, processor.Invocations.Count); // SetParentProvider/OnShutdown/Dispose/OnStart called.
int maxRetries = 3;
using var c = new HttpClient(new RetryHandler(new HttpClientHandler(), maxRetries));
await c.SendAsync(request);
// number of exported spans should be 3(maxRetries)
Assert.Equal(3, exportedItems.Count());
var spanid1 = exportedItems[0].SpanId;
var spanid2 = exportedItems[1].SpanId;
var spanid3 = exportedItems[2].SpanId;
// Validate span ids are different
Assert.NotEqual(spanid1, spanid2);
Assert.NotEqual(spanid3, spanid1);
Assert.NotEqual(spanid2, spanid3);
}
[Fact]

View File

@ -0,0 +1,52 @@
// <copyright file="RetryHandler.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 System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace OpenTelemetry.Tests
{
public class RetryHandler : DelegatingHandler
{
private int maxRetries;
public RetryHandler(HttpMessageHandler innerHandler, int maxRetries)
: base(innerHandler)
{
this.maxRetries = maxRetries;
}
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request,
CancellationToken cancellationToken)
{
HttpResponseMessage response = null;
for (int i = 0; i < this.maxRetries; i++)
{
try
{
response = await base.SendAsync(request, cancellationToken);
}
catch
{
}
}
return response;
}
}
}