Enable Azure Trace instrumentation on .NET Framework (#2857)

This commit is contained in:
Paulo Janotti 2023-08-18 12:07:56 -07:00 committed by GitHub
parent 2c91bebb86
commit dcf3dc9b26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 11 additions and 15 deletions

View File

@ -9,6 +9,8 @@ This component adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h
### Added
- Added support for Azure SDK traces instrumentation on .NET Framework.
### Changed
- [MySql.Data](https://www.nuget.org/packages/MySql.Data/) instrumentation is now

View File

@ -128,7 +128,7 @@ due to lack of stable semantic convention.
|-----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------|----------------------|-----------------------------------------------------------------------------------------------------------------------------------|
| `ASPNET` | ASP.NET (.NET Framework) MVC / WebApi \[1\] **Not supported on .NET** | * | source & bytecode | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `ASPNETCORE` | ASP.NET Core **Not supported on .NET Framework** | * | source | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `AZURE` | [Azure SDK](https://azure.github.io/azure-sdk/releases/latest/index.html) **Not supported on .NET Framework** | \[2\] | source | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `AZURE` | [Azure SDK](https://azure.github.io/azure-sdk/releases/latest/index.html) | \[2\] | source | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `ELASTICSEARCH` | [Elastic.Clients.Elasticsearch](https://www.nuget.org/packages/Elastic.Clients.Elasticsearch) | ≥8.0.0 | source | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `ENTITYFRAMEWORKCORE` | [Microsoft.EntityFrameworkCore](https://www.nuget.org/packages/) **Not supported on .NET Framework** | ≥6.0.12 | source | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `GRAPHQL` | [GraphQL](https://www.nuget.org/packages/GraphQL) **Not supported on .NET Framework** | ≥7.5.0 | source | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |

View File

@ -46,6 +46,7 @@ internal static class EnvironmentConfigurationTracerHelper
TracerInstrumentation.Quartz => Wrappers.AddQuartzInstrumentation(builder, pluginManager, lazyInstrumentationLoader),
TracerInstrumentation.MongoDB => builder.AddSource("MongoDB.Driver.Core.Extensions.DiagnosticSources"),
TracerInstrumentation.MySqlConnector => builder.AddSource("MySqlConnector"),
TracerInstrumentation.Azure => Wrappers.AddAzureInstrumentation(builder),
#if NET6_0_OR_GREATER
TracerInstrumentation.AspNetCore => Wrappers.AddAspNetCoreInstrumentation(builder, pluginManager, lazyInstrumentationLoader),
TracerInstrumentation.MassTransit => builder.AddSource("MassTransit"),
@ -53,7 +54,6 @@ internal static class EnvironmentConfigurationTracerHelper
TracerInstrumentation.StackExchangeRedis => builder.AddSource("OpenTelemetry.Instrumentation.StackExchangeRedis"),
TracerInstrumentation.EntityFrameworkCore => Wrappers.AddEntityFrameworkCoreInstrumentation(builder, pluginManager, lazyInstrumentationLoader),
TracerInstrumentation.GraphQL => Wrappers.AddGraphQLInstrumentation(builder, pluginManager, lazyInstrumentationLoader, settings),
TracerInstrumentation.Azure => Wrappers.AddAzureInstrumentation(builder),
#endif
_ => null
};
@ -166,6 +166,7 @@ internal static class EnvironmentConfigurationTracerHelper
return builder.AddSource("GraphQL");
}
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
public static TracerProviderBuilder AddAzureInstrumentation(TracerProviderBuilder builder)
@ -173,7 +174,6 @@ internal static class EnvironmentConfigurationTracerHelper
AppContext.SetSwitch("Azure.Experimental.EnableActivitySource", true);
return builder.AddSource("Azure.*");
}
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
public static TracerProviderBuilder AddSqlClientInstrumentation(TracerProviderBuilder builder, PluginManager pluginManager, LazyInstrumentationLoader lazyInstrumentationLoader)

View File

@ -123,10 +123,8 @@ internal enum TracerInstrumentation
/// </summary>
MySqlConnector = 17,
#if NET6_0_OR_GREATER
/// <summary>
/// Azure SDK instrumentation.
/// </summary>
Azure = 18
#endif
}

View File

@ -302,9 +302,9 @@ internal static class Instrumentation
case TracerInstrumentation.GraphQL:
DelayedInitialization.Traces.AddGraphQL(LazyInstrumentationLoader, pluginManager, tracerSettings);
break;
#endif
case TracerInstrumentation.Azure:
break;
#endif
case TracerInstrumentation.MongoDB:
break;
case TracerInstrumentation.Npgsql:

View File

@ -42,7 +42,7 @@
<PackageVersion Include="StackExchange.Redis" Version="2.6.122" />
<PackageVersion Include="StrongNamer" Version="0.2.5" />
<PackageVersion Include="System.Collections.Immutable" Version="7.0.0" />
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="7.0.0" />
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="7.0.2" />
<PackageVersion Include="System.Reactive" Version="6.0.0" />
<PackageVersion Include="System.Runtime.InteropServices" Version="4.3.0" />
<PackageVersion Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />

View File

@ -14,8 +14,6 @@
// limitations under the License.
// </copyright>
#if NET6_0_OR_GREATER
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Containers;
using IntegrationTests.Helpers;
@ -75,4 +73,3 @@ public class AzureFixture : IAsyncLifetime
await container.DisposeAsync();
}
}
#endif

View File

@ -14,8 +14,6 @@
// limitations under the License.
// </copyright>
#if NET6_0_OR_GREATER
using IntegrationTests.Helpers;
using Xunit.Abstractions;
@ -48,6 +46,10 @@ public class AzureTests : TestHelper
collector.Expect("System.Net.Http");
#elif NET6_0_OR_GREATER
collector.Expect("OpenTelemetry.Instrumentation.Http.HttpClient");
#elif NETFRAMEWORK
// On .NET Framework the "OpenTelemetry.Instrumentation.Http.HttpWebRequest"
// ends up being suppressed by the addition of headers via the Azure instrumentation
// See https://github.com/open-telemetry/opentelemetry-dotnet/blob/f6a1c04e8115a828dd33269f639daf2924796bae/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs#L279-L284
#endif
RunTestApplication(new()
@ -59,4 +61,3 @@ public class AzureTests : TestHelper
collector.AssertExpectations();
}
}
#endif

View File

@ -250,9 +250,7 @@ public class SettingsTests : IDisposable
[InlineData("WCFCLIENT", TracerInstrumentation.WcfClient)]
#endif
[InlineData("MYSQLCONNECTOR", TracerInstrumentation.MySqlConnector)]
#if NET6_0_OR_GREATER
[InlineData("AZURE", TracerInstrumentation.Azure)]
#endif
internal void TracerSettings_Instrumentations_SupportedValues(string tracerInstrumentation, TracerInstrumentation expectedTracerInstrumentation)
{
Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesInstrumentationEnabled, "false");