Skip to content

Commit

Permalink
MySqlConnector - traces instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek committed Jun 21, 2023
1 parent 54804fe commit 905e413
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 19 deletions.
29 changes: 14 additions & 15 deletions .cspell/other.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
appcmd
AWSSDK
bitness
bytecode
Expand All @@ -9,15 +10,25 @@ distro
Dockerfiles
ducktype
dylib
ENTITYFRAMEWORKCORE
envvars
GRPCNETCLIENT
HKLM
HTTPCLIENT
ILOGGER
inetsrv
LINQ
MASSTRANSIT
metricsexporter
mkdir
mktemp
MSMQ
myapp
MYSQLCONNECTOR
MYSQLDATA
NETRUNTIME
Npgsql
NSERVICEBUS
omnisharp
OPENTRACING
OTEL_DOTNET_AUTO_FLUSH_ON_UNHANDLEDEXCEPTION
Expand All @@ -28,25 +39,13 @@ protobuf
protos
Serilog
spdlog
SQLCLIENT
sqlserver
STACKEXCHANGEREDIS
TMPDIR
tracesexporter
unencrypted
UNENCRYPTEDSUPPORT
vcpkg
ILOGGER
NSERVICEBUS
NETRUNTIME
HTTPCLIENT
STACKEXCHANGEREDIS
SQLCLIENT
NSERVICEBUS
MYSQLDATA
MASSTRANSIT
HTTPCLIENT
GRPCNETCLIENT
ENTITYFRAMEWORKCORE
appcmd
inetsrv
WCFCLIENT
WCFSERVICE
WCFSERVICE
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This release is built on top of [OpenTelemetry .NET](https://github.com/open-tel
- The environment variable `OTEL_DOTNET_AUTO_FAIL_FAST_ENABLED` could be
used to enable or disable the failing process when
automatic instrumentation cannot be executed.
- Add support for MySqlConnector traces instrumentation.

### Changed

Expand Down
15 changes: 15 additions & 0 deletions OpenTelemetry.AutoInstrumentation.sln
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.AutoInstrumen
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SourceGenerators", "src\SourceGenerators\SourceGenerators.csproj", "{28FCC3BC-A609-4400-9831-03741A24A89C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApplication.MySqlConnector", "test\test-applications\integrations\TestApplication.MySqlConnector\TestApplication.MySqlConnector.csproj", "{C46AF7DB-AD9A-48BD-ABE7-BD9B3A6ED7A4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -907,6 +909,18 @@ Global
{28FCC3BC-A609-4400-9831-03741A24A89C}.Release|x64.Build.0 = Release|Any CPU
{28FCC3BC-A609-4400-9831-03741A24A89C}.Release|x86.ActiveCfg = Release|Any CPU
{28FCC3BC-A609-4400-9831-03741A24A89C}.Release|x86.Build.0 = Release|Any CPU
{C46AF7DB-AD9A-48BD-ABE7-BD9B3A6ED7A4}.Debug|Any CPU.ActiveCfg = Debug|x64
{C46AF7DB-AD9A-48BD-ABE7-BD9B3A6ED7A4}.Debug|Any CPU.Build.0 = Debug|x64
{C46AF7DB-AD9A-48BD-ABE7-BD9B3A6ED7A4}.Debug|x64.ActiveCfg = Debug|x64
{C46AF7DB-AD9A-48BD-ABE7-BD9B3A6ED7A4}.Debug|x64.Build.0 = Debug|x64
{C46AF7DB-AD9A-48BD-ABE7-BD9B3A6ED7A4}.Debug|x86.ActiveCfg = Debug|x86
{C46AF7DB-AD9A-48BD-ABE7-BD9B3A6ED7A4}.Debug|x86.Build.0 = Debug|x86
{C46AF7DB-AD9A-48BD-ABE7-BD9B3A6ED7A4}.Release|Any CPU.ActiveCfg = Release|x64
{C46AF7DB-AD9A-48BD-ABE7-BD9B3A6ED7A4}.Release|Any CPU.Build.0 = Release|x64
{C46AF7DB-AD9A-48BD-ABE7-BD9B3A6ED7A4}.Release|x64.ActiveCfg = Release|x64
{C46AF7DB-AD9A-48BD-ABE7-BD9B3A6ED7A4}.Release|x64.Build.0 = Release|x64
{C46AF7DB-AD9A-48BD-ABE7-BD9B3A6ED7A4}.Release|x86.ActiveCfg = Release|x86
{C46AF7DB-AD9A-48BD-ABE7-BD9B3A6ED7A4}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -976,6 +990,7 @@ Global
{65619BD1-4517-400C-8071-C1409A7D255E} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
{11BD3D9A-D413-4D8C-A815-7D4ABB38A0BA} = {5C915382-C886-457D-8641-9E766D8E5A17}
{28FCC3BC-A609-4400-9831-03741A24A89C} = {9E5F0022-0A50-40BF-AC6A-C3078585ECAB}
{C46AF7DB-AD9A-48BD-ABE7-BD9B3A6ED7A4} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {160A1D00-1F5B-40F8-A155-621B4459D78F}
Expand Down
8 changes: 8 additions & 0 deletions build/LibraryVersions.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ public static class LibraryVersion
"2.19.2",
}
},
{
"TestApplication.MySqlConnector",
new List<string>
{
"2.0.0",
"2.2.6",
}
},
{
"TestApplication.MySqlData",
new List<string>
Expand Down
1 change: 1 addition & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ due to lack of stable semantic convention.
| `QUARTZ` | [Quartz](https://www.nuget.org/packages/Quartz) **Not supported on .NET Framework 4.7.1 and older** | ≥3.4.0 | source | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `MASSTRANSIT` | [MassTransit](https://www.nuget.org/packages/MassTransit) **Not supported on .NET Framework** | ≥8.0.0 | source | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `MONGODB` | [MongoDB.Driver.Core](https://www.nuget.org/packages/MongoDB.Driver.Core) | ≥2.13.3 & < 3.0.0 | source & bytecode | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `MYSQLCONNECTOR` | [MySqlConnector](https://www.nuget.org/packages/MySqlConnector) | ≥2.0.0 | source | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `MYSQLDATA` | [MySql.Data](https://www.nuget.org/packages/MySql.Data) **Not supported on .NET Framework** | ≥6.10.7 | source & bytecode \[2\] | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `NPGSQL` | [Npgsql](https://www.nuget.org/packages/Npgsql) | ≥6.0.0 | source | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `NSERVICEBUS` | [NServiceBus](https://www.nuget.org/packages/NServiceBus) | ≥8.0.0 | source & bytecode | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

using System.Runtime.CompilerServices;
using OpenTelemetry.AutoInstrumentation.Loading;
using OpenTelemetry.AutoInstrumentation.Loading.Initializers;
using OpenTelemetry.AutoInstrumentation.Plugins;
using OpenTelemetry.Trace;

Expand Down Expand Up @@ -46,6 +45,7 @@ public static TracerProviderBuilder UseEnvironmentVariables(
TracerInstrumentation.Elasticsearch => builder.AddSource("Elastic.Clients.Elasticsearch.ElasticsearchClient"),
TracerInstrumentation.Quartz => Wrappers.AddQuartzInstrumentation(builder, pluginManager, lazyInstrumentationLoader),
TracerInstrumentation.MongoDB => builder.AddSource("MongoDB.Driver.Core.Extensions.DiagnosticSources"),
TracerInstrumentation.MySqlConnector => builder.AddSource("MySqlConnector"),
#if NET6_0_OR_GREATER
TracerInstrumentation.AspNetCore => Wrappers.AddAspNetCoreInstrumentation(builder, pluginManager, lazyInstrumentationLoader),
TracerInstrumentation.MassTransit => builder.AddSource("MassTransit"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ internal enum TracerInstrumentation
/// <summary>
/// WcfClient instrumentation.
/// </summary>
WcfClient = 16
WcfClient = 16,
#endif

/// <summary>
/// MySqlConnector instrumentation.
/// </summary>
MySqlConnector = 17
}
2 changes: 2 additions & 0 deletions src/OpenTelemetry.AutoInstrumentation/Instrumentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ private static void AddLazilyLoadedTraceInstrumentations(LazyInstrumentationLoad
break;
case TracerInstrumentation.Elasticsearch:
break;
case TracerInstrumentation.MySqlConnector:
break;
default:
Logger.Warning($"Configured trace instrumentation type is not supported: {instrumentation}");
if (FailFastSettings.Value.FailFast)
Expand Down
1 change: 1 addition & 0 deletions test/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
<PackageVersion Include="MongoDB.Driver" Version="2.19.2" />
<PackageVersion Include="Moq" Version="4.18.4" />
<PackageVersion Include="MySqlConnector" Version="2.2.6" />
<PackageVersion Include="MySql.Data" Version="8.0.32.1" />
<PackageVersion Include="NServiceBus" Version="8.1.1" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
Expand Down
9 changes: 9 additions & 0 deletions test/IntegrationTests/LibraryVersions.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ public static class LibraryVersion
new object[] { "2.13.3" },
new object[] { "2.15.0" },
new object[] { "2.19.2" },
#endif
};
public static readonly IReadOnlyCollection<object[]> MySqlConnector = new List<object[]>
{
#if DEFAULT_TEST_PACKAGE_VERSIONS
new object[] { string.Empty }
#else
new object[] { "2.0.0" },
new object[] { "2.2.6" },
#endif
};
public static readonly IReadOnlyCollection<object[]> MySqlData = new List<object[]>
Expand Down
2 changes: 0 additions & 2 deletions test/IntegrationTests/MySqlCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// limitations under the License.
// </copyright>

#if NET6_0_OR_GREATER
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Containers;
using IntegrationTests.Helpers;
Expand Down Expand Up @@ -75,4 +74,3 @@ private static async Task ShutdownMySqlContainerAsync(IContainer container)
await container.DisposeAsync();
}
}
#endif
51 changes: 51 additions & 0 deletions test/IntegrationTests/MySqlConnectorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// <copyright file="MySqlConnectorTests.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using IntegrationTests.Helpers;
using Xunit.Abstractions;

namespace IntegrationTests;

[Collection(MySqlCollection.Name)]
public class MySqlConnectorTests : TestHelper
{
private readonly MySqlFixture _mySql;

public MySqlConnectorTests(ITestOutputHelper output, MySqlFixture mySql)
: base("MySqlConnector", output)
{
_mySql = mySql;
}

[Theory]
[Trait("Category", "EndToEnd")]
[Trait("Containers", "Linux")]
[MemberData(nameof(LibraryVersion.MySqlConnector), MemberType = typeof(LibraryVersion))]
public void SubmitsTraces(string packageVersion)
{
using var collector = new MockSpansCollector(Output);
SetExporter(collector);
collector.Expect("MySqlConnector");

RunTestApplication(new()
{
Arguments = $"--mysql {_mySql.Port}",
PackageVersion = packageVersion
});

collector.AssertExpectations();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ internal void Propagators_FailFast()
#if NETFRAMEWORK
[InlineData("WCFCLIENT", TracerInstrumentation.WcfClient)]
#endif
[InlineData("MYSQLCONNECTOR", TracerInstrumentation.MySqlConnector)]
internal void TracerSettings_Instrumentations_SupportedValues(string tracerInstrumentation, TracerInstrumentation expectedTracerInstrumentation)
{
Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesInstrumentationEnabled, "false");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// <copyright file="Program.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using MySqlConnector;
using TestApplication.Shared;

namespace TestApplication.MySqlConnector;

public static class Program
{
public static async Task Main(string[] args)
{
ConsoleHelper.WriteSplashScreen(args);

var mySqlPort = GetMySqlPort(args);

var connString = $@"Server=127.0.0.1;Port={mySqlPort};Uid=root";

using var connection = new MySqlConnection(connString);
await connection.OpenAsync();

using var cmd = new MySqlCommand(@"SELECT 123;", connection);
using var reader = await cmd.ExecuteReaderAsync();
while (await reader.ReadAsync())
{
Console.WriteLine(reader.GetInt32(0));
}
}

private static string GetMySqlPort(string[] args)
{
if (args.Length > 1)
{
return args[1];
}

return "3306";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MySqlConnector" VersionOverride="$(LibraryVersion)" />
</ItemGroup>

</Project>
11 changes: 11 additions & 0 deletions tools/LibraryVersionsGenerator/PackageVersionDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ internal static class PackageVersionDefinitions
}
},
new()
{
IntegrationName = "MySqlConnector",
NugetPackageName = "MySqlConnector",
TestApplicationName = "TestApplication.MySqlConnector",
Versions = new List<string>
{
"2.0.0",
"*"
}
},
new()
{
IntegrationName = "MySqlData",
NugetPackageName = "MySql.Data",
Expand Down

0 comments on commit 905e413

Please sign in to comment.