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

No SQL dependency calls logged with Microsoft.Data.SqlClient 3.0.0 #2346

Closed
kiwiant opened this issue Jul 28, 2021 · 8 comments
Closed

No SQL dependency calls logged with Microsoft.Data.SqlClient 3.0.0 #2346

kiwiant opened this issue Jul 28, 2021 · 8 comments
Labels

Comments

@kiwiant
Copy link

kiwiant commented Jul 28, 2021

net48
Microsoft.Data.SqlClient 3.0.0
Microsoft.ApplicationInsights.* 2.17.0

Zero SQL dependency calls are logged when Microsoft.Data.SqlClient 3.0.0 is used. Roll back to 2.1.3 all good. Upgrade to Microsoft.Data.SqlClient 3.0.0 and no SQL dependencies logged. Everything else is the same (config, code, packages).

.NET Core is unaffected.

Sounds like a new version of issue #2032.


WebApplication1.zip

@kiwiant kiwiant added the bug label Jul 28, 2021
@cijothomas
Copy link
Contributor

@TimothyMothra Could you take a look at the repro? Ms.Data.Sql 3.0.0 is a major version bump, so technically it may have some breaking changes affecting us.

@mbakalov
Copy link
Member

Hey all!

I took a look at this and issue is likely due to PR #897 in SqlClient. They've changed the event source quite significantly.

Instead of writing event like this:

[Event(BeginExecuteEventId, Keywords = Keywords.ExecutionTrace, Task = Tasks.ExecuteCommand, Opcode = EventOpcode.Start)]
internal void BeginExecute(int objectId, string dataSource, string database, string commandText)
{
	if (Log.IsExecutionTraceEnabled())
	{
		WriteEvent(BeginExecuteEventId, objectId, dataSource, database, commandText);
	}
}

It is now doing this instead:

internal void TryBeginExecuteEvent(int objectId, Guid? connectionId, string commandText, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "")
{
	if (Log.IsExecutionTraceEnabled())
	{
		BeginExecute(GetFormattedMessage(SqlCommand_ClassName, memberName, EventType.INFO,
			string.Format("Object Id {0}, Client Connection Id {1}, Command Text {2}", objectId, connectionId, commandText)));
	}
}

// ...

[Event(BeginExecuteEventId, Keywords = Keywords.ExecutionTrace, Task = Tasks.ExecuteCommand, Opcode = EventOpcode.Start)]
internal void BeginExecute(string message) =>
	WriteEvent(BeginExecuteEventId, message);

So we just get a text message now instead of DataSource/Database/CommandText. Not sure about the best way to deal with this, probably we should see if the SqlClient team could change it back to more structured logging - not even getting server/db values is unfortunate!

@kiwiant
Copy link
Author

kiwiant commented Aug 18, 2021

Interesting as it works when used in .NET Core solution.

@mbakalov I see you have referenced this issue in PR #897. Thanks.

@mbakalov
Copy link
Member

@pmgallo
Copy link

pmgallo commented Nov 12, 2021

This is still happening with version Microsoft.Data.SqlClient 3.0.1 and .net fw 4.8.1. Is there any workaround to fix this?

Thanks

@mbakalov
Copy link
Member

@pmgallo - it got fixed for the upcoming 4.0.0 version and should be available in the preview releases (https://github.com/dotnet/SqlClient/releases) at least.

Thanks!

@pmgallo
Copy link

pmgallo commented Nov 15, 2021

@pmgallo - it got fixed for the upcoming 4.0.0 version and should be available in the preview releases (https://github.com/dotnet/SqlClient/releases) at least.

Thanks!

Hi @mbakalov,

Thanks for your response. I tried the version 4.0.0-preview3.21293.2 and it works as expected. It'll do for now

Thanks again!

Regards

@TimothyMothra
Copy link
Member

closing this as it has been fixed in SqlClient v4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants