Add EntityFrameworkCore traces instrumentation (#2065)
This commit is contained in:
parent
74099de9b4
commit
f7597fb622
|
@ -16,7 +16,8 @@ This beta release is built on top of [OpenTelemetry .NET](https://github.com/ope
|
|||
### Added
|
||||
|
||||
- Support configuring `OTEL_*` settings using `App.config` and `Web.config`.
|
||||
- Add Quartz traces instrumentation.
|
||||
- Add support for Quartz traces instrumentation.
|
||||
- Add support for EntityFrameworkCore traces instrumentations.
|
||||
|
||||
### Changed
|
||||
|
||||
|
|
|
@ -151,7 +151,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApplication.AspNet.NetF
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApplication.MultipleAppDomains.NetFramework", "test\test-applications\integrations\TestApplication.MultipleAppDomains.NetFramework\TestApplication.MultipleAppDomains.NetFramework.csproj", "{A0338846-2AF8-4D96-ADA7-EBD4F010D08F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApplication.Quartz", "test\test-applications\integrations\TestApplication.Quartz\TestApplication.Quartz.csproj", "{B48780CE-8AAB-44D3-9CD1-8491584352B5}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApplication.Quartz", "test\test-applications\integrations\TestApplication.Quartz\TestApplication.Quartz.csproj", "{B48780CE-8AAB-44D3-9CD1-8491584352B5}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApplication.EntityFrameworkCore", "test\test-applications\integrations\TestApplication.EntityFrameworkCore\TestApplication.EntityFrameworkCore.csproj", "{036A56A4-4EEF-42E3-9857-B9B00D302BF9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -721,6 +723,18 @@ Global
|
|||
{B48780CE-8AAB-44D3-9CD1-8491584352B5}.Release|x64.Build.0 = Release|x64
|
||||
{B48780CE-8AAB-44D3-9CD1-8491584352B5}.Release|x86.ActiveCfg = Release|x86
|
||||
{B48780CE-8AAB-44D3-9CD1-8491584352B5}.Release|x86.Build.0 = Release|x86
|
||||
{036A56A4-4EEF-42E3-9857-B9B00D302BF9}.Debug|Any CPU.ActiveCfg = Debug|x64
|
||||
{036A56A4-4EEF-42E3-9857-B9B00D302BF9}.Debug|Any CPU.Build.0 = Debug|x64
|
||||
{036A56A4-4EEF-42E3-9857-B9B00D302BF9}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{036A56A4-4EEF-42E3-9857-B9B00D302BF9}.Debug|x64.Build.0 = Debug|x64
|
||||
{036A56A4-4EEF-42E3-9857-B9B00D302BF9}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{036A56A4-4EEF-42E3-9857-B9B00D302BF9}.Debug|x86.Build.0 = Debug|x86
|
||||
{036A56A4-4EEF-42E3-9857-B9B00D302BF9}.Release|Any CPU.ActiveCfg = Release|x64
|
||||
{036A56A4-4EEF-42E3-9857-B9B00D302BF9}.Release|Any CPU.Build.0 = Release|x64
|
||||
{036A56A4-4EEF-42E3-9857-B9B00D302BF9}.Release|x64.ActiveCfg = Release|x64
|
||||
{036A56A4-4EEF-42E3-9857-B9B00D302BF9}.Release|x64.Build.0 = Release|x64
|
||||
{036A56A4-4EEF-42E3-9857-B9B00D302BF9}.Release|x86.ActiveCfg = Release|x86
|
||||
{036A56A4-4EEF-42E3-9857-B9B00D302BF9}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -777,6 +791,7 @@ Global
|
|||
{5FDB5603-21D3-446A-8B50-36DACCF7C2FF} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
|
||||
{A0338846-2AF8-4D96-ADA7-EBD4F010D08F} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
|
||||
{B48780CE-8AAB-44D3-9CD1-8491584352B5} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
|
||||
{036A56A4-4EEF-42E3-9857-B9B00D302BF9} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {160A1D00-1F5B-40F8-A155-621B4459D78F}
|
||||
|
|
|
@ -59,23 +59,24 @@ for more details.
|
|||
|
||||
### Traces instrumentations
|
||||
|
||||
| ID | Instrumented library | Supported versions | Instrumentation type |
|
||||
|----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------|-------------------------|
|
||||
| `AspNet` | ASP.NET (.NET Framework) MVC / WebApi \[1\] | * | source |
|
||||
| `AspNet` | ASP.NET Core | * | source |
|
||||
| `Elasticsearch` | [Elastic.Clients.Elasticsearch](https://www.nuget.org/packages/Elastic.Clients.Elasticsearch) | ≥8.0.0 | source |
|
||||
| `GraphQL` | [GraphQL](https://www.nuget.org/packages/GraphQL) | ≥2.3.0 & < 3.0.0 | bytecode |
|
||||
| `GrpcNetClient` | [Grpc.Net.Client](https://www.nuget.org/packages/Grpc.Net.Client) | ≥2.43.0 & < 3.0.0 | source |
|
||||
| `HttpClient` | [System.Net.Http.HttpClient](https://docs.microsoft.com/dotnet/api/system.net.http.httpclient) and [System.Net.HttpWebRequest](https://docs.microsoft.com/dotnet/api/system.net.httpwebrequest) | * | source |
|
||||
| `Quartz` | [Quartz](https://www.nuget.org/packages/Quartz) **Not supported on .NET Framework 4.7.1 and older** | ≥3.4.0 | source |
|
||||
| `MassTransit` | [MassTransit](https://www.nuget.org/packages/MassTransit) **Not supported on .NET Framework** | ≥8.0.0 | source |
|
||||
| `MongoDB` | [MongoDB.Driver.Core](https://www.nuget.org/packages/MongoDB.Driver.Core) **Not supported on .NET Framework** | ≥2.13.3 & < 3.0.0 | source & bytecode |
|
||||
| `MySqlData` | [MySql.Data](https://www.nuget.org/packages/MySql.Data) **Not supported on .NET Framework** | ≥6.10.7 | source & bytecode \[2\] |
|
||||
| `Npgsql` | [Npgsql](https://www.nuget.org/packages/Npgsql) | ≥6.0.0 | source |
|
||||
| `NServiceBus` | [NServiceBus](https://www.nuget.org/packages/NServiceBus) | ≥8.0.0 | source & bytecode |
|
||||
| `SqlClient` | [Microsoft.Data.SqlClient](https://www.nuget.org/packages/Microsoft.Data.SqlClient) and [System.Data.SqlClient](https://www.nuget.org/packages/System.Data.SqlClient) | * | source |
|
||||
| `StackExchangeRedis` | [StackExchange.Redis](https://www.nuget.org/packages/StackExchange.Redis) **Not supported on .NET Framework** | ≥2.0.405 < 3.0.0 | source & bytecode |
|
||||
| `Wcf` | [System.ServiceModel](https://www.nuget.org/packages/System.ServiceModel) **No support for server side on .NET**. For configuration see [WCF Instrumentation Configuration](wcf-config.md) | * \[3\] | source |
|
||||
| ID | Instrumented library | Supported versions | Instrumentation type |
|
||||
|-----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------|-------------------------|
|
||||
| `AspNet` | ASP.NET (.NET Framework) MVC / WebApi \[1\] | * | source |
|
||||
| `AspNet` | ASP.NET Core | * | source |
|
||||
| `Elasticsearch` | [Elastic.Clients.Elasticsearch](https://www.nuget.org/packages/Elastic.Clients.Elasticsearch) | ≥8.0.0 | source |
|
||||
| `EntityFrameworkCore` | [Microsoft.EntityFrameworkCore](https://www.nuget.org/packages/) **Not supported on .NET Framework** | ≥6.0.12 | source |
|
||||
| `GraphQL` | [GraphQL](https://www.nuget.org/packages/GraphQL) | ≥2.3.0 & < 3.0.0 | bytecode |
|
||||
| `GrpcNetClient` | [Grpc.Net.Client](https://www.nuget.org/packages/Grpc.Net.Client) | ≥2.43.0 & < 3.0.0 | source |
|
||||
| `HttpClient` | [System.Net.Http.HttpClient](https://docs.microsoft.com/dotnet/api/system.net.http.httpclient) and [System.Net.HttpWebRequest](https://docs.microsoft.com/dotnet/api/system.net.httpwebrequest) | * | source |
|
||||
| `Quartz` | [Quartz](https://www.nuget.org/packages/Quartz) **Not supported on .NET Framework 4.7.1 and older** | ≥3.4.0 | source |
|
||||
| `MassTransit` | [MassTransit](https://www.nuget.org/packages/MassTransit) **Not supported on .NET Framework** | ≥8.0.0 | source |
|
||||
| `MongoDB` | [MongoDB.Driver.Core](https://www.nuget.org/packages/MongoDB.Driver.Core) **Not supported on .NET Framework** | ≥2.13.3 & < 3.0.0 | source & bytecode |
|
||||
| `MySqlData` | [MySql.Data](https://www.nuget.org/packages/MySql.Data) **Not supported on .NET Framework** | ≥6.10.7 | source & bytecode \[2\] |
|
||||
| `Npgsql` | [Npgsql](https://www.nuget.org/packages/Npgsql) | ≥6.0.0 | source |
|
||||
| `NServiceBus` | [NServiceBus](https://www.nuget.org/packages/NServiceBus) | ≥8.0.0 | source & bytecode |
|
||||
| `SqlClient` | [Microsoft.Data.SqlClient](https://www.nuget.org/packages/Microsoft.Data.SqlClient) and [System.Data.SqlClient](https://www.nuget.org/packages/System.Data.SqlClient) | * | source |
|
||||
| `StackExchangeRedis` | [StackExchange.Redis](https://www.nuget.org/packages/StackExchange.Redis) **Not supported on .NET Framework** | ≥2.0.405 < 3.0.0 | source & bytecode |
|
||||
| `Wcf` | [System.ServiceModel](https://www.nuget.org/packages/System.ServiceModel) **No support for server side on .NET**. For configuration see [WCF Instrumentation Configuration](wcf-config.md) | * \[3\] | source |
|
||||
|
||||
\[1\]: Only integrated pipeline mode is supported.
|
||||
|
||||
|
|
|
@ -65,20 +65,21 @@ public class MyPlugin
|
|||
|
||||
### Tracing
|
||||
|
||||
| Options type | NuGet package | NuGet version |
|
||||
|------------------------------------------------------------------------------------------------|--------------------------------------------------|---------------|
|
||||
| OpenTelemetry.Exporter.ConsoleExporterOptions | OpenTelemetry.Exporter.Console | 1.4.0-rc.2 |
|
||||
| OpenTelemetry.Exporter.ZipkinExporterOptions | OpenTelemetry.Exporter.Zipkin | 1.4.0-rc.2 |
|
||||
| OpenTelemetry.Exporter.OtlpExporterOptions | OpenTelemetry.Exporter.OpenTelemetryProtocol | 1.4.0-rc.2 |
|
||||
| OpenTelemetry.Instrumentation.AspNet.AspNetInstrumentationOptions | OpenTelemetry.Instrumentation.AspNet | 1.0.0-rc9.7 |
|
||||
| OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions | OpenTelemetry.Instrumentation.AspNetCore | 1.0.0-rc9.11 |
|
||||
| OpenTelemetry.Instrumentation.GrpcNetClient.GrpcClientInstrumentationOptions | OpenTelemetry.Instrumentation.GrpcNetClient | 1.0.0-rc9.11 |
|
||||
| OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions | OpenTelemetry.Instrumentation.Http | 1.0.0-rc9.11 |
|
||||
| OpenTelemetry.Instrumentation.Quartz.QuartzInstrumentationOptions | OpenTelemetry.Instrumentation.Quartz | 1.0.0-alpha.1 |
|
||||
| OpenTelemetry.Instrumentation.SqlClient.SqlClientInstrumentationOptions | OpenTelemetry.Instrumentation.SqlClient | 1.0.0-rc9.11 |
|
||||
| OpenTelemetry.Instrumentation.StackExchangeRedis.StackExchangeRedisCallsInstrumentationOptions | OpenTelemetry.Instrumentation.StackExchangeRedis | 1.0.0-rc9.7 |
|
||||
| OpenTelemetry.Instrumentation.MySqlData.MySqlDataInstrumentationOptions | OpenTelemetry.Instrumentation.MySqlData | 1.0.0-beta.4 |
|
||||
| OpenTelemetry.Instrumentation.Wcf.WcfInstrumentationOptions | OpenTelemetry.Instrumentation.Wcf | 1.0.0-rc.8 |
|
||||
| Options type | NuGet package | NuGet version |
|
||||
|------------------------------------------------------------------------------------------------|---------------------------------------------------|---------------|
|
||||
| OpenTelemetry.Exporter.ConsoleExporterOptions | OpenTelemetry.Exporter.Console | 1.4.0-rc.2 |
|
||||
| OpenTelemetry.Exporter.ZipkinExporterOptions | OpenTelemetry.Exporter.Zipkin | 1.4.0-rc.2 |
|
||||
| OpenTelemetry.Exporter.OtlpExporterOptions | OpenTelemetry.Exporter.OpenTelemetryProtocol | 1.4.0-rc.2 |
|
||||
| OpenTelemetry.Instrumentation.AspNet.AspNetInstrumentationOptions | OpenTelemetry.Instrumentation.AspNet | 1.0.0-rc9.7 |
|
||||
| OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions | OpenTelemetry.Instrumentation.AspNetCore | 1.0.0-rc9.11 |
|
||||
| OpenTelemetry.Instrumentation.EntityFrameworkCore.EntityFrameworkInstrumentationOptions | OpenTelemetry.Instrumentation.EntityFrameworkCore | 1.0.0-beta.3 |
|
||||
| OpenTelemetry.Instrumentation.GrpcNetClient.GrpcClientInstrumentationOptions | OpenTelemetry.Instrumentation.GrpcNetClient | 1.0.0-rc9.11 |
|
||||
| OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions | OpenTelemetry.Instrumentation.Http | 1.0.0-rc9.11 |
|
||||
| OpenTelemetry.Instrumentation.Quartz.QuartzInstrumentationOptions | OpenTelemetry.Instrumentation.Quartz | 1.0.0-alpha.1 |
|
||||
| OpenTelemetry.Instrumentation.SqlClient.SqlClientInstrumentationOptions | OpenTelemetry.Instrumentation.SqlClient | 1.0.0-rc9.11 |
|
||||
| OpenTelemetry.Instrumentation.StackExchangeRedis.StackExchangeRedisCallsInstrumentationOptions | OpenTelemetry.Instrumentation.StackExchangeRedis | 1.0.0-rc9.7 |
|
||||
| OpenTelemetry.Instrumentation.MySqlData.MySqlDataInstrumentationOptions | OpenTelemetry.Instrumentation.MySqlData | 1.0.0-beta.4 |
|
||||
| OpenTelemetry.Instrumentation.Wcf.WcfInstrumentationOptions | OpenTelemetry.Instrumentation.Wcf | 1.0.0-rc.8 |
|
||||
|
||||
### Metrics
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
<dependency id="OpenTelemetry.Shims.OpenTracing" version="1.0.0-rc9.11" />
|
||||
<dependency id="OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs" version="1.4.0-rc.2" />
|
||||
<dependency id="OpenTelemetry.Instrumentation.AspNetCore" version="1.0.0-rc9.11" />
|
||||
<dependency id="OpenTelemetry.Instrumentation.EntityFrameworkCore" version="1.0.0-beta.3" />
|
||||
<dependency id="OpenTelemetry.Instrumentation.MySqlData" version="1.0.0-beta.5" />
|
||||
<dependency id="OpenTelemetry.Instrumentation.StackExchangeRedis" version="1.0.0-rc9.7" />
|
||||
</group>
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
<PackageVersion Include="OpenTelemetry.Extensions.Propagators" Version="1.4.0-rc.2" />
|
||||
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNet" Version="1.0.0-rc9.7" />
|
||||
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc9.11" />
|
||||
<PackageVersion Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" Version="1.0.0-beta.3" />
|
||||
<PackageVersion Include="OpenTelemetry.Instrumentation.GrpcNetClient" Version="1.0.0-rc9.11" />
|
||||
<PackageVersion Include="OpenTelemetry.Instrumentation.MySqlData" Version="1.0.0-beta.5" />
|
||||
<PackageVersion Include="OpenTelemetry.Instrumentation.Process" Version="1.0.0-alpha.4" />
|
||||
|
|
|
@ -48,6 +48,7 @@ internal static class EnvironmentConfigurationTracerHelper
|
|||
TracerInstrumentation.MongoDB => builder.AddSource("MongoDB.Driver.Core.Extensions.DiagnosticSources"),
|
||||
TracerInstrumentation.MySqlData => Wrappers.AddMySqlClientInstrumentation(builder, pluginManager, lazyInstrumentationLoader),
|
||||
TracerInstrumentation.StackExchangeRedis => builder.AddSource("OpenTelemetry.Instrumentation.StackExchangeRedis"),
|
||||
TracerInstrumentation.EntityFrameworkCore => Wrappers.AddEntityFrameworkCoreInstrumentation(builder, pluginManager, lazyInstrumentationLoader),
|
||||
#endif
|
||||
_ => null
|
||||
};
|
||||
|
@ -189,6 +190,16 @@ internal static class EnvironmentConfigurationTracerHelper
|
|||
.AddLegacySource("Quartz.Job.Veto");
|
||||
}
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static TracerProviderBuilder AddEntityFrameworkCoreInstrumentation(TracerProviderBuilder builder, PluginManager pluginManager, LazyInstrumentationLoader lazyInstrumentationLoader)
|
||||
{
|
||||
lazyInstrumentationLoader.Add(new EntityFrameworkCoreInitializer(pluginManager));
|
||||
|
||||
return builder.AddSource("OpenTelemetry.EntityFrameworkCore");
|
||||
}
|
||||
#endif
|
||||
|
||||
// Exporters
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
|
|
|
@ -95,5 +95,12 @@ internal enum TracerInstrumentation
|
|||
/// <summary>
|
||||
/// Quartz instrumentation.
|
||||
/// </summary>
|
||||
Quartz = 13
|
||||
Quartz = 13,
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
/// <summary>
|
||||
/// Entity Framework Core instrumentation.
|
||||
/// </summary>
|
||||
EntityFrameworkCore = 14
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
// <copyright file="EntityFrameworkCoreInitializer.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>
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
using OpenTelemetry.AutoInstrumentation.Plugins;
|
||||
|
||||
namespace OpenTelemetry.AutoInstrumentation.Loading.Initializers;
|
||||
|
||||
internal class EntityFrameworkCoreInitializer : InstrumentationInitializer
|
||||
{
|
||||
private readonly PluginManager _pluginManager;
|
||||
|
||||
public EntityFrameworkCoreInitializer(PluginManager pluginManager)
|
||||
: base("Microsoft.EntityFrameworkCore")
|
||||
{
|
||||
_pluginManager = pluginManager;
|
||||
}
|
||||
|
||||
public override void Initialize(ILifespanManager lifespanManager)
|
||||
{
|
||||
var instrumentationType = Type.GetType("OpenTelemetry.Instrumentation.EntityFrameworkCore.EntityFrameworkInstrumentation, OpenTelemetry.Instrumentation.EntityFrameworkCore")!;
|
||||
|
||||
var options = new OpenTelemetry.Instrumentation.EntityFrameworkCore.EntityFrameworkInstrumentationOptions();
|
||||
|
||||
_pluginManager.ConfigureTracesOptions(options);
|
||||
|
||||
var instrumentation = Activator.CreateInstance(instrumentationType, options)!;
|
||||
|
||||
lifespanManager.Track(instrumentation);
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -34,6 +34,7 @@
|
|||
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
|
||||
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.MySqlData" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.StackExchangeRedis" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
<PackageVersion Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
|
||||
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
|
||||
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.0" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.12" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
/net/OpenTelemetry.Extensions.DependencyInjection.dll,
|
||||
/net/OpenTelemetry.Extensions.Propagators.dll,
|
||||
/net/OpenTelemetry.Instrumentation.AspNetCore.dll,
|
||||
/net/OpenTelemetry.Instrumentation.EntityFrameworkCore.dll,
|
||||
/net/OpenTelemetry.Instrumentation.GrpcNetClient.dll,
|
||||
/net/OpenTelemetry.Instrumentation.Http.dll,
|
||||
/net/OpenTelemetry.Instrumentation.MySqlData.dll,
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
/net/OpenTelemetry.Extensions.DependencyInjection.dll,
|
||||
/net/OpenTelemetry.Extensions.Propagators.dll,
|
||||
/net/OpenTelemetry.Instrumentation.AspNetCore.dll,
|
||||
/net/OpenTelemetry.Instrumentation.EntityFrameworkCore.dll,
|
||||
/net/OpenTelemetry.Instrumentation.GrpcNetClient.dll,
|
||||
/net/OpenTelemetry.Instrumentation.Http.dll,
|
||||
/net/OpenTelemetry.Instrumentation.MySqlData.dll,
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
/net/OpenTelemetry.Extensions.DependencyInjection.dll,
|
||||
/net/OpenTelemetry.Extensions.Propagators.dll,
|
||||
/net/OpenTelemetry.Instrumentation.AspNetCore.dll,
|
||||
/net/OpenTelemetry.Instrumentation.EntityFrameworkCore.dll,
|
||||
/net/OpenTelemetry.Instrumentation.GrpcNetClient.dll,
|
||||
/net/OpenTelemetry.Instrumentation.Http.dll,
|
||||
/net/OpenTelemetry.Instrumentation.MySqlData.dll,
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
\net\OpenTelemetry.Extensions.DependencyInjection.dll,
|
||||
\net\OpenTelemetry.Extensions.Propagators.dll,
|
||||
\net\OpenTelemetry.Instrumentation.AspNetCore.dll,
|
||||
\net\OpenTelemetry.Instrumentation.EntityFrameworkCore.dll,
|
||||
\net\OpenTelemetry.Instrumentation.GrpcNetClient.dll,
|
||||
\net\OpenTelemetry.Instrumentation.Http.dll,
|
||||
\net\OpenTelemetry.Instrumentation.MySqlData.dll,
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
// <copyright file="EntityFrameworkCoreTests.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>
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
|
||||
using IntegrationTests.Helpers;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace IntegrationTests;
|
||||
|
||||
public class EntityFrameworkCoreTests : TestHelper
|
||||
{
|
||||
public EntityFrameworkCoreTests(ITestOutputHelper output)
|
||||
: base("EntityFrameworkCore", output)
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", "EndToEnd")]
|
||||
public void SubmitsTraces()
|
||||
{
|
||||
using var collector = new MockSpansCollector(Output);
|
||||
SetExporter(collector);
|
||||
collector.Expect("OpenTelemetry.EntityFrameworkCore");
|
||||
|
||||
RunTestApplication();
|
||||
|
||||
collector.AssertExpectations();
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -194,6 +194,9 @@ public class SettingsTests : IDisposable
|
|||
[InlineData(nameof(TracerInstrumentation.NServiceBus), TracerInstrumentation.NServiceBus)]
|
||||
[InlineData(nameof(TracerInstrumentation.Elasticsearch), TracerInstrumentation.Elasticsearch)]
|
||||
[InlineData(nameof(TracerInstrumentation.Quartz), TracerInstrumentation.Quartz)]
|
||||
#if NET6_0_OR_GREATER
|
||||
[InlineData(nameof(TracerInstrumentation.EntityFrameworkCore), TracerInstrumentation.EntityFrameworkCore)]
|
||||
#endif
|
||||
internal void TracerSettings_Instrumentations_SupportedValues(string tracerInstrumentation, TracerInstrumentation expectedTracerInstrumentation)
|
||||
{
|
||||
Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.Instrumentations, tracerInstrumentation);
|
||||
|
|
|
@ -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 System.Data.Common;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using TestApplication.EntityFrameworkCore;
|
||||
using TestApplication.Shared;
|
||||
|
||||
ConsoleHelper.WriteSplashScreen(args);
|
||||
|
||||
var contextOptions = new DbContextOptionsBuilder<TestContext>()
|
||||
.UseSqlite(CreateInMemoryDatabase())
|
||||
.Options;
|
||||
|
||||
await using var connection = RelationalOptionsExtension.Extract(contextOptions).Connection;
|
||||
|
||||
await using (var context = new TestContext(contextOptions))
|
||||
{
|
||||
await context.Database.EnsureCreatedAsync();
|
||||
await context.AddAsync(new TestItem { Name = "TestItem" });
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
await using (var context = new TestContext(contextOptions))
|
||||
{
|
||||
foreach (var testItem in context.Set<TestItem>())
|
||||
{
|
||||
Console.WriteLine($"{testItem.Id} {testItem.Name}");
|
||||
}
|
||||
}
|
||||
|
||||
static DbConnection CreateInMemoryDatabase()
|
||||
{
|
||||
var connection = new SqliteConnection("Filename=:memory:");
|
||||
connection.Open();
|
||||
return connection;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\dependency-libs\TestApplication.Shared\TestApplication.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,38 @@
|
|||
// <copyright file="TestContext.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 Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace TestApplication.EntityFrameworkCore;
|
||||
|
||||
public class TestContext : DbContext
|
||||
{
|
||||
public TestContext(DbContextOptions options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<TestItem>(
|
||||
b =>
|
||||
{
|
||||
b.Property("Id");
|
||||
b.HasKey("Id");
|
||||
b.Property(e => e.Name);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
// <copyright file="TestItem.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>
|
||||
|
||||
namespace TestApplication.EntityFrameworkCore;
|
||||
|
||||
public class TestItem
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string? Name { get; set; }
|
||||
}
|
Loading…
Reference in New Issue