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

SqlClient instrumentation doesn't work on netfx using Microsoft.Data.SqlClient 3.0.0 #1737

Closed
mbakalov opened this issue Aug 18, 2021 · 4 comments
Labels
bug Something isn't working comp:instrumentation.sqlclient Things related to OpenTelemetry.Instrumentation.SqlClient

Comments

@mbakalov
Copy link

mbakalov commented Aug 18, 2021

New major release of SqlClient has changed their EventSource from 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);
	}
}

To this (PR open-telemetry/opentelemetry-dotnet#897):

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);

Our SqlEventSourceListener expects 4 items in the payload (ObjectId, DataSource, Database, CommandText) but now gets only "Message" and doesn't log anything.

It looks like we're unable to get the server/db anymore on netfx which is unfortunate. Opening this issue here to track resolution, but probably best to ask SqlClient team to make some changes in their EventSource if they can.

@mbakalov mbakalov added the bug Something isn't working label Aug 18, 2021
@mbakalov
Copy link
Author

cc @cijothomas

@Wraith2
Copy link
Contributor

Wraith2 commented Sep 10, 2021

What limitations are there on changes to the events that are emitted?

For example do you actually check that there are exactly 4 items or could we add more after the ones you're expecting? The ConnectionID that was added is very useful for debug tracing complex async issues and it would be good to be able to keep it without breaking upstream consumers. If we moved it to the end would it be out of your way or would it still break things?

@mbakalov
Copy link
Author

@Wraith2, just checked and both OpenTelemetry and AppInsights expect simply >=4 items (see linked code). As long as the first 4 are what we expect, it should be safe to add any additional things you need to the end!

@reyang reyang transferred this issue from open-telemetry/opentelemetry-dotnet May 13, 2024
@reyang reyang added the comp:instrumentation.sqlclient Things related to OpenTelemetry.Instrumentation.SqlClient label May 13, 2024
@Kielek
Copy link
Contributor

Kielek commented May 14, 2024

@Kielek Kielek closed this as not planned Won't fix, can't repro, duplicate, stale May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working comp:instrumentation.sqlclient Things related to OpenTelemetry.Instrumentation.SqlClient
Projects
None yet
Development

No branches or pull requests

4 participants