-
Notifications
You must be signed in to change notification settings - Fork 784
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 instrumentation to support Microsoft.Data.SqlClient EventSource #1599
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1599 +/- ##
=======================================
Coverage 80.56% 80.56%
=======================================
Files 242 243 +1
Lines 6582 6582
=======================================
Hits 5303 5303
Misses 1279 1279
|
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.
LGTM. Please add an entry in chagelog.md.
We need to update tests to use mds as well rigth?
@cijothomas - thanks, yes, working on that still, will push later today. The semantics of the new EventSource are different a bit too (it now captures CommandText always, not just for SPs) so I want to make sure that is supported properly as well. |
Actually, annoyingly that behavior is different enough that it is going to result in confusing API.
private void WriteBeginExecuteEvent()
{
if (SqlEventSource.Log.IsEnabled() && Connection != null)
{
string commandText = CommandType == CommandType.StoredProcedure ? CommandText : string.Empty;
SqlEventSource.Log.BeginExecute(GetHashCode(), Connection.DataSource, Connection.Database, commandText);
}
} While MDS does this: private void WriteBeginExecuteEvent()
{
if (Connection != null)
{
SqlClientEventSource.Log.BeginExecute(GetHashCode(), Connection.DataSource, Connection.Database, CommandText);
}
} So MDS always reports This becomes confusing because the "options" has two separate settings for those: To clean this up, I am suggesting the following in the // .NET Framework implementation uses SqlEventSource from which we can't reliably distinguish
// StoredProcedures from regular Text sql commands.
#if NETFRAMEWORK
/// <summary>
/// Gets or sets a value indicating whether or not the <see cref="SqlClientInstrumentation"/> should
/// add the text of the executed Sql commands as the <see cref="SemanticConventions.AttributeDbStatement"/> tag.
/// Default value: False.
/// </summary>
public bool SetStatementText { get; set; }
#else
/// <summary>
/// Gets or sets a value indicating whether or not the <see cref="SqlClientInstrumentation"/> should add the names of <see cref="CommandType.StoredProcedure"/> commands as the <see cref="SemanticConventions.AttributeDbStatement"/> tag. Default value: True.
/// </summary>
public bool SetStoredProcedureCommandName { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not the <see cref="SqlClientInstrumentation"/> should add the text of <see cref="CommandType.Text"/> commands as the <see cref="SemanticConventions.AttributeDbStatement"/> tag. Default value: False.
/// </summary>
public bool SetTextCommandContent { get; set; }
#endif |
Alternatively, the instrumentation can set |
Can we instead use separate listeners for MDS and SDS? Then listener know exactly if its getting sp or sqltext. |
src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlEventSourceListener.netfx.cs
Outdated
Show resolved
Hide resolved
Yeah that is the issue I think. Even if MDS was a separate listener, it just gets a |
@mbakalov Bummer about the change to command text by MS! I like your idea to change the options. |
Separate SqlClientInstrumentationOptions for netcore and netfx. Upgrade MDS nuget to the newer version that actually uses the new EventSource name. Don't reference the diagnostic listener from the sql even source code.
Introduced a separate It turned out that the reason net461 tests were failing was only somewhat related to the renaming of the EventSource. The test project was referencing MDS nuget version 1.1.1, which actually still uses the old EventSource name :), so the tests should have worked. And they mostly did, but were flaky for a reason similar to what was being discussed in elastic/apm-agent-dotnet#704 (comment). When running both I upgraded the MDS nuget to the latest version (2.1.0) and now with the support of the new EventSource all tests pass. I did a CHANGELOG.md update and a few minor comment clarifications and fixes. Still need to add a few more new tests and update README. |
Highlights of changes:
|
src/OpenTelemetry.Instrumentation.SqlClient/SqlClientInstrumentationOptions.cs
Outdated
Show resolved
Hide resolved
@mbakalov Thanks a lot! ALso, open to any other suggestion for the names for these: .NET core |
Thanks @cijothomas, I wasn't sure about the default, will update to false! |
As for the property names, maybe:
|
Changed the default to |
For namings, alternate proposal: netfx "Sets DBStatement semantic convention" can be the general comment for all, as its coming directly from spec. Then specifically clarify |
public const string ActivitySourceName = "OpenTelemetry.SqlClient"; | ||
public const string ActivityName = ActivitySourceName + ".Execute"; | ||
|
||
public const string MicrosoftSqlServerDatabaseSystemName = "mssql"; |
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.
nit: Might be better to move this definition to semantic conventions, that's where it came from (https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/database.md#connection-level-attributes).
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.
Thanks, I'll update this! Other things ("db.statement") are being pulled from semantic conventions so better to be consistent.
...lemetry.Instrumentation.SqlClient.Tests/OpenTelemetry.Instrumentation.SqlClient.Tests.csproj
Show resolved
Hide resolved
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 of comments, but LGTM.
Good to merge as has enough approvals, and no blocking comments. We just need to see if any better names are possible for the options. |
Fixes #1597.
Changes
SqlClientInstrumentationOptions
now has different public API on .NET Core and .NET FrameworkSqlClientDiagnosticListener
.NET Core-only (it was referencing the options properties no longer available on .NET Framework)SqlActivitySourceHelper
SetStatementText
is false by defaultBackground
Recently,
Microsoft.Data.SqlClient
renamed their EventSource from "Microsoft-AdoNet-SystemData" to "Microsoft.Data.SqlClient.EventSource". TheSystem.Data.SqlClient
still uses the old event source, so the instrumentation needs to listen to both event sources.TODO:
CHANGELOG.md
updated for non-trivial changes* [ ] Changes in public API reviewed - shouldn't be any public API changesSetStatementText