From da53a1824c8a9094209e37d330150564a2ff6290 Mon Sep 17 00:00:00 2001 From: martincostello Date: Fri, 3 Feb 2023 14:14:38 +0000 Subject: [PATCH] Use assembly information version for User-Agent Use `AssemblyInformationalVersionAttribute` for the `User-Agent` value. See https://github.com/open-telemetry/opentelemetry-dotnet/pull/4120/files/6f04561448ae211287f885d8b699fc68d853de29#r1094245847. --- .../OtlpExporterOptions.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs index 18efd9de04b..53f4979c6ca 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs @@ -15,6 +15,7 @@ // using System.Diagnostics; +using System.Reflection; #if NETFRAMEWORK using System.Net.Http; #endif @@ -51,7 +52,7 @@ public class OtlpExporterOptions private const OtlpExportProtocol DefaultOtlpExportProtocol = OtlpExportProtocol.Grpc; private const string UserAgentProduct = "OTel-OTLP-Exporter-Dotnet"; - private static readonly Version UserAgentProductVersion = GetAssemblyVersion(); + private static readonly string UserAgentProductVersion = GetAssemblyVersion(); private Uri endpoint; @@ -204,12 +205,12 @@ internal static void RegisterOtlpExporterOptionsFactory(IServiceCollection servi sp.GetRequiredService>().Get(name))); } - private static Version GetAssemblyVersion() + private static string GetAssemblyVersion() { try { - var assemblyName = typeof(OtlpExporterOptions).Assembly.GetName(); - return assemblyName.Version; + var assemblyVersion = typeof(OtlpExporterOptions).Assembly.GetCustomAttribute(); + return assemblyVersion.InformationalVersion; } catch (Exception) {