Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Exporter.OpenTelemetryProtocol] User agent changed to OTel-OTLP-Exporter-Dotnet/{NuGet Package Version} #5528

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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