DataDog / dd-trace-dotnet

.NET Client Library for Datadog APM
https://docs.datadoghq.com/tracing/
Apache License 2.0
443 stars 138 forks source link

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

Closed jacob-m-nielsen closed 3 years ago

jacob-m-nielsen commented 3 years ago

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

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

kevingosse commented 3 years ago

Hello,

I've tried running your code but it works fine for me, with and without transaction: https://gist.github.com/kevingosse/7cdfbdf242cfd776225448f11b68eb10

What version of Microsoft.Data.SqlClient are you using? Please keep in mind that we don't support 3.0.0 yet.

jacob-m-nielsen commented 3 years ago

We are indeed using v3.0.0, so that clarifies the problem. Do you have an idea on when 3.0.0 will be supported?

kevingosse commented 3 years ago

I'll try to squeeze that in the next release or the one after, so expect it in the coming weeks.

kevingosse commented 3 years ago

Version 1.28.0 has been released, and includes support of Microsoft.Data.SqlClient 3.*.