Skip to content

Instrumentation not working for Microsoft.Data.SqlClient.SqlCommand inside a transaction #1552

@jacob-m-nielsen

Description

@jacob-m-nielsen

Describe the bug
According to https://github.com/DataDog/dd-trace-dotnet/releases/tag/v1.21.0 support was added for automatic instrumentation of Microsoft.Data.SqlClient.SqlCommand.

This works as expected as long as the SqlCommand is not inside a Microsoft.Data.SqlClient.SqlTransaction. Any SqlCommand's in a SqlTransaction do not have traces.

To Reproduce
Steps to reproduce the behavior:

  1. Create a .NET 5 Console App
  2. Add the Microsoft.Data.SqlClient and Datadog.Trace NuGet packages
  3. Manuall start a trace and execute a query against SQL Server e.g.:
using (var traceScope = Tracer.Instance.StartActive("some.operation"))
{
	await using var connection = new SqlConnection(_configuration.Value.SqlServerConnectionString);
	connection.Open();
	await using SqlTransaction transaction = connection.BeginTransaction();

	await using var command = new SqlCommand(@"..", connection, transaction);

	await using (SqlDataReader reader = await command.ExecuteReaderAsync())
	{
		if (reader.Read())
		{

		}
	}

	transaction.Commit();
}

Expected behavior
The query is expected to be visible in the corresponding APM trace

Runtime environment (please complete the following information):

  • Instrumentation mode: manual
  • Tracer version: 1.27.1
  • OS: ASP.NET docker image on GCP (mcr.microsoft.com/dotnet/aspnet:5.0)
  • CLR: .NET 5

Additional context
Oskar Rittsél asked me to create this ticket.

Metadata

Metadata

Assignees

Labels

area:automatic-instrumentationAutomatic instrumentation managed C# code (Datadog.Trace.ClrProfiler.Managed)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions