Bug #111126 Add support for .NET distributed tracing
Submitted: 24 May 6:07 Modified: 24 May 7:10
Reporter: heart moon Email Updates:
Status: Verified Impact on me:
Category:Connector / NET Severity:S4 (Feature request)
Version:8.0.33 OS:Any
Assigned to: CPU Architecture:Any

[24 May 6:07] heart moon
Distributed tracing is a diagnostic technique that helps engineers localize failures and performance issues within applications, especially those that may be distributed across multiple machines or processes. This technique tracks requests through an application correlating together work done by different application components and separating it from other work the application may be doing for concurrent requests. For example, a request to a typical web service might be first received by a load balancer, then forwarded to a web server process, which then makes several queries to a database. Using distributed tracing allows engineers to distinguish if any of those steps failed, how long each step took, and potentially logging messages produced by each step as it ran.

Connector/NET uses TraceSource to trace MySQL events, which lacks support for distributed tracing.

Currently the OpenTelemetry community is using TraceSource to instrument. But in version 8.0.33 it includes a commit https://github.com/mysql/mysql-connector-net/commit/291c2f31fa9d7bf1b3c02bd7da19db1b66f89a... that uses async all the way, which breaks the support for OpenTelemetry instrumentation (see github issue https://github.com/open-telemetry/opentelemetry-dotnet-contrib/issues/1157).

Could you please consider adding native support for distributed tracing?

How to repeat:
Create a Console project and add package OpenTelemetry.Instrumentation.MySqlData.
Add option Logging=true to connection string to enable tracing events.

using OpenTelemetry.Trace;

public class Program
    public static void Main(string[] args)
        using var tracerProvider = Sdk.CreateTracerProviderBuilder()

Suggested fix:
Possible fix 1:
in https://github.com/mysql/mysql-connector-net/blob/8.0/MySQL.Data/src/TracingDriver.cs

Create Activity in SendQueryAsync method, so application can subscribe to this to instrument.

Possible fix 2:
in https://github.com/mysql/mysql-connector-net/blob/8.0/MySQL.Data/src/TracingDriver.cs

Generate a Guid for each query in SendQueryAsync and pass it to MySqlTrace.TraceEvent, this allows developers to corelate different trace events into a complete operation.
[24 May 7:10] MySQL Verification Team

Thank you for the feature request!