Use assembly information version for User-Agent (#4143)

Use `AssemblyInformationalVersionAttribute` for the `User-Agent` value.
See 6f04561448 (r1094245847).

Co-authored-by: Alan West <3676547+alanwest@users.noreply.github.com>
This commit is contained in:
Martin Costello 2023-02-08 04:33:34 +00:00 committed by GitHub
parent 1273e83d55
commit 1a9a492e02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -15,6 +15,7 @@
// </copyright>
using System.Diagnostics;
using System.Reflection;
#if NETFRAMEWORK
using System.Net.Http;
#endif
@ -51,7 +52,7 @@ namespace OpenTelemetry.Exporter
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 @@ namespace OpenTelemetry.Exporter
sp.GetRequiredService<IOptionsMonitor<BatchExportActivityProcessorOptions>>().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<AssemblyInformationalVersionAttribute>();
return assemblyVersion.InformationalVersion;
}
catch (Exception)
{