diff --git a/test/Benchmarks/Helper/LocalServer.cs b/test/Benchmarks/Helper/LocalServer.cs
deleted file mode 100644
index dcc14e7b7..000000000
--- a/test/Benchmarks/Helper/LocalServer.cs
+++ /dev/null
@@ -1,85 +0,0 @@
-//
-// 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.
-//
-
-#if NETCOREAPP
-
-using System;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Builder;
-using Microsoft.AspNetCore.Hosting;
-using Microsoft.AspNetCore.Http;
-using Microsoft.Extensions.DependencyInjection;
-using OpenTelemetry;
-using OpenTelemetry.Trace;
-
-namespace Benchmarks.Helper
-{
- public class LocalServer : IDisposable
- {
- private readonly IWebHost host;
- private TracerProvider tracerProvider;
-
- public LocalServer(string url, bool enableTracerProvider = false)
- {
- void ConfigureTestServices(IServiceCollection services)
- {
- if (enableTracerProvider)
- {
- this.tracerProvider = Sdk.CreateTracerProviderBuilder()
- .AddAspNetCoreInstrumentation()
- .Build();
- }
- }
-
- this.host = new WebHostBuilder()
- .UseKestrel()
- .UseStartup()
- .UseUrls(url)
- .ConfigureServices(configure => ConfigureTestServices(configure))
- .Build();
-
- Task.Run(() => this.host.Run());
- }
-
- public void Dispose()
- {
- try
- {
- this.tracerProvider.Dispose();
- this.host.Dispose();
- }
- catch (Exception)
- {
- // ignored, see https://github.com/aspnet/KestrelHttpServer/issues/1513
- // Kestrel 2.0.0 should have fix it, but it does not seem important for our tests
- }
-
- GC.SuppressFinalize(this);
- }
-
- private class Startup
- {
- public void Configure(IApplicationBuilder app)
- {
- app.Run(async (context) =>
- {
- await context.Response.WriteAsync("Hello World!").ConfigureAwait(false);
- });
- }
- }
- }
-}
-#endif
diff --git a/test/Benchmarks/Helper/ValuesController.cs b/test/Benchmarks/Helper/ValuesController.cs
deleted file mode 100644
index 41da05856..000000000
--- a/test/Benchmarks/Helper/ValuesController.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-//
-// 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.
-//
-
-#if !NETFRAMEWORK
-using System.Collections.Generic;
-using Microsoft.AspNetCore.Mvc;
-
-namespace Benchmark.Helper
-{
- [Route("api/[controller]")]
- public class ValuesController : Controller
- {
- // GET api/values
- [HttpGet]
- public IEnumerable Get()
- {
- return new string[] { "value1", "value2" };
- }
- }
-}
-#endif
diff --git a/test/Benchmarks/Instrumentation/AspNetCoreInstrumentationBenchmarks.cs b/test/Benchmarks/Instrumentation/AspNetCoreInstrumentationBenchmarks.cs
index dd3160d72..021ebc7a2 100644
--- a/test/Benchmarks/Instrumentation/AspNetCoreInstrumentationBenchmarks.cs
+++ b/test/Benchmarks/Instrumentation/AspNetCoreInstrumentationBenchmarks.cs
@@ -15,29 +15,27 @@
//
#if !NETFRAMEWORK
-using System.Net.Http;
-using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using Microsoft.AspNetCore.Builder;
-using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using OpenTelemetry;
+using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
/*
// * Summary *
-BenchmarkDotNet=v0.13.2, OS=Windows 11 (10.0.22621.521)
-Intel Core i7-8850H CPU 2.60GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
-.NET SDK=7.0.100-preview.6.22275.1
- [Host] : .NET 6.0.9 (6.0.922.41905), X64 RyuJIT AVX2
+BenchmarkDotNet=v0.13.3, OS=Windows 10 (10.0.19045.2604)
+Intel Core i7-4790 CPU 3.60GHz (Haswell), 1 CPU, 8 logical and 4 physical cores
+.NET SDK=7.0.103
+ [Host] : .NET 7.0.3 (7.0.323.6910), X64 RyuJIT AVX2
Job=InProcess Toolchain=InProcessEmitToolchain
| Method | Mean | Error | StdDev | Gen0 | Allocated |
|-------------------------------------------- |---------:|--------:|--------:|-------:|----------:|
-| UninstrumentedAspNetCoreApp | 172.3 us | 2.35 us | 2.09 us | 0.9766 | 4.73 KB |
-| InstrumentedAspNetCoreAppWithDefaultOptions | 175.2 us | 2.52 us | 2.10 us | 0.9766 | 4.86 KB |
+| UninstrumentedAspNetCoreApp | 149.4 us | 2.94 us | 2.75 us | 0.4883 | 2.54 KB |
+| InstrumentedAspNetCoreAppWithDefaultOptions | 171.9 us | 2.65 us | 2.48 us | 0.7324 | 3.79 KB |
*/
namespace Benchmarks.Instrumentation
@@ -48,6 +46,7 @@ namespace Benchmarks.Instrumentation
private HttpClient httpClient;
private WebApplication app;
private TracerProvider tracerProvider;
+ private MeterProvider meterProvider;
[GlobalSetup(Target = nameof(UninstrumentedAspNetCoreApp))]
public void UninstrumentedAspNetCoreAppGlobalSetup()
@@ -65,6 +64,12 @@ namespace Benchmarks.Instrumentation
this.tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddAspNetCoreInstrumentation()
.Build();
+
+ var exportedItems = new List();
+ this.meterProvider = Sdk.CreateMeterProviderBuilder()
+ .AddAspNetCoreInstrumentation()
+ .AddInMemoryExporter(exportedItems)
+ .Build();
}
[GlobalCleanup(Target = nameof(UninstrumentedAspNetCoreApp))]
@@ -80,29 +85,29 @@ namespace Benchmarks.Instrumentation
this.httpClient.Dispose();
await this.app.DisposeAsync().ConfigureAwait(false);
this.tracerProvider.Dispose();
+ this.meterProvider.Dispose();
}
[Benchmark]
public async Task UninstrumentedAspNetCoreApp()
{
- var httpResponse = await this.httpClient.GetAsync("http://localhost:5000/api/values").ConfigureAwait(false);
+ var httpResponse = await this.httpClient.GetAsync("http://localhost:5000").ConfigureAwait(false);
httpResponse.EnsureSuccessStatusCode();
}
[Benchmark]
public async Task InstrumentedAspNetCoreAppWithDefaultOptions()
{
- var httpResponse = await this.httpClient.GetAsync("http://localhost:5000/api/values").ConfigureAwait(false);
+ var httpResponse = await this.httpClient.GetAsync("http://localhost:5000").ConfigureAwait(false);
httpResponse.EnsureSuccessStatusCode();
}
private void StartWebApplication()
{
var builder = WebApplication.CreateBuilder();
- builder.Services.AddControllers();
builder.Logging.ClearProviders();
var app = builder.Build();
- app.MapControllers();
+ app.MapGet("/", () => $"Hello World!");
app.RunAsync();
this.app = app;
diff --git a/test/Benchmarks/Instrumentation/InstrumentedAspNetCoreBenchmark.cs b/test/Benchmarks/Instrumentation/InstrumentedAspNetCoreBenchmark.cs
deleted file mode 100644
index 4672a0ade..000000000
--- a/test/Benchmarks/Instrumentation/InstrumentedAspNetCoreBenchmark.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-//
-// 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.
-//
-
-#if !NETFRAMEWORK
-using System.Net.Http;
-using System.Threading.Tasks;
-using BenchmarkDotNet.Attributes;
-using Benchmarks.Helper;
-
-namespace Benchmarks.Instrumentation
-{
- [InProcess]
- public class InstrumentedAspNetCoreBenchmark
- {
- private const string LocalhostUrl = "http://localhost:5050";
-
- private HttpClient client;
- private LocalServer localServer;
-
- [GlobalSetup]
- public void GlobalSetup()
- {
- this.localServer = new LocalServer(LocalhostUrl, true);
- this.client = new HttpClient();
- }
-
- [GlobalCleanup]
- public void GlobalCleanup()
- {
- this.localServer.Dispose();
- this.client.Dispose();
- }
-
- [Benchmark]
- public async Task InstrumentedAspNetCoreGetPage()
- {
- var httpResponse = await this.client.GetAsync(LocalhostUrl).ConfigureAwait(false);
- httpResponse.EnsureSuccessStatusCode();
- }
- }
-}
-#endif
diff --git a/test/Benchmarks/Instrumentation/UninstrumentedAspNetCoreBenchmark.cs b/test/Benchmarks/Instrumentation/UninstrumentedAspNetCoreBenchmark.cs
deleted file mode 100644
index b207c9160..000000000
--- a/test/Benchmarks/Instrumentation/UninstrumentedAspNetCoreBenchmark.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-//
-// 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.
-//
-
-#if !NETFRAMEWORK
-using System.Net.Http;
-using System.Threading.Tasks;
-using BenchmarkDotNet.Attributes;
-using Benchmarks.Helper;
-
-namespace Benchmarks.Instrumentation
-{
- [InProcess]
- public class UninstrumentedAspNetCoreBenchmark
- {
- private const string LocalhostUrl = "http://localhost:5050";
-
- private HttpClient client;
- private LocalServer localServer;
-
- [GlobalSetup]
- public void GlobalSetup()
- {
- this.localServer = new LocalServer(LocalhostUrl);
- this.client = new HttpClient();
- }
-
- [GlobalCleanup]
- public void GlobalCleanup()
- {
- this.client.Dispose();
- this.localServer.Dispose();
- }
-
- [Benchmark]
- public async Task SimpleAspNetCoreGetPage()
- {
- var httpResponse = await this.client.GetAsync(LocalhostUrl).ConfigureAwait(false);
- httpResponse.EnsureSuccessStatusCode();
- }
- }
-}
-#endif