提交 3718ebf5 编写于 作者: A Ahoo Wang 提交者: Lemon

update SmartSql-version to v4.0.0 (#178)

* update SmartSql-version -> v4.0.0

* add SkyApm.Sample.SmartSql.csproj
add SmartSql.CommandExecuter Diagnostics
上级 67dcdc18
......@@ -6,7 +6,6 @@
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\SkyApm.Agent.AspNetCore\SkyApm.Agent.AspNetCore.csproj" />
<ProjectReference Include="..\..\src\SkyApm.Diagnostics.EntityFrameworkCore.Sqlite\SkyApm.Diagnostics.EntityFrameworkCore.Sqlite.csproj" />
</ItemGroup>
......@@ -16,7 +15,6 @@
<Version>2.1.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" />
<PackageReference Include="SmartSql.DIExtension" Version="4.0.0-rc1" />
</ItemGroup>
<ItemGroup>
......
using Microsoft.AspNetCore.Builder;
using System;
using System.Globalization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
......@@ -8,8 +10,6 @@ using Microsoft.Extensions.Logging;
using SkyApm.Sample.Backend.Models;
using SkyApm.Sample.Backend.Sampling;
using SkyApm.Tracing;
using SmartSql;
using SmartSql.DataSource;
namespace SkyApm.Sample.Backend
{
......@@ -26,21 +26,13 @@ namespace SkyApm.Sample.Backend
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
var sqliteConnection = new SqliteConnection("DataSource=:memory:");
sqliteConnection.Open();
services.AddEntityFrameworkSqlite().AddDbContext<SampleDbContext>(c => c.UseSqlite(sqliteConnection));
services.AddSingleton<ISamplingInterceptor, CustomSamplingInterceptor>();
services.AddSmartSql(sp =>
{
return SmartSqlBuilder
.AddDataSource(DbProvider.SQLSERVER, "Data Source=.;Initial Catalog=SmartSqlTestDB;Integrated Security=True")
.UseLoggerFactory(sp.GetService<ILoggerFactory>())
.UseCache(false)
.Build();
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
......
......@@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartSql;
namespace SkyApm.Sample.Backend.Controllers
namespace SkyApm.Sample.SmartSql.Controllers
{
[Route("[controller]/[action]")]
[ApiController]
......@@ -31,7 +31,7 @@ namespace SkyApm.Sample.Backend.Controllers
{
return await _sqlMapper.QueryAsync<dynamic>(new RequestContext
{
RealSql = "SELECT Top (1000) T.* From T_AllPrimitive T With(NoLock)"
RealSql = "SELECT T.* From T_User T Limit 100"
});
}
[HttpGet]
......@@ -39,9 +39,10 @@ namespace SkyApm.Sample.Backend.Controllers
{
return _sqlMapper.Query<dynamic>(new RequestContext
{
RealSql = "SELECT Top (1000) T.* From T_AllPrimitive T With(NoLock)"
RealSql = "SELECT T.* From T_User T Limit 100"
});
}
[HttpGet]
public IEnumerable<dynamic> Transaction()
{
......@@ -51,7 +52,7 @@ namespace SkyApm.Sample.Backend.Controllers
var list = _sqlMapper.Query<dynamic>(new RequestContext
{
RealSql = "SELECT Top (1000) T.* From T_AllPrimitive T With(NoLock)"
RealSql = "SELECT T.* From T_User T Limit 100"
});
_sqlMapper.CommitTransaction();
return list;
......
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace SkyApm.Sample.SmartSql
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
}
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"SkyApm.Sample.SmartSql": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"applicationUrl": "http://localhost:5003",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "SkyAPM.Agent.AspNetCore"
}
}
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="SmartSql.DIExtension" Version="4.0.3" />
<PackageReference Include="System.Data.SQLite" Version="1.0.110" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\SkyApm.Agent.AspNetCore\SkyApm.Agent.AspNetCore.csproj" />
</ItemGroup>
<ItemGroup>
<Content Update="skyapm.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<None Update="SmartSqlTestDB.db">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using SmartSql;
using SmartSql.DataSource;
namespace SkyApm.Sample.SmartSql
{
public class Startup
{
public Startup(IConfiguration configuration)
{
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().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddSmartSql(sp => new SmartSqlBuilder()
.UseLoggerFactory(sp.GetService<ILoggerFactory>())
.UseDataSource(DbProvider.SQLITE, "Data Source=SmartSqlTestDB.db;Version=3;")
.UseCache(false)
.Build());
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
}
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*"
}
{
"SkyWalking": {
"ServiceName": "asp-net-core-SmartSql",
"Namespace": "",
"HeaderVersions": [
"sw6"
],
"Sampling": {
"SamplePer3Secs": -1,
"Percentage": -1.0
},
"Logging": {
"Level": "Information",
"FilePath": "logs/skyapm-{Date}.log"
},
"Transport": {
"Interval": 3000,
"ProtocolVersion": "v6",
"QueueSize": 30000,
"BatchSize": 3000,
"gRPC": {
"Servers": "localhost:11800",
"Timeout": 100000,
"ConnectTimeout": 100000,
"ReportTimeout": 600000
}
}
}
}
\ No newline at end of file
......@@ -82,6 +82,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.DotNet.CLI", "src\Sk
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Diagnostics.SmartSql", "src\SkyApm.Diagnostics.SmartSql\SkyApm.Diagnostics.SmartSql.csproj", "{B43160C8-C9E3-43F6-83E9-A9A45B32F022}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkyApm.Sample.SmartSql", "sample\SkyApm.Sample.SmartSql\SkyApm.Sample.SmartSql.csproj", "{8E2B336B-8138-4179-A754-A1D0C0471654}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -176,6 +178,10 @@ Global
{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.Build.0 = Release|Any CPU
{8E2B336B-8138-4179-A754-A1D0C0471654}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E2B336B-8138-4179-A754-A1D0C0471654}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E2B336B-8138-4179-A754-A1D0C0471654}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E2B336B-8138-4179-A754-A1D0C0471654}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -211,6 +217,7 @@ Global
{2F7EEC69-35F4-4D31-B52A-7465D65E9DE0} = {A4E67E09-3156-4D30-B451-F24F706E96C4}
{E909EEF5-5EBF-43F3-AB4A-6B2FB56EF89B} = {1B0865AF-369E-493C-AA6F-C56D3E520A22}
{B43160C8-C9E3-43F6-83E9-A9A45B32F022} = {B5E677CF-2920-4B0A-A056-E73F6B2CF2BC}
{8E2B336B-8138-4179-A754-A1D0C0471654} = {844CEACD-4C85-4B15-9E2B-892B01FDA4BB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {94C0DA2C-CCCB-4314-93A2-9809B5DD0583}
......
......@@ -12,7 +12,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SmartSql" Version="4.0.0-rc3" PrivateAssets="All" />
<PackageReference Include="SmartSql" Version="4.0.3" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SkyApm.Abstractions\SkyApm.Abstractions.csproj" />
......
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using SkyApm.Tracing;
......@@ -196,9 +197,10 @@ namespace SkyApm.Diagnostics.SmartSql
if (context != null)
{
context.Span.AddTag("from_cache", eventData.ExecutionContext.Result.FromCache);
context.Span.Peer = new Common.StringOrIntValue(eventData.DbSession.Connection?.DataSource);
context.Span.AddTag(Common.Tags.DB_INSTANCE, eventData.DbSession.Connection?.Database);
context.Span.AddTag(Common.Tags.DB_STATEMENT, eventData.ExecutionContext.Request.RealSql);
var resultSize = eventData.ExecutionContext.Result.IsList
? (eventData.ExecutionContext.Result.GetData() as ICollection)?.Count
: 1;
context.Span.AddTag("result_size", resultSize?.ToString());
_tracingContext.Release(context);
}
}
......@@ -213,5 +215,40 @@ namespace SkyApm.Diagnostics.SmartSql
}
}
#endregion
#region CommandExecuter
[DiagnosticName(SmartSqlDiagnosticListenerExtensions.SMART_SQL_BEFORE_COMMAND_EXECUTER_EXECUTE)]
public void BeforeCommandExecuterExecute([Object]CommandExecuterExecuteBeforeEventData eventData)
{
var context = _tracingContext.CreateLocalSegmentContext(eventData.Operation);
context.Span.SpanLayer = Tracing.Segments.SpanLayer.DB;
context.Span.Component = Common.Components.SMART_SQL;
context.Span.AddTag(Common.Tags.DB_TYPE, "Sql");
}
[DiagnosticName(SmartSqlDiagnosticListenerExtensions.SMART_SQL_AFTER_COMMAND_EXECUTER_EXECUTE)]
public void AfterCommandExecuterExecute([Object]CommandExecuterExecuteAfterEventData eventData)
{
var context = _localSegmentContextAccessor.Context;
if (context != null)
{
context.Span.Peer = new Common.StringOrIntValue(eventData.ExecutionContext.DbSession.Connection?.DataSource);
context.Span.AddTag(Common.Tags.DB_INSTANCE, eventData.ExecutionContext.DbSession.Connection?.Database);
context.Span.AddTag(Common.Tags.DB_STATEMENT, eventData.ExecutionContext.Request.RealSql);
_tracingContext.Release(context);
}
}
[DiagnosticName(SmartSqlDiagnosticListenerExtensions.SMART_SQL_ERROR_COMMAND_EXECUTER_EXECUTE)]
public void ErrorCommandExecuterExecute([Object]CommandExecuterExecuteErrorEventData eventData)
{
var context = _localSegmentContextAccessor.Context;
if (context != null)
{
context.Span.ErrorOccurred(eventData.Exception);
_tracingContext.Release(context);
}
}
#endregion
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册