Skip to content

Commit fc0fa43

Browse files
committed
automatically handle assembly redirection
1 parent 49ca5fb commit fc0fa43

4 files changed

Lines changed: 25 additions & 8 deletions

File tree

build/AssemblyRedirectionSourceGenerator.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,15 @@ private static string GenerateSourceContents(SortedDictionary<string, AssemblyNa
5050
#include "cor_profiler.h"
5151
5252
#ifdef _WIN32
53+
#define STR(Z1) #Z1
54+
#define AUTO_MAJOR STR(OTEL_AUTO_VERSION_MAJOR)
55+
5356
namespace trace
5457
{
5558
void CorProfiler::InitNetFxAssemblyRedirectsMap()
5659
{
60+
const USHORT auto_major = atoi(AUTO_MAJOR);
61+
5762
assembly_version_redirect_map_.insert({
5863
{{GenerateEntries(assemblies)}}
5964
});
@@ -73,7 +78,14 @@ private static string GenerateEntries(SortedDictionary<string, AssemblyNameDefin
7378
foreach (var kvp in assemblies)
7479
{
7580
var v = kvp.Value.Version!;
76-
sb.AppendLine($" {{ L\"{kvp.Key}\", {{{v.Major}, {v.Minor}, {v.Build}, {v.Revision}}} }},");
81+
if(kvp.Key != "OpenTelemetry.AutoInstrumentation")
82+
{
83+
sb.AppendLine($" {{ L\"{kvp.Key}\", {{{v.Major}, {v.Minor}, {v.Build}, {v.Revision}}} }},");
84+
}
85+
else
86+
{
87+
sb.AppendLine($" {{ L\"{kvp.Key}\", {{auto_major, 0, 0, 0}} }},");
88+
}
7789
}
7890

7991
return sb.ToString()

src/OpenTelemetry.AutoInstrumentation.Native/OpenTelemetry.AutoInstrumentation.Native.vcxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
<ConformanceMode>true</ConformanceMode>
9595
<SDLCheck>true</SDLCheck>
9696
<MultiProcessorCompilation>true</MultiProcessorCompilation>
97-
<PreprocessorDefinitions>SPDLOG_COMPILED_LIB;SPDLOG_FMT_EXTERNAL;BIT64;HOST_64BIT;AMD64;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
97+
<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)</PreprocessorDefinitions>
9898
<AdditionalIncludeDirectories>$(LIB_INCLUDES);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
9999
<TreatWarningAsError>true</TreatWarningAsError>
100100
</ClCompile>
@@ -116,7 +116,7 @@
116116
<ConformanceMode>true</ConformanceMode>
117117
<SDLCheck>true</SDLCheck>
118118
<MultiProcessorCompilation>true</MultiProcessorCompilation>
119-
<PreprocessorDefinitions>SPDLOG_COMPILED_LIB;SPDLOG_FMT_EXTERNAL;_UNICODE;UNICODE;X86;HOST_X86;%(PreprocessorDefinitions)</PreprocessorDefinitions>
119+
<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)</PreprocessorDefinitions>
120120
<AdditionalIncludeDirectories>$(LIB_INCLUDES);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
121121
<TreatWarningAsError>true</TreatWarningAsError>
122122
</ClCompile>
@@ -143,7 +143,7 @@
143143
<ConformanceMode>true</ConformanceMode>
144144
<SDLCheck>true</SDLCheck>
145145
<MultiProcessorCompilation>true</MultiProcessorCompilation>
146-
<PreprocessorDefinitions>SPDLOG_COMPILED_LIB;SPDLOG_FMT_EXTERNAL;_TARGET_64BIT;BIT64;HOST_64BIT;AMD64;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
146+
<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)</PreprocessorDefinitions>
147147
<AdditionalIncludeDirectories>$(LIB_INCLUDES);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
148148
<TreatWarningAsError>true</TreatWarningAsError>
149149
</ClCompile>
@@ -169,7 +169,7 @@
169169
<ConformanceMode>true</ConformanceMode>
170170
<SDLCheck>true</SDLCheck>
171171
<MultiProcessorCompilation>true</MultiProcessorCompilation>
172-
<PreprocessorDefinitions>SPDLOG_COMPILED_LIB;SPDLOG_FMT_EXTERNAL;_UNICODE;UNICODE;X86;HOST_X86;%(PreprocessorDefinitions)</PreprocessorDefinitions>
172+
<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)</PreprocessorDefinitions>
173173
<AdditionalIncludeDirectories>$(LIB_INCLUDES);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
174174
<TreatWarningAsError>true</TreatWarningAsError>
175175
</ClCompile>

src/OpenTelemetry.AutoInstrumentation.Native/netfx_assembly_redirection.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88
#include "cor_profiler.h"
99

1010
#ifdef _WIN32
11+
#define STR(Z1) #Z1
12+
#define AUTO_MAJOR STR(OTEL_AUTO_VERSION_MAJOR)
13+
1114
namespace trace
1215
{
1316
void CorProfiler::InitNetFxAssemblyRedirectsMap()
1417
{
18+
const USHORT auto_major = atoi(AUTO_MAJOR);
19+
1520
assembly_version_redirect_map_.insert({
1621
{ L"Google.Protobuf", {3, 23, 4, 0} },
1722
{ L"Grpc.Core", {2, 0, 0, 0} },
@@ -33,7 +38,7 @@ void CorProfiler::InitNetFxAssemblyRedirectsMap()
3338
{ L"OpenTelemetry", {1, 0, 0, 0} },
3439
{ L"OpenTelemetry.Api", {1, 0, 0, 0} },
3540
{ L"OpenTelemetry.Api.ProviderBuilderExtensions", {1, 0, 0, 0} },
36-
{ L"OpenTelemetry.AutoInstrumentation", {1, 0, 0, 0} },
41+
{ L"OpenTelemetry.AutoInstrumentation", {auto_major, 0, 0, 0} },
3742
{ L"OpenTelemetry.Exporter.Console", {1, 0, 0, 0} },
3843
{ L"OpenTelemetry.Exporter.OpenTelemetryProtocol", {1, 0, 0, 0} },
3944
{ L"OpenTelemetry.Exporter.Prometheus.HttpListener", {1, 0, 0, 0} },

src/OpenTelemetry.AutoInstrumentation.Native/version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#define STRTMP4(V1, V2, V3, V4) #V1 "." #V2 "." #V3 "." #V4
1111
#define STR4(V1, V2, V3, V4) STRTMP4(V1, V2, V3, V4)
1212
#define VERSION_3PARTS STR3(OTEL_AUTO_VERSION_MAJOR, OTEL_AUTO_VERSION_MINOR, OTEL_AUTO_VERSION_PATCH)
13-
#define VERSION_4PARTS STR4(OTEL_AUTO_VERSION_MAJOR, OTEL_AUTO_VERSION_MINOR, OTEL_AUTO_VERSION_PATCH, 0)
13+
#define VERSION_4PARTS STR4(OTEL_AUTO_VERSION_MAJOR, 0, 0, 0)
1414

1515
const auto PROFILER_VERSION = VERSION_3PARTS;
16-
const auto FILE_VERSION = VERSION_4PARTS;
16+
const auto FILE_VERSION = VERSION_4PARTS;

0 commit comments

Comments
 (0)