From 770e0b528f3f25baedf02ad1d92d47b9791e50bc Mon Sep 17 00:00:00 2001 From: Yanpeng Wang Date: Thu, 6 Jan 2022 16:30:16 +0800 Subject: [PATCH] fixed:Incorrect component name when using Pomelo.EntityFrameworkCore.MySlq (#428) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update version.props (#424) * fix(SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql):added support for new version EntityFrameworkCore.Pomelo.MySql fix(SkyApm.Diagnostics.EntityFrameworkCore):Fixed an issue that the component name of EntityFrameworkCore could not be obtained correctly in SkyWalking-UI Co-authored-by: 郭刚平 <512979011@qq.com> Co-authored-by: 延鹏 王 --- ...EntityFrameworkCoreSpanMetadataProvider.cs | 3 ++- .../DatabaseProviderBuilderExtensions.cs | 1 + .../MySqlConnectorSpanMetadataProvider.cs | 23 +++++++++++++++++++ ...EntityFrameworkCoreSpanMetadataProvider.cs | 5 ++-- ...EntityFrameworkCoreSpanMetadataProvider.cs | 3 ++- ...ntityFrameworkCoreSegmentContextFactory.cs | 4 ++-- ...EntityFrameworkCoreSpanMetadataProvider.cs | 2 +- 7 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 src/SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql/MySqlConnectorSpanMetadataProvider.cs diff --git a/src/SkyApm.Diagnostics.EntityFrameworkCore.Npgsql/NpgsqlEntityFrameworkCoreSpanMetadataProvider.cs b/src/SkyApm.Diagnostics.EntityFrameworkCore.Npgsql/NpgsqlEntityFrameworkCoreSpanMetadataProvider.cs index 872ae8ab..d090900c 100644 --- a/src/SkyApm.Diagnostics.EntityFrameworkCore.Npgsql/NpgsqlEntityFrameworkCoreSpanMetadataProvider.cs +++ b/src/SkyApm.Diagnostics.EntityFrameworkCore.Npgsql/NpgsqlEntityFrameworkCoreSpanMetadataProvider.cs @@ -17,12 +17,13 @@ */ using System.Data.Common; +using SkyApm.Common; namespace SkyApm.Diagnostics.EntityFrameworkCore { public class NpgsqlEntityFrameworkCoreSpanMetadataProvider : IEntityFrameworkCoreSpanMetadataProvider { - public string Component { get; } = Common.Components.NPGSQL_ENTITYFRAMEWORKCORE_POSTGRESQL.GetStringValue(); + public StringOrIntValue Component { get; } = Components.NPGSQL_ENTITYFRAMEWORKCORE_POSTGRESQL; public bool Match(DbConnection connection) { diff --git a/src/SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql/DatabaseProviderBuilderExtensions.cs b/src/SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql/DatabaseProviderBuilderExtensions.cs index 03690214..1e8f6a81 100644 --- a/src/SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql/DatabaseProviderBuilderExtensions.cs +++ b/src/SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql/DatabaseProviderBuilderExtensions.cs @@ -24,6 +24,7 @@ public static class DatabaseProviderBuilderExtensions { public static DatabaseProviderBuilder AddPomeloMysql(this DatabaseProviderBuilder builder) { + builder.Services.AddSingleton(); builder.Services.AddSingleton(); return builder; } diff --git a/src/SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql/MySqlConnectorSpanMetadataProvider.cs b/src/SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql/MySqlConnectorSpanMetadataProvider.cs new file mode 100644 index 00000000..02dc5cff --- /dev/null +++ b/src/SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql/MySqlConnectorSpanMetadataProvider.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Data.Common; +using System.Text; +using SkyApm.Common; + +namespace SkyApm.Diagnostics.EntityFrameworkCore +{ + public class MySqlConnectorSpanMetadataProvider : IEntityFrameworkCoreSpanMetadataProvider + { + public StringOrIntValue Component { get; } = Components.POMELO_ENTITYFRAMEWORKCORE_MYSQL; + + public bool Match(DbConnection connection) + { + return connection.GetType().FullName == "MySqlConnector.MySqlConnection"; + } + + public string GetPeer(DbConnection connection) + { + return connection.DataSource; + } + } +} diff --git a/src/SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql/MySqlEntityFrameworkCoreSpanMetadataProvider.cs b/src/SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql/MySqlEntityFrameworkCoreSpanMetadataProvider.cs index 72dc9da8..a0436a1a 100644 --- a/src/SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql/MySqlEntityFrameworkCoreSpanMetadataProvider.cs +++ b/src/SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql/MySqlEntityFrameworkCoreSpanMetadataProvider.cs @@ -17,13 +17,14 @@ */ using System.Data.Common; +using SkyApm.Common; namespace SkyApm.Diagnostics.EntityFrameworkCore { public class MySqlEntityFrameworkCoreSpanMetadataProvider : IEntityFrameworkCoreSpanMetadataProvider { - public string Component { get; } = Common.Components.POMELO_ENTITYFRAMEWORKCORE_MYSQL.GetStringValue(); - + public StringOrIntValue Component { get; } = Components.POMELO_ENTITYFRAMEWORKCORE_MYSQL; + public bool Match(DbConnection connection) { return connection.GetType().FullName == "MySql.Data.MySqlClient.MySqlConnection"; diff --git a/src/SkyApm.Diagnostics.EntityFrameworkCore.Sqlite/SqliteEntityFrameworkCoreSpanMetadataProvider.cs b/src/SkyApm.Diagnostics.EntityFrameworkCore.Sqlite/SqliteEntityFrameworkCoreSpanMetadataProvider.cs index c19f9012..f2aedad3 100644 --- a/src/SkyApm.Diagnostics.EntityFrameworkCore.Sqlite/SqliteEntityFrameworkCoreSpanMetadataProvider.cs +++ b/src/SkyApm.Diagnostics.EntityFrameworkCore.Sqlite/SqliteEntityFrameworkCoreSpanMetadataProvider.cs @@ -17,12 +17,13 @@ */ using System.Data.Common; +using SkyApm.Common; namespace SkyApm.Diagnostics.EntityFrameworkCore { public class SqliteEntityFrameworkCoreSpanMetadataProvider : IEntityFrameworkCoreSpanMetadataProvider { - public string Component { get; } = Common.Components.ENTITYFRAMEWORKCORE_SQLITE.GetStringValue(); + public StringOrIntValue Component { get; } = Components.ENTITYFRAMEWORKCORE_SQLITE; public bool Match(DbConnection connection) { diff --git a/src/SkyApm.Diagnostics.EntityFrameworkCore/EntityFrameworkCoreSegmentContextFactory.cs b/src/SkyApm.Diagnostics.EntityFrameworkCore/EntityFrameworkCoreSegmentContextFactory.cs index 20179cb9..b47f2a86 100644 --- a/src/SkyApm.Diagnostics.EntityFrameworkCore/EntityFrameworkCoreSegmentContextFactory.cs +++ b/src/SkyApm.Diagnostics.EntityFrameworkCore/EntityFrameworkCoreSegmentContextFactory.cs @@ -70,14 +70,14 @@ private SegmentContext CreateExitSegment(string operationName, DbCommand dbComma { var context = _tracingContext.CreateExitSegmentContext(operationName, metadataProvider.GetPeer(dbCommand.Connection)); - context.Span.Component = new StringOrIntValue(metadataProvider.Component); + context.Span.Component = metadataProvider.Component; return context; } private SegmentContext CreateLocalSegment(string operationName, DbCommand dbCommand) { var context = _tracingContext.CreateLocalSegmentContext(operationName); - context.Span.Component = Common.Components.ENTITYFRAMEWORKCORE; + context.Span.Component = Components.ENTITYFRAMEWORKCORE; return context; } } diff --git a/src/SkyApm.Diagnostics.EntityFrameworkCore/IEntityFrameworkCoreSpanMetadataProvider.cs b/src/SkyApm.Diagnostics.EntityFrameworkCore/IEntityFrameworkCoreSpanMetadataProvider.cs index 45f3b336..b28a64fc 100644 --- a/src/SkyApm.Diagnostics.EntityFrameworkCore/IEntityFrameworkCoreSpanMetadataProvider.cs +++ b/src/SkyApm.Diagnostics.EntityFrameworkCore/IEntityFrameworkCoreSpanMetadataProvider.cs @@ -22,7 +22,7 @@ namespace SkyApm.Diagnostics.EntityFrameworkCore { public interface IEntityFrameworkCoreSpanMetadataProvider { - string Component { get; } + Common.StringOrIntValue Component { get; } bool Match(DbConnection connection);