Documentation Home
Connectors and APIs Manual
Download this Manual
PDF (US Ltr) - 4.1Mb
PDF (A4) - 4.1Mb


4.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 8.1.0 MySQL.Data.OpenTelemetry and MySQL.Data NuGet packages.

    Note

    The Connector/NET MSI file does not include support 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.