-
Notifications
You must be signed in to change notification settings - Fork 204
WIP Ensure sql statements end up in ActivitySource #63
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -760,7 +760,7 @@ internal async Task<MySqlDataReader> ExecuteReaderAsync(CommandBehavior behavior | |
|
||
// Tell whoever is listening that we have started out command | ||
#if NET5_0_OR_GREATER | ||
CurrentActivity = MySQLActivitySource.CommandStart(this); | ||
CurrentActivity = MySQLActivitySource.CommandStart(this, sql); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While I wanted to avoid passing in the |
||
#endif | ||
try | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -477,6 +477,10 @@ public void DontAllowBatching() | |
using (MySqlConnection c = new MySqlConnection(connStr.GetConnectionString(true))) | ||
{ | ||
c.Open(); | ||
|
||
using var _ = AddActivityListener( | ||
(activity) => Assert.AreEqual("SELECT 1", activity.GetTagItem("db.statement")) | ||
); | ||
MySqlCommand cmd = new MySqlCommand("SELECT 1", c); | ||
cmd.ExecuteScalar(); | ||
} | ||
|
@@ -490,6 +494,13 @@ public void TableCommandType() | |
ExecuteSQL("CREATE TABLE Test1 (id INT, name VARCHAR(20))"); | ||
ExecuteSQL("INSERT INTO Test1 VALUES (2, 'B')"); | ||
|
||
using var _ = AddActivityListener((activity) => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test would not have passed without code change |
||
{ | ||
Assert.AreEqual("Test,Test1", activity.GetTagItem("db.sql.table")); | ||
Assert.AreEqual("SELECT * FROM Test,Test1", activity.GetTagItem("db.statement")); | ||
} | ||
); | ||
|
||
MySqlCommand cmd = new MySqlCommand("Test,Test1", Connection); | ||
cmd.CommandType = CommandType.TableDirect; | ||
using (MySqlDataReader reader = cmd.ExecuteReader()) | ||
|
@@ -949,6 +960,7 @@ public void LastInsertedIdInMultipleStatements() | |
cmd.ExecuteNonQuery(); | ||
Assert.AreEqual(2, cmd.LastInsertedId); | ||
|
||
using var _ = AddActivityListener((activity) => Assert.AreEqual("SELECT * FROM Test", activity.GetTagItem("db.statement"))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test would not have passed without code change |
||
cmd.CommandText = "SELECT * FROM Test"; | ||
int id = 1; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -333,6 +333,37 @@ public string GetMySqlServerIp(bool isIpV6 = false) | |
|
||
return isIpV6 ? ipv6 : ipv4; | ||
} | ||
|
||
// XXX This shouldn't be the final form - it probably shouldn't be placed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't very good; I'm fairly new to dotnet unit testing and NUnit, so I tried to be a little generic but not too much. In general I wasn't sure whether to make specific tests for Something I was doubly unsure of: This isn't relevant for runtimes which don't have |
||
// here, the logic is incomplete, etc. Was good for a few hacky tests | ||
public static ActivityListener AddActivityListener(Action<Activity> activityCheck) | ||
{ | ||
var listener = new ActivityListener | ||
{ | ||
ShouldListenTo = source => | ||
{ | ||
return source.Name == "connector-net"; | ||
}, | ||
ActivityStopped = activity => | ||
{ | ||
Assert.AreEqual("mysql", activity.GetTagItem("db.system")); | ||
|
||
if (activityCheck == null) | ||
{ | ||
Assert.Fail("Activity raised without a checking function"); | ||
} | ||
else | ||
{ | ||
activityCheck(activity); | ||
} | ||
}, | ||
Sample = (ref ActivityCreationOptions<ActivityContext> options) => ActivitySamplingResult.AllData, | ||
}; | ||
|
||
ActivitySource.AddActivityListener(listener); | ||
|
||
return listener; | ||
} | ||
#endregion | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OriginalCommandText
was a bit of a mystery to me - it may have made sense when the code looked different, but I don't understand when the sql query at time of call isn't good. I analysed the code paths in the PR description and they all seemed very understandable.Is there an edge case I'm missing?