# No SQL tracing for .net 5

**URL:** <https://discuss.elastic.co/t/no-sql-tracing-for-net-5/279609>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [July 26, 2021, 10:00am UTC](https://discuss.elastic.co/t/no-sql-tracing-for-net-5/279609 "2021-07-26T10:00:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Danny\_Stommen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danny_stommen/32/77845_2.png) [@Danny\_Stommen](https://discuss.elastic.co/u/Danny_Stommen)\
**Post date:** [July 26, 2021, 10:00am UTC](https://discuss.elastic.co/t/no-sql-tracing-for-net-5/279609/1 "2021-07-26T10:00:30Z")

</div>

Hi,

Basically I'm experiecing the same issue as described here:

> <https://github.com/elastic/apm-agent-dotnet/issues/1025>
>
> Initially I created this as a question here: https://discuss.elastic.co/t/no-sql…-tracing-when-using-dapper-in-net-5/255032
> 
> But I realized it should probably go as an issue here on github. 
> 
> APM Agent language and version:
> C# 1.6.1
> 
> \<PackageReference Include="Elastic.Apm.AspNetCore" Version="1.6.1" /\>
> \<PackageReference Include="Elastic.Apm.NetCoreAll" Version="1.6.1" /\>
> \<PackageReference Include="Elastic.Apm.SqlClient" Version="1.6.1" /\>
> Original install method (e.g. download page, yum, deb, from source, etc.) and version:
> Nuget
> 
> Hi!
> 
> We have a Web API which uses Dapper for data access. However we get no tracing for the SQL call. We are running .Net 5.0
> 
> In the Configure method in Startup.cs
> 
> app.UseElasticApm(Configuration, new SqlClientDiagnosticSubscriber(), new HttpDiagnosticsSubscriber());
> The code which calls the database looks like this
> 
> using IDbConnection db = new SqlConnection(\_configuration.InsuranceConnection());
> 
> const string getAllaArbetsgivareIdnProcName = "\[dbo\].\[Stored\_Procedure\]";
> 
> var allaArbetsgivareId = await db.QueryAsync\<Guid\>(getAllaArbetsgivareIdnProcName, null, commandType: CommandType.StoredProcedure);
> And it's using
> 
> using Microsoft.Data.SqlClient;
> Logs from the application
> https://pastebin.ubuntu.com/p/wxWzQpRwWb/
> 
> Ubuntu Pastebin
> How it looks in Kibana
> 
> !\[image\](https://user-images.githubusercontent.com/61051475/98806582-aff84d80-2419-11eb-9f39-a72d0e8967be.png)
> 
> We have antoher Web API running .net core 3.1 where it seems to be working.

Which should be fixed here:

> <https://github.com/elastic/apm-agent-dotnet/pull/1042>
>
> This commit adds SqlClientDiagnosticListener
> for .NET 5.0, when .NET 5.0 is the… detected
> platform. This follows the same branch as
> .NET Core.
> 
> Fixes elastic/apm-agent-dotnet#1025

However, I still don't have any traces for any SQL transaction.

Our API is running .NET 5 (inside kubernetes).  
Elastic.Apm.NetCoreAll is version 1.10.0

Setup code in `Startup.cs`

```auto
        Environment.SetEnvironmentVariable("ELASTIC_APM_ENVIRONMENT", Configuration.Instance.Environment);
        Environment.SetEnvironmentVariable("ELASTIC_APM_SERVICE_NAME", "authentication-api");
        Environment.SetEnvironmentVariable("ELASTIC_APM_SECRET_TOKEN", "XXXX");
        Environment.SetEnvironmentVariable("ELASTIC_APM_SERVER_URL", "some-url");
        app.UseAllElasticApm();

```

Am I missing something, or is this still a bug?

Thanks,  
Danny

---

<div class="post-metadata">

**Author:** ![GregKalapos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregkalapos/32/37205_2.png) [@GregKalapos](https://discuss.elastic.co/u/GregKalapos)\
**Post date:** [July 26, 2021, 10:49am UTC](https://discuss.elastic.co/t/no-sql-tracing-for-net-5/279609/2 "2021-07-26T10:49:15Z")

</div>

Hi @Danny_Stommen,

the bug should be fixed and included in version `1.10.0` (which is the one you use). We [have tests covering](https://github.com/elastic/apm-agent-dotnet/blob/master/test/Elastic.Apm.SqlClient.Tests/Elastic.Apm.SqlClient.Tests.csproj#L7) .NET 5, so I think the original issue you linked is fixed.

To better troubleshoot this, maybe a few questions:

- The problem is that you don't see spans for the SQL queries, right? So there is no sign of the SQL call in the trace? Or are there SQL spans, but some info is missing?
- How are your SQL queries generated? You use things like `SqlCommand` directly (like [here](https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlcommand?view=dotnet-plat-ext-5.0)), or is it Entity Framework (Core), or some other thing? What I want to get to with this question is that maybe you use something that we currently don't support. [Here](https://www.elastic.co/guide/en/apm/agent/dotnet/current/supported-technologies.html#supported-data-access-technologies) is a list of DB libraries the agent monitors.

---

<div class="post-metadata">

**Author:** ![Danny\_Stommen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danny_stommen/32/77845_2.png) [@Danny\_Stommen](https://discuss.elastic.co/u/Danny_Stommen)\
**Post date:** [July 27, 2021, 6:13am UTC](https://discuss.elastic.co/t/no-sql-tracing-for-net-5/279609/3 "2021-07-27T06:13:04Z")

</div>

Hi Greg,

_The problem is that you don't see spans for the SQL queries, right?_  
Exactly! So basically we have gaps in our tracing timelines.

_The problem is that you don't see spans for the SQL queries, right?_  
We're using [Dapper.net](http://Dapper.net). For example:

```auto
      using var connection = await _MySqlConnectionFactory.CreateConnectionAsync();
      string statement = "SELECT * FROM some-table";
      
      var result = await connection.QueryAsync<SomeModel>(statement);

```

I believe Dapper is using DbCommand under the hood.

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [July 27, 2021, 6:24am UTC](https://discuss.elastic.co/t/no-sql-tracing-for-net-5/279609/4 "2021-07-27T06:24:34Z")

</div>

> [@Danny\_Stommen](#):
>
> `_MySqlConnectionFactory`

Are you using a MySQL [ADO.NET](http://ADO.NET) provider?

---

<div class="post-metadata">

**Author:** ![Danny\_Stommen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danny_stommen/32/77845_2.png) [@Danny\_Stommen](https://discuss.elastic.co/u/Danny_Stommen)\
**Post date:** [July 28, 2021, 2:03pm UTC](https://discuss.elastic.co/t/no-sql-tracing-for-net-5/279609/5 "2021-07-28T14:03:26Z")

</div>

Implementation of the CreateConnectionAsync is this one:

```auto
public async Task<IDbConnection> CreateConnectionAsync() {
  var connection = new MySql.Data.MySqlClient.MySqlConnection(GetConnectionString());
  await connection.OpenAsync();

  return connection;
}

```

Where `MySql.Data.MySqlClient.MySqlConnection` comes from the MySql.Data nuget package

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [July 29, 2021, 8:27am UTC](https://discuss.elastic.co/t/no-sql-tracing-for-net-5/279609/6 "2021-07-29T08:27:27Z")

</div>

Thanks for the confirmation. Currently, there's no auto instrumentation for MySQL with the .NET agent; There's an open issue to track it:

> <https://github.com/elastic/apm-agent-dotnet/issues/1231>
>
> \*\*Is your feature request related to a problem? Please describe.\*\*
> I would like… to be able to have instrumentation of database queries using Dapper and MySQL, currently the only db client supported is MS SqlClient unless you are using EF or EFCore.
> 
> \*\*Describe the solution you'd like\*\*
> I would like a package similar to ElasticApm.SqlClient for MySQL.Data DB client.
> 
> \*\*Describe alternatives you've considered\*\*
> I've considered trying to build this mysql.
> 
> \*\*Additional context\*\*
> Appreciate all of the work that goes into APM, it already supports most of our stack with the exception of the DB layer.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 19, 2021, 4:27am UTC](https://discuss.elastic.co/t/no-sql-tracing-for-net-5/279609/7 "2021-08-19T04:27:41Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
