Refactor asp.net core test apps (#3558)

This commit is contained in:
Vishwesh Bankwar 2022-08-08 20:41:03 -07:00 committed by GitHub
parent 361912efa7
commit b8385a8ca0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 120 additions and 616 deletions

View File

@ -208,8 +208,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Tests.Stress"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs", "src\OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs\OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs.csproj", "{6E1A5FA3-E024-4972-9EDC-11E36C5A0D6F}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs", "src\OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs\OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs.csproj", "{6E1A5FA3-E024-4972-9EDC-11E36C5A0D6F}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApp.AspNetCore.6.0", "test\TestApp.AspNetCore.6.0\TestApp.AspNetCore.6.0.csproj", "{0076C657-564F-4787-9FFF-52D9D55166E8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "source-generation", "docs\logs\source-generation\source-generation.csproj", "{1F6CC903-04C9-4E7C-B388-C215C467BFB9}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "source-generation", "docs\logs\source-generation\source-generation.csproj", "{1F6CC903-04C9-4E7C-B388-C215C467BFB9}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "getting-started-prometheus-grafana", "docs\metrics\getting-started-prometheus-grafana\getting-started-prometheus-grafana.csproj", "{41B784AA-3301-4126-AF9F-1D59BD04B0BF}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "getting-started-prometheus-grafana", "docs\metrics\getting-started-prometheus-grafana\getting-started-prometheus-grafana.csproj", "{41B784AA-3301-4126-AF9F-1D59BD04B0BF}"
@ -244,7 +242,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.Prom
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Tests.Stress.Traces", "test\OpenTelemetry.Tests.Stress.Traces\OpenTelemetry.Tests.Stress.Traces.csproj", "{5697662B-5F14-4E32-BB11-1D8942782AB6}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Tests.Stress.Traces", "test\OpenTelemetry.Tests.Stress.Traces\OpenTelemetry.Tests.Stress.Traces.csproj", "{5697662B-5F14-4E32-BB11-1D8942782AB6}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApp.AspNetCore.7.0", "test\TestApp.AspNetCore.7.0\TestApp.AspNetCore.7.0.csproj", "{6BCAEBBA-C805-454B-8E13-F9C161910E4A}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApp.AspNetCore", "test\TestApp.AspNetCore\TestApp.AspNetCore.csproj", "{5FDAF679-DE5A-4C73-A49B-8ABCF2399229}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -436,10 +434,6 @@ Global
{6E1A5FA3-E024-4972-9EDC-11E36C5A0D6F}.Debug|Any CPU.Build.0 = Debug|Any CPU {6E1A5FA3-E024-4972-9EDC-11E36C5A0D6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6E1A5FA3-E024-4972-9EDC-11E36C5A0D6F}.Release|Any CPU.ActiveCfg = Release|Any CPU {6E1A5FA3-E024-4972-9EDC-11E36C5A0D6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6E1A5FA3-E024-4972-9EDC-11E36C5A0D6F}.Release|Any CPU.Build.0 = Release|Any CPU {6E1A5FA3-E024-4972-9EDC-11E36C5A0D6F}.Release|Any CPU.Build.0 = Release|Any CPU
{0076C657-564F-4787-9FFF-52D9D55166E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0076C657-564F-4787-9FFF-52D9D55166E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0076C657-564F-4787-9FFF-52D9D55166E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0076C657-564F-4787-9FFF-52D9D55166E8}.Release|Any CPU.Build.0 = Release|Any CPU
{1F6CC903-04C9-4E7C-B388-C215C467BFB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1F6CC903-04C9-4E7C-B388-C215C467BFB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F6CC903-04C9-4E7C-B388-C215C467BFB9}.Debug|Any CPU.Build.0 = Debug|Any CPU {1F6CC903-04C9-4E7C-B388-C215C467BFB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F6CC903-04C9-4E7C-B388-C215C467BFB9}.Release|Any CPU.ActiveCfg = Release|Any CPU {1F6CC903-04C9-4E7C-B388-C215C467BFB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -508,10 +502,10 @@ Global
{5697662B-5F14-4E32-BB11-1D8942782AB6}.Debug|Any CPU.Build.0 = Debug|Any CPU {5697662B-5F14-4E32-BB11-1D8942782AB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5697662B-5F14-4E32-BB11-1D8942782AB6}.Release|Any CPU.ActiveCfg = Release|Any CPU {5697662B-5F14-4E32-BB11-1D8942782AB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5697662B-5F14-4E32-BB11-1D8942782AB6}.Release|Any CPU.Build.0 = Release|Any CPU {5697662B-5F14-4E32-BB11-1D8942782AB6}.Release|Any CPU.Build.0 = Release|Any CPU
{6BCAEBBA-C805-454B-8E13-F9C161910E4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5FDAF679-DE5A-4C73-A49B-8ABCF2399229}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6BCAEBBA-C805-454B-8E13-F9C161910E4A}.Debug|Any CPU.Build.0 = Debug|Any CPU {5FDAF679-DE5A-4C73-A49B-8ABCF2399229}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6BCAEBBA-C805-454B-8E13-F9C161910E4A}.Release|Any CPU.ActiveCfg = Release|Any CPU {5FDAF679-DE5A-4C73-A49B-8ABCF2399229}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BCAEBBA-C805-454B-8E13-F9C161910E4A}.Release|Any CPU.Build.0 = Release|Any CPU {5FDAF679-DE5A-4C73-A49B-8ABCF2399229}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -543,13 +537,12 @@ Global
{EA60B549-F712-4ABE-8E44-FCA83B78C06E} = {3277B1C0-BDFE-4460-9B0D-D9A661FB48DB} {EA60B549-F712-4ABE-8E44-FCA83B78C06E} = {3277B1C0-BDFE-4460-9B0D-D9A661FB48DB}
{1F9D7748-D099-4E25-97F5-9C969D6FF969} = {3277B1C0-BDFE-4460-9B0D-D9A661FB48DB} {1F9D7748-D099-4E25-97F5-9C969D6FF969} = {3277B1C0-BDFE-4460-9B0D-D9A661FB48DB}
{81234AFA-B4E7-4D0D-AB97-FD559C78EDA2} = {3277B1C0-BDFE-4460-9B0D-D9A661FB48DB} {81234AFA-B4E7-4D0D-AB97-FD559C78EDA2} = {3277B1C0-BDFE-4460-9B0D-D9A661FB48DB}
{0076C657-564F-4787-9FFF-52D9D55166E8} = {77C7929A-2EED-4AA6-8705-B5C443C8AA0F}
{1F6CC903-04C9-4E7C-B388-C215C467BFB9} = {3862190B-E2C5-418E-AFDC-DB281FB5C705} {1F6CC903-04C9-4E7C-B388-C215C467BFB9} = {3862190B-E2C5-418E-AFDC-DB281FB5C705}
{41B784AA-3301-4126-AF9F-1D59BD04B0BF} = {3277B1C0-BDFE-4460-9B0D-D9A661FB48DB} {41B784AA-3301-4126-AF9F-1D59BD04B0BF} = {3277B1C0-BDFE-4460-9B0D-D9A661FB48DB}
{6C7A1595-36D6-4229-BBB5-5A6B5791791D} = {3862190B-E2C5-418E-AFDC-DB281FB5C705} {6C7A1595-36D6-4229-BBB5-5A6B5791791D} = {3862190B-E2C5-418E-AFDC-DB281FB5C705}
{9A07D215-90AC-4BAF-BCDB-73D74FD3A5C5} = {3862190B-E2C5-418E-AFDC-DB281FB5C705} {9A07D215-90AC-4BAF-BCDB-73D74FD3A5C5} = {3862190B-E2C5-418E-AFDC-DB281FB5C705}
{F5EFF065-7AF5-4D7D-8038-CC419ABD8777} = {E359BB2B-9AEC-497D-B321-7DF2450C3B8E} {F5EFF065-7AF5-4D7D-8038-CC419ABD8777} = {E359BB2B-9AEC-497D-B321-7DF2450C3B8E}
{6BCAEBBA-C805-454B-8E13-F9C161910E4A} = {77C7929A-2EED-4AA6-8705-B5C443C8AA0F} {5FDAF679-DE5A-4C73-A49B-8ABCF2399229} = {77C7929A-2EED-4AA6-8705-B5C443C8AA0F}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {55639B5C-0770-4A22-AB56-859604650521} SolutionGuid = {55639B5C-0770-4A22-AB56-859604650521}

View File

@ -44,7 +44,7 @@
<MoqPkgVer>[4.14.5,5.0)</MoqPkgVer> <MoqPkgVer>[4.14.5,5.0)</MoqPkgVer>
<RabbitMQClientPkgVer>[6.1.0,7.0)</RabbitMQClientPkgVer> <RabbitMQClientPkgVer>[6.1.0,7.0)</RabbitMQClientPkgVer>
<RuntimeInstrumentationPkgVer>[1.0.0,2.0)</RuntimeInstrumentationPkgVer> <RuntimeInstrumentationPkgVer>[1.0.0,2.0)</RuntimeInstrumentationPkgVer>
<SwashbuckleAspNetCorePkgVer>[6.2.3]</SwashbuckleAspNetCorePkgVer> <SwashbuckleAspNetCorePkgVer>[6.4.0]</SwashbuckleAspNetCorePkgVer>
<SystemTextJsonPkgVer>6.0.5</SystemTextJsonPkgVer> <SystemTextJsonPkgVer>6.0.5</SystemTextJsonPkgVer>
<XUnitRunnerVisualStudioPkgVer>[2.4.3,3.0)</XUnitRunnerVisualStudioPkgVer> <XUnitRunnerVisualStudioPkgVer>[2.4.3,3.0)</XUnitRunnerVisualStudioPkgVer>
<XUnitPkgVer>[2.4.1,3.0)</XUnitPkgVer> <XUnitPkgVer>[2.4.1,3.0)</XUnitPkgVer>

View File

@ -31,25 +31,19 @@ using OpenTelemetry.Context.Propagation;
using OpenTelemetry.Instrumentation.AspNetCore.Implementation; using OpenTelemetry.Instrumentation.AspNetCore.Implementation;
using OpenTelemetry.Tests; using OpenTelemetry.Tests;
using OpenTelemetry.Trace; using OpenTelemetry.Trace;
using TestApp.AspNetCore;
#if NET6_0
using TestApp.AspNetCore._6._0;
#endif
#if NET7_0
using TestApp.AspNetCore._7._0;
#endif
using Xunit; using Xunit;
namespace OpenTelemetry.Instrumentation.AspNetCore.Tests namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
{ {
// See https://github.com/aspnet/Docs/tree/master/aspnetcore/test/integration-tests/samples/2.x/IntegrationTestsSample // See https://github.com/aspnet/Docs/tree/master/aspnetcore/test/integration-tests/samples/2.x/IntegrationTestsSample
public sealed class BasicTests public sealed class BasicTests
: IClassFixture<WebApplicationFactory<Startup>>, IDisposable : IClassFixture<WebApplicationFactory<Program>>, IDisposable
{ {
private readonly WebApplicationFactory<Startup> factory; private readonly WebApplicationFactory<Program> factory;
private TracerProvider tracerProvider = null; private TracerProvider tracerProvider = null;
public BasicTests(WebApplicationFactory<Startup> factory) public BasicTests(WebApplicationFactory<Program> factory)
{ {
this.factory = factory; this.factory = factory;
} }

View File

@ -18,22 +18,16 @@ using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost; using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry.Trace; using OpenTelemetry.Trace;
#if NET6_0
using TestApp.AspNetCore._6._0;
#endif
#if NET7_0
using TestApp.AspNetCore._7._0;
#endif
using Xunit; using Xunit;
namespace OpenTelemetry.Instrumentation.AspNetCore.Tests namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
{ {
public class DependencyInjectionConfigTests public class DependencyInjectionConfigTests
: IClassFixture<WebApplicationFactory<Startup>> : IClassFixture<WebApplicationFactory<Program>>
{ {
private readonly WebApplicationFactory<Startup> factory; private readonly WebApplicationFactory<Program> factory;
public DependencyInjectionConfigTests(WebApplicationFactory<Startup> factory) public DependencyInjectionConfigTests(WebApplicationFactory<Program> factory)
{ {
this.factory = factory; this.factory = factory;
} }

View File

@ -25,22 +25,17 @@ using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost; using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry.Trace; using OpenTelemetry.Trace;
#if NET6_0 using TestApp.AspNetCore;
using TestApp.AspNetCore._6._0;
#endif
#if NET7_0
using TestApp.AspNetCore._7._0;
#endif
using Xunit; using Xunit;
namespace OpenTelemetry.Instrumentation.AspNetCore.Tests namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
{ {
public class IncomingRequestsCollectionsIsAccordingToTheSpecTests public class IncomingRequestsCollectionsIsAccordingToTheSpecTests
: IClassFixture<WebApplicationFactory<Startup>> : IClassFixture<WebApplicationFactory<Program>>
{ {
private readonly WebApplicationFactory<Startup> factory; private readonly WebApplicationFactory<Program> factory;
public IncomingRequestsCollectionsIsAccordingToTheSpecTests(WebApplicationFactory<Startup> factory) public IncomingRequestsCollectionsIsAccordingToTheSpecTests(WebApplicationFactory<Program> factory)
{ {
this.factory = factory; this.factory = factory;
} }

View File

@ -21,23 +21,17 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.AspNetCore.Mvc.Testing;
using OpenTelemetry.Metrics; using OpenTelemetry.Metrics;
using OpenTelemetry.Trace; using OpenTelemetry.Trace;
#if NET6_0
using TestApp.AspNetCore._6._0;
#endif
#if NET7_0
using TestApp.AspNetCore._7._0;
#endif
using Xunit; using Xunit;
namespace OpenTelemetry.Instrumentation.AspNetCore.Tests namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
{ {
public class MetricTests public class MetricTests
: IClassFixture<WebApplicationFactory<Startup>>, IDisposable : IClassFixture<WebApplicationFactory<Program>>, IDisposable
{ {
private readonly WebApplicationFactory<Startup> factory; private readonly WebApplicationFactory<Program> factory;
private MeterProvider meterProvider = null; private MeterProvider meterProvider = null;
public MetricTests(WebApplicationFactory<Startup> factory) public MetricTests(WebApplicationFactory<Program> factory)
{ {
this.factory = factory; this.factory = factory;
} }

View File

@ -19,6 +19,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Exporter.InMemory\OpenTelemetry.Exporter.InMemory.csproj" /> <ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Exporter.InMemory\OpenTelemetry.Exporter.InMemory.csproj" />
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.AspNetCore\OpenTelemetry.Instrumentation.AspNetCore.csproj" /> <ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.AspNetCore\OpenTelemetry.Instrumentation.AspNetCore.csproj" />
<ProjectReference Include="$(RepoRoot)\test\TestApp.AspNetCore\TestApp.AspNetCore.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -28,12 +29,10 @@
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'"> <ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<ProjectReference Include="$(RepoRoot)\test\TestApp.AspNetCore.7.0\TestApp.AspNetCore.7.0.csproj" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.0-preview.5.22303.8" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.0-preview.5.22303.8" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'"> <ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<ProjectReference Include="$(RepoRoot)\test\TestApp.AspNetCore.6.0\TestApp.AspNetCore.6.0.csproj" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.0" />
</ItemGroup> </ItemGroup>

View File

@ -22,6 +22,7 @@
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.AspNetCore\OpenTelemetry.Instrumentation.AspNetCore.csproj" /> <ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.AspNetCore\OpenTelemetry.Instrumentation.AspNetCore.csproj" />
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.Http\OpenTelemetry.Instrumentation.Http.csproj" /> <ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.Http\OpenTelemetry.Instrumentation.Http.csproj" />
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry\OpenTelemetry.csproj" /> <ProjectReference Include="$(RepoRoot)\src\OpenTelemetry\OpenTelemetry.csproj" />
<ProjectReference Include="$(RepoRoot)\test\TestApp.AspNetCore\TestApp.AspNetCore.csproj" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\ActivityHelperExtensions.cs" Link="Includes\ActivityHelperExtensions.cs" /> <Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\ActivityHelperExtensions.cs" Link="Includes\ActivityHelperExtensions.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\StatusHelper.cs" Link="Includes\StatusHelper.cs" /> <Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\StatusHelper.cs" Link="Includes\StatusHelper.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\IActivityEnumerator.cs" Link="Includes\IActivityEnumerator.cs" /> <Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\IActivityEnumerator.cs" Link="Includes\IActivityEnumerator.cs" />

View File

@ -1,24 +0,0 @@
// <copyright file="AssemblyInfo.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.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage(
"StyleCop.CSharp.NamingRules",
"SA1300",
Justification = "Reviewed.",
Scope = "namespaceanddescendants",
Target = "TestApp.AspNetCore._6._0")]

View File

@ -1,33 +0,0 @@
// <copyright file="Program.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 Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace TestApp.AspNetCore._6._0
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
}

View File

@ -1,66 +0,0 @@
// <copyright file="Startup.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 Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace TestApp.AspNetCore._6._0
{
public class Startup
{
public Startup(IConfiguration configuration)
{
this.Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddSingleton<HttpClient>();
services.AddSingleton(
new CallbackMiddleware.CallbackMiddlewareImpl());
services.AddSingleton(
new ActivityMiddleware.ActivityMiddlewareImpl());
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMiddleware<CallbackMiddleware>();
app.UseMiddleware<ActivityMiddleware>();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}

View File

@ -1,25 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="wwwroot\**" />
<Content Remove="wwwroot\**" />
<EmbeddedResource Remove="wwwroot\**" />
<None Remove="wwwroot\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Api\OpenTelemetry.Api.csproj" />
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.AspNetCore\OpenTelemetry.Instrumentation.AspNetCore.csproj" />
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Extensions.Hosting\OpenTelemetry.Extensions.Hosting.csproj" />
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry\OpenTelemetry.csproj" />
</ItemGroup>
</Project>

View File

@ -1,10 +0,0 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}

View File

@ -1,15 +0,0 @@
{
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Warning"
}
},
"Console": {
"LogLevel": {
"Default": "Warning"
}
}
}
}

View File

@ -1,61 +0,0 @@
// <copyright file="ActivityMiddleware.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.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace TestApp.AspNetCore._7._0
{
public class ActivityMiddleware
{
private readonly ActivityMiddlewareImpl impl;
private readonly RequestDelegate next;
public ActivityMiddleware(RequestDelegate next, ActivityMiddlewareImpl impl)
{
this.next = next;
this.impl = impl;
}
public async Task InvokeAsync(HttpContext context)
{
if (this.impl != null)
{
this.impl.PreProcess(context);
}
await this.next(context);
if (this.impl != null)
{
this.impl.PostProcess(context);
}
}
public class ActivityMiddlewareImpl
{
public virtual void PreProcess(HttpContext context)
{
// do nothing
}
public virtual void PostProcess(HttpContext context)
{
// do nothing
}
}
}
}

View File

@ -1,24 +0,0 @@
// <copyright file="AssemblyInfo.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.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage(
"StyleCop.CSharp.NamingRules",
"SA1300",
Justification = "Reviewed.",
Scope = "namespaceanddescendants",
Target = "TestApp.AspNetCore._7._0")]

View File

@ -1,51 +0,0 @@
// <copyright file="CallbackMiddleware.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.Threading.Tasks;
using Microsoft.AspNetCore.Http;
#pragma warning disable SA1300 // Element should begin with upper-case letter
namespace TestApp.AspNetCore._7._0
#pragma warning restore SA1300 // Element should begin with upper-case letter
{
public class CallbackMiddleware
{
private readonly CallbackMiddlewareImpl impl;
private readonly RequestDelegate next;
public CallbackMiddleware(RequestDelegate next, CallbackMiddlewareImpl impl)
{
this.next = next;
this.impl = impl;
}
public async Task InvokeAsync(HttpContext context)
{
if (this.impl == null || await this.impl.ProcessAsync(context))
{
await this.next(context);
}
}
public class CallbackMiddlewareImpl
{
public virtual async Task<bool> ProcessAsync(HttpContext context)
{
return await Task.FromResult(true);
}
}
}
}

View File

@ -1,48 +0,0 @@
// <copyright file="ChildActivityController.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.Collections.Generic;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using OpenTelemetry;
#pragma warning disable SA1300 // Element should begin with upper-case letter
namespace TestApp.AspNetCore._7._0.Controllers
#pragma warning restore SA1300 // Element should begin with upper-case letter
{
public class ChildActivityController : Controller
{
[Route("api/GetChildActivityTraceContext")]
public Dictionary<string, string> GetChildActivityTraceContext()
{
var result = new Dictionary<string, string>();
var activity = new Activity("ActivityInsideHttpRequest");
activity.Start();
result["TraceId"] = activity.Context.TraceId.ToString();
result["ParentSpanId"] = activity.ParentSpanId.ToString();
result["TraceState"] = activity.Context.TraceState;
activity.Stop();
return result;
}
[Route("api/GetChildActivityBaggageContext")]
public IReadOnlyDictionary<string, string> GetChildActivityBaggageContext()
{
var result = Baggage.Current.GetBaggage();
return result;
}
}
}

View File

@ -1,58 +0,0 @@
// <copyright file="ValuesController.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.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
#pragma warning disable SA1300 // Element should begin with upper-case letter
namespace TestApp.AspNetCore._7._0.Controllers
#pragma warning restore SA1300 // Element should begin with upper-case letter
{
[Route("api/[controller]")]
public class ValuesController : Controller
{
// GET api/values
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/values
[HttpPost]
public void Post([FromBody] string value)
{
}
// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}

View File

@ -1,35 +0,0 @@
// <copyright file="Program.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 Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
#pragma warning disable SA1300 // Element should begin with upper-case letter
namespace TestApp.AspNetCore._7._0
#pragma warning restore SA1300 // Element should begin with upper-case letter
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
}

View File

@ -1,68 +0,0 @@
// <copyright file="Startup.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 Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
#pragma warning disable SA1300 // Element should begin with upper-case letter
namespace TestApp.AspNetCore._7._0
#pragma warning restore SA1300 // Element should begin with upper-case letter
{
public class Startup
{
public Startup(IConfiguration configuration)
{
this.Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddSingleton<HttpClient>();
services.AddSingleton(
new CallbackMiddleware.CallbackMiddlewareImpl());
services.AddSingleton(
new ActivityMiddleware.ActivityMiddlewareImpl());
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMiddleware<CallbackMiddleware>();
app.UseMiddleware<ActivityMiddleware>();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}

View File

@ -1,10 +0,0 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}

View File

@ -1,15 +0,0 @@
{
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Warning"
}
},
"Console": {
"LogLevel": {
"Default": "Warning"
}
}
}
}

View File

@ -14,10 +14,7 @@
// limitations under the License. // limitations under the License.
// </copyright> // </copyright>
using System.Threading.Tasks; namespace TestApp.AspNetCore
using Microsoft.AspNetCore.Http;
namespace TestApp.AspNetCore._6._0
{ {
public class ActivityMiddleware public class ActivityMiddleware
{ {

View File

@ -14,10 +14,7 @@
// limitations under the License. // limitations under the License.
// </copyright> // </copyright>
using System.Threading.Tasks; namespace TestApp.AspNetCore
using Microsoft.AspNetCore.Http;
namespace TestApp.AspNetCore._6._0
{ {
public class CallbackMiddleware public class CallbackMiddleware
{ {

View File

@ -19,10 +19,11 @@ using System.Diagnostics;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using OpenTelemetry; using OpenTelemetry;
namespace TestApp.AspNetCore._6._0.Controllers namespace TestApp.AspNetCore.Controllers
{ {
public class ChildActivityController : Controller public class ChildActivityController : Controller
{ {
[HttpGet]
[Route("api/GetChildActivityTraceContext")] [Route("api/GetChildActivityTraceContext")]
public Dictionary<string, string> GetChildActivityTraceContext() public Dictionary<string, string> GetChildActivityTraceContext()
{ {
@ -31,11 +32,16 @@ namespace TestApp.AspNetCore._6._0.Controllers
activity.Start(); activity.Start();
result["TraceId"] = activity.Context.TraceId.ToString(); result["TraceId"] = activity.Context.TraceId.ToString();
result["ParentSpanId"] = activity.ParentSpanId.ToString(); result["ParentSpanId"] = activity.ParentSpanId.ToString();
result["TraceState"] = activity.Context.TraceState; if (activity.Context.TraceState != null)
{
result["TraceState"] = activity.Context.TraceState;
}
activity.Stop(); activity.Stop();
return result; return result;
} }
[HttpGet]
[Route("api/GetChildActivityBaggageContext")] [Route("api/GetChildActivityBaggageContext")]
public IReadOnlyDictionary<string, string> GetChildActivityBaggageContext() public IReadOnlyDictionary<string, string> GetChildActivityBaggageContext()
{ {

View File

@ -16,7 +16,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace TestApp.AspNetCore._6._0.Controllers namespace TestApp.AspNetCore.Controllers
{ {
[Route("api/[controller]")] [Route("api/[controller]")]
public class ValuesController : Controller public class ValuesController : Controller

View File

@ -0,0 +1,65 @@
// <copyright file="Program.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 TestApp.AspNetCore;
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddMvc();
builder.Services.AddSingleton<HttpClient>();
builder.Services.AddSingleton(
new CallbackMiddleware.CallbackMiddlewareImpl());
builder.Services.AddSingleton(
new ActivityMiddleware.ActivityMiddlewareImpl());
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.UseMiddleware<CallbackMiddleware>();
app.UseMiddleware<ActivityMiddleware>();
app.Run();
}
}

View File

@ -1,18 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0</TargetFramework> <TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Remove="wwwroot\**" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="$(SwashbuckleAspNetCorePkgVer)" />
<Content Remove="wwwroot\**" />
<EmbeddedResource Remove="wwwroot\**" />
<None Remove="wwwroot\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.0-preview.4.22259.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}