Skip to content

Commit

Permalink
[Exporter.OpenTelemetryProtocol] User agent changed to OTel-OTLP-Expo…
Browse files Browse the repository at this point in the history
…rter-Dotnet/{NuGet Package Version} (#5528)

Co-authored-by: Vishwesh Bankwar <vishweshbankwar@users.noreply.github.com>
  • Loading branch information
Kielek and vishweshbankwar committed Apr 10, 2024
1 parent a4e5cf5 commit 876e4fa
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 17 deletions.
5 changes: 5 additions & 0 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
* Fix native AoT warnings in `OpenTelemetry.Exporter.OpenTelemetryProtocol`.
([#5520](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5520))

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

## 1.8.0

Released 2024-Apr-02
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#if NETFRAMEWORK
using System.Net.Http;
#endif
using System.Reflection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -38,8 +37,6 @@ public class OtlpExporterOptions : IOtlpExporterOptions

internal readonly Func<HttpClient> DefaultHttpClientFactory;

private const string UserAgentProduct = "OTel-OTLP-Exporter-Dotnet";

private OtlpExportProtocol? protocol;
private Uri? endpoint;
private int? timeoutMilliseconds;
Expand Down Expand Up @@ -227,16 +224,8 @@ internal OtlpExporterOptions ApplyDefaults(OtlpExporterOptions defaultExporterOp

private static string GetUserAgentString()
{
try
{
var assemblyVersion = typeof(OtlpExporterOptions).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
var informationalVersion = assemblyVersion?.InformationalVersion;
return string.IsNullOrEmpty(informationalVersion) ? UserAgentProduct : $"{UserAgentProduct}/{informationalVersion}";
}
catch (Exception)
{
return UserAgentProduct;
}
var assembly = typeof(OtlpExporterOptions).Assembly;
return $"OTel-OTLP-Exporter-Dotnet/{assembly.GetPackageVersion()}";
}

private void ApplyConfiguration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Reflection;
using OpenTelemetry.Context.Propagation;
using OpenTelemetry.Instrumentation.Http;
using OpenTelemetry.Internal;
using OpenTelemetry.Trace;

namespace OpenTelemetry.Instrumentation.GrpcNetClient.Implementation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Diagnostics;
using System.Reflection;
using OpenTelemetry.Internal;
using OpenTelemetry.Trace;

namespace OpenTelemetry.Instrumentation.SqlClient.Implementation;
Expand Down
1 change: 0 additions & 1 deletion src/OpenTelemetry/Sdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Diagnostics.CodeAnalysis;
#endif
using OpenTelemetry.Context.Propagation;
using OpenTelemetry.Instrumentation;
using OpenTelemetry.Internal;
using OpenTelemetry.Logs;
using OpenTelemetry.Metrics;
Expand Down
7 changes: 5 additions & 2 deletions src/Shared/AssemblyVersionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

#nullable enable

using System.Diagnostics;
using System.Reflection;

namespace OpenTelemetry.Instrumentation;
namespace OpenTelemetry.Internal;

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

var informationalVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion;
var informationalVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
Debug.Assert(!string.IsNullOrEmpty(informationalVersion), "AssemblyInformationalVersionAttribute was not found in assembly");

var indexOfPlusSign = informationalVersion!.IndexOf('+');
return indexOfPlusSign > 0
? informationalVersion.Substring(0, indexOfPlusSign)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#nullable enable

using System.Reflection;
using OpenTelemetry.Instrumentation;
using OpenTelemetry.Internal;
using Xunit;

namespace OpenTelemetry.Tests;
Expand Down

0 comments on commit 876e4fa

Please sign in to comment.