-
Notifications
You must be signed in to change notification settings - Fork 305
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
[SqlClient] Include instance in db.namespace
and activity name, start activity with required tags
#2277
[SqlClient] Include instance in db.namespace
and activity name, start activity with required tags
#2277
Conversation
db.namespace
and activity name, start activity with required tags
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2277 +/- ##
===========================================
+ Coverage 73.91% 90.90% +16.99%
===========================================
Files 267 8 -259
Lines 9615 308 -9307
===========================================
- Hits 7107 280 -6827
+ Misses 2508 28 -2480
Flags with carried forward coverage won't be shown. Click here to find out more.
|
private static SqlClientTestCase[] TestCases => | ||
[ | ||
new SqlClientTestCase | ||
{ | ||
ConnectionString = @"Data Source=SomeServer", |
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.
I will be expanding these test cases in follow up PRs, but wanted to model in this PR what I plan to do.
I find the InlineData
attributes onerous when they include a lot of parameters. It's more code, but I prefer creating a class to represent complex test cases. I find it easier to read and understand the cases covered.
if (options.EmitNewAttributes && !string.IsNullOrEmpty(databaseName)) | ||
{ | ||
var dbNamespace = !string.IsNullOrEmpty(connectionDetails.InstanceName) | ||
? $"{connectionDetails.InstanceName}.{databaseName}" // TODO: Refactor SqlConnectionDetails to include database to avoid string allocation here. |
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.
Left a couple TODOs here. I'm considering adding database name to the SqlConnectionDetails that gets cached. This could mean though that the cache could be a little bigger in the event that multiple databases were accessed for a given instance.
|
||
public static readonly IEnumerable<KeyValuePair<string, object?>> CreationTags = new[] | ||
public static TagList GetTagListFromConnectionInfo(string? dataSource, string? databaseName, SqlClientTraceInstrumentationOptions options, out string activityName) |
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.
TagList
is a sizeable struct
. It would probably be faster to return by reference a la:
-public static TagList GetTagListFromConnectionInfo(
+public static void GetTagListFromConnectionInfo(
string? dataSource,
string? databaseName,
SqlClientTraceInstrumentationOptions options,
- out string activityName)
+ out string activityName,
+ out TagList tags)
Probably the name sucks too 🤣 GetSamplerTagsFromConnectionInfo
🤷
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.
Probably the name sucks too 🤣 GetSamplerTagsFromConnectionInfo
Yea I agree. I'm gonna leave it sucky for now cause I don't know what to call it yet. This code may continue to be refactored a bit once I integrate metric instrumentation which will also need what this method is doing.
ActivityKind.Client, | ||
default(ActivityContext), | ||
SqlActivitySourceHelper.CreationTags); | ||
startTags); |
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.
Interesting that StartActivity
doesn't have an overload which accepts TagList
. We should ask @tarekgh for one 🤣
In the meantime, maybe don't use TagList
at all. Because this will box it up.
A ThreadStatic
is probably fine we did that here:
Lines 30 to 31 in 0351a0b
[ThreadStatic] | |
private static KeyValuePair<string, object?>[]? cachedTagsStorage; |
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.
Yea, I was bummed there was no StartActivity
with TagList
as well 😢.
A ThreadStatic is probably fine we did that here
I had a similar thought to use ThreadStatic. Ultimately, these tags will need to be shared by the metric instrumentation as well. A ThreadStatic would allow us to capture them on command start and then use them on command end when recording the metric. I'll try this in a follow up.
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.
Interesting that StartActivity doesn't have an overload which accepts TagList. We should ask @tarekgh for one 🤣
You may update dotnet/runtime#103245 (comment) with whatever request. the runtime issue was talking about CreateActivity but can include StartActivity too.
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.
Some feedback but LGTM
Fixes #2236
Towards #2224
Towards #2237
Per the MSSQL conventions:
In addition to including the instance name in the
db.namespace
attribute, this PR begins to address conforming the activity name to the conventions and starting the activity with required tags.db.namespace
andserver.address
/server.port
in the activity name when appropriate.db.system
db.namespace
server.address
server.port