Skip to content

Commit

Permalink
fixed:Incorrect component name when using Pomelo.EntityFrameworkCore.…
Browse files Browse the repository at this point in the history
…MySlq (#428)

* 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: 郭刚平 <[email protected]>
Co-authored-by: 延鹏 王 <[email protected]>
  • Loading branch information
3 people authored Jan 6, 2022
1 parent 3a9ab3b commit 770e0b5
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static class DatabaseProviderBuilderExtensions
{
public static DatabaseProviderBuilder AddPomeloMysql(this DatabaseProviderBuilder builder)
{
builder.Services.AddSingleton<IEntityFrameworkCoreSpanMetadataProvider, MySqlConnectorSpanMetadataProvider>();
builder.Services.AddSingleton<IEntityFrameworkCoreSpanMetadataProvider, MySqlEntityFrameworkCoreSpanMetadataProvider>();
return builder;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace SkyApm.Diagnostics.EntityFrameworkCore
{
public interface IEntityFrameworkCoreSpanMetadataProvider
{
string Component { get; }
Common.StringOrIntValue Component { get; }

bool Match(DbConnection connection);

Expand Down

0 comments on commit 770e0b5

Please sign in to comment.