From 33877cd234071edf177d7ddeea3178c075bdad78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=AA=E4=BA=94=E6=B5=B7?= Date: Thu, 16 Feb 2023 16:41:02 +0800 Subject: [PATCH 1/2] log db statement with parameter value when use SmartSql --- .../SmartSqlTracingDiagnosticProcessor.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/SkyApm.Diagnostics.SmartSql/SmartSqlTracingDiagnosticProcessor.cs b/src/SkyApm.Diagnostics.SmartSql/SmartSqlTracingDiagnosticProcessor.cs index a5bf8684..048c682b 100644 --- a/src/SkyApm.Diagnostics.SmartSql/SmartSqlTracingDiagnosticProcessor.cs +++ b/src/SkyApm.Diagnostics.SmartSql/SmartSqlTracingDiagnosticProcessor.cs @@ -26,6 +26,7 @@ using SkyApm.Tracing.Segments; using SmartSql; using SmartSql.Diagnostics; +using SmartSql.Utils; namespace SkyApm.Diagnostics.SmartSql { @@ -249,7 +250,12 @@ public void BeforeCommandExecuterExecute([Object]CommandExecuterExecuteBeforeEve var context = CreateSmartSqlLocalSegmentContext(eventData.Operation); if (eventData.ExecutionContext.Request.RealSql != null) { - context.Span.AddTag(Common.Tags.DB_STATEMENT, eventData.ExecutionContext.Request.RealSql); + //context.Span.AddTag(Common.Tags.DB_STATEMENT, eventData.ExecutionContext.Request.RealSql); + var sql = eventData.ExecutionContext.FormatSql(true); + var spliter = "Sql with parameter value: "; + var startIndex = sql.IndexOf(spliter) + spliter.Length; + sql = sql.Substring(startIndex); + context.Span.AddTag(Common.Tags.DB_STATEMENT, sql); } } [DiagnosticName(SmartSqlDiagnosticListenerExtensions.SMART_SQL_AFTER_COMMAND_EXECUTER_EXECUTE)] From aba1bc4ab0a9c3517814c45275adb7af4fe376bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=AA=E4=BA=94=E6=B5=B7?= Date: Thu, 16 Feb 2023 17:00:10 +0800 Subject: [PATCH 2/2] delete old codes --- .../SmartSqlTracingDiagnosticProcessor.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SkyApm.Diagnostics.SmartSql/SmartSqlTracingDiagnosticProcessor.cs b/src/SkyApm.Diagnostics.SmartSql/SmartSqlTracingDiagnosticProcessor.cs index 048c682b..55d00df6 100644 --- a/src/SkyApm.Diagnostics.SmartSql/SmartSqlTracingDiagnosticProcessor.cs +++ b/src/SkyApm.Diagnostics.SmartSql/SmartSqlTracingDiagnosticProcessor.cs @@ -250,7 +250,6 @@ public void BeforeCommandExecuterExecute([Object]CommandExecuterExecuteBeforeEve var context = CreateSmartSqlLocalSegmentContext(eventData.Operation); if (eventData.ExecutionContext.Request.RealSql != null) { - //context.Span.AddTag(Common.Tags.DB_STATEMENT, eventData.ExecutionContext.Request.RealSql); var sql = eventData.ExecutionContext.FormatSql(true); var spliter = "Sql with parameter value: "; var startIndex = sql.IndexOf(spliter) + spliter.Length;