Unverified Commit 10b85e67 authored by Lemon's avatar Lemon Committed by GitHub

Fix Asp.Net Core package version conflicts (#137)

parent ccad0cf3
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" /> <PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite">
<Version>2.1.0</Version>
</PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Update="appsettings.json"> <Content Update="appsettings.json">
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
* *
*/ */
using System;
namespace SkyWalking.Config namespace SkyWalking.Config
{ {
[Config("SkyWalking")] [Config("SkyWalking")]
...@@ -23,6 +25,7 @@ namespace SkyWalking.Config ...@@ -23,6 +25,7 @@ namespace SkyWalking.Config
{ {
public string Namespace { get; set; } public string Namespace { get; set; }
[Obsolete("Use ServiceName.")]
public string ApplicationCode { get; set; } public string ApplicationCode { get; set; }
public string ServiceName { get; set; } public string ServiceName { get; set; }
......
...@@ -11,8 +11,7 @@ ...@@ -11,8 +11,7 @@
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\SkyWalking.Abstractions\SkyWalking.Abstractions.csproj" /> <ProjectReference Include="..\SkyWalking.Abstractions\SkyWalking.Abstractions.csproj" />
......
...@@ -36,7 +36,8 @@ namespace SkyWalking.AspNetCore.Diagnostics ...@@ -36,7 +36,8 @@ namespace SkyWalking.AspNetCore.Diagnostics
private readonly InstrumentationConfig _config; private readonly InstrumentationConfig _config;
private readonly IContextCarrierFactory _contextCarrierFactory; private readonly IContextCarrierFactory _contextCarrierFactory;
public HostingTracingDiagnosticProcessor(IConfigAccessor configAccessor,IContextCarrierFactory contextCarrierFactory) public HostingTracingDiagnosticProcessor(IConfigAccessor configAccessor,
IContextCarrierFactory contextCarrierFactory)
{ {
_config = configAccessor.Get<InstrumentationConfig>(); _config = configAccessor.Get<InstrumentationConfig>();
_contextCarrierFactory = contextCarrierFactory; _contextCarrierFactory = contextCarrierFactory;
...@@ -48,7 +49,7 @@ namespace SkyWalking.AspNetCore.Diagnostics ...@@ -48,7 +49,7 @@ namespace SkyWalking.AspNetCore.Diagnostics
var carrier = _contextCarrierFactory.Create(); var carrier = _contextCarrierFactory.Create();
foreach (var item in carrier.Items) foreach (var item in carrier.Items)
item.HeadValue = httpContext.Request.Headers[item.HeadKey]; item.HeadValue = httpContext.Request.Headers[item.HeadKey];
var httpRequestSpan = ContextManager.CreateEntrySpan($"{_config.ApplicationCode} {httpContext.Request.Path}", carrier); var httpRequestSpan = ContextManager.CreateEntrySpan(httpContext.Request.Path, carrier);
httpRequestSpan.AsHttp(); httpRequestSpan.AsHttp();
httpRequestSpan.SetComponent(ComponentsDefine.AspNetCore); httpRequestSpan.SetComponent(ComponentsDefine.AspNetCore);
Tags.Url.Set(httpRequestSpan, httpContext.Request.Path); Tags.Url.Set(httpRequestSpan, httpContext.Request.Path);
...@@ -57,7 +58,10 @@ namespace SkyWalking.AspNetCore.Diagnostics ...@@ -57,7 +58,10 @@ namespace SkyWalking.AspNetCore.Diagnostics
new Dictionary<string, object> new Dictionary<string, object>
{ {
{"event", "AspNetCore Hosting BeginRequest"}, {"event", "AspNetCore Hosting BeginRequest"},
{"message", $"Request starting {httpContext.Request.Protocol} {httpContext.Request.Method} {httpContext.Request.GetDisplayUrl()}"} {
"message",
$"Request starting {httpContext.Request.Protocol} {httpContext.Request.Method} {httpContext.Request.GetDisplayUrl()}"
}
}); });
httpContext.Items[HttpContextDiagnosticStrings.SpanKey] = httpRequestSpan; httpContext.Items[HttpContextDiagnosticStrings.SpanKey] = httpRequestSpan;
} }
...@@ -82,25 +86,28 @@ namespace SkyWalking.AspNetCore.Diagnostics ...@@ -82,25 +86,28 @@ namespace SkyWalking.AspNetCore.Diagnostics
new Dictionary<string, object> new Dictionary<string, object>
{ {
{"event", "AspNetCore Hosting EndRequest"}, {"event", "AspNetCore Hosting EndRequest"},
{"message", $"Request finished {httpContext.Response.StatusCode} {httpContext.Response.ContentType}"} {
"message",
$"Request finished {httpContext.Response.StatusCode} {httpContext.Response.ContentType}"
}
}); });
ContextManager.StopSpan(httpRequestSpan); ContextManager.StopSpan(httpRequestSpan);
} }
[DiagnosticName("Microsoft.AspNetCore.Diagnostics.UnhandledException")] [DiagnosticName("Microsoft.AspNetCore.Diagnostics.UnhandledException")]
public void DiagnosticUnhandledException([Property]HttpContext httpContext, [Property]Exception exception) public void DiagnosticUnhandledException([Property] HttpContext httpContext, [Property] Exception exception)
{ {
ContextManager.ActiveSpan?.ErrorOccurred()?.Log(exception); ContextManager.ActiveSpan?.ErrorOccurred()?.Log(exception);
} }
[DiagnosticName("Microsoft.AspNetCore.Hosting.UnhandledException")] [DiagnosticName("Microsoft.AspNetCore.Hosting.UnhandledException")]
public void HostingUnhandledException([Property]HttpContext httpContext, [Property]Exception exception) public void HostingUnhandledException([Property] HttpContext httpContext, [Property] Exception exception)
{ {
ContextManager.ActiveSpan?.ErrorOccurred()?.Log(exception); ContextManager.ActiveSpan?.ErrorOccurred()?.Log(exception);
} }
//[DiagnosticName("Microsoft.AspNetCore.Mvc.BeforeAction")] //[DiagnosticName("Microsoft.AspNetCore.Mvc.BeforeAction")]
public void BeforeAction([Property]ActionDescriptor actionDescriptor, [Property]HttpContext httpContext) public void BeforeAction([Property] ActionDescriptor actionDescriptor, [Property] HttpContext httpContext)
{ {
var span = httpContext.Items[HttpContextDiagnosticStrings.SpanKey] as ISpan; var span = httpContext.Items[HttpContextDiagnosticStrings.SpanKey] as ISpan;
if (span == null) if (span == null)
...@@ -108,12 +115,13 @@ namespace SkyWalking.AspNetCore.Diagnostics ...@@ -108,12 +115,13 @@ namespace SkyWalking.AspNetCore.Diagnostics
return; return;
} }
var events = new Dictionary<string, object> {{"event", "AspNetCore.Mvc Executing action method"}, {"Action method", actionDescriptor.DisplayName}}; var events = new Dictionary<string, object>
{{"event", "AspNetCore.Mvc Executing action method"}, {"Action method", actionDescriptor.DisplayName}};
span.Log(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), events); span.Log(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), events);
} }
//[DiagnosticName("Microsoft.AspNetCore.Mvc.AfterAction")] //[DiagnosticName("Microsoft.AspNetCore.Mvc.AfterAction")]
public void AfterAction([Property]ActionDescriptor actionDescriptor, [Property]HttpContext httpContext) public void AfterAction([Property] ActionDescriptor actionDescriptor, [Property] HttpContext httpContext)
{ {
var span = httpContext.Items[HttpContextDiagnosticStrings.SpanKey] as ISpan; var span = httpContext.Items[HttpContextDiagnosticStrings.SpanKey] as ISpan;
if (span == null) if (span == null)
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.0.0" PrivateAssets="All" />
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="DotNetCore.CAP" Version="2.3.1" /> <PackageReference Include="DotNetCore.CAP" Version="2.3.1" PrivateAssets="All" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
...@@ -25,10 +25,10 @@ namespace SkyWalking.Diagnostics.EntityFrameworkCore ...@@ -25,10 +25,10 @@ namespace SkyWalking.Diagnostics.EntityFrameworkCore
public class NpgsqlEFCoreSpanMetadataProvider : IEfCoreSpanMetadataProvider public class NpgsqlEFCoreSpanMetadataProvider : IEfCoreSpanMetadataProvider
{ {
public IComponent Component { get; } = ComponentsDefine.Npgsql_EntityFrameworkCore_PostgreSQL; public IComponent Component { get; } = ComponentsDefine.Npgsql_EntityFrameworkCore_PostgreSQL;
public bool Match(DbConnection connection) public bool Match(DbConnection connection)
{ {
return connection is NpgsqlConnection; return connection.GetType().FullName == "Npgsql.NpgsqlConnection";
} }
public string GetPeer(DbConnection connection) public string GetPeer(DbConnection connection)
......
...@@ -18,6 +18,6 @@ ...@@ -18,6 +18,6 @@
<ProjectReference Include="..\SkyWalking.Utilities.DependencyInjection\SkyWalking.Utilities.DependencyInjection.csproj" /> <ProjectReference Include="..\SkyWalking.Utilities.DependencyInjection\SkyWalking.Utilities.DependencyInjection.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.1.2" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.0" PrivateAssets="All"/>
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
...@@ -28,7 +28,7 @@ namespace SkyWalking.Diagnostics.EntityFrameworkCore ...@@ -28,7 +28,7 @@ namespace SkyWalking.Diagnostics.EntityFrameworkCore
public bool Match(DbConnection connection) public bool Match(DbConnection connection)
{ {
return connection is MySqlConnection; return connection.GetType().FullName == "MySql.Data.MySqlClient.MySqlConnection";
} }
public string GetPeer(DbConnection connection) public string GetPeer(DbConnection connection)
......
...@@ -18,6 +18,6 @@ ...@@ -18,6 +18,6 @@
<ProjectReference Include="..\SkyWalking.Utilities.DependencyInjection\SkyWalking.Utilities.DependencyInjection.csproj" /> <ProjectReference Include="..\SkyWalking.Utilities.DependencyInjection\SkyWalking.Utilities.DependencyInjection.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.1.4" /> <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.1.4" PrivateAssets="All" />
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
...@@ -18,6 +18,6 @@ ...@@ -18,6 +18,6 @@
<ProjectReference Include="..\SkyWalking.Utilities.DependencyInjection\SkyWalking.Utilities.DependencyInjection.csproj" /> <ProjectReference Include="..\SkyWalking.Utilities.DependencyInjection\SkyWalking.Utilities.DependencyInjection.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.0.0" PrivateAssets="All"/>
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
...@@ -25,10 +25,10 @@ namespace SkyWalking.Diagnostics.EntityFrameworkCore ...@@ -25,10 +25,10 @@ namespace SkyWalking.Diagnostics.EntityFrameworkCore
public class SqliteEFCoreSpanMetadataProvider : IEfCoreSpanMetadataProvider public class SqliteEFCoreSpanMetadataProvider : IEfCoreSpanMetadataProvider
{ {
public IComponent Component { get; } = ComponentsDefine.EntityFrameworkCore_Sqlite; public IComponent Component { get; } = ComponentsDefine.EntityFrameworkCore_Sqlite;
public bool Match(DbConnection connection) public bool Match(DbConnection connection)
{ {
return connection is SqliteConnection; return connection.GetType().FullName == "Microsoft.Data.Sqlite.SqliteConnection";
} }
public string GetPeer(DbConnection connection) public string GetPeer(DbConnection connection)
...@@ -36,12 +36,12 @@ namespace SkyWalking.Diagnostics.EntityFrameworkCore ...@@ -36,12 +36,12 @@ namespace SkyWalking.Diagnostics.EntityFrameworkCore
string dataSource; string dataSource;
switch (connection.DataSource) switch (connection.DataSource)
{ {
case "": case "":
dataSource = "sqlite:memory:db"; dataSource = "sqlite:memory:db";
break; break;
default: default:
dataSource = connection.DataSource; dataSource = connection.DataSource;
break; break;
} }
return $"{dataSource}"; return $"{dataSource}";
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
<RootNamespace>SkyWalking.Diagnostics.EntityFrameworkCore</RootNamespace> <RootNamespace>SkyWalking.Diagnostics.EntityFrameworkCore</RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0" PrivateAssets="All"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.2.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.0.0" PrivateAssets="All"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\SkyWalking.Abstractions\SkyWalking.Abstractions.csproj" /> <ProjectReference Include="..\SkyWalking.Abstractions\SkyWalking.Abstractions.csproj" />
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="MySql.Data" Version="6.10.7" /> <PackageReference Include="MySql.Data" Version="6.10.7" PrivateAssets="All" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
...@@ -17,6 +17,6 @@ ...@@ -17,6 +17,6 @@
<ProjectReference Include="..\SkyWalking.Utilities.DependencyInjection\SkyWalking.Utilities.DependencyInjection.csproj" /> <ProjectReference Include="..\SkyWalking.Utilities.DependencyInjection\SkyWalking.Utilities.DependencyInjection.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="System.Data.SqlClient" Version="4.6.0" /> <PackageReference Include="System.Data.SqlClient" Version="4.6.0" PrivateAssets="All" />
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.2.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.2.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>
...@@ -15,6 +15,6 @@ ...@@ -15,6 +15,6 @@
<ProjectReference Include="..\SkyWalking.Core\SkyWalking.Core.csproj" /> <ProjectReference Include="..\SkyWalking.Core\SkyWalking.Core.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.0.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
...@@ -29,7 +29,9 @@ namespace SkyWalking.Utilities.Logging ...@@ -29,7 +29,9 @@ namespace SkyWalking.Utilities.Logging
{ {
public class DefaultLoggerFactory : ILoggerFactory public class DefaultLoggerFactory : ILoggerFactory
{ {
private const string outputTemplate = @"{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{ApplicationCode}] [{Level}] {SourceContext} : {Message}{NewLine}{Exception}"; private const string outputTemplate =
@"{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{ApplicationCode}] [{Level}] {SourceContext} : {Message}{NewLine}{Exception}";
private readonly MSLoggerFactory _loggerFactory; private readonly MSLoggerFactory _loggerFactory;
private readonly LoggingConfig _loggingConfig; private readonly LoggingConfig _loggingConfig;
...@@ -41,13 +43,12 @@ namespace SkyWalking.Utilities.Logging ...@@ -41,13 +43,12 @@ namespace SkyWalking.Utilities.Logging
var level = EventLevel(_loggingConfig.Level); var level = EventLevel(_loggingConfig.Level);
_loggerFactory.AddSerilog(new LoggerConfiguration(). _loggerFactory.AddSerilog(new LoggerConfiguration().MinimumLevel.Verbose().Enrich
MinimumLevel.Verbose(). .WithProperty("SourceContext", null).Enrich
Enrich.WithProperty("SourceContext", null). .WithProperty(nameof(instrumentationConfig.ServiceName),
Enrich.WithProperty(nameof(instrumentationConfig.ApplicationCode), instrumentationConfig.ApplicationCode). instrumentationConfig.ServiceName ?? instrumentationConfig.ApplicationCode).Enrich
Enrich.FromLogContext(). .FromLogContext().WriteTo.RollingFile(_loggingConfig.FilePath, level, outputTemplate, null, 1073741824,
WriteTo.RollingFile(_loggingConfig.FilePath, level, outputTemplate, null, 1073741824, 31, null, false, false, TimeSpan.FromMilliseconds(500)). 31, null, false, false, TimeSpan.FromMilliseconds(500)).CreateLogger());
CreateLogger());
} }
public ILogger CreateLogger(Type type) public ILogger CreateLogger(Type type)
...@@ -57,7 +58,9 @@ namespace SkyWalking.Utilities.Logging ...@@ -57,7 +58,9 @@ namespace SkyWalking.Utilities.Logging
private static LogEventLevel EventLevel(string level) private static LogEventLevel EventLevel(string level)
{ {
return LogEventLevel.TryParse<LogEventLevel>(level, out var logEventLevel) ? logEventLevel : LogEventLevel.Error; return LogEventLevel.TryParse<LogEventLevel>(level, out var logEventLevel)
? logEventLevel
: LogEventLevel.Error;
} }
} }
} }
\ No newline at end of file
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="2.0.2" /> <PackageReference Include="Serilog.Extensions.Logging" Version="2.0.2" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" /> <PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
</ItemGroup> </ItemGroup>
......
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