From 8a6b5c79654a8bb9da4e3dbe5928f01a2ca77f44 Mon Sep 17 00:00:00 2001 From: Paulo Janotti Date: Mon, 30 Jan 2023 12:05:47 -0800 Subject: [PATCH 01/14] Temporarily disable flaky build task (#2126) --- build/Build.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/build/Build.cs b/build/Build.cs index fba2ed0651..9d6cb407a8 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -85,7 +85,6 @@ void DeleteReparsePoints(string path) .After(Clean) .DependsOn(CreateRequiredDirectories) .DependsOn(Restore) - .DependsOn(GenerateNetFxTransientDependencies) .DependsOn(CompileManagedSrc) .DependsOn(PublishManagedProfiler) .DependsOn(GenerateNetFxAssemblyRedirectionSource) From b901defd92e59e7529a82ac39dd3c0202762eb19 Mon Sep 17 00:00:00 2001 From: Paulo Janotti Date: Mon, 30 Jan 2023 22:33:26 -0800 Subject: [PATCH 02/14] Fix example PlayGround on Windows (#2129) --- dev/envvars.sh | 87 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 30 deletions(-) diff --git a/dev/envvars.sh b/dev/envvars.sh index 89609aa289..d915b764ad 100644 --- a/dev/envvars.sh +++ b/dev/envvars.sh @@ -1,16 +1,42 @@ #!/bin/bash -case "$(uname -s | tr '[:upper:]' '[:lower:]')" in - linux*) - if [ "$(ldd /bin/ls | grep -m1 'musl')" ]; then - DOTNET_RUNTIME_ID="linux-musl" - else - DOTNET_RUNTIME_ID="linux-x64" - fi +# guess OS_TYPE if not provided +OS_TYPE=${OS_TYPE:-} +if [ -z "$OS_TYPE" ]; then + case "$(uname -s | tr '[:upper:]' '[:lower:]')" in + cygwin_nt*|mingw*|msys_nt*) + OS_TYPE="windows" + ;; + linux*) + if [ "$(ldd /bin/ls | grep -m1 'musl')" ]; then + OS_TYPE="linux-musl" + else + OS_TYPE="linux-glibc" + fi + ;; + darwin*) + OS_TYPE="macos" + ;; + esac +fi + +# validate input +case "$OS_TYPE" in + "linux-glibc") + DOTNET_RUNTIME_ID="linux-x64" + ;; + "linux-musl") + DOTNET_RUNTIME_ID="linux-musl-x64" ;; - darwin*) + "macos") DOTNET_RUNTIME_ID="osx-x64" ;; + "windows") + ;; + *) + echo "Set the operating system type using the OS_TYPE environment variable. Supported values: linux-glibc, linux-musl, macos, windows." >&2 + return 2 + ;; esac uname_os() { @@ -46,28 +72,6 @@ SUFIX=$(native_sufix) OS=$(uname_os) ENABLE_PROFILING=${ENABLE_PROFILING:-1} -# Enable .NET Framework Profiling API -if [ "$OS" == "windows" ] -then - export COR_ENABLE_PROFILING="${ENABLE_PROFILING}" - export COR_PROFILER="{918728DD-259F-4A6A-AC2B-B85E1B658318}" - export COR_PROFILER_PATH="${CURDIR}/bin/tracer-home/OpenTelemetry.AutoInstrumentation.Native.${SUFIX}" - # Set paths for both bitness on Windows, see https://docs.microsoft.com/en-us/dotnet/core/run-time-config/debugging-profiling#profiler-location - export COR_PROFILER_PATH_64="${CURDIR}/bin/tracer-home/win-x64/OpenTelemetry.AutoInstrumentation.Native.${SUFIX}" - export COR_PROFILER_PATH_32="${CURDIR}/bin/tracer-home/win-x86/OpenTelemetry.AutoInstrumentation.Native.${SUFIX}" -fi - -# Enable .NET Core Profiling API -export CORECLR_ENABLE_PROFILING="${ENABLE_PROFILING}" -export CORECLR_PROFILER="{918728DD-259F-4A6A-AC2B-B85E1B658318}" -export CORECLR_PROFILER_PATH="${CURDIR}/bin/tracer-home/$DOTNET_RUNTIME_ID/OpenTelemetry.AutoInstrumentation.Native.${SUFIX}" -if [ "$OS" == "windows" ] -then - # Set paths for both bitness on Windows, see https://docs.microsoft.com/en-us/dotnet/core/run-time-config/debugging-profiling#profiler-location - export CORECLR_PROFILER_PATH_64="${CURDIR}/bin/tracer-home/win-x64/OpenTelemetry.AutoInstrumentation.Native.${SUFIX}" - export CORECLR_PROFILER_PATH_32="${CURDIR}/bin/tracer-home/win-x86/OpenTelemetry.AutoInstrumentation.Native.${SUFIX}" -fi - # Configure .NET Core runtime export DOTNET_ADDITIONAL_DEPS="${CURDIR}/bin/tracer-home/AdditionalDeps" export DOTNET_SHARED_STORE="${CURDIR}/bin/tracer-home/store" @@ -87,3 +91,26 @@ export OTEL_DOTNET_AUTO_EXCLUDE_PROCESSES=${OTEL_DOTNET_AUTO_EXCLUDE_PROCESSES:- export OTEL_DOTNET_AUTO_TRACES_CONSOLE_EXPORTER_ENABLED=${OTEL_DOTNET_AUTO_TRACES_CONSOLE_EXPORTER_ENABLED:-true} export OTEL_DOTNET_AUTO_METRICS_CONSOLE_EXPORTER_ENABLED=${OTEL_DOTNET_AUTO_METRICS_CONSOLE_EXPORTER_ENABLED:-true} export OTEL_DOTNET_AUTO_LOGS_CONSOLE_EXPORTER_ENABLED=${OTEL_DOTNET_AUTO_LOGS_CONSOLE_EXPORTER_ENABLED:-true} + +# Enable .NET Framework Profiling API +if [ "$OS" == "windows" ] +then + export COR_ENABLE_PROFILING="${ENABLE_PROFILING}" + export COR_PROFILER="{918728DD-259F-4A6A-AC2B-B85E1B658318}" + export COR_PROFILER_PATH="${CURDIR}/bin/tracer-home/OpenTelemetry.AutoInstrumentation.Native.${SUFIX}" + # Set paths for both bitness on Windows, see https://docs.microsoft.com/en-us/dotnet/core/run-time-config/debugging-profiling#profiler-location + export COR_PROFILER_PATH_64="${CURDIR}/bin/tracer-home/win-x64/OpenTelemetry.AutoInstrumentation.Native.${SUFIX}" + export COR_PROFILER_PATH_32="${CURDIR}/bin/tracer-home/win-x86/OpenTelemetry.AutoInstrumentation.Native.${SUFIX}" +fi + +# Enable .NET Core Profiling API +export CORECLR_ENABLE_PROFILING="${ENABLE_PROFILING}" +export CORECLR_PROFILER="{918728DD-259F-4A6A-AC2B-B85E1B658318}" + if [ "$OS_TYPE" == "windows" ] + then + # Set paths for both bitness on Windows, see https://docs.microsoft.com/en-us/dotnet/core/run-time-config/debugging-profiling#profiler-location + export CORECLR_PROFILER_PATH_64="$OTEL_DOTNET_AUTO_HOME/win-x64/OpenTelemetry.AutoInstrumentation.Native.$SUFIX" + export CORECLR_PROFILER_PATH_32="$OTEL_DOTNET_AUTO_HOME/win-x86/OpenTelemetry.AutoInstrumentation.Native.$SUFIX" + else + export CORECLR_PROFILER_PATH="$OTEL_DOTNET_AUTO_HOME/$DOTNET_RUNTIME_ID/OpenTelemetry.AutoInstrumentation.Native.$SUFIX" + fi From 078fa00b799aa163e6438903fc4b54f308993551 Mon Sep 17 00:00:00 2001 From: xiang17 Date: Tue, 31 Jan 2023 21:42:50 -0800 Subject: [PATCH 03/14] Exclude assets from Microsoft.Bcl.AsyncInterfaces library (#2135) --- src/CommonExcludedAssets.props | 2 ++ src/Directory.Packages.props | 4 ++-- ...BuildTests.DistributionStructure_alpine-linux.verified.txt | 1 - .../BuildTests.DistributionStructure_linux.verified.txt | 1 - .../BuildTests.DistributionStructure_osx.verified.txt | 1 - .../BuildTests.DistributionStructure_windows.verified.txt | 1 - 6 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/CommonExcludedAssets.props b/src/CommonExcludedAssets.props index ce387a124a..1a6d6f18db 100644 --- a/src/CommonExcludedAssets.props +++ b/src/CommonExcludedAssets.props @@ -18,5 +18,7 @@ + + diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index eb421be3d4..91b37107df 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -28,6 +28,7 @@ + @@ -38,13 +39,12 @@ - + - diff --git a/test/IntegrationTests/BuildTests.DistributionStructure_alpine-linux.verified.txt b/test/IntegrationTests/BuildTests.DistributionStructure_alpine-linux.verified.txt index 8705fb8655..73ffe29b85 100644 --- a/test/IntegrationTests/BuildTests.DistributionStructure_alpine-linux.verified.txt +++ b/test/IntegrationTests/BuildTests.DistributionStructure_alpine-linux.verified.txt @@ -9,7 +9,6 @@ /net/Grpc.Core.Api.dll, /net/Grpc.Net.Client.dll, /net/Grpc.Net.Common.dll, - /net/Microsoft.Bcl.AsyncInterfaces.dll, /net/OpenTelemetry.Api.dll, /net/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.deps.json, /net/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.dll, diff --git a/test/IntegrationTests/BuildTests.DistributionStructure_linux.verified.txt b/test/IntegrationTests/BuildTests.DistributionStructure_linux.verified.txt index 0605b085d8..09f030187d 100644 --- a/test/IntegrationTests/BuildTests.DistributionStructure_linux.verified.txt +++ b/test/IntegrationTests/BuildTests.DistributionStructure_linux.verified.txt @@ -9,7 +9,6 @@ /net/Grpc.Core.Api.dll, /net/Grpc.Net.Client.dll, /net/Grpc.Net.Common.dll, - /net/Microsoft.Bcl.AsyncInterfaces.dll, /net/OpenTelemetry.Api.dll, /net/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.deps.json, /net/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.dll, diff --git a/test/IntegrationTests/BuildTests.DistributionStructure_osx.verified.txt b/test/IntegrationTests/BuildTests.DistributionStructure_osx.verified.txt index e166b6f093..45ee9b12ee 100644 --- a/test/IntegrationTests/BuildTests.DistributionStructure_osx.verified.txt +++ b/test/IntegrationTests/BuildTests.DistributionStructure_osx.verified.txt @@ -8,7 +8,6 @@ /net/Grpc.Core.Api.dll, /net/Grpc.Net.Client.dll, /net/Grpc.Net.Common.dll, - /net/Microsoft.Bcl.AsyncInterfaces.dll, /net/OpenTelemetry.Api.dll, /net/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.deps.json, /net/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.dll, diff --git a/test/IntegrationTests/BuildTests.DistributionStructure_windows.verified.txt b/test/IntegrationTests/BuildTests.DistributionStructure_windows.verified.txt index 84ff4936aa..26e3350733 100644 --- a/test/IntegrationTests/BuildTests.DistributionStructure_windows.verified.txt +++ b/test/IntegrationTests/BuildTests.DistributionStructure_windows.verified.txt @@ -8,7 +8,6 @@ \net\Grpc.Core.Api.dll, \net\Grpc.Net.Client.dll, \net\Grpc.Net.Common.dll, - \net\Microsoft.Bcl.AsyncInterfaces.dll, \net\OpenTelemetry.Api.dll, \net\OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.deps.json, \net\OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.dll, From 8a5f599fb27099b626ddbdb1a62b8229ecff8c91 Mon Sep 17 00:00:00 2001 From: Paulo Janotti Date: Tue, 31 Jan 2023 22:40:10 -0800 Subject: [PATCH 04/14] Make dotnet CLI issue more visible in the docs (#2128) Co-authored-by: Fabrizio Ferri-Benedetti --- docs/README.md | 19 +++++++++++++++++++ docs/troubleshooting.md | 6 +++++- examples/playground/README.md | 2 +- instrument.sh | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 3c9af1cf75..1224849d11 100644 --- a/docs/README.md +++ b/docs/README.md @@ -76,6 +76,25 @@ See [config.md#instrumented-libraries-and-frameworks](config.md#instrumented-lib ## Get started +### Considerations on scope + +Currently, instrumenting [`self-contained`](https://learn.microsoft.com/en-us/dotnet/core/deploying/#publish-self-contained) +applications is not supported. Note that a `self-contained` applications is +automatically generated in .NET 7.0 whenever the `dotnet publish` or `dotnet build` +command is used with a Runtime Identifier (RID) parameter, for example when `-r` +or `--runtime` is used when running the command. The `dotnet` CLI is +a `self-contained` application and it's incompatible with automatic instrumentation. + +To build and launch an instrumented application, take the following into account: + +- Don't set the automatic instrumentation environment variables in the same session +used to run the `dotnet` tool. +- Don't launch the application to be instrumented using `dotnet run` or +`dotnet `. Build the application in an isolated shell, without the +automatic instrumentation environment variables set, and use a separate +session with the automatic instrumentation variables to directly launch +the executable. + ### Install Download and extract the appropriate binaries from diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index a946ce2c87..9d9abad7e0 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -2,12 +2,16 @@ ## dotnet is crashing -Instrumenting `dotnet` often results in a crash. +Currently, instrumenting self-contained applications and the `dotnet` +CLI tool in particular is not supported. See [(#1744)](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/issues/1744). Therefore, we advise executing `dotnet build` before instrumenting the terminal session or calling it in a separate terminal session. +See the [Get started](./README.md#get-started) +section for more information. + ## Assembly version conflicts OpenTelemetry .NET NuGet packages and its dependencies diff --git a/examples/playground/README.md b/examples/playground/README.md index 667bf63917..f3bc48a001 100644 --- a/examples/playground/README.md +++ b/examples/playground/README.md @@ -16,7 +16,7 @@ following the [developing instructions](../../docs/developing.md). ## Playground application You can use the `run.sh` helper script to build -and run the playground application with auto instrumenation. +and run the playground application with auto instrumentation. ```sh ./examples/playground/run.sh diff --git a/instrument.sh b/instrument.sh index 6cb447da11..c674bdfa9c 100755 --- a/instrument.sh +++ b/instrument.sh @@ -1,6 +1,7 @@ #!/bin/sh # guess OS_TYPE if not provided +OS_TYPE=${OS_TYPE:-} if [ -z "$OS_TYPE" ]; then case "$(uname -s | tr '[:upper:]' '[:lower:]')" in cygwin_nt*|mingw*|msys_nt*) From 04ad208621befda28aa3a9f214152417808edea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 1 Feb 2023 09:54:00 +0100 Subject: [PATCH 05/14] LICENSE includes shipped dependent licenses (#2134) --- LICENSE | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/LICENSE b/LICENSE index 261eeb9e9f..9c74803e7d 100644 --- a/LICENSE +++ b/LICENSE @@ -199,3 +199,110 @@ 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. + +--------------------------------------------------------------------------- + +OpenTelemetry .NET Automatic Instrumentation components + +OpenTelemetry .NET Automatic Instrumentation project contains components with +separate copyright notices and license terms: + +Library Google.Protobuf is under the following copyright: +Copyright 2008 Google Inc. All rights reserved under BSD-3-Clause license +(https://github.com/protocolbuffers/protobuf/blob/main/LICENSE). + +Libraries +- Google.Protobuf, +- Grpc.Net.Common, +- Grpc.Net.Client +are under the following copyright: +Copyright 2019 The gRPC Authors under Apache License Version 2.0 +(https://github.com/grpc/grpc-dotnet/blob/master/LICENSE). + +Libraries +- OpenTelemetry.Api, +- OpenTelemetry.Exporter.Console, +- OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs, +- OpenTelemetry.Exporter.OpenTelemetryProtocol, +- OpenTelemetry.Exporter.Prometheus.HttpListener, +- OpenTelemetry.Exporter.Zipkin, +- OpenTelemetry.Extensions.DependencyInjection, +- OpenTelemetry.Extensions.Propagators, +- OpenTelemetry.Instrumentation.AspNetCore, +- OpenTelemetry.Instrumentation.GrpcNetClient, +- OpenTelemetry.Instrumentation.Http, +- OpenTelemetry.Instrumentation.SqlClient, +- OpenTelemetry.Shims.OpenTracing, +- OpenTelemetry +are under the following copyright: +Copyright The OpenTelemetry Authors under Apache License Version 2.0 +(https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/LICENSE). + +Libraries +- OpenTelemetry.Api, +- OpenTelemetry.Instrumentation.EntityFrameworkCore, +- OpenTelemetry.Instrumentation.MySqlData, +- OpenTelemetry.Instrumentation.Process, +- OpenTelemetry.Instrumentation.Quartz, +- OpenTelemetry.Instrumentation.Runtime, +- OpenTelemetry.Instrumentation.StackExchangeRedis, +- OpenTelemetry.Instrumentation.Wcf +are under the following copyright: +Copyright The OpenTelemetry Authors under Apache License Version 2.0 +(https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/main/LICENSE). + +Library OpenTracing is under the following copyright: +Copyright The OpenTracing Authors under Apache License Version 2.0 +(https://github.com/opentracing/opentracing-csharp/blob/master/LICENSE). + +Libraries +- System.Diagnostics.DiagnosticSource, +- System.Security.Permissions, +- Microsoft.Extensions.Configuration.Abstractions, +- Microsoft.Extensions.Configuration.Binder, +- Microsoft.Extensions.Configuration.EnvironmentVariables, +- Microsoft.Extensions.Configuration, +- Microsoft.Extensions.DependencyInjection.Abstractions, +- Microsoft.Extensions.DependencyInjection, +- Microsoft.Extensions.Logging.Abstractions, +- Microsoft.Extensions.Logging.Configuration, +- Microsoft.Extensions.Logging, +- Microsoft.Extensions.Options.ConfigurationExtensions, +- Microsoft.Extensions.Options, +- Microsoft.Extensions.Primitives +are under the following copyright: +Copyright (c) .NET Foundation and Contributors under the MIT License (MIT) +(https://github.com/dotnet/runtime/blob/main/LICENSE.TXT). + +Libraries +- System.Private.ServiceModel, +- System.ServiceModel.Primitives, +- System.ServiceModel +are under the following copyright: +Copyright (c) .NET Foundation and Contributors under the MIT License (MIT) +(https://github.com/dotnet/wcf/blob/main/LICENSE.TXT). + +Library DnsClient is under the following copyright: +Copyright The DnsClient.NET Authors under Apache License Version 2.0 +(https://github.com/opentracing/opentracing-csharp/blob/master/LICENSE). + +Libraries +- MongoDB.Bson, +- MongoDB.Driver.Core, +- libzstd, +- snappy32, +- snappy64, +- MongoDB.Libmongocrypt, +- libmongocrypt, +- mongocrypt +are under the following copyright: +Copyright 2010-present MongoDB Inc. under Apache License Version 2.0 +(https://github.com/mongodb/mongo-csharp-driver/blob/master/License.txt). + +Library MongoDB.Driver.Core.Extensions.DiagnosticSources is under the following copyright: +Copyright MongoDB.Driver.Core.Extensions.DiagnosticSources Authors under Apache License Version 2.0 +(https://github.com/jbogard/MongoDB.Driver.Core.Extensions.DiagnosticSources/blob/master/LICENSE). + +Library SharpCompress is under the following copyright: +Copyright (c) 2014 Adam Hathcock under the MIT License (MIT) +(https://github.com/adamhathcock/sharpcompress/blob/master/LICENSE.txt). From 425ba038bf3085a5f898ff9aa4ea0f515f62c16b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 Feb 2023 13:56:27 +0100 Subject: [PATCH 06/14] Bump Verify.Xunit from 19.7.1 to 19.8.1 in /test (#2136) Bumps [Verify.Xunit](https://github.com/VerifyTests/Verify) from 19.7.1 to 19.8.1. - [Release notes](https://github.com/VerifyTests/Verify/releases) - [Commits](https://github.com/VerifyTests/Verify/compare/19.7.1...19.8.1) --- updated-dependencies: - dependency-name: Verify.Xunit dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- test/Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Directory.Packages.props b/test/Directory.Packages.props index 51af682849..c4b619677d 100644 --- a/test/Directory.Packages.props +++ b/test/Directory.Packages.props @@ -40,7 +40,7 @@ - + From 857799404ea743dd7002c4c05ab420d6284be74c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Wed, 1 Feb 2023 14:53:34 +0100 Subject: [PATCH 07/14] Fix to use app.config in .NET Fx Windows Services (#2137) --- docs/windows-service-instrumentation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/windows-service-instrumentation.md b/docs/windows-service-instrumentation.md index fa0b990918..b62fb09d83 100644 --- a/docs/windows-service-instrumentation.md +++ b/docs/windows-service-instrumentation.md @@ -25,7 +25,7 @@ Register-OpenTelemetryForWindowsService -WindowsServiceName "WindowsServiceName" > `Restart-Service -Name $WindowsServiceName -Force` in PowerShell. For .NET Framework applications you can configure the most common `OTEL_` settings -(like `OTEL_RESOURCE_ATTRIBUTES`) via `appSettings` in `Web.config`. +(like `OTEL_RESOURCE_ATTRIBUTES`) via `appSettings` in `App.config`. The alternative is to set environment variables for the Windows Service in the Windows Registry. From 740b80210111e9a4c4df0816ca8743f4d1b76f82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 1 Feb 2023 20:42:10 +0100 Subject: [PATCH 08/14] Env var instrumentation improvements (#2088) --- CHANGELOG.md | 18 +++ docs/config.md | 32 +++-- ...lemetry.AutoInstrumentation.Native.vcxproj | 2 + .../bytecode_instrumentations.h | 13 ++ .../cor_profiler.cpp | 12 +- .../environment_variables.h | 53 ++----- .../environment_variables_util.h | 18 ++- .../integration_loader.cpp | 23 +-- .../integration_loader.h | 13 +- .../util.cpp | 25 ++++ .../util.h | 4 + .../Configurations/ConfigurationExtensions.cs | 51 ++----- .../Configurations/ConfigurationKeys.cs | 29 ++-- .../Configurations/LogSettings.cs | 9 +- .../Configurations/MetricSettings.cs | 9 +- .../Configurations/TracerSettings.cs | 9 +- test/IntegrationTests/AspNetTests.cs | 3 +- test/IntegrationTests/GraphQLTests.cs | 3 +- test/IntegrationTests/GrpcNetClientTests.cs | 3 +- test/IntegrationTests/ModuleTests.cs | 7 +- test/IntegrationTests/SmokeTests.cs | 38 +++-- .../integration_loader_test.cpp | 136 +++--------------- .../Configurations/ConfigurationTests.cs | 84 +++-------- .../Configurations/SettingsTests.cs | 68 ++++----- .../TestApplication.CustomSdk.csproj | 2 +- tools/IntegrationsJsonGenerator/Program.cs | 57 ++++++-- 26 files changed, 320 insertions(+), 401 deletions(-) create mode 100644 src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h diff --git a/CHANGELOG.md b/CHANGELOG.md index fa9ee5e05d..ad069eb046 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,24 @@ This beta release is built on top of [OpenTelemetry .NET](https://github.com/ope to `linux-musl-x64` for Linux musl and `OpenTelemetry.AutoInstrumentation.Native.dylib` to `osx-x64` for MacOS. +- Change the way to manage enabled instrumentations. The following environmental + variables: + - `OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS`, + - `OTEL_DOTNET_AUTO_TRACES_DISABLED_INSTRUMENTATIONS`, + - `OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS`, + - `OTEL_DOTNET_AUTO_METRICS_DISABLED_INSTRUMENTATIONS`, + - `OTEL_DOTNET_AUTO_LOGS_ENABLED_INSTRUMENTATIONS`, + - `OTEL_DOTNET_AUTO_LOGS_DISABLED_INSTRUMENTATIONS` + + are replaced by: + + - `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`, + - `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED`, + - `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED`, + - `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED`, + - `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED`, + - `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED`, + - `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED`. ### Deprecated diff --git a/docs/config.md b/docs/config.md index c3ecf87770..2a10c151f5 100644 --- a/docs/config.md +++ b/docs/config.md @@ -62,15 +62,29 @@ for more details. ## Instrumentations -| Environment variable | Description | Default value | -|------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------| -| `OTEL_DOTNET_AUTO_INTEGRATIONS_FILE` | List of bytecode instrumentations JSON configuration filepaths, delimited by the platform-specific path separator (`;` on Windows, `:` on Linux and macOS). For example: `%ProfilerDirectory%/integrations.json`. It is required for bytecode instrumentations. | | -| `OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS` | Comma-separated list of traces source instrumentations you want to enable. Set to `none` to disable all trace instrumentations. | all available instrumentations | -| `OTEL_DOTNET_AUTO_TRACES_DISABLED_INSTRUMENTATIONS` | Comma-separated list of traces source and bytecode instrumentations you want to disable. | | -| `OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS` | Comma-separated list of metrics source instrumentations you want to enable. Set to `none` to disable all metric instrumentations. | all available instrumentations | -| `OTEL_DOTNET_AUTO_METRICS_DISABLED_INSTRUMENTATIONS` | Comma-separated list of metrics source instrumentations you want to disable. | | -| `OTEL_DOTNET_AUTO_LOGS_ENABLED_INSTRUMENTATIONS` | Comma-separated list of logs source instrumentations you want to enable. Set to `none` to disable all metric instrumentations. | all available instrumentations | -| `OTEL_DOTNET_AUTO_LOGS_DISABLED_INSTRUMENTATIONS` | Comma-separated list of logs source instrumentations you want to disable. | | +All instrumentations are enabled by default for all signal types +(traces, metrics, and logs). + +You can disable all instrumentations for a specific signal type by setting +the `OTEL_DOTNET_AUTO_{SIGNAL}_INSTRUMENTATION_ENABLED` +environment variable to `false`. + +For a more granular approach, you can disable specific instrumentations +for a given signal type by setting +the `OTEL_DOTNET_AUTO_{SIGNAL}_{0}_INSTRUMENTATION_ENABLED` +environment variable to `false`, where `{SIGNAL}` is the type of signal, +for example `TRACES`, and `{0}` is the case-sensitive name of the instrumentation. + +| Environment variable | Description | Default value | +|--------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------| +| `OTEL_DOTNET_AUTO_INTEGRATIONS_FILE` | List of bytecode instrumentations JSON configuration filepaths, delimited by the platform-specific path separator (`;` on Windows, `:` on Linux and macOS). For example: `%ProfilerDirectory%/integrations.json`. It is required for bytecode instrumentations. | | +| `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | Disables all instrumentations. | `true` | +| `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | Disables all trace instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific trace instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | Disables all metric instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific metric instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | Disables all log instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific log instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | ### Traces instrumentations diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/OpenTelemetry.AutoInstrumentation.Native.vcxproj b/src/OpenTelemetry.AutoInstrumentation.Native/OpenTelemetry.AutoInstrumentation.Native.vcxproj index 874bea799a..a3c025d710 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/OpenTelemetry.AutoInstrumentation.Native.vcxproj +++ b/src/OpenTelemetry.AutoInstrumentation.Native/OpenTelemetry.AutoInstrumentation.Native.vcxproj @@ -180,6 +180,7 @@ + @@ -199,6 +200,7 @@ + diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h b/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h new file mode 100644 index 0000000000..ff5763d167 --- /dev/null +++ b/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h @@ -0,0 +1,13 @@ +// Auto-generated file, do not change it - generated by the IntegrationsJsonGenerator +#ifndef BYTECODE_INSTRUMENTATIONS_H +#define BYTECODE_INSTRUMENTATIONS_H + +#include "string.h" + +namespace trace +{ +inline std::unordered_map trace_integration_names = {{WStr("StrongNamedValidation"), WStr("OTEL_DOTNET_AUTO_TRACES_StrongNamedValidation_INSTRUMENTATION_ENABLED")}, {WStr("StackExchangeRedis"), WStr("OTEL_DOTNET_AUTO_TRACES_StackExchangeRedis_INSTRUMENTATION_ENABLED")}, {WStr("NServiceBus"), WStr("OTEL_DOTNET_AUTO_TRACES_NServiceBus_INSTRUMENTATION_ENABLED")}, {WStr("MySqlData"), WStr("OTEL_DOTNET_AUTO_TRACES_MySqlData_INSTRUMENTATION_ENABLED")}, {WStr("MongoDB"), WStr("OTEL_DOTNET_AUTO_TRACES_MongoDB_INSTRUMENTATION_ENABLED")}, {WStr("GraphQL"), WStr("OTEL_DOTNET_AUTO_TRACES_GraphQL_INSTRUMENTATION_ENABLED")}}; +inline std::unordered_map metric_integration_names = {{WStr("NServiceBus"), WStr("OTEL_DOTNET_AUTO_METRICS_NServiceBus_INSTRUMENTATION_ENABLED")}}; +inline std::unordered_map log_integration_names = {{WStr("ILogger"), WStr("OTEL_DOTNET_AUTO_LOGS_ILogger_INSTRUMENTATION_ENABLED")}}; +} +#endif diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp b/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp index 7e6b8b596c..58814e46c4 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp +++ b/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp @@ -4,6 +4,7 @@ #include #include +#include "bytecode_instrumentations.h" #include "clr_helpers.h" #include "dllmain.h" #include "environment_variables.h" @@ -163,19 +164,16 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un rejit_handler = new RejitHandler(this->info_, callback); - + const bool instrumentation_enabled_by_default = AreInstrumentationsEnabledByDefault(); // load all integrations from JSON files const LoadIntegrationConfiguration configuration( AreTracesEnabled(), - GetEnvironmentValues(environment::enabled_traces_integrations), - GetEnvironmentValues(environment::disabled_traces_integrations), + GetEnabledEnvironmentValues(AreTracesInstrumentationsEnabledByDefault(instrumentation_enabled_by_default), trace_integration_names), AreMetricsEnabled(), - GetEnvironmentValues(environment::enabled_metrics_integrations), - GetEnvironmentValues(environment::disabled_metrics_integrations), + GetEnabledEnvironmentValues(AreMetricsInstrumentationsEnabledByDefault(instrumentation_enabled_by_default), metric_integration_names), AreLogsEnabled(), - GetEnvironmentValues(environment::enabled_logs_integrations), - GetEnvironmentValues(environment::disabled_logs_integrations)); + GetEnabledEnvironmentValues(AreLogsInstrumentationsEnabledByDefault(instrumentation_enabled_by_default), log_integration_names)); LoadIntegrationsFromEnvironment(integration_methods_, configuration); Logger::Debug("Number of Integrations loaded: ", integration_methods_.size()); diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables.h b/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables.h index e2bc51ae17..b5fee2336f 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables.h @@ -24,60 +24,33 @@ const WSTRING profiler_home_path = WStr("OTEL_DOTNET_AUTO_HOME"); // "MyApp.exe,dotnet.exe" const WSTRING exclude_process_names = WStr("OTEL_DOTNET_AUTO_EXCLUDE_PROCESSES"); +// Whether instrumentations are enabled. If not set (default), all instrumentations are enabled. +const WSTRING instrumentation_enabled = + WStr("OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED"); + // Whether traces are enabled or not. If not set (default), traces are enabled. const WSTRING traces_enabled = WStr("OTEL_DOTNET_AUTO_TRACES_ENABLED"); -// Sets a list of integrations to enable. If not set (default), all integrations are enabled. -// Supports multiple values separated with comma, for example: -// "ElasticsearchNet,AspNetWebApi2" -const WSTRING enabled_traces_integrations = - WStr("OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS"); - -// Sets a list of integrations to disable. Status of other integrations will remain -// unchanged. Calculation order: OTEL_DOTNET_AUTO_TRACES_DISABLED_INSTRUMENTATIONS -// then if instrumentation is not explicitly disabled OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS is checked. -// Supports multiple values separated with comma, for example: -// "ElasticsearchNet,AspNetWebApi2" -const WSTRING disabled_traces_integrations = - WStr("OTEL_DOTNET_AUTO_TRACES_DISABLED_INSTRUMENTATIONS"); +// Whether traces instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED is used. +const WSTRING traces_instrumentation_enabled = + WStr("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED"); // Whether metrics are enabled or not. If not set (default), traces are enabled. const WSTRING metrics_enabled = WStr("OTEL_DOTNET_AUTO_METRICS_ENABLED"); -// Sets a list of integrations to enable. If not set (default), all integrations are enabled. -// Supports multiple values separated with comma, for example: -// "ElasticsearchNet,AspNetWebApi2" -const WSTRING enabled_metrics_integrations = - WStr("OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS"); - -// Sets a list of integrations to disable. Status of other integrations will remain -// unchanged. Calculation order: OTEL_DOTNET_AUTO_METRICS_DISABLED_INSTRUMENTATIONS -// then if instrumentation is not explicitly disabled OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS is checked. -// Supports multiple values separated with comma, for example: -// "ElasticsearchNet,AspNetWebApi2" -const WSTRING disabled_metrics_integrations = - WStr("OTEL_DOTNET_AUTO_METRICS_DISABLED_INSTRUMENTATIONS"); +// Whether metrics instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED is used. +const WSTRING metrics_instrumentation_enabled = + WStr("OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED"); // Whether logs are enabled or not. If not set (default), logs are enabled. const WSTRING logs_enabled = WStr("OTEL_DOTNET_AUTO_LOGS_ENABLED"); -// Sets a list of integrations to enable. If not set (default), all integrations -// are enabled. Supports multiple values separated with comma, for example: -// "ElasticsearchNet,AspNetWebApi2" -const WSTRING enabled_logs_integrations = - WStr("OTEL_DOTNET_AUTO_LOGS_ENABLED_INSTRUMENTATIONS"); - -// Sets a list of integrations to disable. Status of other integrations will -// remain unchanged. Calculation order: -// OTEL_DOTNET_AUTO_LOGS_DISABLED_INSTRUMENTATIONS then if instrumentation is -// not explicitly disabled OTEL_DOTNET_AUTO_LOGS_ENABLED_INSTRUMENTATIONS is -// checked. Supports multiple values separated with comma, for example: -// "ElasticsearchNet,AspNetWebApi2" -const WSTRING disabled_logs_integrations = - WStr("OTEL_DOTNET_AUTO_LOGS_DISABLED_INSTRUMENTATIONS"); +// Whether logs instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED is used. +const WSTRING logs_instrumentation_enabled = + WStr("OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED"); // Sets the directory for the profiler's log file. // If not set, default is diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables_util.h b/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables_util.h index 1c12ac93cc..5549b036cc 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables_util.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables_util.h @@ -78,6 +78,22 @@ bool IsNetFxAssemblyRedirectionEnabled() { ToBooleanWithDefault(GetEnvironmentValue(environment::netfx_assembly_redirection_enabled), true); } +bool AreInstrumentationsEnabledByDefault() { + ToBooleanWithDefault(GetEnvironmentValue(environment::instrumentation_enabled), true); +} + +bool AreTracesInstrumentationsEnabledByDefault(const bool enabled_if_not_configured) { + ToBooleanWithDefault(GetEnvironmentValue(environment::traces_instrumentation_enabled), enabled_if_not_configured); +} + +bool AreMetricsInstrumentationsEnabledByDefault(const bool enabled_if_not_configured) { + ToBooleanWithDefault(GetEnvironmentValue(environment::metrics_instrumentation_enabled), enabled_if_not_configured); +} + +bool AreLogsInstrumentationsEnabledByDefault(const bool enabled_if_not_configured) { + ToBooleanWithDefault(GetEnvironmentValue(environment::logs_instrumentation_enabled), enabled_if_not_configured); +} + } // namespace trace -#endif // OTEL_CLR_PROFILER_ENVIRONMENT_VARIABLES_UTIL_H_ \ No newline at end of file +#endif // OTEL_CLR_PROFILER_ENVIRONMENT_VARIABLES_UTIL_H_ diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/integration_loader.cpp b/src/OpenTelemetry.AutoInstrumentation.Native/integration_loader.cpp index 3a5c857863..a7c4a1cdf7 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/integration_loader.cpp +++ b/src/OpenTelemetry.AutoInstrumentation.Native/integration_loader.cpp @@ -119,23 +119,8 @@ namespace { bool InstrumentationEnabled( const WSTRING name, - const std::vector& enabledIntegrationNames, - const std::vector& disabledIntegrationNames) + const std::vector& enabledIntegrationNames) { - // check if the integration is disabled - for (const WSTRING& disabledName : disabledIntegrationNames) - { - if (name == disabledName) - { - return false; - } - } - - if (enabledIntegrationNames.empty()) - { - return true; - } - // check if the integration is enabled for (const WSTRING& enabledName : enabledIntegrationNames) { @@ -178,7 +163,7 @@ namespace return; } - if (!InstrumentationEnabled(name, configuration.enabledTraceIntegrationNames, configuration.disabledTraceIntegrationNames)) + if (!InstrumentationEnabled(name, configuration.enabledTraceIntegrationNames)) { return; } @@ -189,7 +174,7 @@ namespace { return; } - if (!InstrumentationEnabled(name, configuration.enabledMetricIntegrationNames, configuration.disabledMetricIntegrationNames)) + if (!InstrumentationEnabled(name, configuration.enabledMetricIntegrationNames)) { return; } @@ -200,7 +185,7 @@ namespace { return; } - if (!InstrumentationEnabled(name, configuration.enabledLogIntegrationNames, configuration.disabledLogIntegrationNames)) + if (!InstrumentationEnabled(name, configuration.enabledLogIntegrationNames)) { return; } diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/integration_loader.h b/src/OpenTelemetry.AutoInstrumentation.Native/integration_loader.h index fb67736635..22f8721851 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/integration_loader.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/integration_loader.h @@ -20,33 +20,24 @@ class LoadIntegrationConfiguration { public: LoadIntegrationConfiguration(bool traces_enabled, std::vector enabled_trace_integration_names, - std::vector disabled_trace_integration_names, bool metrics_enabled, std::vector enabled_metric_integration_names, - std::vector disabled_metric_integration_names, bool logs_enabled, - std::vector enabled_log_integration_names, - std::vector disabled_log_integration_names) + std::vector enabled_log_integration_names) : traces_enabled(traces_enabled), enabledTraceIntegrationNames(std::move(enabled_trace_integration_names)), - disabledTraceIntegrationNames(std::move(disabled_trace_integration_names)), metrics_enabled(metrics_enabled), enabledMetricIntegrationNames(std::move(enabled_metric_integration_names)), - disabledMetricIntegrationNames(std::move(disabled_metric_integration_names)), logs_enabled(logs_enabled), - enabledLogIntegrationNames(std::move(enabled_log_integration_names)), - disabledLogIntegrationNames(std::move(disabled_log_integration_names)) { + enabledLogIntegrationNames(std::move(enabled_log_integration_names)) { } const bool traces_enabled; const std::vector enabledTraceIntegrationNames; - const std::vector disabledTraceIntegrationNames; const bool metrics_enabled; const std::vector enabledMetricIntegrationNames; - const std::vector disabledMetricIntegrationNames; const bool logs_enabled; const std::vector enabledLogIntegrationNames; - const std::vector disabledLogIntegrationNames; }; // LoadIntegrationsFromEnvironment loads integrations from any files specified diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/util.cpp b/src/OpenTelemetry.AutoInstrumentation.Native/util.cpp index cde66bb293..4c6d164b48 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/util.cpp +++ b/src/OpenTelemetry.AutoInstrumentation.Native/util.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -102,6 +103,30 @@ std::vector GetEnvironmentValues(const WSTRING& name) return GetEnvironmentValues(name, L','); } +std::vector GetEnabledEnvironmentValues(const bool enabled_by_default, const std::unordered_map& values_map) +{ + std::vector values; + + for (const auto& value : values_map) + { + bool enabled = enabled_by_default; + const auto env_value = GetEnvironmentValue(value.second); + if (env_value == WStr("true")) + { + enabled = true; + } + else if (env_value == WStr("false")) + { + enabled = false; + } + if (enabled) + { + values.push_back(value.first); + } + } + + return values; +} std::vector GetEnvironmentVariables(const std::vector &prefixes) { diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/util.h b/src/OpenTelemetry.AutoInstrumentation.Native/util.h index 193702ac5e..2dbca03e9c 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/util.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/util.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "string.h" @@ -35,6 +36,9 @@ std::vector GetEnvironmentValues(const WSTRING& name); // GetEnvironmentVariables returns list of all environment variable std::vector GetEnvironmentVariables(const std::vector &prefixes); +// GetEnabledEnvironmentValues returns collection of enabled elements from values_map +std::vector GetEnabledEnvironmentValues(const bool enabled_by_default, const std::unordered_map &values_map); + // Convert Hex to string WSTRING HexStr(const void* data, int len); diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs index 2c662f9c2d..8fd68e70b7 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs @@ -14,59 +14,28 @@ // limitations under the License. // +using System.Globalization; + namespace OpenTelemetry.AutoInstrumentation.Configurations; internal static class ConfigurationExtensions { - public static IList ParseEnabledEnumList(this Configuration source, string enabledConfiguration, string disabledConfiguration, string error) + public static IList ParseEnabledEnumList(this Configuration source, bool enabledByDefault, string enabledConfigurationTemplate) where TEnum : struct, Enum, IConvertible { - var instrumentations = new Dictionary(); - var enabledInstrumentations = source.GetString(enabledConfiguration); - if (enabledInstrumentations != null) - { - if (enabledInstrumentations == Constants.ConfigurationValues.None) - { - return Array.Empty(); - } + var allConfigurations = Enum.GetValues(typeof(TEnum)).Cast().ToArray(); + var enabledConfigurations = new List(allConfigurations.Length); - foreach (var instrumentation in enabledInstrumentations.Split(Constants.ConfigurationValues.Separator)) - { - if (Enum.TryParse(instrumentation, out TEnum parsedType)) - { - instrumentations[instrumentation] = parsedType; - } - else - { - throw new FormatException(string.Format(error, instrumentation)); - } - } - } - else + foreach (var configuration in allConfigurations) { - instrumentations = Enum.GetValues(typeof(TEnum)) - .Cast() - .ToDictionary( - key => Enum.GetName(typeof(TEnum), key)!, - val => val); - } + var configurationEnabled = source.GetBool(string.Format(CultureInfo.InvariantCulture, enabledConfigurationTemplate, configuration)) ?? enabledByDefault; - var disabledInstrumentations = source.GetString(disabledConfiguration); - if (disabledInstrumentations != null) - { - foreach (var instrumentation in disabledInstrumentations.Split(Constants.ConfigurationValues.Separator)) + if (configurationEnabled) { - if (Enum.TryParse(instrumentation, out TEnum _)) - { - instrumentations.Remove(instrumentation); - } - else - { - throw new FormatException(string.Format(error, instrumentation)); - } + enabledConfigurations.Add(configuration); } } - return instrumentations.Values.ToList(); + return enabledConfigurations; } } diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs index 2c41956add..f42066e470 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs @@ -55,6 +55,11 @@ internal static class ConfigurationKeys /// public const string SetupSdk = "OTEL_DOTNET_AUTO_SETUP_SDK"; + /// + /// Configuration key for enabling all instrumentations. + /// + public const string InstrumentationEnabled = "OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED"; + /// /// Configuration keys for traces. /// @@ -82,14 +87,14 @@ public static class Traces public const string ConsoleExporterEnabled = "OTEL_DOTNET_AUTO_TRACES_CONSOLE_EXPORTER_ENABLED"; /// - /// Configuration key for comma separated list of enabled trace instrumentations. + /// Configuration key for disabling all trace instrumentations. /// - public const string Instrumentations = "OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS"; + public const string TracesInstrumentationEnabled = "OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED"; /// - /// Configuration key for comma separated list of disabled trace instrumentations. + /// Configuration key template for disabled trace instrumentations. /// - public const string DisabledInstrumentations = "OTEL_DOTNET_AUTO_TRACES_DISABLED_INSTRUMENTATIONS"; + public const string EnabledTracesInstrumentationTemplate = "OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED"; /// /// Configuration key for additional names to be added to the tracer at the startup. @@ -146,14 +151,14 @@ public static class Metrics public const string ConsoleExporterEnabled = "OTEL_DOTNET_AUTO_METRICS_CONSOLE_EXPORTER_ENABLED"; /// - /// Configuration key for comma separated list of enabled metric instrumentations. + /// Configuration key for disabling all metrics instrumentations. /// - public const string Instrumentations = "OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS"; + public const string MetricsInstrumentationEnabled = "OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED"; /// - /// Configuration key for comma separated list of disabled metric instrumentations. + /// Configuration key template for enabled metric instrumentations. /// - public const string DisabledInstrumentations = "OTEL_DOTNET_AUTO_METRICS_DISABLED_INSTRUMENTATIONS"; + public const string EnabledMetricsInstrumentationTemplate = "OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED"; /// /// Configuration key for additional names to be added to the meter at the startup. @@ -189,14 +194,14 @@ public static class Logs public const string IncludeFormattedMessage = "OTEL_DOTNET_AUTO_LOGS_INCLUDE_FORMATTED_MESSAGE"; /// - /// Configuration key for comma separated list of enabled logs instrumentations. + /// Configuration key for disabling all log instrumentations. /// - public const string Instrumentations = "OTEL_DOTNET_AUTO_LOGS_ENABLED_INSTRUMENTATIONS"; + public const string LogsInstrumentationEnabled = "OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED"; /// - /// Configuration key for comma separated list of disabled logs instrumentations. + /// Configuration key template for enabled log instrumentations. /// - public const string DisabledInstrumentations = "OTEL_DOTNET_AUTO_LOGS_DISABLED_INSTRUMENTATIONS"; + public const string EnabledLogsInstrumentationTemplate = "OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED"; } /// diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs index 2267277130..121cd7035e 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs @@ -53,10 +53,13 @@ protected override void OnLoad(Configuration configuration) ConsoleExporterEnabled = configuration.GetBool(ConfigurationKeys.Logs.ConsoleExporterEnabled) ?? false; IncludeFormattedMessage = configuration.GetBool(ConfigurationKeys.Logs.IncludeFormattedMessage) ?? false; + var instrumentationEnabledByDefault = + configuration.GetBool(ConfigurationKeys.Logs.LogsInstrumentationEnabled) ?? + configuration.GetBool(ConfigurationKeys.InstrumentationEnabled) ?? true; + EnabledInstrumentations = configuration.ParseEnabledEnumList( - enabledConfiguration: ConfigurationKeys.Logs.Instrumentations, - disabledConfiguration: ConfigurationKeys.Logs.DisabledInstrumentations, - error: "The \"{0}\" is not recognized as supported logs instrumentation and cannot be enabled or disabled."); + enabledByDefault: instrumentationEnabledByDefault, + enabledConfigurationTemplate: ConfigurationKeys.Logs.EnabledLogsInstrumentationTemplate); } private static LogExporter ParseLogExporter(Configuration configuration) diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs index de30770c28..64be6ace47 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs @@ -51,10 +51,13 @@ protected override void OnLoad(Configuration configuration) MetricExporter = ParseMetricExporter(configuration); ConsoleExporterEnabled = configuration.GetBool(ConfigurationKeys.Metrics.ConsoleExporterEnabled) ?? false; + var instrumentationEnabledByDefault = + configuration.GetBool(ConfigurationKeys.Metrics.MetricsInstrumentationEnabled) ?? + configuration.GetBool(ConfigurationKeys.InstrumentationEnabled) ?? true; + EnabledInstrumentations = configuration.ParseEnabledEnumList( - enabledConfiguration: ConfigurationKeys.Metrics.Instrumentations, - disabledConfiguration: ConfigurationKeys.Metrics.DisabledInstrumentations, - error: "The \"{0}\" is not recognized as supported metrics instrumentation and cannot be enabled or disabled."); + enabledByDefault: instrumentationEnabledByDefault, + enabledConfigurationTemplate: ConfigurationKeys.Metrics.EnabledMetricsInstrumentationTemplate); var additionalSources = configuration.GetString(ConfigurationKeys.Metrics.AdditionalSources); if (additionalSources != null) diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs index e722f1135b..99b2f3ba86 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs @@ -76,10 +76,13 @@ protected override void OnLoad(Configuration configuration) TracesExporter = ParseTracesExporter(configuration); ConsoleExporterEnabled = configuration.GetBool(ConfigurationKeys.Traces.ConsoleExporterEnabled) ?? false; + var instrumentationEnabledByDefault = + configuration.GetBool(ConfigurationKeys.Traces.TracesInstrumentationEnabled) ?? + configuration.GetBool(ConfigurationKeys.InstrumentationEnabled) ?? true; + EnabledInstrumentations = configuration.ParseEnabledEnumList( - enabledConfiguration: ConfigurationKeys.Traces.Instrumentations, - disabledConfiguration: ConfigurationKeys.Traces.DisabledInstrumentations, - error: "The \"{0}\" is not recognized as supported trace instrumentation and cannot be enabled or disabled."); + enabledByDefault: instrumentationEnabledByDefault, + enabledConfigurationTemplate: ConfigurationKeys.Traces.EnabledTracesInstrumentationTemplate); var additionalSources = configuration.GetString(ConfigurationKeys.Traces.AdditionalSources); if (additionalSources != null) diff --git a/test/IntegrationTests/AspNetTests.cs b/test/IntegrationTests/AspNetTests.cs index 7bcadde9cb..b1fcbf3d04 100644 --- a/test/IntegrationTests/AspNetTests.cs +++ b/test/IntegrationTests/AspNetTests.cs @@ -108,7 +108,8 @@ public async Task SubmitMetrics() _environmentVariables["OTEL_METRICS_EXPORTER"] = "otlp"; _environmentVariables["OTEL_EXPORTER_OTLP_ENDPOINT"] = collectorUrl; _environmentVariables["OTEL_METRIC_EXPORT_INTERVAL"] = "1000"; - _environmentVariables["OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS"] = "AspNet"; // Helps to reduce noise by enabling only AspNet metrics. + _environmentVariables["OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED"] = "false"; // Helps to reduce noise by enabling only AspNet metrics. + _environmentVariables["OTEL_DOTNET_AUTO_METRICS_AspNet_INSTRUMENTATION_ENABLED"] = "true"; // Helps to reduce noise by enabling only AspNet metrics. var webPort = TcpPortProvider.GetOpenPort(); await using var container = await StartContainerAsync(webPort); await CallTestApplicationEndpoint(webPort); diff --git a/test/IntegrationTests/GraphQLTests.cs b/test/IntegrationTests/GraphQLTests.cs index 6ac59207ac..ae726759bb 100644 --- a/test/IntegrationTests/GraphQLTests.cs +++ b/test/IntegrationTests/GraphQLTests.cs @@ -60,7 +60,8 @@ public async Task SubmitsTraces(bool setDocument) Expect(collector, spanName: "subscription NotImplementedSub", graphQLOperationType: "subscription", graphQLOperationName: "NotImplementedSub", graphQLDocument: "subscription NotImplementedSub{throwNotImplementedException{name}}", setDocument: setDocument, verifyFailure: VerifyNotImplementedException); SetEnvironmentVariable("OTEL_DOTNET_AUTO_GRAPHQL_SET_DOCUMENT", setDocument.ToString()); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS", "GraphQL"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_GraphQL_INSTRUMENTATION_ENABLED", "true"); SetEnvironmentVariable("OTEL_TRACES_SAMPLER", "always_on"); SetEnvironmentVariable("OTEL_DOTNET_AUTO_NETFX_REDIRECT_ENABLED", "false"); diff --git a/test/IntegrationTests/GrpcNetClientTests.cs b/test/IntegrationTests/GrpcNetClientTests.cs index 4e675c9f70..64e7724115 100644 --- a/test/IntegrationTests/GrpcNetClientTests.cs +++ b/test/IntegrationTests/GrpcNetClientTests.cs @@ -37,7 +37,8 @@ public void SubmitsTraces() // Grpc.Net.Client is using various version of http communication under the hood. // Enabling only GrpcNetClient instrumentation to have consistent set of spans. - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS", "GrpcNetClient"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_GrpcNetClient_INSTRUMENTATION_ENABLED", "true"); RunTestApplication(); collector.AssertExpectations(); diff --git a/test/IntegrationTests/ModuleTests.cs b/test/IntegrationTests/ModuleTests.cs index 0437b37a83..2341a4b23b 100644 --- a/test/IntegrationTests/ModuleTests.cs +++ b/test/IntegrationTests/ModuleTests.cs @@ -14,14 +14,10 @@ // limitations under the License. // -using System.IO; -using System.Threading.Tasks; using IntegrationTests.Helpers; using Newtonsoft.Json; using OpenTelemetry.AutoInstrumentation; using OpenTelemetry.AutoInstrumentation.Configurations; -using VerifyXunit; -using Xunit; using Xunit.Abstractions; namespace IntegrationTests; @@ -73,8 +69,7 @@ public async Task DefaultNoExporters() [Fact] public async Task Minimal() { - SetEnvironmentVariable(ConfigurationKeys.Traces.Instrumentations, Constants.ConfigurationValues.None); - SetEnvironmentVariable(ConfigurationKeys.Metrics.Instrumentations, Constants.ConfigurationValues.None); + SetEnvironmentVariable(ConfigurationKeys.InstrumentationEnabled, "false"); SetEnvironmentVariable(ConfigurationKeys.Traces.Exporter, Constants.ConfigurationValues.None); SetEnvironmentVariable(ConfigurationKeys.Metrics.Exporter, Constants.ConfigurationValues.None); SetEnvironmentVariable(ConfigurationKeys.Logs.Exporter, Constants.ConfigurationValues.None); diff --git a/test/IntegrationTests/SmokeTests.cs b/test/IntegrationTests/SmokeTests.cs index 4782b947af..ee5898a710 100644 --- a/test/IntegrationTests/SmokeTests.cs +++ b/test/IntegrationTests/SmokeTests.cs @@ -35,7 +35,6 @@ public SmokeTests(ITestOutputHelper output) : base("Smoke", output) { SetEnvironmentVariable("OTEL_SERVICE_NAME", ServiceName); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS", "HttpClient"); } [Fact] @@ -53,7 +52,7 @@ public void WhenStartupHookIsNotEnabled() #if NETFRAMEWORK VerifyTestApplicationInstrumented(); #else - // on .NET Core it is required to set DOTNET_STARTUP_HOOKS + // on .NET it is required to set DOTNET_STARTUP_HOOKS VerifyTestApplicationNotInstrumented(); #endif } @@ -119,6 +118,7 @@ public void TracesResource() collector.ResourceExpector.Expect("telemetry.sdk.version", typeof(OpenTelemetry.Resources.Resource).Assembly.GetCustomAttribute()!.Version); collector.ResourceExpector.Expect("telemetry.auto.version", OpenTelemetry.AutoInstrumentation.Constants.Tracer.Version); + EnableOnlyHttpClientTraceInstrumentation(); SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES", "MyCompany.MyProduct.MyLibrary"); RunTestApplication(); @@ -137,6 +137,7 @@ public void MetricsResource() collector.ResourceExpector.Expect("telemetry.sdk.version", typeof(OpenTelemetry.Resources.Resource).Assembly.GetCustomAttribute()!.Version); collector.ResourceExpector.Expect("telemetry.auto.version", OpenTelemetry.AutoInstrumentation.Constants.Tracer.Version); + EnableOnlyHttpClientTraceInstrumentation(); SetEnvironmentVariable("OTEL_DOTNET_AUTO_METRICS_ADDITIONAL_SOURCES", "MyCompany.MyProduct.MyLibrary"); RunTestApplication(); @@ -156,6 +157,7 @@ public void LogsResource() collector.ResourceExpector.Expect("telemetry.sdk.version", typeof(OpenTelemetry.Resources.Resource).Assembly.GetCustomAttribute()!.Version); collector.ResourceExpector.Expect("telemetry.auto.version", OpenTelemetry.AutoInstrumentation.Constants.Tracer.Version); + EnableOnlyHttpClientTraceInstrumentation(); EnableBytecodeInstrumentation(); RunTestApplication(); @@ -171,6 +173,7 @@ public void OtlpTracesExporter() SetExporter(collector); collector.Expect("MyCompany.MyProduct.MyLibrary", span => span.Name == "SayHello"); + EnableOnlyHttpClientTraceInstrumentation(); SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES", "MyCompany.MyProduct.MyLibrary"); RunTestApplication(); @@ -184,6 +187,7 @@ public void ZipkinExporter() using var collector = new MockZipkinCollector(Output); collector.Expect(span => span.Name == "SayHello" && span.Tags?.GetValueOrDefault("otel.library.name") == "MyCompany.MyProduct.MyLibrary"); + EnableOnlyHttpClientTraceInstrumentation(); SetEnvironmentVariable("OTEL_TRACES_EXPORTER", "zipkin"); SetEnvironmentVariable("OTEL_EXPORTER_ZIPKIN_ENDPOINT", $"http://localhost:{collector.Port}/api/v2/spans"); SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES", "MyCompany.MyProduct.MyLibrary"); @@ -197,6 +201,7 @@ public void ZipkinExporter() [Trait("Category", "EndToEnd")] public void PrometheusExporter() { + EnableOnlyHttpClientTraceInstrumentation(); SetEnvironmentVariable("LONG_RUNNING", "true"); SetEnvironmentVariable("OTEL_METRICS_EXPORTER", "prometheus"); SetEnvironmentVariable("OTEL_DOTNET_AUTO_METRICS_ADDITIONAL_SOURCES", "MyCompany.MyProduct.MyLibrary"); @@ -249,6 +254,7 @@ public void SubmitLogs() SetExporter(collector); collector.Expect(logRecord => Convert.ToString(logRecord.Body) == "{ \"stringValue\": \"Example log message\" }"); + EnableOnlyHttpClientTraceInstrumentation(); SetEnvironmentVariable("OTEL_DOTNET_AUTO_LOGS_INCLUDE_FORMATTED_MESSAGE", "true"); EnableBytecodeInstrumentation(); RunTestApplication(); @@ -257,7 +263,8 @@ public void SubmitLogs() } [Theory] - [InlineData("OTEL_DOTNET_AUTO_LOGS_ENABLED_INSTRUMENTATIONS", "none")] + [InlineData("OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED", "false")] + [InlineData("OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED", "false")] [InlineData("OTEL_DOTNET_AUTO_LOGS_ENABLED", "false")] [InlineData("OTEL_LOGS_EXPORTER", "none")] [Trait("Category", "EndToEnd")] @@ -266,6 +273,7 @@ public void LogsNoneInstrumentations(string envVarName, string envVarVal) using var collector = new MockLogsCollector(Output); SetExporter(collector); + EnableOnlyHttpClientTraceInstrumentation(); SetEnvironmentVariable(envVarName, envVarVal); EnableBytecodeInstrumentation(); RunTestApplication(); @@ -276,8 +284,8 @@ public void LogsNoneInstrumentations(string envVarName, string envVarVal) #endif [Theory] - [InlineData("OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS", "none")] - [InlineData("OTEL_DOTNET_AUTO_TRACES_ENABLED", "false")] + [InlineData("OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED", "false")] + [InlineData("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false")] [InlineData("OTEL_TRACES_EXPORTER", "none")] [Trait("Category", "EndToEnd")] public void TracesNoneInstrumentations(string envVarName, string envVarVal) @@ -290,7 +298,8 @@ public void TracesNoneInstrumentations(string envVarName, string envVarVal) } [Theory] - [InlineData("OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS", "none")] + [InlineData("OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED", "false")] + [InlineData("OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED", "false")] [InlineData("OTEL_DOTNET_AUTO_METRICS_ENABLED", "false")] [InlineData("OTEL_METRICS_EXPORTER", "none")] [Trait("Category", "EndToEnd")] @@ -298,6 +307,7 @@ public void MetricsNoneInstrumentations(string envVarName, string envVarVal) { using var collector = new MockMetricsCollector(Output); SetExporter(collector); + EnableOnlyHttpClientTraceInstrumentation(); SetEnvironmentVariable(envVarName, envVarVal); RunTestApplication(); collector.AssertEmpty(); @@ -309,6 +319,7 @@ public void LogsDisabledInstrumentation() { using var collector = new MockLogsCollector(Output); SetEnvironmentVariable("OTEL_DOTNET_AUTO_LOGS_DISABLED_INSTRUMENTATIONS", "ILogger"); + EnableOnlyHttpClientTraceInstrumentation(); EnableBytecodeInstrumentation(); RunTestApplication(); collector.AssertEmpty(); @@ -319,8 +330,8 @@ public void LogsDisabledInstrumentation() public void MetricsDisabledInstrumentation() { using var collector = new MockMetricsCollector(Output); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS", "HttpClient"); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_METRICS_DISABLED_INSTRUMENTATIONS", "HttpClient"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_METRICS_HttpClient_INSTRUMENTATION_ENABLED", "false"); + EnableOnlyHttpClientTraceInstrumentation(); EnableBytecodeInstrumentation(); RunTestApplication(); collector.AssertEmpty(); @@ -332,7 +343,8 @@ public void TracesDisabledInstrumentation() { using var collector = new MockSpansCollector(Output); SetExporter(collector); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_DISABLED_INSTRUMENTATIONS", "AspNet,HttpClient"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_AspNet_INSTRUMENTATION_ENABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_HttpClient_INSTRUMENTATION_ENABLED", "false"); RunTestApplication(); collector.AssertEmpty(); } @@ -350,6 +362,7 @@ private void VerifyTestApplicationInstrumented() collector.Expect("OpenTelemetry.Instrumentation.Http.HttpClient"); #endif + EnableOnlyHttpClientTraceInstrumentation(); SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES", "MyCompany.MyProduct.MyLibrary"); RunTestApplication(); @@ -361,9 +374,16 @@ private void VerifyTestApplicationNotInstrumented() using var collector = new MockSpansCollector(Output); SetExporter(collector); + EnableOnlyHttpClientTraceInstrumentation(); SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES", "MyCompany.MyProduct.MyLibrary"); RunTestApplication(); collector.AssertEmpty(); } + + private void EnableOnlyHttpClientTraceInstrumentation() + { + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_HttpClient_INSTRUMENTATION_ENABLED", "true"); + } } diff --git a/test/OpenTelemetry.AutoInstrumentation.Native.Tests/integration_loader_test.cpp b/test/OpenTelemetry.AutoInstrumentation.Native.Tests/integration_loader_test.cpp index 28ceaacf47..b7d2e70a8b 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Native.Tests/integration_loader_test.cpp +++ b/test/OpenTelemetry.AutoInstrumentation.Native.Tests/integration_loader_test.cpp @@ -16,7 +16,7 @@ using namespace trace; TEST(IntegrationLoaderTest, HandlesMissingFile) { std::vector integrations; - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {}, true, {}, true, {}); LoadIntegrationsFromFile(L"missing-file", integrations, configuration); EXPECT_EQ(0, integrations.size()); } @@ -25,7 +25,7 @@ TEST(IntegrationLoaderTest, HandlesInvalidIntegrationNoName) { std::vector integrations; std::stringstream str("[{}]"); - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {}, true, {}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); // 0 because name is required EXPECT_EQ(0, integrations.size()); @@ -35,7 +35,7 @@ TEST(IntegrationLoaderTest, HandlesInvalidIntegrationBadJson) { std::vector integrations; std::stringstream str("["); - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {}, true, {}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); EXPECT_EQ(0, integrations.size()); } @@ -44,7 +44,7 @@ TEST(IntegrationLoaderTest, HandlesInvalidIntegrationNotAnObject) { std::vector integrations; std::stringstream str("[1,2,3]"); - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {}, true, {}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); EXPECT_EQ(0, integrations.size()); } @@ -55,7 +55,7 @@ TEST(IntegrationLoaderTest, HandlesInvalidIntegrationNotAnArray) std::stringstream str(R"TEXT( {"name": "test-integration"} )TEXT"); - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {L"test-integration"}, true, {}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); EXPECT_EQ(0, integrations.size()); } @@ -75,7 +75,7 @@ TEST(IntegrationLoaderTest, HandlesSingleIntegrationWithMethodReplacements) }] )TEXT"); - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {L"test-integration"}, true, {}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); EXPECT_EQ(1, integrations.size()); EXPECT_STREQ(L"test-integration", integrations[0].integration_name.c_str()); @@ -96,7 +96,7 @@ TEST(IntegrationLoaderTest, DoesNotCrashWithOutOfRangeVersion) }] )TEXT"); - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {L"test-integration"}, true, {}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); EXPECT_EQ(1, integrations.size()); EXPECT_STREQ(L"test-integration", integrations[0].integration_name.c_str()); @@ -128,7 +128,7 @@ TEST(IntegrationLoaderTest, HandlesSingleIntegrationWithMissingCaller) }] )TEXT"); - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {L"test-integration"}, true, {}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); EXPECT_EQ(1, integrations.size()); EXPECT_STREQ(L"test-integration", integrations[0].integration_name.c_str()); @@ -167,7 +167,7 @@ TEST(IntegrationLoaderTest, HandlesSingleIntegrationWithInvalidTarget) }] )TEXT"); - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {L"test-integration"}, true, {}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); EXPECT_EQ(1, integrations.size()); EXPECT_STREQ(L"test-integration", integrations[0].integration_name.c_str()); @@ -201,7 +201,7 @@ TEST(IntegrationLoaderTest, LoadsFromEnvironment) const std::vector expected_names = {L"test-integration-1", L"test-integration-2"}; std::vector actual_names; std::vector integrations; - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {L"test-integration-1", L"test-integration-2"}, true, {}, true, {}); LoadIntegrationsFromEnvironment(integrations, configuration); for (auto& integration : integrations) { @@ -228,7 +228,7 @@ TEST(IntegrationLoaderTest, DeserializesSignatureTypeArray) }] )TEXT"); - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {L"test-integration"}, true, {}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); const auto target = integrations[0].replacement.target_method; EXPECT_STREQ(L"System.Void", target.signature_types[0].c_str()); @@ -247,7 +247,7 @@ TEST(IntegrationLoaderTest, SupportsEnabledTraceIntegrations) { const std::vector expected_names = {L"test-trace-integration-2"}; std::vector actual_names; - const LoadIntegrationConfiguration configuration(true, {L"test-trace-integration-2"}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {L"test-trace-integration-2"}, true, {}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); for (auto& integration : integrations) { @@ -268,8 +268,7 @@ TEST(IntegrationLoaderTest, SupportsEnabledMetricIntegrations) { const std::vector expected_names = { L"test-metric-integration-2"}; std::vector actual_names; - const LoadIntegrationConfiguration configuration( - true, {}, {}, true, {L"test-metric-integration-2"}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {}, true, {L"test-metric-integration-2"}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); for (auto& integration : integrations) { actual_names.push_back(integration.integration_name); @@ -289,7 +288,7 @@ TEST(IntegrationLoaderTest, SupportsEnabledLogIntegrations) const std::vector expected_names = {L"test-log-integration-2"}; std::vector actual_names; - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {L"test-log-integration-2"}, {}); + const LoadIntegrationConfiguration configuration(true, {}, true, {}, true, {L"test-log-integration-2"}); LoadIntegrationsFromStream(str, integrations, configuration); for (auto& integration : integrations) { @@ -298,109 +297,6 @@ TEST(IntegrationLoaderTest, SupportsEnabledLogIntegrations) EXPECT_EQ(expected_names, actual_names); } -TEST(IntegrationLoaderTest, SupportsDisabledTraceIntegrations) -{ - std::vector integrations; - std::stringstream str(R"TEXT( - [ - { "name": "test-trace-integration-1", "type": "Trace", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-trace-integration-2", "type": "Trace", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] } - ] - )TEXT"); - - const std::vector expected_names = {L"test-trace-integration-1"}; - std::vector actual_names; - const LoadIntegrationConfiguration configuration( - true, {}, {L"test-trace-integration-2"}, true, {}, {}, true, {}, {}); - LoadIntegrationsFromStream(str, integrations, configuration); - for (auto& integration : integrations) - { - actual_names.push_back(integration.integration_name); - } - EXPECT_EQ(expected_names, actual_names); -} - -TEST(IntegrationLoaderTest, SupportsDisabledMetricIntegrations) -{ - std::vector integrations; - std::stringstream str(R"TEXT( - [ - { "name": "test-metric-integration-1", "type": "Metric", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-metric-integration-2", "type": "Metric", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] } - ] - )TEXT"); - - const std::vector expected_names = {L"test-metric-integration-1"}; - std::vector actual_names; - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {L"test-metric-integration-2"}, true, {}, {}); - LoadIntegrationsFromStream(str, integrations, configuration); - for (auto& integration : integrations) - { - actual_names.push_back(integration.integration_name); - } - EXPECT_EQ(expected_names, actual_names); -} - -TEST(IntegrationLoaderTest, SupportsDisabledLogIntegrations) -{ - std::vector integrations; - std::stringstream str(R"TEXT( - [ - { "name": "test-log-integration-1", "type": "Log", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-log-integration-2", "type": "Log", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] } - ] - )TEXT"); - - const std::vector expected_names = {L"test-log-integration-1"}; - std::vector actual_names; - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {L"test-log-integration-2"}); - LoadIntegrationsFromStream(str, integrations, configuration); - for (auto& integration : integrations) - { - actual_names.push_back(integration.integration_name); - } - EXPECT_EQ(expected_names, actual_names); -} - -TEST(IntegrationLoaderTest, SupportsEnabledAndDisabledIntegrations) -{ - std::vector integrations; - std::stringstream str(R"TEXT( - [ - { "name": "test-trace-integration-1", "type": "Trace", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-trace-integration-2", "type": "Trace", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-trace-integration-3", "type": "Trace", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-metric-integration-1", "type": "Metric", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-metric-integration-2", "type": "Metric", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-metric-integration-3", "type": "Metric", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-log-integration-1", "type": "Log", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-log-integration-2", "type": "Log", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-log-integration-3", "type": "Log", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] } - ] - )TEXT"); - - const std::vector expected_names = {L"test-trace-integration-1", L"test-log-integration-1", L"test-metric-integration-1"}; - std::vector actual_names; - const LoadIntegrationConfiguration configuration( - true, - {L"test-trace-integration-1", L"test-trace-integration-2"}, - {L"test-trace-integration-2", L"test-trace-integration-3"}, - true, - {L"test-metric-integration-1", L"test-metric-integration-2"}, - {L"test-metric-integration-2", L"test-metric-integration-3"}, - true, - {L"test-log-integration-1", L"test-log-integration-2"}, - {L"test-log-integration-2", L"test-log-integration-3"}); - - LoadIntegrationsFromStream(str, integrations, configuration); - - for (auto& integration : integrations) - { - actual_names.push_back(integration.integration_name); - } - EXPECT_EQ(expected_names, actual_names); -} - TEST(IntegrationLoaderTest, SupportsDisableAllIntegrations) { std::vector integrations; std::stringstream str(R"TEXT( @@ -413,7 +309,7 @@ TEST(IntegrationLoaderTest, SupportsDisableAllIntegrations) { const std::vector expected_names = {}; std::vector actual_names; - const LoadIntegrationConfiguration configuration(false, {}, {}, false, {}, {}, false, {}, {}); + const LoadIntegrationConfiguration configuration(false, {}, false, {}, false, {}); LoadIntegrationsFromStream(str, integrations, configuration); for (auto& integration : integrations) { @@ -435,7 +331,7 @@ TEST(IntegrationLoaderTest, DuplicatedIntegrations) { ] )TEXT"); - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {L"test-integration-1"}, true, {L"test-integration-1"}, true, {L"test-integration-1"}); LoadIntegrationsFromStream(str, integrations, configuration); EXPECT_EQ(4, integrations.size()); diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs index d1afe8fb1d..6a1a5f722c 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs @@ -33,106 +33,66 @@ private enum TestEnum } [Fact] - public void ParseEnabledEnumList_Default() + public void ParseEnabledEnumList_Default_Enabled() { var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection())); var list = source.ParseEnabledEnumList( - enabledConfiguration: "TEST_ENABLED_VALUES", - disabledConfiguration: "TEST_DISABLED_VALUES", - error: "Invalid enum value: {0}"); + enabledByDefault: true, + enabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_ENABLED"); list.Should().Equal(TestEnum.Test1, TestEnum.Test2, TestEnum.Test3); } [Fact] - public void ParseEnabledEnumList_Enabled() + public void ParseEnabledEnumList_Default_Disabled() { - var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection() - { - { "TEST_ENABLED_VALUES", "Test1,Test3" } - })); + var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection())); var list = source.ParseEnabledEnumList( - enabledConfiguration: "TEST_ENABLED_VALUES", - disabledConfiguration: "TEST_DISABLED_VALUES", - error: "Invalid enum value: {0}"); + enabledByDefault: false, + enabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_ENABLED"); - list.Should().Equal(TestEnum.Test1, TestEnum.Test3); + list.Should().BeEmpty(); } [Fact] - public void ParseEnabledEnumList_Disabled() + public void ParseEnabledEnumList_SelectivelyEnabled() { - var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection() + var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection { - { "TEST_DISABLED_VALUES", "Test2" } + { "TEST_CONFIGURATION_Test1_ENABLED", "true" }, + { "TEST_CONFIGURATION_Test3_ENABLED", "true" } })); var list = source.ParseEnabledEnumList( - enabledConfiguration: "TEST_ENABLED_VALUES", - disabledConfiguration: "TEST_DISABLED_VALUES", - error: "Invalid enum value: {0}"); + enabledByDefault: false, + enabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_ENABLED"); list.Should().Equal(TestEnum.Test1, TestEnum.Test3); } [Fact] - public void ParseEnabledEnumList_None() + public void ParseEnabledEnumList_SelectivelyDisabled() { - var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection() + var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection { - { "TEST_ENABLED_VALUES", "none" } + { "TEST_CONFIGURATION_Test2_ENABLED", "false" }, })); var list = source.ParseEnabledEnumList( - enabledConfiguration: "TEST_ENABLED_VALUES", - disabledConfiguration: "TEST_DISABLED_VALUES", - error: "Invalid enum value: {0}"); - - list.Should().BeEmpty(); - } + enabledByDefault: true, + enabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_ENABLED"); - [Fact] - public void ParseEnabledEnumList_Invalid() - { - var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection() - { - { "TEST_ENABLED_VALUES", "invalid" } - })); - - var act = () => source.ParseEnabledEnumList( - enabledConfiguration: "TEST_ENABLED_VALUES", - disabledConfiguration: "TEST_DISABLED_VALUES", - error: "Invalid enum value: {0}"); - - act.Should().Throw() - .WithMessage("Invalid enum value: invalid"); - } - - [Fact] - public void ParseDisabledEnumList_Invalid() - { - var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection() - { - { "TEST_DISABLED_VALUES", "invalid" } - })); - - var act = () => source.ParseEnabledEnumList( - enabledConfiguration: "TEST_ENABLED_VALUES", - disabledConfiguration: "TEST_DISABLED_VALUES", - error: "Invalid enum value: {0}"); - - act.Should().Throw() - .WithMessage("Invalid enum value: invalid"); + list.Should().Equal(TestEnum.Test1, TestEnum.Test3); } [Fact] public void ParseEmptyAsNull_CompositeConfigurationSource() { var mockSource = new Mock(); - mockSource.Setup(x => x.GetString(It.Is(x => x == "TEST_NULL_VALUE"))).Returns(k => null); - mockSource.Setup(x => x.GetString(It.Is(x => x == "TEST_EMPTY_VALUE"))).Returns(k => string.Empty); + mockSource.Setup(x => x.GetString(It.Is(key => key == "TEST_NULL_VALUE"))).Returns(_ => null); + mockSource.Setup(x => x.GetString(It.Is(key => key == "TEST_EMPTY_VALUE"))).Returns(_ => string.Empty); var compositeSource = new Configuration(mockSource.Object); using (new AssertionScope()) diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs index d01d817317..aaec6e88a3 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs @@ -32,9 +32,7 @@ public SettingsTests() public static IEnumerable ExporterEnvVarAndLoadSettingsAction() { yield return new object[] { ConfigurationKeys.Traces.Exporter, new Action(() => Settings.FromDefaultSources()) }; - yield return new object[] { ConfigurationKeys.Traces.Instrumentations, new Action(() => Settings.FromDefaultSources()) }; yield return new object[] { ConfigurationKeys.Metrics.Exporter, new Action(() => Settings.FromDefaultSources()) }; - yield return new object[] { ConfigurationKeys.Metrics.Instrumentations, new Action(() => Settings.FromDefaultSources()) }; yield return new object[] { ConfigurationKeys.Logs.Exporter, new Action(() => Settings.FromDefaultSources()) }; yield return new object[] { ConfigurationKeys.Sdk.Propagators, new Action(() => Settings.FromDefaultSources()) }; } @@ -199,24 +197,14 @@ internal void Propagators_SupportedValues(string propagators, Propagator[] expec #endif internal void TracerSettings_Instrumentations_SupportedValues(string tracerInstrumentation, TracerInstrumentation expectedTracerInstrumentation) { - Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.Instrumentations, tracerInstrumentation); + Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesInstrumentationEnabled, "false"); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Traces.EnabledTracesInstrumentationTemplate, tracerInstrumentation), "true"); var settings = Settings.FromDefaultSources(); settings.EnabledInstrumentations.Should().BeEquivalentTo(new List { expectedTracerInstrumentation }); } - [Fact] - internal void TracerSettings_DisabledInstrumentations() - { - Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.Instrumentations, $"{nameof(TracerInstrumentation.AspNet)},{nameof(TracerInstrumentation.GraphQL)}"); - Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.DisabledInstrumentations, nameof(TracerInstrumentation.GraphQL)); - - var settings = Settings.FromDefaultSources(); - - settings.EnabledInstrumentations.Should().BeEquivalentTo(new List { TracerInstrumentation.AspNet }); - } - [Fact] internal void TracerSettings_TracerSampler() { @@ -240,45 +228,26 @@ internal void TracerSettings_TracerSampler() [InlineData(nameof(MetricInstrumentation.NServiceBus), MetricInstrumentation.NServiceBus)] internal void MeterSettings_Instrumentations_SupportedValues(string meterInstrumentation, MetricInstrumentation expectedMetricInstrumentation) { - Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.Instrumentations, meterInstrumentation); + Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.MetricsInstrumentationEnabled, "false"); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Metrics.EnabledMetricsInstrumentationTemplate, meterInstrumentation), "true"); var settings = Settings.FromDefaultSources(); settings.EnabledInstrumentations.Should().BeEquivalentTo(new List { expectedMetricInstrumentation }); } - [Fact] - internal void MeterSettings_DisabledInstrumentations() - { - Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.Instrumentations, $"{nameof(MetricInstrumentation.NetRuntime)},{nameof(MetricInstrumentation.AspNet)}"); - Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.DisabledInstrumentations, nameof(MetricInstrumentation.AspNet)); - - var settings = Settings.FromDefaultSources(); - - settings.EnabledInstrumentations.Should().BeEquivalentTo(new List { MetricInstrumentation.NetRuntime }); - } - [Theory] [InlineData(nameof(LogInstrumentation.ILogger), LogInstrumentation.ILogger)] internal void LogSettings_Instrumentations_SupportedValues(string logInstrumentation, LogInstrumentation expectedLogInstrumentation) { - Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.Instrumentations, logInstrumentation); + Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.LogsInstrumentationEnabled, "false"); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Logs.EnabledLogsInstrumentationTemplate, logInstrumentation), "true"); var settings = Settings.FromDefaultSources(); settings.EnabledInstrumentations.Should().BeEquivalentTo(new List { expectedLogInstrumentation }); } - [Fact] - internal void LogSettings_DisabledInstrumentations() - { - Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.DisabledInstrumentations, nameof(LogInstrumentation.ILogger)); - - var settings = Settings.FromDefaultSources(); - - settings.EnabledInstrumentations.Should().BeEmpty(); - } - [Theory] [InlineData("true", true)] [InlineData("false", false)] @@ -330,16 +299,29 @@ internal void FlushOnUnhandledException_DependsOnCorrespondingEnvVariable(string private static void ClearEnvVars() { + Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.LogsInstrumentationEnabled, null); + foreach (var logInstrumentation in Enum.GetValues(typeof(LogInstrumentation)).Cast()) + { + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Logs.EnabledLogsInstrumentationTemplate, logInstrumentation), null); + } + Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.Exporter, null); Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.IncludeFormattedMessage, null); - Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.Instrumentations, null); - Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.DisabledInstrumentations, null); + + Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.MetricsInstrumentationEnabled, null); + foreach (var metricInstrumentation in Enum.GetValues(typeof(MetricInstrumentation)).Cast()) + { + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Metrics.EnabledMetricsInstrumentationTemplate, metricInstrumentation), null); + } + Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.Exporter, null); - Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.Instrumentations, null); - Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.DisabledInstrumentations, null); + Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesInstrumentationEnabled, null); + foreach (var tracerInstrumentation in Enum.GetValues(typeof(TracerInstrumentation)).Cast()) + { + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Traces.EnabledTracesInstrumentationTemplate, tracerInstrumentation), null); + } + Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.Exporter, null); - Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.Instrumentations, null); - Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.DisabledInstrumentations, null); Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesSampler, null); Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesSamplerArguments, null); Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.InstrumentationOptions.GraphQLSetDocument, null); diff --git a/test/test-applications/integrations/TestApplication.CustomSdk/TestApplication.CustomSdk.csproj b/test/test-applications/integrations/TestApplication.CustomSdk/TestApplication.CustomSdk.csproj index 1708732ed8..69c606222d 100644 --- a/test/test-applications/integrations/TestApplication.CustomSdk/TestApplication.CustomSdk.csproj +++ b/test/test-applications/integrations/TestApplication.CustomSdk/TestApplication.CustomSdk.csproj @@ -9,7 +9,7 @@ - + diff --git a/tools/IntegrationsJsonGenerator/Program.cs b/tools/IntegrationsJsonGenerator/Program.cs index 1d71f228e0..631cbcf230 100644 --- a/tools/IntegrationsJsonGenerator/Program.cs +++ b/tools/IntegrationsJsonGenerator/Program.cs @@ -32,7 +32,7 @@ var assemblyInstrumentMethodAttributes = autoInstrumentationLib.DefinedTypes .Where(type => InheritsFrom(type, instrumentMethodAttributeName)).Select(x => x.FullName); -var integrations = new Dictionary<(string, string), Integration>(); +var integrations = new Dictionary<(string IntegrationType, string IntegrationName), Integration>(); foreach (var typeInfo in autoInstrumentationLib.GetTypes()) { foreach (var attribute in typeInfo.GetCustomAttributes() @@ -40,33 +40,48 @@ { var integration = ConvertToIntegration(typeInfo.FullName!, attribute); - if (!integrations.ContainsKey((integration.IntegartionType, integration.IntegrationName))) + if (!integrations.ContainsKey((integration.IntegrationType, integration.IntegrationName))) { integrations.Add( - (integration.IntegartionType, integration.IntegrationName), + (integration.IntegrationType, integration.IntegrationName), new Integration { Name = integration.IntegrationName, - Type = integration.IntegartionType, + Type = integration.IntegrationType, MethodReplacements = new List { integration.MethodReplacement } }); } else { - var integration2 = integrations[(integration.IntegartionType, integration.IntegrationName)]; + var integration2 = integrations[(integration.IntegrationType, integration.IntegrationName)]; integration2.MethodReplacements.Add(integration.MethodReplacement); } } } -var productionIntegrations = integrations.Where(x => x.Key.Item2 != "StrongNamedValidation").Select(x => x.Value) +var productionIntegrations = integrations.Where(x => x.Key.IntegrationName != "StrongNamedValidation").Select(x => x.Value) .OrderBy(x => x.Name).ToArray(); -var testIntegrations = integrations.Where(x => x.Key.Item2 == "StrongNamedValidation").Select(x => AppendMockIntegrations(x.Value)) +var testIntegrations = integrations.Where(x => x.Key.IntegrationName == "StrongNamedValidation").Select(x => AppendMockIntegrations(x.Value)) .OrderBy(x => x.Name).ToArray(); +Dictionary> byteCodeIntegrationsByType = new(); + +foreach (var (integrationType, integrationName) in integrations.Keys) +{ + if (byteCodeIntegrationsByType.TryGetValue(integrationType, out var integrationNames)) + { + integrationNames.Add(integrationName); + } + else + { + byteCodeIntegrationsByType.Add(integrationType, new List { integrationName }); + } +} + UpdateIntegrationFile(Path.Combine(solutionFolder, "integrations.json"), productionIntegrations); UpdateIntegrationFile(Path.Combine(solutionFolder, "test", "IntegrationTests", "StrongNamedTestsIntegrations.json"), testIntegrations); +UpdateNativeInstrumentationFile(Path.Combine(solutionFolder, "src", "OpenTelemetry.AutoInstrumentation.Native", "bytecode_instrumentations.h"), byteCodeIntegrationsByType); bool InheritsFrom(Type type, string baseType) { @@ -86,7 +101,7 @@ bool InheritsFrom(Type type, string baseType) } } -(string IntegartionType, string IntegrationName, MethodReplacement MethodReplacement) ConvertToIntegration(string wrapperTypeName, Attribute attribute) +(string IntegrationType, string IntegrationName, MethodReplacement MethodReplacement) ConvertToIntegration(string wrapperTypeName, Attribute attribute) { var integrationName = GetPropertyValue("IntegrationName", attribute); var integrationType = GetPropertyValue("Type", attribute).ToString()!; @@ -159,6 +174,32 @@ void UpdateIntegrationFile(string filePath, Integration[] productionIntegrations JsonSerializer.Serialize(fileStream, productionIntegrations1, jsonSerializerOptions); } +void UpdateNativeInstrumentationFile(string filePath, Dictionary> bytecodeIntegrations) +{ + using var fileStream = new FileStream(filePath, FileMode.Truncate); + + using var writer = new StreamWriter(fileStream); + writer.WriteLine($"// Auto-generated file, do not change it - generated by the {nameof(IntegrationsJsonGenerator)}"); + writer.WriteLine("#ifndef BYTECODE_INSTRUMENTATIONS_H"); + writer.WriteLine("#define BYTECODE_INSTRUMENTATIONS_H"); + writer.WriteLine(); + writer.WriteLine("#include \"string.h\""); + writer.WriteLine(); + writer.WriteLine("namespace trace"); + writer.WriteLine("{"); + foreach (var bytecodeIntegration in bytecodeIntegrations) + { + writer.Write("inline std::unordered_map "); + writer.Write(bytecodeIntegration.Key.ToLowerInvariant()); + writer.Write("_integration_names = {"); + writer.Write(string.Join(", ", bytecodeIntegration.Value.Select(name => $"{{WStr(\"{name}\"), WStr(\"OTEL_DOTNET_AUTO_{bytecodeIntegration.Key.ToUpperInvariant()}S_{name}_INSTRUMENTATION_ENABLED\")}}"))); + writer.WriteLine("};"); + } + + writer.WriteLine("}"); + writer.WriteLine("#endif"); +} + static string GetSourceFilePathName([CallerFilePath] string? callerFilePath = null) => callerFilePath ?? string.Empty; From 3be2bd2874676419ac2c59a44c933fc4ff948619 Mon Sep 17 00:00:00 2001 From: xiang17 Date: Wed, 1 Feb 2023 12:28:12 -0800 Subject: [PATCH 09/14] Remove non-library files from distribution (#2139) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove non-library files from distribution * Fix whitespace formatting * Remove all XML files, including artifact.xml files in store folder --------- Co-authored-by: Piotr Kiełkowicz --- build/Build.Steps.cs | 8 ++++++++ ....DistributionStructure_alpine-linux.verified.txt | 12 ------------ ...ldTests.DistributionStructure_linux.verified.txt | 12 ------------ ...uildTests.DistributionStructure_osx.verified.txt | 12 ------------ ...Tests.DistributionStructure_windows.verified.txt | 13 ------------- 5 files changed, 8 insertions(+), 49 deletions(-) diff --git a/build/Build.Steps.cs b/build/Build.Steps.cs index 3b9213fcf0..7366b935a4 100644 --- a/build/Build.Steps.cs +++ b/build/Build.Steps.cs @@ -235,6 +235,14 @@ partial class Build .EnableNoRestore() .SetFramework(TargetFramework.NET6_0) .SetOutput(TracerHomeDirectory / MapToFolderOutput(TargetFramework.NET6_0))); + + // Remove non-library files + TracerHomeDirectory.GlobFiles("**/*.xml").ForEach(DeleteFile); + (TracerHomeDirectory / "net").GlobFiles("*.json").ForEach(DeleteFile); + if (IsWin) + { + (TracerHomeDirectory / "netfx").GlobFiles("*.json").ForEach(DeleteFile); + } }); Target PublishNativeProfiler => _ => _ diff --git a/test/IntegrationTests/BuildTests.DistributionStructure_alpine-linux.verified.txt b/test/IntegrationTests/BuildTests.DistributionStructure_alpine-linux.verified.txt index 73ffe29b85..c815e50a7c 100644 --- a/test/IntegrationTests/BuildTests.DistributionStructure_alpine-linux.verified.txt +++ b/test/IntegrationTests/BuildTests.DistributionStructure_alpine-linux.verified.txt @@ -10,22 +10,14 @@ /net/Grpc.Net.Client.dll, /net/Grpc.Net.Common.dll, /net/OpenTelemetry.Api.dll, - /net/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.deps.json, /net/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.dll, /net/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.pdb, - /net/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.xml, - /net/OpenTelemetry.AutoInstrumentation.Loader.deps.json, /net/OpenTelemetry.AutoInstrumentation.Loader.dll, /net/OpenTelemetry.AutoInstrumentation.Loader.pdb, - /net/OpenTelemetry.AutoInstrumentation.Loader.xml, - /net/OpenTelemetry.AutoInstrumentation.StartupHook.deps.json, /net/OpenTelemetry.AutoInstrumentation.StartupHook.dll, /net/OpenTelemetry.AutoInstrumentation.StartupHook.pdb, - /net/OpenTelemetry.AutoInstrumentation.StartupHook.xml, - /net/OpenTelemetry.AutoInstrumentation.deps.json, /net/OpenTelemetry.AutoInstrumentation.dll, /net/OpenTelemetry.AutoInstrumentation.pdb, - /net/OpenTelemetry.AutoInstrumentation.xml, /net/OpenTelemetry.Exporter.Console.dll, /net/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs.dll, /net/OpenTelemetry.Exporter.OpenTelemetryProtocol.dll, @@ -52,7 +44,6 @@ /net/System.Security.Permissions.dll, /net/System.ServiceModel.Primitives.dll, /net/System.ServiceModel.dll, - /store/x64/net6.0/artifact.xml, /store/x64/net6.0/dnsclient/1.4.0/lib/netstandard2.1/DnsClient.dll, /store/x64/net6.0/microsoft.extensions.configuration.abstractions/7.0.0/lib/net6.0/Microsoft.Extensions.Configuration.Abstractions.dll, /store/x64/net6.0/microsoft.extensions.configuration.binder/7.0.0/lib/net6.0/Microsoft.Extensions.Configuration.Binder.dll, @@ -78,7 +69,6 @@ /store/x64/net6.0/mongodb.libmongocrypt/1.2.2/runtimes/win/native/mongocrypt.dll, /store/x64/net6.0/sharpcompress/0.23.0/lib/netstandard2.0/SharpCompress.dll, /store/x64/net6.0/system.diagnostics.diagnosticsource/7.0.0/lib/net6.0/System.Diagnostics.DiagnosticSource.dll, - /store/x64/net7.0/artifact.xml, /store/x64/net7.0/dnsclient/1.4.0/lib/netstandard2.1/DnsClient.dll, /store/x64/net7.0/microsoft.extensions.configuration.abstractions/7.0.0/lib/net7.0/Microsoft.Extensions.Configuration.Abstractions.dll, /store/x64/net7.0/microsoft.extensions.configuration.binder/7.0.0/lib/net7.0/Microsoft.Extensions.Configuration.Binder.dll, @@ -103,7 +93,6 @@ /store/x64/net7.0/mongodb.libmongocrypt/1.2.2/runtimes/osx/native/libmongocrypt.dylib, /store/x64/net7.0/mongodb.libmongocrypt/1.2.2/runtimes/win/native/mongocrypt.dll, /store/x64/net7.0/sharpcompress/0.23.0/lib/netstandard2.0/SharpCompress.dll, - /store/x86/net6.0/artifact.xml, /store/x86/net6.0/dnsclient/1.4.0/lib/netstandard2.1/DnsClient.dll, /store/x86/net6.0/microsoft.extensions.configuration.abstractions/7.0.0/lib/net6.0/Microsoft.Extensions.Configuration.Abstractions.dll, /store/x86/net6.0/microsoft.extensions.configuration.binder/7.0.0/lib/net6.0/Microsoft.Extensions.Configuration.Binder.dll, @@ -129,7 +118,6 @@ /store/x86/net6.0/mongodb.libmongocrypt/1.2.2/runtimes/win/native/mongocrypt.dll, /store/x86/net6.0/sharpcompress/0.23.0/lib/netstandard2.0/SharpCompress.dll, /store/x86/net6.0/system.diagnostics.diagnosticsource/7.0.0/lib/net6.0/System.Diagnostics.DiagnosticSource.dll, - /store/x86/net7.0/artifact.xml, /store/x86/net7.0/dnsclient/1.4.0/lib/netstandard2.1/DnsClient.dll, /store/x86/net7.0/microsoft.extensions.configuration.abstractions/7.0.0/lib/net7.0/Microsoft.Extensions.Configuration.Abstractions.dll, /store/x86/net7.0/microsoft.extensions.configuration.binder/7.0.0/lib/net7.0/Microsoft.Extensions.Configuration.Binder.dll, diff --git a/test/IntegrationTests/BuildTests.DistributionStructure_linux.verified.txt b/test/IntegrationTests/BuildTests.DistributionStructure_linux.verified.txt index 09f030187d..9dd53e2092 100644 --- a/test/IntegrationTests/BuildTests.DistributionStructure_linux.verified.txt +++ b/test/IntegrationTests/BuildTests.DistributionStructure_linux.verified.txt @@ -10,22 +10,14 @@ /net/Grpc.Net.Client.dll, /net/Grpc.Net.Common.dll, /net/OpenTelemetry.Api.dll, - /net/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.deps.json, /net/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.dll, /net/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.pdb, - /net/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.xml, - /net/OpenTelemetry.AutoInstrumentation.Loader.deps.json, /net/OpenTelemetry.AutoInstrumentation.Loader.dll, /net/OpenTelemetry.AutoInstrumentation.Loader.pdb, - /net/OpenTelemetry.AutoInstrumentation.Loader.xml, - /net/OpenTelemetry.AutoInstrumentation.StartupHook.deps.json, /net/OpenTelemetry.AutoInstrumentation.StartupHook.dll, /net/OpenTelemetry.AutoInstrumentation.StartupHook.pdb, - /net/OpenTelemetry.AutoInstrumentation.StartupHook.xml, - /net/OpenTelemetry.AutoInstrumentation.deps.json, /net/OpenTelemetry.AutoInstrumentation.dll, /net/OpenTelemetry.AutoInstrumentation.pdb, - /net/OpenTelemetry.AutoInstrumentation.xml, /net/OpenTelemetry.Exporter.Console.dll, /net/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs.dll, /net/OpenTelemetry.Exporter.OpenTelemetryProtocol.dll, @@ -52,7 +44,6 @@ /net/System.Security.Permissions.dll, /net/System.ServiceModel.Primitives.dll, /net/System.ServiceModel.dll, - /store/x64/net6.0/artifact.xml, /store/x64/net6.0/dnsclient/1.4.0/lib/netstandard2.1/DnsClient.dll, /store/x64/net6.0/microsoft.extensions.configuration.abstractions/7.0.0/lib/net6.0/Microsoft.Extensions.Configuration.Abstractions.dll, /store/x64/net6.0/microsoft.extensions.configuration.binder/7.0.0/lib/net6.0/Microsoft.Extensions.Configuration.Binder.dll, @@ -78,7 +69,6 @@ /store/x64/net6.0/mongodb.libmongocrypt/1.2.2/runtimes/win/native/mongocrypt.dll, /store/x64/net6.0/sharpcompress/0.23.0/lib/netstandard2.0/SharpCompress.dll, /store/x64/net6.0/system.diagnostics.diagnosticsource/7.0.0/lib/net6.0/System.Diagnostics.DiagnosticSource.dll, - /store/x64/net7.0/artifact.xml, /store/x64/net7.0/dnsclient/1.4.0/lib/netstandard2.1/DnsClient.dll, /store/x64/net7.0/microsoft.extensions.configuration.abstractions/7.0.0/lib/net7.0/Microsoft.Extensions.Configuration.Abstractions.dll, /store/x64/net7.0/microsoft.extensions.configuration.binder/7.0.0/lib/net7.0/Microsoft.Extensions.Configuration.Binder.dll, @@ -103,7 +93,6 @@ /store/x64/net7.0/mongodb.libmongocrypt/1.2.2/runtimes/osx/native/libmongocrypt.dylib, /store/x64/net7.0/mongodb.libmongocrypt/1.2.2/runtimes/win/native/mongocrypt.dll, /store/x64/net7.0/sharpcompress/0.23.0/lib/netstandard2.0/SharpCompress.dll, - /store/x86/net6.0/artifact.xml, /store/x86/net6.0/dnsclient/1.4.0/lib/netstandard2.1/DnsClient.dll, /store/x86/net6.0/microsoft.extensions.configuration.abstractions/7.0.0/lib/net6.0/Microsoft.Extensions.Configuration.Abstractions.dll, /store/x86/net6.0/microsoft.extensions.configuration.binder/7.0.0/lib/net6.0/Microsoft.Extensions.Configuration.Binder.dll, @@ -129,7 +118,6 @@ /store/x86/net6.0/mongodb.libmongocrypt/1.2.2/runtimes/win/native/mongocrypt.dll, /store/x86/net6.0/sharpcompress/0.23.0/lib/netstandard2.0/SharpCompress.dll, /store/x86/net6.0/system.diagnostics.diagnosticsource/7.0.0/lib/net6.0/System.Diagnostics.DiagnosticSource.dll, - /store/x86/net7.0/artifact.xml, /store/x86/net7.0/dnsclient/1.4.0/lib/netstandard2.1/DnsClient.dll, /store/x86/net7.0/microsoft.extensions.configuration.abstractions/7.0.0/lib/net7.0/Microsoft.Extensions.Configuration.Abstractions.dll, /store/x86/net7.0/microsoft.extensions.configuration.binder/7.0.0/lib/net7.0/Microsoft.Extensions.Configuration.Binder.dll, diff --git a/test/IntegrationTests/BuildTests.DistributionStructure_osx.verified.txt b/test/IntegrationTests/BuildTests.DistributionStructure_osx.verified.txt index 45ee9b12ee..6c1ad5e6f4 100644 --- a/test/IntegrationTests/BuildTests.DistributionStructure_osx.verified.txt +++ b/test/IntegrationTests/BuildTests.DistributionStructure_osx.verified.txt @@ -9,22 +9,14 @@ /net/Grpc.Net.Client.dll, /net/Grpc.Net.Common.dll, /net/OpenTelemetry.Api.dll, - /net/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.deps.json, /net/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.dll, /net/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.pdb, - /net/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.xml, - /net/OpenTelemetry.AutoInstrumentation.Loader.deps.json, /net/OpenTelemetry.AutoInstrumentation.Loader.dll, /net/OpenTelemetry.AutoInstrumentation.Loader.pdb, - /net/OpenTelemetry.AutoInstrumentation.Loader.xml, - /net/OpenTelemetry.AutoInstrumentation.StartupHook.deps.json, /net/OpenTelemetry.AutoInstrumentation.StartupHook.dll, /net/OpenTelemetry.AutoInstrumentation.StartupHook.pdb, - /net/OpenTelemetry.AutoInstrumentation.StartupHook.xml, - /net/OpenTelemetry.AutoInstrumentation.deps.json, /net/OpenTelemetry.AutoInstrumentation.dll, /net/OpenTelemetry.AutoInstrumentation.pdb, - /net/OpenTelemetry.AutoInstrumentation.xml, /net/OpenTelemetry.Exporter.Console.dll, /net/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs.dll, /net/OpenTelemetry.Exporter.OpenTelemetryProtocol.dll, @@ -52,7 +44,6 @@ /net/System.ServiceModel.Primitives.dll, /net/System.ServiceModel.dll, /osx-x64/OpenTelemetry.AutoInstrumentation.Native.dylib, - /store/x64/net6.0/artifact.xml, /store/x64/net6.0/dnsclient/1.4.0/lib/netstandard2.1/DnsClient.dll, /store/x64/net6.0/microsoft.extensions.configuration.abstractions/7.0.0/lib/net6.0/Microsoft.Extensions.Configuration.Abstractions.dll, /store/x64/net6.0/microsoft.extensions.configuration.binder/7.0.0/lib/net6.0/Microsoft.Extensions.Configuration.Binder.dll, @@ -78,7 +69,6 @@ /store/x64/net6.0/mongodb.libmongocrypt/1.2.2/runtimes/win/native/mongocrypt.dll, /store/x64/net6.0/sharpcompress/0.23.0/lib/netstandard2.0/SharpCompress.dll, /store/x64/net6.0/system.diagnostics.diagnosticsource/7.0.0/lib/net6.0/System.Diagnostics.DiagnosticSource.dll, - /store/x64/net7.0/artifact.xml, /store/x64/net7.0/dnsclient/1.4.0/lib/netstandard2.1/DnsClient.dll, /store/x64/net7.0/microsoft.extensions.configuration.abstractions/7.0.0/lib/net7.0/Microsoft.Extensions.Configuration.Abstractions.dll, /store/x64/net7.0/microsoft.extensions.configuration.binder/7.0.0/lib/net7.0/Microsoft.Extensions.Configuration.Binder.dll, @@ -103,7 +93,6 @@ /store/x64/net7.0/mongodb.libmongocrypt/1.2.2/runtimes/osx/native/libmongocrypt.dylib, /store/x64/net7.0/mongodb.libmongocrypt/1.2.2/runtimes/win/native/mongocrypt.dll, /store/x64/net7.0/sharpcompress/0.23.0/lib/netstandard2.0/SharpCompress.dll, - /store/x86/net6.0/artifact.xml, /store/x86/net6.0/dnsclient/1.4.0/lib/netstandard2.1/DnsClient.dll, /store/x86/net6.0/microsoft.extensions.configuration.abstractions/7.0.0/lib/net6.0/Microsoft.Extensions.Configuration.Abstractions.dll, /store/x86/net6.0/microsoft.extensions.configuration.binder/7.0.0/lib/net6.0/Microsoft.Extensions.Configuration.Binder.dll, @@ -129,7 +118,6 @@ /store/x86/net6.0/mongodb.libmongocrypt/1.2.2/runtimes/win/native/mongocrypt.dll, /store/x86/net6.0/sharpcompress/0.23.0/lib/netstandard2.0/SharpCompress.dll, /store/x86/net6.0/system.diagnostics.diagnosticsource/7.0.0/lib/net6.0/System.Diagnostics.DiagnosticSource.dll, - /store/x86/net7.0/artifact.xml, /store/x86/net7.0/dnsclient/1.4.0/lib/netstandard2.1/DnsClient.dll, /store/x86/net7.0/microsoft.extensions.configuration.abstractions/7.0.0/lib/net7.0/Microsoft.Extensions.Configuration.Abstractions.dll, /store/x86/net7.0/microsoft.extensions.configuration.binder/7.0.0/lib/net7.0/Microsoft.Extensions.Configuration.Binder.dll, diff --git a/test/IntegrationTests/BuildTests.DistributionStructure_windows.verified.txt b/test/IntegrationTests/BuildTests.DistributionStructure_windows.verified.txt index 26e3350733..5b0af4ecb6 100644 --- a/test/IntegrationTests/BuildTests.DistributionStructure_windows.verified.txt +++ b/test/IntegrationTests/BuildTests.DistributionStructure_windows.verified.txt @@ -9,22 +9,14 @@ \net\Grpc.Net.Client.dll, \net\Grpc.Net.Common.dll, \net\OpenTelemetry.Api.dll, - \net\OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.deps.json, \net\OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.dll, \net\OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.pdb, - \net\OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper.xml, - \net\OpenTelemetry.AutoInstrumentation.Loader.deps.json, \net\OpenTelemetry.AutoInstrumentation.Loader.dll, \net\OpenTelemetry.AutoInstrumentation.Loader.pdb, - \net\OpenTelemetry.AutoInstrumentation.Loader.xml, - \net\OpenTelemetry.AutoInstrumentation.StartupHook.deps.json, \net\OpenTelemetry.AutoInstrumentation.StartupHook.dll, \net\OpenTelemetry.AutoInstrumentation.StartupHook.pdb, - \net\OpenTelemetry.AutoInstrumentation.StartupHook.xml, - \net\OpenTelemetry.AutoInstrumentation.deps.json, \net\OpenTelemetry.AutoInstrumentation.dll, \net\OpenTelemetry.AutoInstrumentation.pdb, - \net\OpenTelemetry.AutoInstrumentation.xml, \net\OpenTelemetry.Exporter.Console.dll, \net\OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs.dll, \net\OpenTelemetry.Exporter.OpenTelemetryProtocol.dll, @@ -71,7 +63,6 @@ \netfx\OpenTelemetry.Api.dll, \netfx\OpenTelemetry.AutoInstrumentation.dll, \netfx\OpenTelemetry.AutoInstrumentation.pdb, - \netfx\OpenTelemetry.AutoInstrumentation.xml, \netfx\OpenTelemetry.Exporter.Console.dll, \netfx\OpenTelemetry.Exporter.OpenTelemetryProtocol.dll, \netfx\OpenTelemetry.Exporter.Prometheus.HttpListener.dll, @@ -197,7 +188,6 @@ \netfx\libgrpc_csharp_ext.x64.dylib, \netfx\libgrpc_csharp_ext.x64.so, \netfx\netstandard.dll, - \store\x64\net6.0\artifact.xml, \store\x64\net6.0\dnsclient\1.4.0\lib\netstandard2.1\DnsClient.dll, \store\x64\net6.0\microsoft.extensions.configuration.abstractions\7.0.0\lib\net6.0\Microsoft.Extensions.Configuration.Abstractions.dll, \store\x64\net6.0\microsoft.extensions.configuration.binder\7.0.0\lib\net6.0\Microsoft.Extensions.Configuration.Binder.dll, @@ -223,7 +213,6 @@ \store\x64\net6.0\mongodb.libmongocrypt\1.2.2\runtimes\win\native\mongocrypt.dll, \store\x64\net6.0\sharpcompress\0.23.0\lib\netstandard2.0\SharpCompress.dll, \store\x64\net6.0\system.diagnostics.diagnosticsource\7.0.0\lib\net6.0\System.Diagnostics.DiagnosticSource.dll, - \store\x64\net7.0\artifact.xml, \store\x64\net7.0\dnsclient\1.4.0\lib\netstandard2.1\DnsClient.dll, \store\x64\net7.0\microsoft.extensions.configuration.abstractions\7.0.0\lib\net7.0\Microsoft.Extensions.Configuration.Abstractions.dll, \store\x64\net7.0\microsoft.extensions.configuration.binder\7.0.0\lib\net7.0\Microsoft.Extensions.Configuration.Binder.dll, @@ -248,7 +237,6 @@ \store\x64\net7.0\mongodb.libmongocrypt\1.2.2\runtimes\osx\native\libmongocrypt.dylib, \store\x64\net7.0\mongodb.libmongocrypt\1.2.2\runtimes\win\native\mongocrypt.dll, \store\x64\net7.0\sharpcompress\0.23.0\lib\netstandard2.0\SharpCompress.dll, - \store\x86\net6.0\artifact.xml, \store\x86\net6.0\dnsclient\1.4.0\lib\netstandard2.1\DnsClient.dll, \store\x86\net6.0\microsoft.extensions.configuration.abstractions\7.0.0\lib\net6.0\Microsoft.Extensions.Configuration.Abstractions.dll, \store\x86\net6.0\microsoft.extensions.configuration.binder\7.0.0\lib\net6.0\Microsoft.Extensions.Configuration.Binder.dll, @@ -274,7 +262,6 @@ \store\x86\net6.0\mongodb.libmongocrypt\1.2.2\runtimes\win\native\mongocrypt.dll, \store\x86\net6.0\sharpcompress\0.23.0\lib\netstandard2.0\SharpCompress.dll, \store\x86\net6.0\system.diagnostics.diagnosticsource\7.0.0\lib\net6.0\System.Diagnostics.DiagnosticSource.dll, - \store\x86\net7.0\artifact.xml, \store\x86\net7.0\dnsclient\1.4.0\lib\netstandard2.1\DnsClient.dll, \store\x86\net7.0\microsoft.extensions.configuration.abstractions\7.0.0\lib\net7.0\Microsoft.Extensions.Configuration.Abstractions.dll, \store\x86\net7.0\microsoft.extensions.configuration.binder\7.0.0\lib\net7.0\Microsoft.Extensions.Configuration.Binder.dll, From e1a7525f3309bec1a87b3b5b8ea10a7517597ec7 Mon Sep 17 00:00:00 2001 From: xiang17 Date: Wed, 1 Feb 2023 17:57:24 -0800 Subject: [PATCH 10/14] PowerShell module: add progress bar to GAC installation step (#2140) --- OpenTelemetry.DotNet.Auto.psm1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/OpenTelemetry.DotNet.Auto.psm1 b/OpenTelemetry.DotNet.Auto.psm1 index acbc8cd721..8743b26cf3 100644 --- a/OpenTelemetry.DotNet.Auto.psm1 +++ b/OpenTelemetry.DotNet.Auto.psm1 @@ -238,8 +238,12 @@ function Install-OpenTelemetryCore() { [System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") | Out-Null $publish = New-Object System.EnterpriseServices.Internal.Publish $dlls = Get-ChildItem -Path $installDir\netfx\ -Filter *.dll -File - foreach ($dll in $dlls) { - $publish.GacInstall($dll.FullName) + for ($i = 0; $i -le $dlls.Count; $i++) { + $percentageComplete = $i / $dlls.Count * 100 + Write-Progress -Activity "Registering .NET Framweworks dlls in GAC" ` + -Status "Module $($i+1) out of $($dlls.Count). Installing $($dlls[$i].Name):" ` + -PercentComplete $percentageComplete + $publish.GacInstall($dlls[$i].FullName) } } catch { From fc205e349b953e3410bc16dfc29937838638c97a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Thu, 2 Feb 2023 09:21:54 +0100 Subject: [PATCH 11/14] Env var instrumentation - uppercase id (#2141) --- .cspell/other.txt | 12 +++++ docs/config.md | 52 +++++++++---------- .../bytecode_instrumentations.h | 6 +-- .../Configurations/ConfigurationExtensions.cs | 2 +- test/IntegrationTests/AspNetTests.cs | 2 +- test/IntegrationTests/GraphQLTests.cs | 2 +- test/IntegrationTests/GrpcNetClientTests.cs | 2 +- test/IntegrationTests/SmokeTests.cs | 8 +-- .../Configurations/ConfigurationTests.cs | 6 +-- .../Configurations/SettingsTests.cs | 46 ++++++++-------- tools/IntegrationsJsonGenerator/Program.cs | 2 +- 11 files changed, 76 insertions(+), 64 deletions(-) diff --git a/.cspell/other.txt b/.cspell/other.txt index c0c6b66e08..d2d428babc 100644 --- a/.cspell/other.txt +++ b/.cspell/other.txt @@ -33,3 +33,15 @@ tracesexporter unencrypted UNENCRYPTEDSUPPORT vcpkg +ILOGGER +NSERVICEBUS +NETRUNTIME +HTTPCLIENT +STACKEXCHANGEREDIS +SQLCLIENT +NSERVICEBUS +MYSQLDATA +MASSTRANSIT +HTTPCLIENT +GRPCNETCLIENT +ENTITYFRAMEWORKCORE diff --git a/docs/config.md b/docs/config.md index 2a10c151f5..eecb82436c 100644 --- a/docs/config.md +++ b/docs/config.md @@ -80,32 +80,32 @@ for example `TRACES`, and `{0}` is the case-sensitive name of the instrumentatio | `OTEL_DOTNET_AUTO_INTEGRATIONS_FILE` | List of bytecode instrumentations JSON configuration filepaths, delimited by the platform-specific path separator (`;` on Windows, `:` on Linux and macOS). For example: `%ProfilerDirectory%/integrations.json`. It is required for bytecode instrumentations. | | | `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | Disables all instrumentations. | `true` | | `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | Disables all trace instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | -| `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific trace instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific trace instrumentation, where `{0}` is the uppercase id of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | | `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | Disables all metric instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | -| `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific metric instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific metric instrumentation, where `{0}` is the uppercase id of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | | `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | Disables all log instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | -| `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific log instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific log instrumentation, where `{0}` is the uppercase id of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | ### 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 | -| `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 | +| `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. @@ -118,12 +118,12 @@ for example `TRACES`, and `{0}` is the case-sensitive name of the instrumentatio | ID | Instrumented library | Supported versions | Instrumentation type | |---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------|----------------------| -| `AspNet` | ASP.NET Framework \[1\] | * | source | -| `AspNet` | ASP.NET Core \[2\] | * | 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 | -| `NetRuntime` | [OpenTelemetry.Instrumentation.Runtime](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Runtime) | * | source | -| `Process` | [OpenTelemetry.Instrumentation.Process](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Process) | * | source | -| `NServiceBus` | [NServiceBus](https://www.nuget.org/packages/NServiceBus) | ≥8.0.0 | source & bytecode | +| `ASPNET` | ASP.NET Framework \[1\] | * | source | +| `ASPNET` | ASP.NET Core \[2\] | * | 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 | +| `NETRUNTIME` | [OpenTelemetry.Instrumentation.Runtime](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Runtime) | * | source | +| `PROCESS` | [OpenTelemetry.Instrumentation.Process](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Process) | * | source | +| `NSERVICEBUS` | [NServiceBus](https://www.nuget.org/packages/NServiceBus) | ≥8.0.0 | source & bytecode | \[1\]: The ASP.NET metrics are generated only if the `AspNet` trace instrumentation is also enabled. @@ -135,7 +135,7 @@ for example `TRACES`, and `{0}` is the case-sensitive name of the instrumentatio | ID | Instrumented library | Supported versions | Instrumentation type | |---------|---------------------------------------------------------------------------------------------------------------------------------|--------------------|------------------------| -| ILogger | [Microsoft.Extensions.Logging](https://www.nuget.org/packages/Microsoft.Extensions.Logging) **Not supported on .NET Framework** | ≥6.0.0 | bytecode or source [1] | +| ILOGGER | [Microsoft.Extensions.Logging](https://www.nuget.org/packages/Microsoft.Extensions.Logging) **Not supported on .NET Framework** | ≥6.0.0 | bytecode or source [1] | **[1]**: For ASP.NET Core applications, the `LoggingBuilder` instrumentation can be enabled without using the .NET CLR Profiler by setting diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h b/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h index ff5763d167..2b2796b9db 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h @@ -6,8 +6,8 @@ namespace trace { -inline std::unordered_map trace_integration_names = {{WStr("StrongNamedValidation"), WStr("OTEL_DOTNET_AUTO_TRACES_StrongNamedValidation_INSTRUMENTATION_ENABLED")}, {WStr("StackExchangeRedis"), WStr("OTEL_DOTNET_AUTO_TRACES_StackExchangeRedis_INSTRUMENTATION_ENABLED")}, {WStr("NServiceBus"), WStr("OTEL_DOTNET_AUTO_TRACES_NServiceBus_INSTRUMENTATION_ENABLED")}, {WStr("MySqlData"), WStr("OTEL_DOTNET_AUTO_TRACES_MySqlData_INSTRUMENTATION_ENABLED")}, {WStr("MongoDB"), WStr("OTEL_DOTNET_AUTO_TRACES_MongoDB_INSTRUMENTATION_ENABLED")}, {WStr("GraphQL"), WStr("OTEL_DOTNET_AUTO_TRACES_GraphQL_INSTRUMENTATION_ENABLED")}}; -inline std::unordered_map metric_integration_names = {{WStr("NServiceBus"), WStr("OTEL_DOTNET_AUTO_METRICS_NServiceBus_INSTRUMENTATION_ENABLED")}}; -inline std::unordered_map log_integration_names = {{WStr("ILogger"), WStr("OTEL_DOTNET_AUTO_LOGS_ILogger_INSTRUMENTATION_ENABLED")}}; +inline std::unordered_map trace_integration_names = {{WStr("StrongNamedValidation"), WStr("OTEL_DOTNET_AUTO_TRACES_STRONGNAMEDVALIDATION_INSTRUMENTATION_ENABLED")}, {WStr("StackExchangeRedis"), WStr("OTEL_DOTNET_AUTO_TRACES_STACKEXCHANGEREDIS_INSTRUMENTATION_ENABLED")}, {WStr("NServiceBus"), WStr("OTEL_DOTNET_AUTO_TRACES_NSERVICEBUS_INSTRUMENTATION_ENABLED")}, {WStr("MySqlData"), WStr("OTEL_DOTNET_AUTO_TRACES_MYSQLDATA_INSTRUMENTATION_ENABLED")}, {WStr("MongoDB"), WStr("OTEL_DOTNET_AUTO_TRACES_MONGODB_INSTRUMENTATION_ENABLED")}, {WStr("GraphQL"), WStr("OTEL_DOTNET_AUTO_TRACES_GRAPHQL_INSTRUMENTATION_ENABLED")}}; +inline std::unordered_map metric_integration_names = {{WStr("NServiceBus"), WStr("OTEL_DOTNET_AUTO_METRICS_NSERVICEBUS_INSTRUMENTATION_ENABLED")}}; +inline std::unordered_map log_integration_names = {{WStr("ILogger"), WStr("OTEL_DOTNET_AUTO_LOGS_ILOGGER_INSTRUMENTATION_ENABLED")}}; } #endif diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs index 8fd68e70b7..46953c20ba 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs @@ -28,7 +28,7 @@ public static IList ParseEnabledEnumList(this Configuration source foreach (var configuration in allConfigurations) { - var configurationEnabled = source.GetBool(string.Format(CultureInfo.InvariantCulture, enabledConfigurationTemplate, configuration)) ?? enabledByDefault; + var configurationEnabled = source.GetBool(string.Format(CultureInfo.InvariantCulture, enabledConfigurationTemplate, configuration.ToString().ToUpperInvariant())) ?? enabledByDefault; if (configurationEnabled) { diff --git a/test/IntegrationTests/AspNetTests.cs b/test/IntegrationTests/AspNetTests.cs index b1fcbf3d04..9b5c5f256f 100644 --- a/test/IntegrationTests/AspNetTests.cs +++ b/test/IntegrationTests/AspNetTests.cs @@ -109,7 +109,7 @@ public async Task SubmitMetrics() _environmentVariables["OTEL_EXPORTER_OTLP_ENDPOINT"] = collectorUrl; _environmentVariables["OTEL_METRIC_EXPORT_INTERVAL"] = "1000"; _environmentVariables["OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED"] = "false"; // Helps to reduce noise by enabling only AspNet metrics. - _environmentVariables["OTEL_DOTNET_AUTO_METRICS_AspNet_INSTRUMENTATION_ENABLED"] = "true"; // Helps to reduce noise by enabling only AspNet metrics. + _environmentVariables["OTEL_DOTNET_AUTO_METRICS_ASPNET_INSTRUMENTATION_ENABLED"] = "true"; // Helps to reduce noise by enabling only AspNet metrics. var webPort = TcpPortProvider.GetOpenPort(); await using var container = await StartContainerAsync(webPort); await CallTestApplicationEndpoint(webPort); diff --git a/test/IntegrationTests/GraphQLTests.cs b/test/IntegrationTests/GraphQLTests.cs index ae726759bb..f437350824 100644 --- a/test/IntegrationTests/GraphQLTests.cs +++ b/test/IntegrationTests/GraphQLTests.cs @@ -61,7 +61,7 @@ public async Task SubmitsTraces(bool setDocument) SetEnvironmentVariable("OTEL_DOTNET_AUTO_GRAPHQL_SET_DOCUMENT", setDocument.ToString()); SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false"); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_GraphQL_INSTRUMENTATION_ENABLED", "true"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_GRAPHQL_INSTRUMENTATION_ENABLED", "true"); SetEnvironmentVariable("OTEL_TRACES_SAMPLER", "always_on"); SetEnvironmentVariable("OTEL_DOTNET_AUTO_NETFX_REDIRECT_ENABLED", "false"); diff --git a/test/IntegrationTests/GrpcNetClientTests.cs b/test/IntegrationTests/GrpcNetClientTests.cs index 64e7724115..81e4f840a1 100644 --- a/test/IntegrationTests/GrpcNetClientTests.cs +++ b/test/IntegrationTests/GrpcNetClientTests.cs @@ -38,7 +38,7 @@ public void SubmitsTraces() // Grpc.Net.Client is using various version of http communication under the hood. // Enabling only GrpcNetClient instrumentation to have consistent set of spans. SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false"); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_GrpcNetClient_INSTRUMENTATION_ENABLED", "true"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_GRPCNETCLIENT_INSTRUMENTATION_ENABLED", "true"); RunTestApplication(); collector.AssertExpectations(); diff --git a/test/IntegrationTests/SmokeTests.cs b/test/IntegrationTests/SmokeTests.cs index ee5898a710..f46ff29941 100644 --- a/test/IntegrationTests/SmokeTests.cs +++ b/test/IntegrationTests/SmokeTests.cs @@ -330,7 +330,7 @@ public void LogsDisabledInstrumentation() public void MetricsDisabledInstrumentation() { using var collector = new MockMetricsCollector(Output); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_METRICS_HttpClient_INSTRUMENTATION_ENABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_METRICS_HTTPCLIENT_INSTRUMENTATION_ENABLED", "false"); EnableOnlyHttpClientTraceInstrumentation(); EnableBytecodeInstrumentation(); RunTestApplication(); @@ -343,8 +343,8 @@ public void TracesDisabledInstrumentation() { using var collector = new MockSpansCollector(Output); SetExporter(collector); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_AspNet_INSTRUMENTATION_ENABLED", "false"); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_HttpClient_INSTRUMENTATION_ENABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ASPNET_INSTRUMENTATION_ENABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_HTTPCLIENT_INSTRUMENTATION_ENABLED", "false"); RunTestApplication(); collector.AssertEmpty(); } @@ -384,6 +384,6 @@ private void VerifyTestApplicationNotInstrumented() private void EnableOnlyHttpClientTraceInstrumentation() { SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false"); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_HttpClient_INSTRUMENTATION_ENABLED", "true"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_HTTPCLIENT_INSTRUMENTATION_ENABLED", "true"); } } diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs index 6a1a5f722c..f69b2090f3 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs @@ -61,8 +61,8 @@ public void ParseEnabledEnumList_SelectivelyEnabled() { var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection { - { "TEST_CONFIGURATION_Test1_ENABLED", "true" }, - { "TEST_CONFIGURATION_Test3_ENABLED", "true" } + { "TEST_CONFIGURATION_TEST1_ENABLED", "true" }, + { "TEST_CONFIGURATION_TEST3_ENABLED", "true" } })); var list = source.ParseEnabledEnumList( @@ -77,7 +77,7 @@ public void ParseEnabledEnumList_SelectivelyDisabled() { var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection { - { "TEST_CONFIGURATION_Test2_ENABLED", "false" }, + { "TEST_CONFIGURATION_TEST2_ENABLED", "false" }, })); var list = source.ParseEnabledEnumList( diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs index aaec6e88a3..37f5f600e9 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs @@ -175,25 +175,25 @@ internal void Propagators_SupportedValues(string propagators, Propagator[] expec } [Theory] - [InlineData(nameof(TracerInstrumentation.AspNet), TracerInstrumentation.AspNet)] - [InlineData(nameof(TracerInstrumentation.GraphQL), TracerInstrumentation.GraphQL)] - [InlineData(nameof(TracerInstrumentation.HttpClient), TracerInstrumentation.HttpClient)] + [InlineData("ASPNET", TracerInstrumentation.AspNet)] + [InlineData("GRAPHQL", TracerInstrumentation.GraphQL)] + [InlineData("HTTPCLIENT", TracerInstrumentation.HttpClient)] #if NET6_0_OR_GREATER - [InlineData(nameof(TracerInstrumentation.MongoDB), TracerInstrumentation.MongoDB)] - [InlineData(nameof(TracerInstrumentation.MySqlData), TracerInstrumentation.MySqlData)] - [InlineData(nameof(TracerInstrumentation.StackExchangeRedis), TracerInstrumentation.StackExchangeRedis)] + [InlineData("MONGODB", TracerInstrumentation.MongoDB)] + [InlineData("MYSQLDATA", TracerInstrumentation.MySqlData)] + [InlineData("STACKEXCHANGEREDIS", TracerInstrumentation.StackExchangeRedis)] #endif - [InlineData(nameof(TracerInstrumentation.Npgsql), TracerInstrumentation.Npgsql)] - [InlineData(nameof(TracerInstrumentation.SqlClient), TracerInstrumentation.SqlClient)] - [InlineData(nameof(TracerInstrumentation.GrpcNetClient), TracerInstrumentation.GrpcNetClient)] + [InlineData("NPGSQL", TracerInstrumentation.Npgsql)] + [InlineData("SQLCLIENT", TracerInstrumentation.SqlClient)] + [InlineData("GRPCNETCLIENT", TracerInstrumentation.GrpcNetClient)] #if NET6_0_OR_GREATER - [InlineData(nameof(TracerInstrumentation.MassTransit), TracerInstrumentation.MassTransit)] + [InlineData("MASSTRANSIT", TracerInstrumentation.MassTransit)] #endif - [InlineData(nameof(TracerInstrumentation.NServiceBus), TracerInstrumentation.NServiceBus)] - [InlineData(nameof(TracerInstrumentation.Elasticsearch), TracerInstrumentation.Elasticsearch)] - [InlineData(nameof(TracerInstrumentation.Quartz), TracerInstrumentation.Quartz)] + [InlineData("NSERVICEBUS", TracerInstrumentation.NServiceBus)] + [InlineData("ELASTICSEARCH", TracerInstrumentation.Elasticsearch)] + [InlineData("QUARTZ", TracerInstrumentation.Quartz)] #if NET6_0_OR_GREATER - [InlineData(nameof(TracerInstrumentation.EntityFrameworkCore), TracerInstrumentation.EntityFrameworkCore)] + [InlineData("ENTITYFRAMEWORKCORE", TracerInstrumentation.EntityFrameworkCore)] #endif internal void TracerSettings_Instrumentations_SupportedValues(string tracerInstrumentation, TracerInstrumentation expectedTracerInstrumentation) { @@ -221,11 +221,11 @@ internal void TracerSettings_TracerSampler() } [Theory] - [InlineData(nameof(MetricInstrumentation.NetRuntime), MetricInstrumentation.NetRuntime)] - [InlineData(nameof(MetricInstrumentation.AspNet), MetricInstrumentation.AspNet)] - [InlineData(nameof(MetricInstrumentation.HttpClient), MetricInstrumentation.HttpClient)] - [InlineData(nameof(MetricInstrumentation.Process), MetricInstrumentation.Process)] - [InlineData(nameof(MetricInstrumentation.NServiceBus), MetricInstrumentation.NServiceBus)] + [InlineData("NETRUNTIME", MetricInstrumentation.NetRuntime)] + [InlineData("ASPNET", MetricInstrumentation.AspNet)] + [InlineData("HTTPCLIENT", MetricInstrumentation.HttpClient)] + [InlineData("PROCESS", MetricInstrumentation.Process)] + [InlineData("NSERVICEBUS", MetricInstrumentation.NServiceBus)] internal void MeterSettings_Instrumentations_SupportedValues(string meterInstrumentation, MetricInstrumentation expectedMetricInstrumentation) { Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.MetricsInstrumentationEnabled, "false"); @@ -237,7 +237,7 @@ internal void MeterSettings_Instrumentations_SupportedValues(string meterInstrum } [Theory] - [InlineData(nameof(LogInstrumentation.ILogger), LogInstrumentation.ILogger)] + [InlineData("ILOGGER", LogInstrumentation.ILogger)] internal void LogSettings_Instrumentations_SupportedValues(string logInstrumentation, LogInstrumentation expectedLogInstrumentation) { Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.LogsInstrumentationEnabled, "false"); @@ -302,7 +302,7 @@ private static void ClearEnvVars() Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.LogsInstrumentationEnabled, null); foreach (var logInstrumentation in Enum.GetValues(typeof(LogInstrumentation)).Cast()) { - Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Logs.EnabledLogsInstrumentationTemplate, logInstrumentation), null); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Logs.EnabledLogsInstrumentationTemplate, logInstrumentation.ToString().ToUpperInvariant()), null); } Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.Exporter, null); @@ -311,14 +311,14 @@ private static void ClearEnvVars() Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.MetricsInstrumentationEnabled, null); foreach (var metricInstrumentation in Enum.GetValues(typeof(MetricInstrumentation)).Cast()) { - Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Metrics.EnabledMetricsInstrumentationTemplate, metricInstrumentation), null); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Metrics.EnabledMetricsInstrumentationTemplate, metricInstrumentation.ToString().ToUpperInvariant()), null); } Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.Exporter, null); Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesInstrumentationEnabled, null); foreach (var tracerInstrumentation in Enum.GetValues(typeof(TracerInstrumentation)).Cast()) { - Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Traces.EnabledTracesInstrumentationTemplate, tracerInstrumentation), null); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Traces.EnabledTracesInstrumentationTemplate, tracerInstrumentation.ToString().ToUpperInvariant()), null); } Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.Exporter, null); diff --git a/tools/IntegrationsJsonGenerator/Program.cs b/tools/IntegrationsJsonGenerator/Program.cs index 631cbcf230..b70e598be2 100644 --- a/tools/IntegrationsJsonGenerator/Program.cs +++ b/tools/IntegrationsJsonGenerator/Program.cs @@ -192,7 +192,7 @@ void UpdateNativeInstrumentationFile(string filePath, Dictionary "); writer.Write(bytecodeIntegration.Key.ToLowerInvariant()); writer.Write("_integration_names = {"); - writer.Write(string.Join(", ", bytecodeIntegration.Value.Select(name => $"{{WStr(\"{name}\"), WStr(\"OTEL_DOTNET_AUTO_{bytecodeIntegration.Key.ToUpperInvariant()}S_{name}_INSTRUMENTATION_ENABLED\")}}"))); + writer.Write(string.Join(", ", bytecodeIntegration.Value.Select(name => $"{{WStr(\"{name}\"), WStr(\"OTEL_DOTNET_AUTO_{bytecodeIntegration.Key.ToUpperInvariant()}S_{name.ToUpperInvariant()}_INSTRUMENTATION_ENABLED\")}}"))); writer.WriteLine("};"); } From 9dedd85aea952e8b9fe19b8c1bf4b0f63102a7e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Thu, 2 Feb 2023 10:14:37 +0100 Subject: [PATCH 12/14] Split ASP.NET and ASP.NET Core instrumentation id (#2142) --- CHANGELOG.md | 3 +++ docs/config.md | 8 +++---- .../Configurations/DelayedInitialization.cs | 24 ++++++++++++++----- .../EnvironmentConfigurationMetricHelper.cs | 23 ++++++++++++------ .../EnvironmentConfigurationTracerHelper.cs | 22 +++++++++++------ .../Configurations/MetricInstrumentation.cs | 19 +++++++++++---- .../Configurations/TracerInstrumentation.cs | 9 ++++++- .../Instrumentation.cs | 16 +++++++++++-- test/IntegrationTests/SmokeTests.cs | 1 - .../Configurations/SettingsTests.cs | 10 +++++++- 10 files changed, 101 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad069eb046..aa931a6160 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,9 @@ This beta release is built on top of [OpenTelemetry .NET](https://github.com/ope - `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED`, - `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED`. +- Change instrumentation id for ASP.NET Core traces and metrics instrumentation + from `AspNet` to `ASPNETCORE`. + ### Deprecated ### Removed diff --git a/docs/config.md b/docs/config.md index eecb82436c..83e251dc87 100644 --- a/docs/config.md +++ b/docs/config.md @@ -90,8 +90,8 @@ for example `TRACES`, and `{0}` is the case-sensitive name of the instrumentatio | ID | Instrumented library | Supported versions | Instrumentation type | |-----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------|-------------------------| -| `ASPNET` | ASP.NET (.NET Framework) MVC / WebApi \[1\] | * | source | -| `ASPNET` | ASP.NET Core | * | source | +| `ASPNET` | ASP.NET (.NET Framework) MVC / WebApi \[1\] **Not supported on .NET** | * | source | +| `ASPNETCORE` | ASP.NET Core **Not supported on .NET Framework** | * | 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 | @@ -118,8 +118,8 @@ for example `TRACES`, and `{0}` is the case-sensitive name of the instrumentatio | ID | Instrumented library | Supported versions | Instrumentation type | |---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------|----------------------| -| `ASPNET` | ASP.NET Framework \[1\] | * | source | -| `ASPNET` | ASP.NET Core \[2\] | * | source | +| `ASPNET` | ASP.NET Framework \[1\] **Not supported on .NET** | * | source | +| `ASPNETCORE` | ASP.NET Core \[2\] **Not supported on .NET Framework** | * | 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 | | `NETRUNTIME` | [OpenTelemetry.Instrumentation.Runtime](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Runtime) | * | source | | `PROCESS` | [OpenTelemetry.Instrumentation.Process](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Process) | * | source | diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/DelayedInitialization.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/DelayedInitialization.cs index a429c7dcfb..dccc69bd08 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/DelayedInitialization.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/DelayedInitialization.cs @@ -25,15 +25,21 @@ internal static class DelayedInitialization { internal static class Traces { +#if NETFRAMEWORK [MethodImpl(MethodImplOptions.NoInlining)] public static void AddAspNet(LazyInstrumentationLoader lazyInstrumentationLoader, PluginManager pluginManager) { -#if NET462 new AspNetInitializer(lazyInstrumentationLoader, pluginManager); -#elif NET6_0_OR_GREATER - lazyInstrumentationLoader.Add(new AspNetCoreInitializer(pluginManager)); + } #endif + +#if NET6_0_OR_GREATER + [MethodImpl(MethodImplOptions.NoInlining)] + public static void AddAspNetCore(LazyInstrumentationLoader lazyInstrumentationLoader, PluginManager pluginManager) + { + lazyInstrumentationLoader.Add(new AspNetCoreInitializer(pluginManager)); } +#endif [MethodImpl(MethodImplOptions.NoInlining)] public static void AddHttpClient(LazyInstrumentationLoader lazyInstrumentationLoader, PluginManager pluginManager) @@ -82,15 +88,21 @@ public static void AddQuartz(LazyInstrumentationLoader lazyInstrumentationLoader internal static class Metrics { +#if NETFRAMEWORK [MethodImpl(MethodImplOptions.NoInlining)] public static void AddAspNet(LazyInstrumentationLoader lazyInstrumentationLoader) { -#if NET462 new AspNetMetricsInitializer(lazyInstrumentationLoader); -#elif NET6_0_OR_GREATER - lazyInstrumentationLoader.Add(new AspNetCoreMetricsInitializer()); + } #endif + +#if NET6_0_OR_GREATER + [MethodImpl(MethodImplOptions.NoInlining)] + public static void AddAspNetCore(LazyInstrumentationLoader lazyInstrumentationLoader) + { + lazyInstrumentationLoader.Add(new AspNetCoreMetricsInitializer()); } +#endif [MethodImpl(MethodImplOptions.NoInlining)] public static void AddHttpClient(LazyInstrumentationLoader lazyInstrumentationLoader) diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/EnvironmentConfigurationMetricHelper.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/EnvironmentConfigurationMetricHelper.cs index ca36b92260..d437dc2a6e 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/EnvironmentConfigurationMetricHelper.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/EnvironmentConfigurationMetricHelper.cs @@ -16,7 +16,6 @@ using System.Runtime.CompilerServices; using OpenTelemetry.AutoInstrumentation.Loading; -using OpenTelemetry.AutoInstrumentation.Loading.Initializers; using OpenTelemetry.AutoInstrumentation.Logging; using OpenTelemetry.AutoInstrumentation.Plugins; using OpenTelemetry.Metrics; @@ -37,11 +36,16 @@ public static MeterProviderBuilder UseEnvironmentVariables( { _ = enabledMeter switch { +#if NETFRAMEWORK MetricInstrumentation.AspNet => Wrappers.AddAspNetInstrumentation(builder, lazyInstrumentationLoader), +#endif MetricInstrumentation.HttpClient => Wrappers.AddHttpClientInstrumentation(builder, lazyInstrumentationLoader), MetricInstrumentation.NetRuntime => Wrappers.AddRuntimeInstrumentation(builder, pluginManager), MetricInstrumentation.Process => Wrappers.AddProcessInstrumentation(builder, pluginManager), MetricInstrumentation.NServiceBus => builder.AddMeter("NServiceBus.Core"), +#if NET6_0_OR_GREATER + MetricInstrumentation.AspNetCore => Wrappers.AddAspNetCoreInstrumentation(builder, lazyInstrumentationLoader), +#endif _ => null, }; } @@ -78,18 +82,23 @@ private static MeterProviderBuilder SetExporter(this MeterProviderBuilder builde private static class Wrappers { // Meters - +#if NETFRAMEWORK [MethodImpl(MethodImplOptions.NoInlining)] public static MeterProviderBuilder AddAspNetInstrumentation(MeterProviderBuilder builder, LazyInstrumentationLoader lazyInstrumentationLoader) { DelayedInitialization.Metrics.AddAspNet(lazyInstrumentationLoader); -#if NET462 - builder.AddMeter("OpenTelemetry.Instrumentation.AspNet"); -#elif NET6_0_OR_GREATER - builder.AddMeter("OpenTelemetry.Instrumentation.AspNetCore"); + return builder.AddMeter("OpenTelemetry.Instrumentation.AspNet"); + } #endif - return builder; + +#if NET6_0_OR_GREATER + [MethodImpl(MethodImplOptions.NoInlining)] + public static MeterProviderBuilder AddAspNetCoreInstrumentation(MeterProviderBuilder builder, LazyInstrumentationLoader lazyInstrumentationLoader) + { + DelayedInitialization.Metrics.AddAspNetCore(lazyInstrumentationLoader); + return builder.AddMeter("OpenTelemetry.Instrumentation.AspNetCore"); } +#endif [MethodImpl(MethodImplOptions.NoInlining)] public static MeterProviderBuilder AddHttpClientInstrumentation(MeterProviderBuilder builder, LazyInstrumentationLoader lazyInstrumentationLoader) diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/EnvironmentConfigurationTracerHelper.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/EnvironmentConfigurationTracerHelper.cs index 611532ff98..3f4c2bb7c6 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/EnvironmentConfigurationTracerHelper.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/EnvironmentConfigurationTracerHelper.cs @@ -34,7 +34,9 @@ public static TracerProviderBuilder UseEnvironmentVariables( { _ = enabledInstrumentation switch { +#if NETFRAMEWORK TracerInstrumentation.AspNet => Wrappers.AddAspNetInstrumentation(builder, pluginManager, lazyInstrumentationLoader), +#endif TracerInstrumentation.GrpcNetClient => Wrappers.AddGrpcClientInstrumentation(builder, pluginManager, lazyInstrumentationLoader), TracerInstrumentation.HttpClient => Wrappers.AddHttpClientInstrumentation(builder, pluginManager, lazyInstrumentationLoader), TracerInstrumentation.Npgsql => builder.AddSource("Npgsql"), @@ -44,6 +46,7 @@ public static TracerProviderBuilder UseEnvironmentVariables( TracerInstrumentation.Elasticsearch => builder.AddSource("Elastic.Clients.Elasticsearch.ElasticsearchClient"), TracerInstrumentation.Quartz => Wrappers.AddQuartzInstrumentation(builder, pluginManager, lazyInstrumentationLoader), #if NET6_0_OR_GREATER + TracerInstrumentation.AspNetCore => Wrappers.AddAspNetCoreInstrumentation(builder, pluginManager, lazyInstrumentationLoader), TracerInstrumentation.MassTransit => builder.AddSource("MassTransit"), TracerInstrumentation.MongoDB => builder.AddSource("MongoDB.Driver.Core.Extensions.DiagnosticSources"), TracerInstrumentation.MySqlData => Wrappers.AddMySqlClientInstrumentation(builder, pluginManager, lazyInstrumentationLoader), @@ -134,20 +137,25 @@ public static TracerProviderBuilder AddHttpClientInstrumentation(TracerProviderB return builder; } +#if NETFRAMEWORK [MethodImpl(MethodImplOptions.NoInlining)] public static TracerProviderBuilder AddAspNetInstrumentation(TracerProviderBuilder builder, PluginManager pluginManager, LazyInstrumentationLoader lazyInstrumentationLoader) { DelayedInitialization.Traces.AddAspNet(lazyInstrumentationLoader, pluginManager); -#if NET462 - builder.AddSource(OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.AspNetSourceName); -#elif NET6_0_OR_GREATER - builder.AddSource("OpenTelemetry.Instrumentation.AspNetCore"); - builder.AddLegacySource("Microsoft.AspNetCore.Hosting.HttpRequestIn"); -#endif - return builder; + return builder.AddSource(OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.AspNetSourceName); } +#endif #if NET6_0_OR_GREATER + [MethodImpl(MethodImplOptions.NoInlining)] + public static TracerProviderBuilder AddAspNetCoreInstrumentation(TracerProviderBuilder builder, PluginManager pluginManager, LazyInstrumentationLoader lazyInstrumentationLoader) + { + DelayedInitialization.Traces.AddAspNetCore(lazyInstrumentationLoader, pluginManager); + return builder + .AddSource("OpenTelemetry.Instrumentation.AspNetCore") + .AddLegacySource("Microsoft.AspNetCore.Hosting.HttpRequestIn"); + } + [MethodImpl(MethodImplOptions.NoInlining)] public static TracerProviderBuilder AddMySqlClientInstrumentation(TracerProviderBuilder builder, PluginManager pluginManager, LazyInstrumentationLoader lazyInstrumentationLoader) { diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricInstrumentation.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricInstrumentation.cs index b44be334eb..3e39f05094 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricInstrumentation.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricInstrumentation.cs @@ -21,28 +21,37 @@ namespace OpenTelemetry.AutoInstrumentation.Configurations; /// internal enum MetricInstrumentation { +#if NETFRAMEWORK /// /// ASP.NET instrumentation. /// - AspNet, + AspNet = 1, +#endif /// /// HttpClient instrumentation. /// - HttpClient, + HttpClient = 2, /// /// .NET Runtime Metrics instrumentation. /// - NetRuntime, + NetRuntime = 3, /// /// Process instrumentation. /// - Process, + Process = 4, /// /// NServiceBus instrumentation. /// - NServiceBus + NServiceBus = 5, + +#if NET6_0_OR_GREATER + /// + /// ASP.NET Core instrumentation. + /// + AspNetCore = 6 +#endif } diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerInstrumentation.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerInstrumentation.cs index 1dab4c89a2..30c208ef03 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerInstrumentation.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerInstrumentation.cs @@ -26,10 +26,12 @@ internal enum TracerInstrumentation /// HttpClient = 0, +#if NETFRAMEWORK /// /// ASP.NET instrumentation. /// AspNet = 1, +#endif /// /// SqlClient instrumentation. @@ -101,6 +103,11 @@ internal enum TracerInstrumentation /// /// Entity Framework Core instrumentation. /// - EntityFrameworkCore = 14 + EntityFrameworkCore = 14, + + /// + /// ASP.NET Core instrumentation. + /// + AspNetCore = 15 #endif } diff --git a/src/OpenTelemetry.AutoInstrumentation/Instrumentation.cs b/src/OpenTelemetry.AutoInstrumentation/Instrumentation.cs index ab4e14d8c0..4460ba3edf 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Instrumentation.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Instrumentation.cs @@ -188,9 +188,16 @@ private static void AddLazilyLoadedMetricInstrumentations(LazyInstrumentationLoa { switch (instrumentation) { +#if NETFRAMEWORK case MetricInstrumentation.AspNet: DelayedInitialization.Metrics.AddAspNet(lazyInstrumentationLoader); break; +#endif +#if NET6_0_OR_GREATER + case MetricInstrumentation.AspNetCore: + DelayedInitialization.Metrics.AddAspNetCore(lazyInstrumentationLoader); + break; +#endif case MetricInstrumentation.HttpClient: DelayedInitialization.Metrics.AddHttpClient(lazyInstrumentationLoader); break; @@ -201,7 +208,7 @@ private static void AddLazilyLoadedMetricInstrumentations(LazyInstrumentationLoa case MetricInstrumentation.NServiceBus: break; default: - Logger.Warning($"Configured metric intrumentation type is not supported: {instrumentation}"); + Logger.Warning($"Configured metric instrumentation type is not supported: {instrumentation}"); break; } } @@ -213,9 +220,11 @@ private static void AddLazilyLoadedTraceInstrumentations(LazyInstrumentationLoad { switch (instrumentation) { +#if NETFRAMEWORK case TracerInstrumentation.AspNet: DelayedInitialization.Traces.AddAspNet(lazyInstrumentationLoader, pluginManager); break; +#endif case TracerInstrumentation.HttpClient: DelayedInitialization.Traces.AddHttpClient(lazyInstrumentationLoader, pluginManager); break; @@ -232,6 +241,9 @@ private static void AddLazilyLoadedTraceInstrumentations(LazyInstrumentationLoad DelayedInitialization.Traces.AddQuartz(lazyInstrumentationLoader, pluginManager); break; #if NET6_0_OR_GREATER + case TracerInstrumentation.AspNetCore: + DelayedInitialization.Traces.AddAspNetCore(lazyInstrumentationLoader, pluginManager); + break; case TracerInstrumentation.MySqlData: DelayedInitialization.Traces.AddMySqlClient(LazyInstrumentationLoader, pluginManager); break; @@ -254,7 +266,7 @@ private static void AddLazilyLoadedTraceInstrumentations(LazyInstrumentationLoad case TracerInstrumentation.Elasticsearch: break; default: - Logger.Warning($"Configured trace intrumentation type is not supported: {instrumentation}"); + Logger.Warning($"Configured trace instrumentation type is not supported: {instrumentation}"); break; } } diff --git a/test/IntegrationTests/SmokeTests.cs b/test/IntegrationTests/SmokeTests.cs index f46ff29941..d040762656 100644 --- a/test/IntegrationTests/SmokeTests.cs +++ b/test/IntegrationTests/SmokeTests.cs @@ -343,7 +343,6 @@ public void TracesDisabledInstrumentation() { using var collector = new MockSpansCollector(Output); SetExporter(collector); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ASPNET_INSTRUMENTATION_ENABLED", "false"); SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_HTTPCLIENT_INSTRUMENTATION_ENABLED", "false"); RunTestApplication(); collector.AssertEmpty(); diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs index 37f5f600e9..3f03ae6169 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs @@ -175,7 +175,9 @@ internal void Propagators_SupportedValues(string propagators, Propagator[] expec } [Theory] +#if NETFRAMEWORK [InlineData("ASPNET", TracerInstrumentation.AspNet)] +#endif [InlineData("GRAPHQL", TracerInstrumentation.GraphQL)] [InlineData("HTTPCLIENT", TracerInstrumentation.HttpClient)] #if NET6_0_OR_GREATER @@ -194,6 +196,7 @@ internal void Propagators_SupportedValues(string propagators, Propagator[] expec [InlineData("QUARTZ", TracerInstrumentation.Quartz)] #if NET6_0_OR_GREATER [InlineData("ENTITYFRAMEWORKCORE", TracerInstrumentation.EntityFrameworkCore)] + [InlineData("ASPNETCORE", TracerInstrumentation.AspNetCore)] #endif internal void TracerSettings_Instrumentations_SupportedValues(string tracerInstrumentation, TracerInstrumentation expectedTracerInstrumentation) { @@ -221,11 +224,16 @@ internal void TracerSettings_TracerSampler() } [Theory] - [InlineData("NETRUNTIME", MetricInstrumentation.NetRuntime)] +#if NETFRAMEWORK [InlineData("ASPNET", MetricInstrumentation.AspNet)] +#endif + [InlineData("NETRUNTIME", MetricInstrumentation.NetRuntime)] [InlineData("HTTPCLIENT", MetricInstrumentation.HttpClient)] [InlineData("PROCESS", MetricInstrumentation.Process)] [InlineData("NSERVICEBUS", MetricInstrumentation.NServiceBus)] +#if NET6_0_OR_GREATER + [InlineData("ASPNETCORE", MetricInstrumentation.AspNetCore)] +#endif internal void MeterSettings_Instrumentations_SupportedValues(string meterInstrumentation, MetricInstrumentation expectedMetricInstrumentation) { Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.MetricsInstrumentationEnabled, "false"); From f857312cf92c5a31c5d790eb619ecab1738f0fc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Thu, 2 Feb 2023 11:22:49 +0100 Subject: [PATCH 13/14] Standardize conditional compilation (#2143) --- .../Handlers/Continuations/ContinuationsHelper.cs | 2 +- .../FrameworkDescription.NetCore.cs | 2 +- .../Instrumentations/Logger/LoggingBuilderIntegration.cs | 2 +- .../MySqlData/MySqlConnectionStringBuilderIntegration.cs | 4 ++-- .../Logger/LogBuilderExtensions.cs | 2 +- test/IntegrationTests/HttpTests.cs | 2 +- test/IntegrationTests/LogTests.cs | 2 +- test/IntegrationTests/MassTransitTests.cs | 2 +- test/IntegrationTests/MongoDBCollection.cs | 2 +- test/IntegrationTests/MongoDBTests.cs | 2 +- test/IntegrationTests/SmokeTests.cs | 6 +++--- test/IntegrationTests/WcfNetFrameworkTests.cs | 2 +- 12 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/Continuations/ContinuationsHelper.cs b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/Continuations/ContinuationsHelper.cs index 700e95ef27..d7037e7bb8 100644 --- a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/Continuations/ContinuationsHelper.cs +++ b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/Continuations/ContinuationsHelper.cs @@ -43,7 +43,7 @@ internal static Type GetResultType(Type parentType) return typeof(object); } -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK internal static TTo Convert(TFrom value) { return Converter.Convert(value); diff --git a/src/OpenTelemetry.AutoInstrumentation/FrameworkDescription.NetCore.cs b/src/OpenTelemetry.AutoInstrumentation/FrameworkDescription.NetCore.cs index 336c9f9780..79470ef25e 100644 --- a/src/OpenTelemetry.AutoInstrumentation/FrameworkDescription.NetCore.cs +++ b/src/OpenTelemetry.AutoInstrumentation/FrameworkDescription.NetCore.cs @@ -14,7 +14,7 @@ // limitations under the License. // -#if !NETFRAMEWORK +#if NET6_0_OR_GREATER using System.Runtime.InteropServices; using System.Text.RegularExpressions; diff --git a/src/OpenTelemetry.AutoInstrumentation/Instrumentations/Logger/LoggingBuilderIntegration.cs b/src/OpenTelemetry.AutoInstrumentation/Instrumentations/Logger/LoggingBuilderIntegration.cs index a89669194b..ff9c3d606d 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Instrumentations/Logger/LoggingBuilderIntegration.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Instrumentations/Logger/LoggingBuilderIntegration.cs @@ -43,7 +43,7 @@ public static class LoggingBuilderIntegration /// A default CallTargetReturn to satisfy the CallTarget contract internal static CallTargetReturn OnMethodEnd(TTarget instance, Exception exception, CallTargetState state) { -#if !NETFRAMEWORK +#if NET6_0_OR_GREATER if (instance is not null) { var logBuilderExtensionsType = Type.GetType("OpenTelemetry.AutoInstrumentation.Logger.LogBuilderExtensions, OpenTelemetry.AutoInstrumentation"); diff --git a/src/OpenTelemetry.AutoInstrumentation/Instrumentations/MySqlData/MySqlConnectionStringBuilderIntegration.cs b/src/OpenTelemetry.AutoInstrumentation/Instrumentations/MySqlData/MySqlConnectionStringBuilderIntegration.cs index 6e12850a0d..4c35e2cc12 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Instrumentations/MySqlData/MySqlConnectionStringBuilderIntegration.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Instrumentations/MySqlData/MySqlConnectionStringBuilderIntegration.cs @@ -33,7 +33,7 @@ namespace OpenTelemetry.AutoInstrumentation.Instrumentations.MySqlData; type: InstrumentationType.Trace)] public static class MySqlConnectionStringBuilderIntegration { -#if !NETFRAMEWORK +#if NET6_0_OR_GREATER private static readonly object TrueAsObject = true; #endif @@ -49,7 +49,7 @@ public static class MySqlConnectionStringBuilderIntegration internal static CallTargetReturn OnMethodEnd(TReturn returnValue, Exception exception, CallTargetState state) where TTarget : struct { -#if !NETFRAMEWORK +#if NET6_0_OR_GREATER var alwaysReturnTrue = (TReturn)TrueAsObject; return new CallTargetReturn(alwaysReturnTrue); diff --git a/src/OpenTelemetry.AutoInstrumentation/Logger/LogBuilderExtensions.cs b/src/OpenTelemetry.AutoInstrumentation/Logger/LogBuilderExtensions.cs index b62344ecab..03349da30f 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Logger/LogBuilderExtensions.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Logger/LogBuilderExtensions.cs @@ -14,7 +14,7 @@ // limitations under the License. // -#if !NETFRAMEWORK +#if NET6_0_OR_GREATER using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; diff --git a/test/IntegrationTests/HttpTests.cs b/test/IntegrationTests/HttpTests.cs index 914ecf6f09..d8d6fcc720 100644 --- a/test/IntegrationTests/HttpTests.cs +++ b/test/IntegrationTests/HttpTests.cs @@ -14,7 +14,7 @@ // limitations under the License. // -#if !NETFRAMEWORK +#if NET6_0_OR_GREATER using FluentAssertions; using FluentAssertions.Execution; using IntegrationTests.Helpers; diff --git a/test/IntegrationTests/LogTests.cs b/test/IntegrationTests/LogTests.cs index 67fac6a839..9a77893a7e 100644 --- a/test/IntegrationTests/LogTests.cs +++ b/test/IntegrationTests/LogTests.cs @@ -14,7 +14,7 @@ // limitations under the License. // -#if !NETFRAMEWORK +#if NET6_0_OR_GREATER using IntegrationTests.Helpers; using Xunit.Abstractions; diff --git a/test/IntegrationTests/MassTransitTests.cs b/test/IntegrationTests/MassTransitTests.cs index 6740405dc2..a6d8dc21cd 100644 --- a/test/IntegrationTests/MassTransitTests.cs +++ b/test/IntegrationTests/MassTransitTests.cs @@ -14,7 +14,7 @@ // limitations under the License. // -#if !NETFRAMEWORK +#if NET6_0_OR_GREATER using IntegrationTests.Helpers; using Xunit; using Xunit.Abstractions; diff --git a/test/IntegrationTests/MongoDBCollection.cs b/test/IntegrationTests/MongoDBCollection.cs index a5fb9c2dc6..fa81eeb129 100644 --- a/test/IntegrationTests/MongoDBCollection.cs +++ b/test/IntegrationTests/MongoDBCollection.cs @@ -14,7 +14,7 @@ // limitations under the License. // -#if !NETFRAMEWORK +#if NET6_0_OR_GREATER using System.Threading.Tasks; using DotNet.Testcontainers.Builders; using DotNet.Testcontainers.Containers; diff --git a/test/IntegrationTests/MongoDBTests.cs b/test/IntegrationTests/MongoDBTests.cs index 8eda5bf0cf..991673726c 100644 --- a/test/IntegrationTests/MongoDBTests.cs +++ b/test/IntegrationTests/MongoDBTests.cs @@ -14,7 +14,7 @@ // limitations under the License. // -#if !NETFRAMEWORK +#if NET6_0_OR_GREATER using IntegrationTests.Helpers; using Xunit; using Xunit.Abstractions; diff --git a/test/IntegrationTests/SmokeTests.cs b/test/IntegrationTests/SmokeTests.cs index d040762656..13b0dfaf35 100644 --- a/test/IntegrationTests/SmokeTests.cs +++ b/test/IntegrationTests/SmokeTests.cs @@ -144,7 +144,7 @@ public void MetricsResource() collector.ResourceExpector.AssertExpectations(); } -#if !NETFRAMEWORK // The feature is not supported on .NET Framework +#if NET6_0_OR_GREATER // The feature is not supported on .NET Framework [Fact] [Trait("Category", "EndToEnd")] public void LogsResource() @@ -196,7 +196,7 @@ public void ZipkinExporter() collector.AssertExpectations(); } -#if NETFRAMEWORK // The test is flaky on Linux and macOS, becasue of https://github.com/dotnet/runtime/issues/28658#issuecomment-462062760 +#if NETFRAMEWORK // The test is flaky on Linux and macOS, because of https://github.com/dotnet/runtime/issues/28658#issuecomment-462062760 [Fact] [Trait("Category", "EndToEnd")] public void PrometheusExporter() @@ -245,7 +245,7 @@ public void PrometheusExporter() } #endif -#if !NETFRAMEWORK // The feature is not supported on .NET Framework +#if NET6_0_OR_GREATER // The feature is not supported on .NET Framework [Fact] [Trait("Category", "EndToEnd")] public void SubmitLogs() diff --git a/test/IntegrationTests/WcfNetFrameworkTests.cs b/test/IntegrationTests/WcfNetFrameworkTests.cs index 05000edbcd..3600b0e5cc 100644 --- a/test/IntegrationTests/WcfNetFrameworkTests.cs +++ b/test/IntegrationTests/WcfNetFrameworkTests.cs @@ -14,7 +14,7 @@ // limitations under the License. // -#if NET462 +#if NETFRAMEWORK using Xunit.Abstractions; namespace IntegrationTests; From fe24131b792e02deb96fdaa50e5b0a2dce1d4226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Thu, 2 Feb 2023 11:56:40 +0100 Subject: [PATCH 14/14] Bump Testcontainers to 2.4.0 (#2144) --- test/Directory.Packages.props | 2 +- test/IntegrationTests/AspNetTests.cs | 4 ++-- .../TestContainers/UntilAsyncOperationIsSucceeded.cs | 3 +-- test/IntegrationTests/MongoDBCollection.cs | 9 ++++----- test/IntegrationTests/MySqlCollection.cs | 11 ++++------- test/IntegrationTests/PostgresCollection.cs | 11 ++++------- test/IntegrationTests/RedisCollection.cs | 11 ++++------- test/IntegrationTests/SqlServerCollection.cs | 9 ++++----- 8 files changed, 24 insertions(+), 36 deletions(-) diff --git a/test/Directory.Packages.props b/test/Directory.Packages.props index c4b619677d..72284efe65 100644 --- a/test/Directory.Packages.props +++ b/test/Directory.Packages.props @@ -39,7 +39,7 @@ - + diff --git a/test/IntegrationTests/AspNetTests.cs b/test/IntegrationTests/AspNetTests.cs index 9b5c5f256f..c1c8d156f7 100644 --- a/test/IntegrationTests/AspNetTests.cs +++ b/test/IntegrationTests/AspNetTests.cs @@ -117,7 +117,7 @@ public async Task SubmitMetrics() collector.AssertExpectations(); } - private async Task StartContainerAsync(int webPort) + private async Task StartContainerAsync(int webPort) { // get path to test application that the profiler will attach to string imageName = $"testapplication-aspnet-netframework"; @@ -131,7 +131,7 @@ private async Task StartContainerAsync(int webPort) Directory.CreateDirectory(logPath); Output.WriteLine("Collecting docker logs to: " + logPath); - var builder = new TestcontainersBuilder() + var builder = new ContainerBuilder() .WithImage(imageName) .WithCleanUp(cleanUp: true) .WithOutputConsumer(Consume.RedirectStdoutAndStderrToConsole()) diff --git a/test/IntegrationTests/Helpers/TestContainers/UntilAsyncOperationIsSucceeded.cs b/test/IntegrationTests/Helpers/TestContainers/UntilAsyncOperationIsSucceeded.cs index 47adaea66e..d51d144c67 100644 --- a/test/IntegrationTests/Helpers/TestContainers/UntilAsyncOperationIsSucceeded.cs +++ b/test/IntegrationTests/Helpers/TestContainers/UntilAsyncOperationIsSucceeded.cs @@ -16,7 +16,6 @@ using DotNet.Testcontainers.Configurations; using DotNet.Testcontainers.Containers; -using Microsoft.Extensions.Logging; namespace IntegrationTests.Helpers.TestContainers; @@ -32,7 +31,7 @@ public UntilAsyncOperationIsSucceeded(Func> operation, int maxCallCou _maxCallCount = maxCallCount; } - public async Task Until(ITestcontainersContainer testcontainers, ILogger logger) + public async Task UntilAsync(IContainer container) { if (++_tryCount > _maxCallCount) { diff --git a/test/IntegrationTests/MongoDBCollection.cs b/test/IntegrationTests/MongoDBCollection.cs index fa81eeb129..d5a85d2dc9 100644 --- a/test/IntegrationTests/MongoDBCollection.cs +++ b/test/IntegrationTests/MongoDBCollection.cs @@ -34,7 +34,7 @@ public class MongoDBFixture : IAsyncLifetime private const int MongoDBPort = 27017; private const string MongoDBImage = "mongo:5.0.6"; - private TestcontainersContainer? _container; + private IContainer? _container; public MongoDBFixture() { @@ -56,9 +56,9 @@ public async Task DisposeAsync() } } - private async Task LaunchMongoContainerAsync(int port) + private async Task LaunchMongoContainerAsync(int port) { - var mongoContainersBuilder = new TestcontainersBuilder() + var mongoContainersBuilder = new ContainerBuilder() .WithImage(MongoDBImage) .WithName($"mongo-db-{port}") .WithPortBinding(port, MongoDBPort) @@ -70,9 +70,8 @@ private async Task LaunchMongoContainerAsync(int port) return container; } - private async Task ShutdownMongoContainerAsync(TestcontainersContainer container) + private async Task ShutdownMongoContainerAsync(IContainer container) { - await container.CleanUpAsync(); await container.DisposeAsync(); } } diff --git a/test/IntegrationTests/MySqlCollection.cs b/test/IntegrationTests/MySqlCollection.cs index 1e7fae3678..507ab90493 100644 --- a/test/IntegrationTests/MySqlCollection.cs +++ b/test/IntegrationTests/MySqlCollection.cs @@ -15,11 +15,9 @@ // #if NET6_0_OR_GREATER -using System.Threading.Tasks; using DotNet.Testcontainers.Builders; using DotNet.Testcontainers.Containers; using IntegrationTests.Helpers; -using Xunit; namespace IntegrationTests; @@ -34,7 +32,7 @@ public class MySqlFixture : IAsyncLifetime private const int MySqlPort = 3306; private const string MySqlImage = "mysql:8.0.29"; - private TestcontainersContainer? _container; + private IContainer? _container; public MySqlFixture() { @@ -56,9 +54,9 @@ public async Task DisposeAsync() } } - private async Task LaunchMySqlContainerAsync(int port) + private async Task LaunchMySqlContainerAsync(int port) { - var containersBuilder = new TestcontainersBuilder() + var containersBuilder = new ContainerBuilder() .WithImage(MySqlImage) .WithName($"mysql-{port}") .WithPortBinding(port, MySqlPort) @@ -71,9 +69,8 @@ private async Task LaunchMySqlContainerAsync(int port) return container; } - private async Task ShutdownMySqlContainerAsync(TestcontainersContainer container) + private async Task ShutdownMySqlContainerAsync(IContainer container) { - await container.CleanUpAsync(); await container.DisposeAsync(); } } diff --git a/test/IntegrationTests/PostgresCollection.cs b/test/IntegrationTests/PostgresCollection.cs index 9796c784ab..8b71abd785 100644 --- a/test/IntegrationTests/PostgresCollection.cs +++ b/test/IntegrationTests/PostgresCollection.cs @@ -14,11 +14,9 @@ // limitations under the License. // -using System.Threading.Tasks; using DotNet.Testcontainers.Builders; using DotNet.Testcontainers.Containers; using IntegrationTests.Helpers; -using Xunit; namespace IntegrationTests; @@ -33,7 +31,7 @@ public class PostgresFixture : IAsyncLifetime private const int PostgresPort = 5432; private const string PostgresImage = "postgres:14.4"; - private TestcontainersContainer? _container; + private IContainer? _container; public PostgresFixture() { @@ -55,9 +53,9 @@ public async Task DisposeAsync() } } - private async Task LaunchPostgresContainerAsync(int port) + private async Task LaunchPostgresContainerAsync(int port) { - var containersBuilder = new TestcontainersBuilder() + var containersBuilder = new ContainerBuilder() .WithImage(PostgresImage) .WithName($"postgres-{port}") .WithPortBinding(port, PostgresPort) @@ -70,9 +68,8 @@ private async Task LaunchPostgresContainerAsync(int por return container; } - private async Task ShutdownPostgresContainerAsync(TestcontainersContainer container) + private async Task ShutdownPostgresContainerAsync(IContainer container) { - await container.CleanUpAsync(); await container.DisposeAsync(); } } diff --git a/test/IntegrationTests/RedisCollection.cs b/test/IntegrationTests/RedisCollection.cs index 33d6017011..3e5dd12aeb 100644 --- a/test/IntegrationTests/RedisCollection.cs +++ b/test/IntegrationTests/RedisCollection.cs @@ -16,11 +16,9 @@ #if NET6_0_OR_GREATER -using System.Threading.Tasks; using DotNet.Testcontainers.Builders; using DotNet.Testcontainers.Containers; using IntegrationTests.Helpers; -using Xunit; namespace IntegrationTests; @@ -35,7 +33,7 @@ public class RedisFixture : IAsyncLifetime private const int RedisPort = 6379; private const string RedisImage = "redis:7.0.4"; - private TestcontainersContainer? _container; + private IContainer? _container; public RedisFixture() { @@ -57,9 +55,9 @@ public async Task DisposeAsync() } } - private async Task LaunchRedisContainerAsync(int port) + private async Task LaunchRedisContainerAsync(int port) { - var containersBuilder = new TestcontainersBuilder() + var containersBuilder = new ContainerBuilder() .WithImage(RedisImage) .WithName($"redis-{port}") .WithPortBinding(port, RedisPort) @@ -71,9 +69,8 @@ private async Task LaunchRedisContainerAsync(int port) return container; } - private async Task ShutdownRedisContainerAsync(TestcontainersContainer container) + private async Task ShutdownRedisContainerAsync(IContainer container) { - await container.CleanUpAsync(); await container.DisposeAsync(); } } diff --git a/test/IntegrationTests/SqlServerCollection.cs b/test/IntegrationTests/SqlServerCollection.cs index aff51cd6ad..24acf4d0f6 100644 --- a/test/IntegrationTests/SqlServerCollection.cs +++ b/test/IntegrationTests/SqlServerCollection.cs @@ -33,7 +33,7 @@ public class SqlServerFixture : IAsyncLifetime private const int DatabasePort = 1433; private const string DatabaseImage = "mcr.microsoft.com/mssql/server:2019-CU17-ubuntu-20.04"; - private TestcontainersContainer? _container; + private IContainer? _container; public SqlServerFixture() { @@ -57,15 +57,14 @@ public async Task DisposeAsync() } } - private static async Task ShutdownSqlServerContainerAsync(TestcontainersContainer container) + private static async Task ShutdownSqlServerContainerAsync(IContainer container) { - await container.CleanUpAsync(); await container.DisposeAsync(); } - private async Task LaunchSqlServerContainerAsync() + private async Task LaunchSqlServerContainerAsync() { - var databaseContainersBuilder = new TestcontainersBuilder() + var databaseContainersBuilder = new ContainerBuilder() .WithImage(DatabaseImage) .WithName($"sql-server-{Port}") .WithPortBinding(Port, DatabasePort)