提交 b08027d4 编写于 作者: J James Yeung 提交者: Savorboard

refactor hosting (#278)

上级 4b5809d7
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Hosting;
namespace SkyApm.Sample.Backend namespace SkyApm.Sample.Backend
{ {
...@@ -8,7 +9,15 @@ namespace SkyApm.Sample.Backend ...@@ -8,7 +9,15 @@ namespace SkyApm.Sample.Backend
public static void Main(string[] args) public static void Main(string[] args)
{ {
BuildHost(args).Run(); BuildHost(args).Run();
} }
#if NETCOREAPP2_1
public static IWebHost BuildHost(string[] args) =>
WebHost.CreateDefaultBuilder<Startup>(args)
.Build();
#else
public static IHost BuildHost(string[] args) => public static IHost BuildHost(string[] args) =>
Host.CreateDefaultBuilder(args) Host.CreateDefaultBuilder(args)
...@@ -16,5 +25,7 @@ namespace SkyApm.Sample.Backend ...@@ -16,5 +25,7 @@ namespace SkyApm.Sample.Backend
{ {
builder.UseStartup<Startup>(); builder.UseStartup<Startup>();
}).Build(); }).Build();
#endif
} }
} }
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFrameworks>netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" /> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" />
...@@ -11,11 +11,15 @@ ...@@ -11,11 +11,15 @@
<ProjectReference Include="..\grpc\SkyApm.Sample.GrpcProto\SkyApm.Sample.GrpcProto.csproj" /> <ProjectReference Include="..\grpc\SkyApm.Sample.GrpcProto\SkyApm.Sample.GrpcProto.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Grpc.AspNetCore" Version="2.26.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite"> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite">
<Version>3.1.0</Version> <Version>3.1.0</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.0" /> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="Grpc.AspNetCore" Version="2.26.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0" PrivateAssets="All" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Update="appsettings.json"> <Content Update="appsettings.json">
......
...@@ -10,6 +10,12 @@ using SkyApm.Sample.Backend.Services; ...@@ -10,6 +10,12 @@ using SkyApm.Sample.Backend.Services;
using SkyApm.Sample.GrpcServer; using SkyApm.Sample.GrpcServer;
using SkyApm.Tracing; using SkyApm.Tracing;
#if NETCOREAPP2_1
using IHostEnvironment = Microsoft.Extensions.Hosting.IHostingEnvironment;
#endif
namespace SkyApm.Sample.Backend namespace SkyApm.Sample.Backend
{ {
public class Startup public class Startup
...@@ -24,7 +30,14 @@ namespace SkyApm.Sample.Backend ...@@ -24,7 +30,14 @@ namespace SkyApm.Sample.Backend
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddControllers(); #if NETCOREAPP2_1
services.AddMvc();
#else
services.AddControllers();
#endif
var sqlLiteConnection = new SqliteConnection("DataSource=:memory:"); var sqlLiteConnection = new SqliteConnection("DataSource=:memory:");
sqlLiteConnection.Open(); sqlLiteConnection.Open();
...@@ -35,7 +48,10 @@ namespace SkyApm.Sample.Backend ...@@ -35,7 +48,10 @@ namespace SkyApm.Sample.Backend
// DI grpc service // DI grpc service
services.AddSingleton<GreeterGrpcService>(); services.AddSingleton<GreeterGrpcService>();
#if !NETCOREAPP2_1
services.AddGrpc(); services.AddGrpc();
#endif
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
...@@ -46,10 +62,15 @@ namespace SkyApm.Sample.Backend ...@@ -46,10 +62,15 @@ namespace SkyApm.Sample.Backend
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
} }
using var scope = app.ApplicationServices.CreateScope(); using (var scope = app.ApplicationServices.CreateScope())
using var sampleDbContext = scope.ServiceProvider.GetService<SampleDbContext>(); using (var sampleDbContext = scope.ServiceProvider.GetService<SampleDbContext>())
sampleDbContext.Database.EnsureCreated(); {
sampleDbContext.Database.EnsureCreated();
}
#if NETCOREAPP2_1
app.UseMvcWithDefaultRoute();
#else
app.UseRouting(); app.UseRouting();
app.UseEndpoints(endpoint => app.UseEndpoints(endpoint =>
...@@ -57,6 +78,7 @@ namespace SkyApm.Sample.Backend ...@@ -57,6 +78,7 @@ namespace SkyApm.Sample.Backend
endpoint.MapDefaultControllerRoute(); endpoint.MapDefaultControllerRoute();
endpoint.MapGrpcService<GreeterImpl>(); endpoint.MapGrpcService<GreeterImpl>();
}); });
#endif
} }
} }
} }
\ No newline at end of file
...@@ -3,10 +3,15 @@ using System.Collections.Generic; ...@@ -3,10 +3,15 @@ using System.Collections.Generic;
using System.Net.Http; using System.Net.Http;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Grpc.Net.Client;
using GrpcGreeter; using GrpcGreeter;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using SkyApm.Sample.Backend.Services; using SkyApm.Sample.Backend.Services;
#if NETCOREAPP2_1
#else
using Grpc.Net.Client;
#endif
namespace SkyApm.Sample.Frontend.Controllers namespace SkyApm.Sample.Frontend.Controllers
{ {
...@@ -61,16 +66,19 @@ namespace SkyApm.Sample.Frontend.Controllers ...@@ -61,16 +66,19 @@ namespace SkyApm.Sample.Frontend.Controllers
return Ok(message); return Ok(message);
} }
#if NETCOREAPP2_1
#else
[HttpGet("greeter/grpc-net")] [HttpGet("greeter/grpc-net")]
public async Task<IActionResult> GrpcNetAsync(string name) public async Task<IActionResult> GrpcNetAsync(string name)
{ {
const string Switch_AllowUnencryptedHttp2 = "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport"; const string Switch_AllowUnencryptedHttp2 = "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport";
AppContext.SetSwitch(Switch_AllowUnencryptedHttp2, true); AppContext.SetSwitch(Switch_AllowUnencryptedHttp2, true);
var channel = GrpcChannel.ForAddress("http://localhost:5003"); var channel = GrpcChannel.ForAddress("http://localhost:5003");
var client = new Greeter.GreeterClient(channel); var client = new Greeter.GreeterClient(channel);
var result = await client.SayHelloAsync(new HelloRequest() { Name = name }); var result = await client.SayHelloAsync(new HelloRequest() { Name = name });
return Ok(result); return Ok(result);
} }
#endif
} }
} }
\ No newline at end of file
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
namespace SkyApm.Sample.Frontend namespace SkyApm.Sample.Frontend
...@@ -10,14 +11,21 @@ namespace SkyApm.Sample.Frontend ...@@ -10,14 +11,21 @@ namespace SkyApm.Sample.Frontend
BuildHost(args).Run(); BuildHost(args).Run();
} }
#if NETCOREAPP2_1
public static IWebHost BuildHost(string[] args) =>
WebHost.CreateDefaultBuilder<Startup>(args)
.Build();
#else
public static IHost BuildHost(string[] args) => public static IHost BuildHost(string[] args) =>
Host.CreateDefaultBuilder(args) Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(builder => .ConfigureWebHostDefaults(builder =>
{ {
builder builder.UseStartup<Startup>();
.UseStartup<Startup>() }).Build();
.UseUrls("http://*:5001");
}) #endif
.Build();
} }
} }
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFrameworks>netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
<RootNamespace>SkyApm.Sample.Backend</RootNamespace> <RootNamespace>SkyApm.Sample.Backend</RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" /> <ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
</ItemGroup>
<ItemGroup>
<PackageReference Include="Grpc.Net.Client" Version="2.26.0" /> <PackageReference Include="Grpc.Net.Client" Version="2.26.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<Content Update="appsettings.json"> <Content Update="appsettings.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
......
...@@ -4,6 +4,12 @@ using Microsoft.Extensions.DependencyInjection; ...@@ -4,6 +4,12 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using SkyApm.Sample.Backend.Services; using SkyApm.Sample.Backend.Services;
#if NETCOREAPP2_1
using IHostEnvironment = Microsoft.Extensions.Hosting.IHostingEnvironment;
#endif
namespace SkyApm.Sample.Frontend namespace SkyApm.Sample.Frontend
{ {
public class Startup public class Startup
...@@ -18,7 +24,13 @@ namespace SkyApm.Sample.Frontend ...@@ -18,7 +24,13 @@ namespace SkyApm.Sample.Frontend
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddControllers(); #if NETCOREAPP2_1
services.AddMvc();
#else
services.AddControllers();
#endif
// DI grpc service // DI grpc service
services.AddSingleton<GreeterGrpcService>(); services.AddSingleton<GreeterGrpcService>();
...@@ -31,13 +43,16 @@ namespace SkyApm.Sample.Frontend ...@@ -31,13 +43,16 @@ namespace SkyApm.Sample.Frontend
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
} }
#if NETCOREAPP2_1
app.UseMvcWithDefaultRoute();
#else
app.UseRouting(); app.UseRouting();
app.UseEndpoints(endpoint => app.UseEndpoints(endpoint =>
{ {
endpoint.MapDefaultControllerRoute(); endpoint.MapDefaultControllerRoute();
}); });
#endif
} }
} }
} }
\ No newline at end of file
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using SkyApm.Agent.GeneralHost;
namespace SkyApm.Sample.GeneralHost namespace SkyApm.Sample.GenericHost
{ {
public class Program public class Program
{ {
...@@ -12,8 +11,8 @@ namespace SkyApm.Sample.GeneralHost ...@@ -12,8 +11,8 @@ namespace SkyApm.Sample.GeneralHost
} }
public static IHostBuilder CreateHostBuilder(string[] args) => public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args) new HostBuilder()
.ConfigureServices(services => services.AddHostedService<Worker>()) .ConfigureServices(services => services.AddHostedService<Worker>())
.AddSkyAPM(); .AddSkyAPM();
} }
} }
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFrameworks>netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
</PropertyGroup> </PropertyGroup>
...@@ -10,9 +10,17 @@ ...@@ -10,9 +10,17 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content> </Content>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.1.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.0" /> <PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.0" />
</ItemGroup>
<ProjectReference Include="..\..\src\SkyApm.Agent.GeneralHost\SkyApm.Agent.GeneralHost.csproj" /> <ItemGroup>
<ProjectReference Include="..\..\src\SkyApm.Agent.Hosting\SkyApm.Agent.Hosting.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
...@@ -6,7 +6,7 @@ using System.Collections.Generic; ...@@ -6,7 +6,7 @@ using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SkyApm.Sample.GeneralHost namespace SkyApm.Sample.GenericHost
{ {
public class Worker : BackgroundService public class Worker : BackgroundService
{ {
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
"QueueSize": 30000, "QueueSize": 30000,
"BatchSize": 3000, "BatchSize": 3000,
"gRPC": { "gRPC": {
"Servers": "192.168.79.132:11800", "Servers": "localhost:11800",
"Timeout": 100000, "Timeout": 100000,
"ConnectTimeout": 100000, "ConnectTimeout": 100000,
"ReportTimeout": 600000 "ReportTimeout": 600000
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
using GrpcGreeter; using GrpcGreeter;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using SkyApm.Agent.GeneralHost;
using System; using System;
using System.Net.Http; using System.Net.Http;
using System.Threading; using System.Threading;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFrameworks>netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
...@@ -11,14 +11,14 @@ ...@@ -11,14 +11,14 @@
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<ItemGroup> <PackageReference Include="Microsoft.Extensions.Hosting" Version="2.1.0" PrivateAssets="All" />
<PackageReference Include="Grpc" Version="2.26.0" /> </ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.0" /> <ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.0" PrivateAssets="All" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\..\src\SkyApm.Agent.GeneralHost\SkyApm.Agent.GeneralHost.csproj" /> <ProjectReference Include="..\..\..\src\SkyApm.Agent.Hosting\SkyApm.Agent.Hosting.csproj" />
<ProjectReference Include="..\SkyApm.Sample.GrpcProto\SkyApm.Sample.GrpcProto.csproj" /> <ProjectReference Include="..\SkyApm.Sample.GrpcProto\SkyApm.Sample.GrpcProto.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
...@@ -84,10 +84,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.DotNet.CLI", "src\Sk ...@@ -84,10 +84,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.DotNet.CLI", "src\Sk
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Diagnostics.SmartSql", "src\SkyApm.Diagnostics.SmartSql\SkyApm.Diagnostics.SmartSql.csproj", "{B43160C8-C9E3-43F6-83E9-A9A45B32F022}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Diagnostics.SmartSql", "src\SkyApm.Diagnostics.SmartSql\SkyApm.Diagnostics.SmartSql.csproj", "{B43160C8-C9E3-43F6-83E9-A9A45B32F022}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Agent.GeneralHost", "src\SkyApm.Agent.GeneralHost\SkyApm.Agent.GeneralHost.csproj", "{4C1CF0E7-4CD3-4731-9A56-E033D5216D58}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Sample.GeneralHost", "sample\SkyApm.Sample.GeneralHost\SkyApm.Sample.GeneralHost.csproj", "{477D705E-576B-46C8-8F1E-9A86EDAE9D86}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Benchmark", "benchmark\SkyApm.Benchmark\SkyApm.Benchmark.csproj", "{33581FDE-ABAF-4C27-A40A-1A2743309399}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Benchmark", "benchmark\SkyApm.Benchmark\SkyApm.Benchmark.csproj", "{33581FDE-ABAF-4C27-A40A-1A2743309399}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmark", "benchmark", "{2B7F59E8-147F-4399-9804-E7EAEF2DCB22}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmark", "benchmark", "{2B7F59E8-147F-4399-9804-E7EAEF2DCB22}"
...@@ -102,7 +98,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Sample.GrpcProto", " ...@@ -102,7 +98,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Sample.GrpcProto", "
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Sample.GrpcServer", "sample\grpc\SkyApm.Sample.GrpcServer\SkyApm.Sample.GrpcServer.csproj", "{0EB6D474-A915-4075-B142-FE07321F3AA9}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Sample.GrpcServer", "sample\grpc\SkyApm.Sample.GrpcServer\SkyApm.Sample.GrpcServer.csproj", "{0EB6D474-A915-4075-B142-FE07321F3AA9}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkyApm.Diagnostics.Grpc.Net.Client", "src\SkyApm.Diagnostics.Grpc.Net.Client\SkyApm.Diagnostics.Grpc.Net.Client.csproj", "{34211B07-381E-4489-AA7F-7697D106B7DC}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Diagnostics.Grpc.Net.Client", "src\SkyApm.Diagnostics.Grpc.Net.Client\SkyApm.Diagnostics.Grpc.Net.Client.csproj", "{34211B07-381E-4489-AA7F-7697D106B7DC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Agent.Hosting", "src\SkyApm.Agent.Hosting\SkyApm.Agent.Hosting.csproj", "{BC56D244-6C76-4E40-8351-B74B636B17A6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Agent.GeneralHost", "src\SkyApm.Agent.GeneralHost\SkyApm.Agent.GeneralHost.csproj", "{D96279FD-0020-427B-85C5-DC1C2336AA25}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Sample.GenericHost", "sample\SkyApm.Sample.GenericHost\SkyApm.Sample.GenericHost.csproj", "{71F61C77-E04F-464D-A0B7-E109CE7E30D7}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
...@@ -198,14 +200,6 @@ Global ...@@ -198,14 +200,6 @@ Global
{B43160C8-C9E3-43F6-83E9-A9A45B32F022}.Debug|Any CPU.Build.0 = Debug|Any CPU {B43160C8-C9E3-43F6-83E9-A9A45B32F022}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B43160C8-C9E3-43F6-83E9-A9A45B32F022}.Release|Any CPU.ActiveCfg = Release|Any CPU {B43160C8-C9E3-43F6-83E9-A9A45B32F022}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B43160C8-C9E3-43F6-83E9-A9A45B32F022}.Release|Any CPU.Build.0 = Release|Any CPU {B43160C8-C9E3-43F6-83E9-A9A45B32F022}.Release|Any CPU.Build.0 = Release|Any CPU
{4C1CF0E7-4CD3-4731-9A56-E033D5216D58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C1CF0E7-4CD3-4731-9A56-E033D5216D58}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C1CF0E7-4CD3-4731-9A56-E033D5216D58}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C1CF0E7-4CD3-4731-9A56-E033D5216D58}.Release|Any CPU.Build.0 = Release|Any CPU
{477D705E-576B-46C8-8F1E-9A86EDAE9D86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{477D705E-576B-46C8-8F1E-9A86EDAE9D86}.Debug|Any CPU.Build.0 = Debug|Any CPU
{477D705E-576B-46C8-8F1E-9A86EDAE9D86}.Release|Any CPU.ActiveCfg = Release|Any CPU
{477D705E-576B-46C8-8F1E-9A86EDAE9D86}.Release|Any CPU.Build.0 = Release|Any CPU
{33581FDE-ABAF-4C27-A40A-1A2743309399}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {33581FDE-ABAF-4C27-A40A-1A2743309399}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{33581FDE-ABAF-4C27-A40A-1A2743309399}.Debug|Any CPU.Build.0 = Debug|Any CPU {33581FDE-ABAF-4C27-A40A-1A2743309399}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33581FDE-ABAF-4C27-A40A-1A2743309399}.Release|Any CPU.ActiveCfg = Release|Any CPU {33581FDE-ABAF-4C27-A40A-1A2743309399}.Release|Any CPU.ActiveCfg = Release|Any CPU
...@@ -230,6 +224,18 @@ Global ...@@ -230,6 +224,18 @@ Global
{34211B07-381E-4489-AA7F-7697D106B7DC}.Debug|Any CPU.Build.0 = Debug|Any CPU {34211B07-381E-4489-AA7F-7697D106B7DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{34211B07-381E-4489-AA7F-7697D106B7DC}.Release|Any CPU.ActiveCfg = Release|Any CPU {34211B07-381E-4489-AA7F-7697D106B7DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{34211B07-381E-4489-AA7F-7697D106B7DC}.Release|Any CPU.Build.0 = Release|Any CPU {34211B07-381E-4489-AA7F-7697D106B7DC}.Release|Any CPU.Build.0 = Release|Any CPU
{BC56D244-6C76-4E40-8351-B74B636B17A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC56D244-6C76-4E40-8351-B74B636B17A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC56D244-6C76-4E40-8351-B74B636B17A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC56D244-6C76-4E40-8351-B74B636B17A6}.Release|Any CPU.Build.0 = Release|Any CPU
{D96279FD-0020-427B-85C5-DC1C2336AA25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D96279FD-0020-427B-85C5-DC1C2336AA25}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D96279FD-0020-427B-85C5-DC1C2336AA25}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D96279FD-0020-427B-85C5-DC1C2336AA25}.Release|Any CPU.Build.0 = Release|Any CPU
{71F61C77-E04F-464D-A0B7-E109CE7E30D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{71F61C77-E04F-464D-A0B7-E109CE7E30D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71F61C77-E04F-464D-A0B7-E109CE7E30D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71F61C77-E04F-464D-A0B7-E109CE7E30D7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
...@@ -265,8 +271,6 @@ Global ...@@ -265,8 +271,6 @@ Global
{2F7EEC69-35F4-4D31-B52A-7465D65E9DE0} = {A4E67E09-3156-4D30-B451-F24F706E96C4} {2F7EEC69-35F4-4D31-B52A-7465D65E9DE0} = {A4E67E09-3156-4D30-B451-F24F706E96C4}
{E909EEF5-5EBF-43F3-AB4A-6B2FB56EF89B} = {1B0865AF-369E-493C-AA6F-C56D3E520A22} {E909EEF5-5EBF-43F3-AB4A-6B2FB56EF89B} = {1B0865AF-369E-493C-AA6F-C56D3E520A22}
{B43160C8-C9E3-43F6-83E9-A9A45B32F022} = {B5E677CF-2920-4B0A-A056-E73F6B2CF2BC} {B43160C8-C9E3-43F6-83E9-A9A45B32F022} = {B5E677CF-2920-4B0A-A056-E73F6B2CF2BC}
{4C1CF0E7-4CD3-4731-9A56-E033D5216D58} = {EF6194B2-9ACB-49B9-8049-DD6AFAEB0399}
{477D705E-576B-46C8-8F1E-9A86EDAE9D86} = {844CEACD-4C85-4B15-9E2B-892B01FDA4BB}
{33581FDE-ABAF-4C27-A40A-1A2743309399} = {2B7F59E8-147F-4399-9804-E7EAEF2DCB22} {33581FDE-ABAF-4C27-A40A-1A2743309399} = {2B7F59E8-147F-4399-9804-E7EAEF2DCB22}
{5E654407-E22F-4696-A33F-C4B372F547BD} = {613F0980-91ED-4064-8E8C-168582EF4AD7} {5E654407-E22F-4696-A33F-C4B372F547BD} = {613F0980-91ED-4064-8E8C-168582EF4AD7}
{8C389735-61CE-405C-972F-3790DF1E823E} = {B5E677CF-2920-4B0A-A056-E73F6B2CF2BC} {8C389735-61CE-405C-972F-3790DF1E823E} = {B5E677CF-2920-4B0A-A056-E73F6B2CF2BC}
...@@ -274,6 +278,9 @@ Global ...@@ -274,6 +278,9 @@ Global
{5576D9C5-8856-44AD-86AD-FE73A22751EF} = {53E9CEBA-2D11-41FD-AA60-0151A5442CC4} {5576D9C5-8856-44AD-86AD-FE73A22751EF} = {53E9CEBA-2D11-41FD-AA60-0151A5442CC4}
{0EB6D474-A915-4075-B142-FE07321F3AA9} = {53E9CEBA-2D11-41FD-AA60-0151A5442CC4} {0EB6D474-A915-4075-B142-FE07321F3AA9} = {53E9CEBA-2D11-41FD-AA60-0151A5442CC4}
{34211B07-381E-4489-AA7F-7697D106B7DC} = {B5E677CF-2920-4B0A-A056-E73F6B2CF2BC} {34211B07-381E-4489-AA7F-7697D106B7DC} = {B5E677CF-2920-4B0A-A056-E73F6B2CF2BC}
{BC56D244-6C76-4E40-8351-B74B636B17A6} = {EF6194B2-9ACB-49B9-8049-DD6AFAEB0399}
{D96279FD-0020-427B-85C5-DC1C2336AA25} = {EF6194B2-9ACB-49B9-8049-DD6AFAEB0399}
{71F61C77-E04F-464D-A0B7-E109CE7E30D7} = {844CEACD-4C85-4B15-9E2B-892B01FDA4BB}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {94C0DA2C-CCCB-4314-93A2-9809B5DD0583} SolutionGuid = {94C0DA2C-CCCB-4314-93A2-9809B5DD0583}
......
/*
* Licensed to the SkyAPM under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The SkyAPM licenses this file to You 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 NETCOREAPP3_1
using Microsoft.Extensions.Hosting;
#else
using Microsoft.AspNetCore.Hosting;
#endif
namespace SkyApm.Agent.AspNetCore
{
internal class HostingEnvironmentProvider : IEnvironmentProvider
{
public string EnvironmentName { get; }
#if NETCOREAPP3_1
public HostingEnvironmentProvider(IHostEnvironment hostingEnvironment)
{
EnvironmentName = hostingEnvironment.EnvironmentName;
}
#else
public HostingEnvironmentProvider(IHostingEnvironment hostingEnvironment)
{
EnvironmentName = hostingEnvironment.EnvironmentName;
}
#endif
}
}
\ No newline at end of file
/*
* Licensed to the SkyAPM under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The SkyAPM licenses this file to You 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.
*
*/
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
namespace SkyApm.Agent.AspNetCore
{
internal class InstrumentationHostedService : IHostedService
{
private readonly IInstrumentStartup _startup;
public InstrumentationHostedService(IInstrumentStartup startup)
{
_startup = startup;
}
public Task StartAsync(CancellationToken cancellationToken)
{
return _startup.StartAsync(cancellationToken);
}
public Task StopAsync(CancellationToken cancellationToken)
{
return _startup.StopAsync(cancellationToken);
}
}
}
\ No newline at end of file
...@@ -14,26 +14,8 @@ ...@@ -14,26 +14,8 @@
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'"> <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.1.0" PrivateAssets="All" /> <PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.1.0" PrivateAssets="All" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\SkyApm.Abstractions\SkyApm.Abstractions.csproj" /> <ProjectReference Include="..\SkyApm.Agent.Hosting\SkyApm.Agent.Hosting.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.AspNetCore\SkyApm.Diagnostics.AspNetCore.csproj" /> <ProjectReference Include="..\SkyApm.Diagnostics.AspNetCore\SkyApm.Diagnostics.AspNetCore.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.CAP\SkyApm.Diagnostics.CAP.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.EntityFrameworkCore.Npgsql\SkyApm.Diagnostics.EntityFrameworkCore.Npgsql.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql\SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.EntityFrameworkCore.Sqlite\SkyApm.Diagnostics.EntityFrameworkCore.Sqlite.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.EntityFrameworkCore\SkyApm.Diagnostics.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\SkyApm.Core\SkyApm.Core.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.Grpc.Net.Client\SkyApm.Diagnostics.Grpc.Net.Client.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.Grpc\SkyApm.Diagnostics.Grpc.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.HttpClient\SkyApm.Diagnostics.HttpClient.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.SmartSql\SkyApm.Diagnostics.SmartSql.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.SqlClient\SkyApm.Diagnostics.SqlClient.csproj" />
<ProjectReference Include="..\SkyApm.Transport.Grpc\SkyApm.Transport.Grpc.csproj" />
<ProjectReference Include="..\SkyApm.Utilities.Configuration\SkyApm.Utilities.Configuration.csproj" />
<ProjectReference Include="..\SkyApm.Utilities.DependencyInjection\SkyApm.Utilities.DependencyInjection.csproj" />
<ProjectReference Include="..\SkyApm.Utilities.Logging\SkyApm.Utilities.Logging.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using SkyApm.Agent.AspNetCore; using SkyApm.Agent.AspNetCore;
using SkyApm.Agent.Hosting;
using SkyApm.AspNetCore.Diagnostics;
[assembly: HostingStartup(typeof(SkyApmHostingStartup))] [assembly: HostingStartup(typeof(SkyApmHostingStartup))]
...@@ -27,7 +29,7 @@ namespace SkyApm.Agent.AspNetCore ...@@ -27,7 +29,7 @@ namespace SkyApm.Agent.AspNetCore
{ {
public void Configure(IWebHostBuilder builder) public void Configure(IWebHostBuilder builder)
{ {
builder.ConfigureServices(services => services.AddSkyAPMCore()); builder.ConfigureServices(services => services.AddSkyAPM(ext => ext.AddAspNetCoreHosting()));
} }
} }
} }
\ No newline at end of file
/*
* Licensed to the SkyAPM under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The SkyAPM licenses this file to You 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.
*
*/
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using SkyApm.Config;
using SkyApm.Diagnostics;
using SkyApm.Diagnostics.EntityFrameworkCore;
using SkyApm.Diagnostics.Grpc;
using SkyApm.Diagnostics.HttpClient;
using SkyApm.Diagnostics.SqlClient;
using SkyApm.Logging;
using SkyApm.Sampling;
using SkyApm.Service;
using SkyApm.Tracing;
using SkyApm.Transport;
using SkyApm.Transport.Grpc;
using SkyApm.Transport.Grpc.V5;
using SkyApm.Transport.Grpc.V6;
using SkyApm.Utilities.Configuration;
using SkyApm.Utilities.DependencyInjection;
using SkyApm.Utilities.Logging;
using System;
using SkyApm.Diagnostics.Grpc.Net.Client;
namespace SkyApm.Agent.GeneralHost
{
internal static class ServiceCollectionExtensions
{
internal static IServiceCollection AddSkyAPMCore(this IServiceCollection services)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
services.AddSingleton<ISegmentDispatcher, AsyncQueueSegmentDispatcher>();
services.AddSingleton<IExecutionService, RegisterService>();
services.AddSingleton<IExecutionService, PingService>();
services.AddSingleton<IExecutionService, ServiceDiscoveryV5Service>();
services.AddSingleton<IExecutionService, SegmentReportService>();
services.AddSingleton<IInstrumentStartup, InstrumentStartup>();
services.AddSingleton<IRuntimeEnvironment>(RuntimeEnvironment.Instance);
services.AddSingleton<TracingDiagnosticProcessorObserver>();
services.AddSingleton<IConfigAccessor, ConfigAccessor>();
services.AddSingleton<IConfigurationFactory, ConfigurationFactory>();
services.AddSingleton<IHostedService, InstrumentationHostedService>();
services.AddSingleton<IEnvironmentProvider, HostingEnvironmentProvider>();
services.AddTracing().AddSampling().AddGrpcTransport().AddLogging();
services.AddSkyApmExtensions()
.AddHttpClient()
.AddGrpcClient()
.AddSqlClient()
.AddGrpc()
.AddEntityFrameworkCore(c => c.AddPomeloMysql().AddNpgsql().AddSqlite());
return services;
}
private static IServiceCollection AddTracing(this IServiceCollection services)
{
services.AddSingleton<ITracingContext, Tracing.TracingContext>();
services.AddSingleton<ICarrierPropagator, CarrierPropagator>();
services.AddSingleton<ICarrierFormatter, Sw3CarrierFormatter>();
services.AddSingleton<ICarrierFormatter, Sw6CarrierFormatter>();
services.AddSingleton<ISegmentContextFactory, SegmentContextFactory>();
services.AddSingleton<IEntrySegmentContextAccessor, EntrySegmentContextAccessor>();
services.AddSingleton<ILocalSegmentContextAccessor, LocalSegmentContextAccessor>();
services.AddSingleton<IExitSegmentContextAccessor, ExitSegmentContextAccessor>();
services.AddSingleton<ISamplerChainBuilder, SamplerChainBuilder>();
services.AddSingleton<IUniqueIdGenerator, UniqueIdGenerator>();
services.AddSingleton<IUniqueIdParser, UniqueIdParser>();
services.AddSingleton<ISegmentContextMapper, SegmentContextMapper>();
services.AddSingleton<IBase64Formatter, Base64Formatter>();
return services;
}
private static IServiceCollection AddSampling(this IServiceCollection services)
{
services.AddSingleton<SimpleCountSamplingInterceptor>();
services.AddSingleton<ISamplingInterceptor>(p => p.GetService<SimpleCountSamplingInterceptor>());
services.AddSingleton<IExecutionService>(p => p.GetService<SimpleCountSamplingInterceptor>());
services.AddSingleton<ISamplingInterceptor, RandomSamplingInterceptor>();
return services;
}
private static IServiceCollection AddGrpcTransport(this IServiceCollection services)
{
services.AddSingleton<ISkyApmClientV5, SkyApmClientV5>();
services.AddSingleton<ISegmentReporter, SegmentReporter>();
services.AddSingleton<ConnectionManager>();
services.AddSingleton<IPingCaller, PingCaller>();
services.AddSingleton<IServiceRegister, ServiceRegister>();
services.AddSingleton<IExecutionService, ConnectService>();
return services;
}
private static IServiceCollection AddLogging(this IServiceCollection services)
{
services.AddSingleton<ILoggerFactory, DefaultLoggerFactory>();
return services;
}
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\build\common.props" /> <Import Project="..\..\build\common.props" />
<PropertyGroup> <PropertyGroup>
<Description>$(Product) ASP.NET Core Agent.</Description> <Description>$(Product) ASP.NET Core Agent.</Description>
<AssemblyTitle>$(PackagePrefix).Agent.GeneralHost</AssemblyTitle> <AssemblyTitle>$(PackagePrefix).Agent.GeneralHost</AssemblyTitle>
<AssemblyName>$(PackagePrefix).Agent.GeneralHost</AssemblyName> <AssemblyName>$(PackagePrefix).Agent.GeneralHost</AssemblyName>
<PackageId>$(PackagePrefix).Agent.GeneralHost</PackageId> <PackageId>$(PackagePrefix).Agent.GeneralHost</PackageId>
<PackageTags>SkyWalking;APM</PackageTags> <PackageTags>SkyWalking;APM</PackageTags>
<PackageReleaseNotes> <PackageReleaseNotes>
</PackageReleaseNotes> </PackageReleaseNotes>
<RootNamespace>SkyApm.Agent.GeneralHost</RootNamespace> <RootNamespace>SkyApm.Agent.GeneralHost</RootNamespace>
<TargetFrameworks>netstandard2.0;netcoreapp3.1</TargetFrameworks> <TargetFrameworks>netstandard2.0;netcoreapp3.1</TargetFrameworks>
</PropertyGroup> </PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="2.1.0" PrivateAssets="All" /> <ItemGroup>
</ItemGroup> <ProjectReference Include="..\SkyApm.Agent.Hosting\SkyApm.Agent.Hosting.csproj" />
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'"> </ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SkyApm.Abstractions\SkyApm.Abstractions.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.EntityFrameworkCore.Npgsql\SkyApm.Diagnostics.EntityFrameworkCore.Npgsql.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql\SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.EntityFrameworkCore.Sqlite\SkyApm.Diagnostics.EntityFrameworkCore.Sqlite.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.EntityFrameworkCore\SkyApm.Diagnostics.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\SkyApm.Core\SkyApm.Core.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.Grpc.Net.Client\SkyApm.Diagnostics.Grpc.Net.Client.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.Grpc\SkyApm.Diagnostics.Grpc.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.HttpClient\SkyApm.Diagnostics.HttpClient.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.SqlClient\SkyApm.Diagnostics.SqlClient.csproj" />
<ProjectReference Include="..\SkyApm.Transport.Grpc\SkyApm.Transport.Grpc.csproj" />
<ProjectReference Include="..\SkyApm.Utilities.Configuration\SkyApm.Utilities.Configuration.csproj" />
<ProjectReference Include="..\SkyApm.Utilities.DependencyInjection\SkyApm.Utilities.DependencyInjection.csproj" />
<ProjectReference Include="..\SkyApm.Utilities.Logging\SkyApm.Utilities.Logging.csproj" />
</ItemGroup>
</Project> </Project>
\ No newline at end of file
...@@ -16,13 +16,13 @@ ...@@ -16,13 +16,13 @@
* *
*/ */
using Microsoft.Extensions.Hosting; using SkyApm.Agent.Hosting;
namespace SkyApm.Agent.GeneralHost namespace Microsoft.Extensions.Hosting
{ {
public static class HostBuilderExtensions public static class HostBuilderExtensions
{ {
public static IHostBuilder AddSkyAPM(this IHostBuilder builder) => public static IHostBuilder AddSkyAPM(this IHostBuilder builder) =>
builder.ConfigureServices((context, services) => services.AddSkyAPMCore()); builder.ConfigureServices((context, services) => services.AddSkyAPM());
} }
} }
\ No newline at end of file
/* /*
* Licensed to the SkyAPM under one or more * Licensed to the SkyAPM under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The SkyAPM licenses this file to You under the Apache License, Version 2.0 * The SkyAPM licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
*/ */
using System; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection; using SkyApm.Config;
using Microsoft.Extensions.Hosting; using SkyApm.Diagnostics;
using SkyApm.Config; using SkyApm.Diagnostics.EntityFrameworkCore;
using SkyApm.Diagnostics; using SkyApm.Diagnostics.Grpc;
using SkyApm.Logging; using SkyApm.Diagnostics.HttpClient;
using SkyApm.Sampling; using SkyApm.Diagnostics.SqlClient;
using SkyApm.Service; using SkyApm.Logging;
using SkyApm.Tracing; using SkyApm.Sampling;
using SkyApm.Transport; using SkyApm.Service;
using SkyApm.Transport.Grpc; using SkyApm.Tracing;
using SkyApm.Transport.Grpc.V5; using SkyApm.Transport;
using SkyApm.Transport.Grpc.V6; using SkyApm.Transport.Grpc;
using SkyApm.Utilities.Configuration; using SkyApm.Transport.Grpc.V5;
using SkyApm.Utilities.Logging; using SkyApm.Transport.Grpc.V6;
using SkyApm.AspNetCore.Diagnostics; using SkyApm.Utilities.Configuration;
using SkyApm.Diagnostics.EntityFrameworkCore; using SkyApm.Utilities.DependencyInjection;
using SkyApm.Diagnostics.HttpClient; using SkyApm.Utilities.Logging;
using SkyApm.Diagnostics.SqlClient; using System;
using SkyApm.Utilities.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using SkyApm.Diagnostics.Grpc; using SkyApm.Diagnostics.Grpc.Net.Client;
using SkyApm.Diagnostics.Grpc.Net.Client;
namespace SkyApm.Agent.Hosting
namespace SkyApm.Agent.AspNetCore {
{ public static class ServiceCollectionExtensions
internal static class ServiceCollectionExtensions {
{ public static IServiceCollection AddSkyAPM(this IServiceCollection services, Action<SkyApmExtensions> extensionsSetup = null)
internal static IServiceCollection AddSkyAPMCore(this IServiceCollection services) {
{ services.AddSkyAPMCore(extensionsSetup);
if (services == null) return services;
{ }
throw new ArgumentNullException(nameof(services));
internal static IServiceCollection AddSkyAPMCore(this IServiceCollection services, Action<SkyApmExtensions> extensionsSetup = null)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
} }
services.AddSingleton<ISegmentDispatcher, AsyncQueueSegmentDispatcher>(); services.AddSingleton<ISegmentDispatcher, AsyncQueueSegmentDispatcher>();
services.AddSingleton<IExecutionService, RegisterService>(); services.AddSingleton<IExecutionService, RegisterService>();
services.AddSingleton<IExecutionService, PingService>(); services.AddSingleton<IExecutionService, PingService>();
services.AddSingleton<IExecutionService, ServiceDiscoveryV5Service>(); services.AddSingleton<IExecutionService, ServiceDiscoveryV5Service>();
services.AddSingleton<IExecutionService, SegmentReportService>(); services.AddSingleton<IExecutionService, SegmentReportService>();
services.AddSingleton<IInstrumentStartup, InstrumentStartup>(); services.AddSingleton<IInstrumentStartup, InstrumentStartup>();
services.AddSingleton<IRuntimeEnvironment>(RuntimeEnvironment.Instance); services.AddSingleton<IRuntimeEnvironment>(RuntimeEnvironment.Instance);
services.AddSingleton<TracingDiagnosticProcessorObserver>(); services.AddSingleton<TracingDiagnosticProcessorObserver>();
services.AddSingleton<IConfigAccessor, ConfigAccessor>(); services.AddSingleton<IConfigAccessor, ConfigAccessor>();
services.AddSingleton<IConfigurationFactory, ConfigurationFactory>(); services.AddSingleton<IConfigurationFactory, ConfigurationFactory>();
services.AddSingleton<IHostedService, InstrumentationHostedService>(); services.AddSingleton<IHostedService, InstrumentationHostedService>();
services.AddSingleton<IEnvironmentProvider, HostingEnvironmentProvider>(); services.AddSingleton<IEnvironmentProvider, HostingEnvironmentProvider>();
services.AddSingleton<IExecutionService, CLRStatsService>(); services.AddTracing().AddSampling().AddGrpcTransport().AddLogging();
services.AddTracing().AddSampling().AddGrpcTransport().AddLogging(); var extensions = services.AddSkyApmExtensions()
services.AddSkyApmExtensions() .AddHttpClient()
.AddAspNetCoreHosting() .AddGrpcClient()
.AddHttpClient() .AddSqlClient()
.AddGrpcClient() .AddGrpc()
.AddSqlClient() .AddEntityFrameworkCore(c => c.AddPomeloMysql().AddNpgsql().AddSqlite());
.AddGrpc()
.AddEntityFrameworkCore(c => c.AddPomeloMysql().AddNpgsql().AddSqlite()); extensionsSetup?.Invoke(extensions);
return services;
} return services;
}
private static IServiceCollection AddTracing(this IServiceCollection services)
{ private static IServiceCollection AddTracing(this IServiceCollection services)
services.AddSingleton<ITracingContext, Tracing.TracingContext>(); {
services.AddSingleton<ICarrierPropagator, CarrierPropagator>(); services.AddSingleton<ITracingContext, TracingContext>();
services.AddSingleton<ICarrierFormatter, Sw3CarrierFormatter>(); services.AddSingleton<ICarrierPropagator, CarrierPropagator>();
services.AddSingleton<ICarrierFormatter, Sw6CarrierFormatter>(); services.AddSingleton<ICarrierFormatter, Sw3CarrierFormatter>();
services.AddSingleton<ISegmentContextFactory, SegmentContextFactory>(); services.AddSingleton<ICarrierFormatter, Sw6CarrierFormatter>();
services.AddSingleton<IEntrySegmentContextAccessor, EntrySegmentContextAccessor>(); services.AddSingleton<ISegmentContextFactory, SegmentContextFactory>();
services.AddSingleton<ILocalSegmentContextAccessor, LocalSegmentContextAccessor>(); services.AddSingleton<IEntrySegmentContextAccessor, EntrySegmentContextAccessor>();
services.AddSingleton<IExitSegmentContextAccessor, ExitSegmentContextAccessor>(); services.AddSingleton<ILocalSegmentContextAccessor, LocalSegmentContextAccessor>();
services.AddSingleton<ISamplerChainBuilder, SamplerChainBuilder>(); services.AddSingleton<IExitSegmentContextAccessor, ExitSegmentContextAccessor>();
services.AddSingleton<IUniqueIdGenerator, UniqueIdGenerator>(); services.AddSingleton<ISamplerChainBuilder, SamplerChainBuilder>();
services.AddSingleton<IUniqueIdParser, UniqueIdParser>(); services.AddSingleton<IUniqueIdGenerator, UniqueIdGenerator>();
services.AddSingleton<ISegmentContextMapper, SegmentContextMapper>(); services.AddSingleton<IUniqueIdParser, UniqueIdParser>();
services.AddSingleton<IBase64Formatter, Base64Formatter>(); services.AddSingleton<ISegmentContextMapper, SegmentContextMapper>();
return services; services.AddSingleton<IBase64Formatter, Base64Formatter>();
} return services;
}
private static IServiceCollection AddSampling(this IServiceCollection services)
{ private static IServiceCollection AddSampling(this IServiceCollection services)
services.AddSingleton<SimpleCountSamplingInterceptor>(); {
services.AddSingleton<ISamplingInterceptor>(p => p.GetService<SimpleCountSamplingInterceptor>()); services.AddSingleton<SimpleCountSamplingInterceptor>();
services.AddSingleton<IExecutionService>(p => p.GetService<SimpleCountSamplingInterceptor>()); services.AddSingleton<ISamplingInterceptor>(p => p.GetService<SimpleCountSamplingInterceptor>());
services.AddSingleton<ISamplingInterceptor, RandomSamplingInterceptor>(); services.AddSingleton<IExecutionService>(p => p.GetService<SimpleCountSamplingInterceptor>());
return services; services.AddSingleton<ISamplingInterceptor, RandomSamplingInterceptor>();
} return services;
}
private static IServiceCollection AddGrpcTransport(this IServiceCollection services)
{ private static IServiceCollection AddGrpcTransport(this IServiceCollection services)
services.AddSingleton<ISkyApmClientV5, SkyApmClientV5>(); {
services.AddSingleton<ISegmentReporter, SegmentReporter>(); services.AddSingleton<ISkyApmClientV5, SkyApmClientV5>();
services.AddSingleton<ConnectionManager>(); services.AddSingleton<ISegmentReporter, SegmentReporter>();
services.AddSingleton<IPingCaller, PingCaller>(); services.AddSingleton<ConnectionManager>();
services.AddSingleton<IServiceRegister, ServiceRegister>(); services.AddSingleton<IPingCaller, PingCaller>();
services.AddSingleton<IExecutionService, ConnectService>(); services.AddSingleton<IServiceRegister, ServiceRegister>();
services.AddSingleton<ICLRStatsReporter, CLRStatsReporter>(); services.AddSingleton<IExecutionService, ConnectService>();
return services; return services;
} }
private static IServiceCollection AddLogging(this IServiceCollection services) private static IServiceCollection AddLogging(this IServiceCollection services)
{ {
services.AddSingleton<ILoggerFactory, DefaultLoggerFactory>(); services.AddSingleton<ILoggerFactory, DefaultLoggerFactory>();
return services; return services;
} }
} }
} }
\ No newline at end of file
...@@ -18,24 +18,21 @@ ...@@ -18,24 +18,21 @@
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
namespace SkyApm.Agent.GeneralHost #if NETSTANDARD2_0
using IHostEnvironment = Microsoft.Extensions.Hosting.IHostingEnvironment;
#endif
namespace SkyApm.Agent.Hosting
{ {
internal class HostingEnvironmentProvider : IEnvironmentProvider internal class HostingEnvironmentProvider : IEnvironmentProvider
{ {
public string EnvironmentName { get; } public string EnvironmentName { get; }
#if NETCOREAPP3_1
public HostingEnvironmentProvider(IHostEnvironment hostingEnvironment)
{
EnvironmentName = hostingEnvironment.EnvironmentName;
}
#else
public HostingEnvironmentProvider(IHostingEnvironment hostingEnvironment) public HostingEnvironmentProvider(IHostEnvironment hostingEnvironment)
{ {
EnvironmentName = hostingEnvironment.EnvironmentName; EnvironmentName = hostingEnvironment.EnvironmentName;
} }
#endif
} }
} }
\ No newline at end of file
/* /*
* Licensed to the SkyAPM under one or more * Licensed to the SkyAPM under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The SkyAPM licenses this file to You under the Apache License, Version 2.0 * The SkyAPM licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
*/ */
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
namespace SkyApm.Agent.GeneralHost namespace SkyApm.Agent.Hosting
{ {
internal class InstrumentationHostedService : IHostedService internal class InstrumentationHostedService : IHostedService
{ {
private readonly IInstrumentStartup _startup; private readonly IInstrumentStartup _startup;
public InstrumentationHostedService(IInstrumentStartup startup) public InstrumentationHostedService(IInstrumentStartup startup)
{ {
_startup = startup; _startup = startup;
} }
public Task StartAsync(CancellationToken cancellationToken) public Task StartAsync(CancellationToken cancellationToken)
{ {
return _startup.StartAsync(cancellationToken); return _startup.StartAsync(cancellationToken);
} }
public Task StopAsync(CancellationToken cancellationToken) public Task StopAsync(CancellationToken cancellationToken)
{ {
return _startup.StopAsync(cancellationToken); return _startup.StopAsync(cancellationToken);
} }
} }
} }
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<Description>$(Product) ASP.NET Core Agent.</Description>
<AssemblyTitle>$(PackagePrefix).Agent.Hosting</AssemblyTitle>
<AssemblyName>$(PackagePrefix).Agent.Hosting</AssemblyName>
<PackageId>$(PackagePrefix).Agent.Hosting</PackageId>
<PackageTags>SkyWalking;APM</PackageTags>
<PackageReleaseNotes>
</PackageReleaseNotes>
<RootNamespace>SkyApm.Agent.Hosting</RootNamespace>
<TargetFrameworks>netstandard2.0;netcoreapp3.1</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="2.1.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SkyApm.Abstractions\SkyApm.Abstractions.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.EntityFrameworkCore.Npgsql\SkyApm.Diagnostics.EntityFrameworkCore.Npgsql.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql\SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.EntityFrameworkCore.Sqlite\SkyApm.Diagnostics.EntityFrameworkCore.Sqlite.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.EntityFrameworkCore\SkyApm.Diagnostics.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\SkyApm.Core\SkyApm.Core.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.Grpc.Net.Client\SkyApm.Diagnostics.Grpc.Net.Client.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.Grpc\SkyApm.Diagnostics.Grpc.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.HttpClient\SkyApm.Diagnostics.HttpClient.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.SqlClient\SkyApm.Diagnostics.SqlClient.csproj" />
<ProjectReference Include="..\SkyApm.Transport.Grpc\SkyApm.Transport.Grpc.csproj" />
<ProjectReference Include="..\SkyApm.Utilities.Configuration\SkyApm.Utilities.Configuration.csproj" />
<ProjectReference Include="..\SkyApm.Utilities.DependencyInjection\SkyApm.Utilities.DependencyInjection.csproj" />
<ProjectReference Include="..\SkyApm.Utilities.Logging\SkyApm.Utilities.Logging.csproj" />
</ItemGroup>
</Project>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册