Documentation Home
MySQL Connector/NET Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 1.3Mb
PDF (A4) - 1.3Mb


MySQL Connector/NET Developer Guide  /  ...  /  Enabling OpenTelemetry Tracing

5.12.1 Enabling OpenTelemetry Tracing

OpenTelementry (OTel) standardizes instrumentation, generation, collecting and exporting telemetry data to be consumed by an Observability backend. For more details on OpenTelemetry, visit its official site.

Starting in Connector/NET 8.1.0, support for OTel is encapsulated in the MySQL.Data.OpenTelemetry NuGet package. This package implements the functionality to add the connector to the tracer provider using OpenTelementry.Api. Connector/NET neither creates nor provides the means to create an OTel exporter. Instead, it relies on the default exporter supplied by your application.

Note

OTel context forwarding works only with MySQL Enterprise Edition, a commercial product. To learn more about commercial products, see https://www.mysql.com/products/.

Requirements for Enabling Tracing

  • .NET 5 and later.

  • Connector/NET MySQL.Data.OpenTelemetry and MySQL.Data NuGet packages.

    Note

    The Connector/NET MSI file does not include support for this OTel implementation.

  • An OpenTelemetry SDK of your choosing and an appropriate exporter package.

  • MySQL Enterprise Edition server with the query attributes enabled. If the server does not support query attributes or has them disabled, then Connector/NET skips the entire context propagation flow.

  • Code that uses OTel instrumentation. If your code does not use instrumentation, then the connector does not forward the current OTel context for each executed statement.

Enabling OpenTelemetry

To enable OTel tracing using the Connector/NET implementation, add the connector to the trace provider builder as follows:

var tracerProvider = sdk.TraceProviderBuilder().AddConnectorNet().Build();

When you build code that links to Connector/NET and uses OTel instrumentation, the additional spans generated by the connector appear in the traces generated by your code. Spans generated by the connector are sent to the same destination (trace exporter) where other spans generated by the user code are sent as configured by user code. It is not possible to send spans generated by the connector to any other destination.