Commit 7400731f by huangzhihong

v2.0.1 : 优化 Diagnostic , 屏蔽路由 /health, 支持netcoreapp3.1

parent f7bd8a69
......@@ -19,6 +19,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bailun.ServiceFabric.Trace.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleApi.Downstream", "samples\SimpleApi.Downstream\SimpleApi.Downstream.csproj", "{30463913-0CCF-41D3-A31B-14F90A87CD88}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E53AC110-8F4B-4921-8BD4-7AFB7773CCF0}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......
{
"sdk": {
"version": "3.1.200"
}
}
\ No newline at end of file
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using System.IO;
namespace SimpleApi.Downstream
{
......@@ -7,7 +9,34 @@ namespace SimpleApi.Downstream
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
var configurationBuilder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile("appsettings.Development.json", true, false)
.AddJsonFile("appsettings.Production.json", true, false)
.AddEnvironmentVariables()
.AddCommandLine(args);
if (args != null)
{
configurationBuilder.AddCommandLine(args);
}
var hostingconfig = configurationBuilder.Build();
IWebHostBuilder builder = new WebHostBuilder();
//builder.ConfigureServices(s => {
// s.AddSingleton(builder);
//});
builder
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseConfiguration(hostingconfig)
.UseStartup<Startup>()
.UseBailunTrace(true, true);
var host = builder.Build();
host.Run();
//CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
......
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="WebApiClient.JIT" Version="1.1.3" />
</ItemGroup>
......
......@@ -26,16 +26,29 @@ namespace SimpleApi.Downstream
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpContextAccessor();
#if NETCOREAPP3_1
services.AddControllers();
#else
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
#endif
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app)
{
app.UseBailunRequestLogging();
#if NETCOREAPP3_1
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
#else
app.UseMvc();
#endif
}
}
}
......@@ -19,7 +19,8 @@
"QueueSize": 30000,
"BatchSize": 3000,
"gRPC": {
"Servers": "skywalking.service.bailuntec.com:8081",
//"Servers": "skywalking.service.bailuntec.com:8081",
"Servers": "118.24.155.252:11800",
"Timeout": 10000,
"ConnectTimeout": 10000,
"ReportTimeout": 600000
......
......@@ -37,6 +37,7 @@ namespace SimpleApi.Controllers
.AddProperty("CustomProperty2", new { Name = "Jack", Age = 18 }) //自定义扩展属性 CustomProperty2
.Information("[api1] Disk quota {Quota} MB exceeded by {Broker}", 12, "RabbitMQ"); //自定义扩展属性 Quota 、Broker
userApi.PostAsync("v1", "v2").InvokeAsync().GetAwaiter().GetResult();
return userApi.GetAsync("dafadfdsfafd").InvokeAsync().GetAwaiter().GetResult();
}
......
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using System.Diagnostics;
using System.IO;
namespace SimpleApi
{
......@@ -8,6 +10,33 @@ namespace SimpleApi
{
public static void Main(string[] args)
{
// var configurationBuilder = new ConfigurationBuilder()
//.SetBasePath(Directory.GetCurrentDirectory())
//.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
//.AddJsonFile("appsettings.Development.json", true, false)
//.AddJsonFile("appsettings.Production.json", true, false)
//.AddEnvironmentVariables()
//.AddCommandLine(args);
// if (args != null)
// {
// configurationBuilder.AddCommandLine(args);
// }
// var hostingconfig = configurationBuilder.Build();
// IWebHostBuilder builder = new WebHostBuilder();
// //builder.ConfigureServices(s => {
// // s.AddSingleton(builder);
// //});
// builder
// .UseKestrel()
// .UseContentRoot(Directory.GetCurrentDirectory())
// .UseConfiguration(hostingconfig)
// .UseStartup<Startup>()
// .UseBailunTrace(true, true);
// var host = builder.Build();
//host.Run();
Serilog.Debugging.SelfLog.Enable(msg => Debug.WriteLine(msg));
CreateWebHostBuilder(args).Build().Run();
}
......
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="WebApiClient.JIT" Version="1.1.3" />
</ItemGroup>
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using SampleApi.MicroServices;
using System;
using WebApiClient;
using Bailun.ServiceFabric.Trace;
using SkyApm.Utilities.DependencyInjection;
namespace SimpleApi
{
......@@ -34,14 +26,30 @@ namespace SimpleApi
opt.HttpHost = new Uri("http://localhost:5001/");
});
#if NETCOREAPP3_1
services.AddControllers();
#else
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
#endif
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app)
{
app.UseBailunRequestLogging();
#if NETCOREAPP3_1
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
#else
app.UseMvc();
#endif
}
}
......
......@@ -19,7 +19,8 @@
"QueueSize": 30000,
"BatchSize": 3000,
"gRPC": {
"Servers": "skywalking.service.bailuntec.com:8081",
//"Servers": "skywalking.service.bailuntec.com:8081",
"Servers": "118.24.155.252:11800",
"Timeout": 10000,
"ConnectTimeout": 10000,
"ReportTimeout": 600000
......
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.1.1" />
<PackageReference Include="WebApiClient.JIT" Version="1.1.3" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="WebApiClient.JIT" Version="1.1.3" />
<ProjectReference Include="..\..\src\Bailun.ServiceFabric.Trace\Bailun.ServiceFabric.Trace.csproj" />
</ItemGroup>
......@@ -23,6 +27,9 @@
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="skyapm.Development.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="skyapm.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
......
......@@ -38,7 +38,8 @@ namespace SimpleConsole
//**************************TODO:业务逻辑**************************
await _userApi.GetByIdAsync(index);
//await _userApi.GetByIdAsync(index);
await _userApi.GetAsync(index.ToString());
Log.Logger.Information($"[console] 第{index}次调用............... ");
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;netcoreapp3.1</TargetFrameworks>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Version>1.0.3</Version>
<Version>2.0.1</Version>
<Description>百伦dotnet core微服务,日志 与 APM</Description>
<AssemblyVersion>2.0.1.0</AssemblyVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Exceptionless" Version="4.3.2027" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="2.1.0" />
<PackageReference Include="Serilog" Version="2.9.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="3.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
......@@ -27,7 +21,19 @@
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="SkyAPM.Agent.AspNetCore" Version="0.9.0" />
<PackageReference Include="SkyAPM.Agent.GeneralHost" Version="0.9.0" />
<!--<PackageReference Include="SkyAPM.Utilities.DependencyInjection" Version="0.9.0" />-->
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.1.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.0" PrivateAssets="All" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.1" />
</ItemGroup>
</Project>
using Bailun.ServiceFabric.Trace;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Http.Internal;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Newtonsoft.Json;
using SkyApm;
......@@ -13,6 +12,10 @@ using System;
using System.IO;
using System.Text;
#if NETSTANDARD2_0
using Microsoft.AspNetCore.Http.Internal;
#endif
namespace Bailun.Diagnostics.AspNetCore
{
public class HostingTracingDiagnosticProcessor : ITracingDiagnosticProcessor
......@@ -113,7 +116,11 @@ namespace Bailun.Diagnostics.AspNetCore
if (request.ContentLength == null || !(request.ContentLength > 0))
return body;
#if NETCOREAPP3_1
request.EnableBuffering();
#else
request.EnableRewind();
#endif
request.Body.Seek(0, SeekOrigin.Begin);
var buffer = new byte[Convert.ToInt32(request.ContentLength)];
......
using Bailun.Diagnostics.AspNetCore;
using Bailun.Diagnostics.HttpClient;
using Bailun.ServiceFabric.Trace;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using SkyApm;
[assembly: HostingStartup(typeof(SkyApmHostingStartup))]
namespace Bailun.ServiceFabric.Trace
{
internal class SkyApmHostingStartup : IHostingStartup
{
public void Configure(IWebHostBuilder builder)
{
builder.ConfigureServices(services =>
{
services.Replace(ServiceDescriptor.Singleton<ITracingDiagnosticProcessor, HostingTracingDiagnosticProcessor>());
services.Replace(ServiceDescriptor.Singleton<ITracingDiagnosticProcessor, HttpClientTracingDiagnosticProcessor>());
});
}
}
}
......@@ -2,10 +2,8 @@
using System;
using Bailun.ServiceFabric.Trace;
using Serilog;
using Microsoft.Extensions.DependencyInjection;
using SkyApm;
using Bailun.Diagnostics.AspNetCore;
using Bailun.Diagnostics.HttpClient;
using System.Linq;
using Microsoft.Extensions.Hosting;
namespace Microsoft.AspNetCore.Hosting
{
......@@ -21,12 +19,21 @@ namespace Microsoft.AspNetCore.Hosting
/// <returns></returns>
public static IWebHostBuilder UseBailunTrace(this IWebHostBuilder builder, bool writeToExceptionless = false, bool writeToConsole = false, Action<LoggerConfiguration> configureLogger = null)
{
return builder.UseBailunSerilog(writeToExceptionless, writeToConsole, configureLogger)
.ConfigureServices(services =>
var assemblyString = builder.GetSetting(WebHostDefaults.HostingStartupAssembliesKey);
if (!string.IsNullOrEmpty(assemblyString))
{
var startupAssemblies = assemblyString.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
if (startupAssemblies.Contains("SkyAPM.Agent.AspNetCore"))
{
services.AddSingleton<ITracingDiagnosticProcessor, HostingTracingDiagnosticProcessor>();
services.AddSingleton<ITracingDiagnosticProcessor, HttpClientTracingDiagnosticProcessor>();
});
startupAssemblies.Add("Bailun.ServiceFabric.Trace");
assemblyString = string.Join(";", startupAssemblies);
builder.UseSetting(WebHostDefaults.HostingStartupAssembliesKey, assemblyString);
}
}
return builder.UseBailunSerilog(writeToExceptionless, writeToConsole, configureLogger);
}
/// <summary>
......
......@@ -13,7 +13,9 @@ namespace Bailun.ServiceFabric.Trace
@"log\.bailuntec\.com.*", //过滤exceptionless 上报
@"/status$", //健康心跳检测
@"v1/kv/.*", //Consul DNS
@"swagger/.*" //swagger 文档
@"swagger/.*",//swagger 文档
@"/health$", //健康心跳检测
@"/favicon.ico$"
};
/// <summary>
/// 是否忽略追踪路由
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment