From fc0fa4318c7657c46ece89e58a223ae552b9b4cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Mon, 24 Jul 2023 13:52:08 +0200 Subject: [PATCH] automatically handle assembly redirection --- build/AssemblyRedirectionSourceGenerator.cs | 14 +++++++++++++- ...penTelemetry.AutoInstrumentation.Native.vcxproj | 8 ++++---- .../netfx_assembly_redirection.h | 7 ++++++- .../version.h | 4 ++-- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/build/AssemblyRedirectionSourceGenerator.cs b/build/AssemblyRedirectionSourceGenerator.cs index 40d68e094d..86714a2988 100644 --- a/build/AssemblyRedirectionSourceGenerator.cs +++ b/build/AssemblyRedirectionSourceGenerator.cs @@ -50,10 +50,15 @@ private static string GenerateSourceContents(SortedDictionarytrue true true - SPDLOG_COMPILED_LIB;SPDLOG_FMT_EXTERNAL;BIT64;HOST_64BIT;AMD64;_UNICODE;UNICODE;%(PreprocessorDefinitions) + SPDLOG_COMPILED_LIB;SPDLOG_FMT_EXTERNAL;BIT64;HOST_64BIT;AMD64;_UNICODE;UNICODE;OTEL_AUTO_VERSION_MAJOR=$(OTEL_AUTO_VERSION_MAJOR);OTEL_AUTO_VERSION_MINOR=$(OTEL_AUTO_VERSION_MINOR);OTEL_AUTO_VERSION_PATCH=$(OTEL_AUTO_VERSION_PATCH);%(PreprocessorDefinitions) $(LIB_INCLUDES);%(AdditionalIncludeDirectories) true @@ -116,7 +116,7 @@ true true true - SPDLOG_COMPILED_LIB;SPDLOG_FMT_EXTERNAL;_UNICODE;UNICODE;X86;HOST_X86;%(PreprocessorDefinitions) + SPDLOG_COMPILED_LIB;SPDLOG_FMT_EXTERNAL;_UNICODE;UNICODE;X86;HOST_X86;OTEL_AUTO_VERSION_MAJOR=$(OTEL_AUTO_VERSION_MAJOR);OTEL_AUTO_VERSION_MINOR=$(OTEL_AUTO_VERSION_MINOR);OTEL_AUTO_VERSION_PATCH=$(OTEL_AUTO_VERSION_PATCH);%(PreprocessorDefinitions) $(LIB_INCLUDES);%(AdditionalIncludeDirectories) true @@ -143,7 +143,7 @@ true true true - SPDLOG_COMPILED_LIB;SPDLOG_FMT_EXTERNAL;_TARGET_64BIT;BIT64;HOST_64BIT;AMD64;_UNICODE;UNICODE;%(PreprocessorDefinitions) + SPDLOG_COMPILED_LIB;SPDLOG_FMT_EXTERNAL;_TARGET_64BIT;BIT64;HOST_64BIT;AMD64;_UNICODE;UNICODE;OTEL_AUTO_VERSION_MAJOR=$(OTEL_AUTO_VERSION_MAJOR);OTEL_AUTO_VERSION_MINOR=$(OTEL_AUTO_VERSION_MINOR);OTEL_AUTO_VERSION_PATCH=$(OTEL_AUTO_VERSION_PATCH);%(PreprocessorDefinitions) $(LIB_INCLUDES);%(AdditionalIncludeDirectories) true @@ -169,7 +169,7 @@ true true true - SPDLOG_COMPILED_LIB;SPDLOG_FMT_EXTERNAL;_UNICODE;UNICODE;X86;HOST_X86;%(PreprocessorDefinitions) + SPDLOG_COMPILED_LIB;SPDLOG_FMT_EXTERNAL;_UNICODE;UNICODE;X86;HOST_X86;OTEL_AUTO_VERSION_MAJOR=$(OTEL_AUTO_VERSION_MAJOR);OTEL_AUTO_VERSION_MINOR=$(OTEL_AUTO_VERSION_MINOR);OTEL_AUTO_VERSION_PATCH=$(OTEL_AUTO_VERSION_PATCH);%(PreprocessorDefinitions) $(LIB_INCLUDES);%(AdditionalIncludeDirectories) true diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/netfx_assembly_redirection.h b/src/OpenTelemetry.AutoInstrumentation.Native/netfx_assembly_redirection.h index 574885dfdc..9d0c11b8b4 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/netfx_assembly_redirection.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/netfx_assembly_redirection.h @@ -8,10 +8,15 @@ #include "cor_profiler.h" #ifdef _WIN32 +#define STR(Z1) #Z1 +#define AUTO_MAJOR STR(OTEL_AUTO_VERSION_MAJOR) + namespace trace { void CorProfiler::InitNetFxAssemblyRedirectsMap() { + const USHORT auto_major = atoi(AUTO_MAJOR); + assembly_version_redirect_map_.insert({ { L"Google.Protobuf", {3, 23, 4, 0} }, { L"Grpc.Core", {2, 0, 0, 0} }, @@ -33,7 +38,7 @@ void CorProfiler::InitNetFxAssemblyRedirectsMap() { L"OpenTelemetry", {1, 0, 0, 0} }, { L"OpenTelemetry.Api", {1, 0, 0, 0} }, { L"OpenTelemetry.Api.ProviderBuilderExtensions", {1, 0, 0, 0} }, - { L"OpenTelemetry.AutoInstrumentation", {1, 0, 0, 0} }, + { L"OpenTelemetry.AutoInstrumentation", {auto_major, 0, 0, 0} }, { L"OpenTelemetry.Exporter.Console", {1, 0, 0, 0} }, { L"OpenTelemetry.Exporter.OpenTelemetryProtocol", {1, 0, 0, 0} }, { L"OpenTelemetry.Exporter.Prometheus.HttpListener", {1, 0, 0, 0} }, diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/version.h b/src/OpenTelemetry.AutoInstrumentation.Native/version.h index e60ad23ac0..97065daaab 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/version.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/version.h @@ -10,7 +10,7 @@ #define STRTMP4(V1, V2, V3, V4) #V1 "." #V2 "." #V3 "." #V4 #define STR4(V1, V2, V3, V4) STRTMP4(V1, V2, V3, V4) #define VERSION_3PARTS STR3(OTEL_AUTO_VERSION_MAJOR, OTEL_AUTO_VERSION_MINOR, OTEL_AUTO_VERSION_PATCH) -#define VERSION_4PARTS STR4(OTEL_AUTO_VERSION_MAJOR, OTEL_AUTO_VERSION_MINOR, OTEL_AUTO_VERSION_PATCH, 0) +#define VERSION_4PARTS STR4(OTEL_AUTO_VERSION_MAJOR, 0, 0, 0) const auto PROFILER_VERSION = VERSION_3PARTS; -const auto FILE_VERSION = VERSION_4PARTS; +const auto FILE_VERSION = VERSION_4PARTS;