Skip to content

Commit 876e4fa

Browse files
[Exporter.OpenTelemetryProtocol] User agent changed to OTel-OTLP-Exporter-Dotnet/{NuGet Package Version} (#5528)
Co-authored-by: Vishwesh Bankwar <vishweshbankwar@users.noreply.github.com>
1 parent a4e5cf5 commit 876e4fa

File tree

7 files changed

+15
-17
lines changed

7 files changed

+15
-17
lines changed

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
* Fix native AoT warnings in `OpenTelemetry.Exporter.OpenTelemetryProtocol`.
66
([#5520](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5520))
77

8+
* `User-Agent` header format changed from
9+
`OTel-OTLP-Exporter-Dotnet/{NuGet Package Version}+{Commit Hash}`
10+
to `OTel-OTLP-Exporter-Dotnet/{NuGet Package Version}`.
11+
([#5528](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5528))
12+
813
## 1.8.0
914

1015
Released 2024-Apr-02

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#if NETFRAMEWORK
88
using System.Net.Http;
99
#endif
10-
using System.Reflection;
1110
using Microsoft.Extensions.Configuration;
1211
using Microsoft.Extensions.DependencyInjection;
1312
using Microsoft.Extensions.Options;
@@ -38,8 +37,6 @@ public class OtlpExporterOptions : IOtlpExporterOptions
3837

3938
internal readonly Func<HttpClient> DefaultHttpClientFactory;
4039

41-
private const string UserAgentProduct = "OTel-OTLP-Exporter-Dotnet";
42-
4340
private OtlpExportProtocol? protocol;
4441
private Uri? endpoint;
4542
private int? timeoutMilliseconds;
@@ -227,16 +224,8 @@ internal OtlpExporterOptions ApplyDefaults(OtlpExporterOptions defaultExporterOp
227224

228225
private static string GetUserAgentString()
229226
{
230-
try
231-
{
232-
var assemblyVersion = typeof(OtlpExporterOptions).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
233-
var informationalVersion = assemblyVersion?.InformationalVersion;
234-
return string.IsNullOrEmpty(informationalVersion) ? UserAgentProduct : $"{UserAgentProduct}/{informationalVersion}";
235-
}
236-
catch (Exception)
237-
{
238-
return UserAgentProduct;
239-
}
227+
var assembly = typeof(OtlpExporterOptions).Assembly;
228+
return $"OTel-OTLP-Exporter-Dotnet/{assembly.GetPackageVersion()}";
240229
}
241230

242231
private void ApplyConfiguration(

src/OpenTelemetry.Instrumentation.GrpcNetClient/Implementation/GrpcClientDiagnosticListener.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Reflection;
99
using OpenTelemetry.Context.Propagation;
1010
using OpenTelemetry.Instrumentation.Http;
11+
using OpenTelemetry.Internal;
1112
using OpenTelemetry.Trace;
1213

1314
namespace OpenTelemetry.Instrumentation.GrpcNetClient.Implementation;

src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlActivitySourceHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Diagnostics;
55
using System.Reflection;
6+
using OpenTelemetry.Internal;
67
using OpenTelemetry.Trace;
78

89
namespace OpenTelemetry.Instrumentation.SqlClient.Implementation;

src/OpenTelemetry/Sdk.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Diagnostics.CodeAnalysis;
77
#endif
88
using OpenTelemetry.Context.Propagation;
9-
using OpenTelemetry.Instrumentation;
109
using OpenTelemetry.Internal;
1110
using OpenTelemetry.Logs;
1211
using OpenTelemetry.Metrics;

src/Shared/AssemblyVersionExtensions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
#nullable enable
55

6+
using System.Diagnostics;
67
using System.Reflection;
78

8-
namespace OpenTelemetry.Instrumentation;
9+
namespace OpenTelemetry.Internal;
910

1011
internal static class AssemblyVersionExtensions
1112
{
@@ -19,7 +20,9 @@ public static string GetPackageVersion(this Assembly assembly)
1920
// The following parts are optional: pre-release label, pre-release version, git height, Git SHA of current commit
2021
// For package version, value of AssemblyInformationalVersionAttribute without commit hash is returned.
2122

22-
var informationalVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion;
23+
var informationalVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
24+
Debug.Assert(!string.IsNullOrEmpty(informationalVersion), "AssemblyInformationalVersionAttribute was not found in assembly");
25+
2326
var indexOfPlusSign = informationalVersion!.IndexOf('+');
2427
return indexOfPlusSign > 0
2528
? informationalVersion.Substring(0, indexOfPlusSign)

test/OpenTelemetry.Tests/Shared/AssemblyVersionExtensionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#nullable enable
55

66
using System.Reflection;
7-
using OpenTelemetry.Instrumentation;
7+
using OpenTelemetry.Internal;
88
using Xunit;
99

1010
namespace OpenTelemetry.Tests;

0 commit comments

Comments
 (0)