Skip to content

Commit

Permalink
[Instrumentation.MysqlData] Compatibility with Mysql.Data 8.0.31. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
moonheart authored Oct 14, 2022
1 parent 427758d commit 841e6e5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Instrumentation.MySqlData/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

* Update OTel API version to `1.3.1`.
([#631](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/631))
* Compatibility with `Mysql.Data` 8.0.31 or later, Users must set `Logging=true`
in their connection string manually.
([#692](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/692))

## 1.0.0-beta.3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Reflection;
using MySql.Data.MySqlClient;
using OpenTelemetry.Trace;

Expand All @@ -37,7 +38,13 @@ public MySqlDataInstrumentation(MySqlDataInstrumentationOptions options = null)
MySqlTrace.Listeners.Clear();
MySqlTrace.Listeners.Add(this);
MySqlTrace.Switch.Level = SourceLevels.Information;
MySqlTrace.QueryAnalysisEnabled = true;

// Mysql.Data removed `MySql.Data.MySqlClient.MySqlTrace.QueryAnalysisEnabled` since 8.0.31 so we need to set this using reflection.
var queryAnalysisEnabled = typeof(MySqlTrace).GetProperty("QueryAnalysisEnabled", BindingFlags.Public | BindingFlags.Static);
if (queryAnalysisEnabled != null)
{
queryAnalysisEnabled.SetValue(null, true);
}
}

/// <inheritdoc />
Expand Down
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Instrumentation.MySqlData/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ the `ConfigureServices` of your `Startup` class. Refer to documentation for
For an ASP.NET application, adding instrumentation is typically done in the
`Global.asax.cs`. Refer to documentation for [OpenTelemetry.Instrumentation.AspNet](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Instrumentation.AspNet/README.md).

Note, If you are using `Mysql.Data` 8.0.31 or later, please add
option `Logging=true` in your connection string to enable tracing.
See issue #691 for details.

## Advanced configuration

This instrumentation can be configured to change the default behavior by using
Expand Down

0 comments on commit 841e6e5

Please sign in to comment.