Skip to content

Commit 1a9a492

Browse files
Use assembly information version for User-Agent (#4143)
Use `AssemblyInformationalVersionAttribute` for the `User-Agent` value. See https://github.com/open-telemetry/opentelemetry-dotnet/pull/4120/files/6f04561448ae211287f885d8b699fc68d853de29#r1094245847. Co-authored-by: Alan West <[email protected]>
1 parent 1273e83 commit 1a9a492

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// </copyright>
1616

1717
using System.Diagnostics;
18+
using System.Reflection;
1819
#if NETFRAMEWORK
1920
using System.Net.Http;
2021
#endif
@@ -51,7 +52,7 @@ public class OtlpExporterOptions
5152
private const OtlpExportProtocol DefaultOtlpExportProtocol = OtlpExportProtocol.Grpc;
5253
private const string UserAgentProduct = "OTel-OTLP-Exporter-Dotnet";
5354

54-
private static readonly Version UserAgentProductVersion = GetAssemblyVersion();
55+
private static readonly string UserAgentProductVersion = GetAssemblyVersion();
5556

5657
private Uri endpoint;
5758

@@ -204,12 +205,12 @@ internal static void RegisterOtlpExporterOptionsFactory(IServiceCollection servi
204205
sp.GetRequiredService<IOptionsMonitor<BatchExportActivityProcessorOptions>>().Get(name)));
205206
}
206207

207-
private static Version GetAssemblyVersion()
208+
private static string GetAssemblyVersion()
208209
{
209210
try
210211
{
211-
var assemblyName = typeof(OtlpExporterOptions).Assembly.GetName();
212-
return assemblyName.Version;
212+
var assemblyVersion = typeof(OtlpExporterOptions).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
213+
return assemblyVersion.InformationalVersion;
213214
}
214215
catch (Exception)
215216
{

0 commit comments

Comments
 (0)