Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log db statement with parameter value when use SmartSql #539

Merged
merged 2 commits into from
Feb 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using SkyApm.Tracing.Segments;
using SmartSql;
using SmartSql.Diagnostics;
using SmartSql.Utils;

namespace SkyApm.Diagnostics.SmartSql
{
Expand Down Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you comment this line?

Copy link
Contributor Author

@xclw2000 xclw2000 Feb 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below varialbe "sql" include "RealSql"
for example:
ReqlSql="select 1 from T where F1=@F1"
sql="selece 1 from T where F1='aaa'"

So it's no need to log RealSql

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean if you try to delete this, delete this. Git is the time machine. We don't need to keep old codes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommit pr after I delete it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if your plan is to remove this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

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)]
Expand Down