Skip to content
Closed
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 @@ -27,6 +27,8 @@ public static THeaders GetHeaders<THeaders>(this OtlpExporterOptions options, Ac
{
var optionHeaders = options.Headers;
var headers = new THeaders();
string? customUserAgent = null;

if (!string.IsNullOrEmpty(optionHeaders))
{
// According to the specification, URL-encoded headers must be supported.
Expand Down Expand Up @@ -56,13 +58,33 @@ public static THeaders GetHeaders<THeaders>(this OtlpExporterOptions options, Ac

var key = pair.Slice(0, equalIndex).Trim().ToString();
var value = pair.Slice(equalIndex + 1).Trim().ToString();
addHeader(headers, key, value);

// Extract custom User-Agent to prepend to default
if (string.Equals(key, "User-Agent", StringComparison.OrdinalIgnoreCase))
{
customUserAgent = value;
}
else
{
addHeader(headers, key, value);
}
}
}

foreach (var header in OtlpExporterOptions.StandardHeaders)
{
addHeader(headers, header.Key, header.Value);
if (string.Equals(header.Key, "User-Agent", StringComparison.OrdinalIgnoreCase))
{
// Create User-Agent with custom prefix if provided
var userAgentValue = string.IsNullOrWhiteSpace(customUserAgent)
? header.Value
: $"{customUserAgent!.Trim()} {header.Value}";
addHeader(headers, header.Key, userAgentValue);
}
else
{
addHeader(headers, header.Key, header.Value);
}
}

return headers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#if NETFRAMEWORK
using System.Net.Http;
#endif
using System.Linq;

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04-arm, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04-arm, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04-arm, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04-arm, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04-arm, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04-arm, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04-arm, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04-arm, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check warning on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

Using directive is unnecessary.

Check warning on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

Using directive is unnecessary.

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-11-arm, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-11-arm, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-11-arm, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-11-arm, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-11-arm, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-11-arm, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check warning on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

Using directive is unnecessary.

Check warning on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

Using directive is unnecessary.

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-11-arm, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-11-arm, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-11-arm, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-11-arm, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-11-arm, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-11-arm, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-11-arm, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-11-arm, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-11-arm, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-11-arm, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-11-arm, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-11-arm, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-11-arm, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-11-arm, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-11-arm, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-11-arm, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-11-arm, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-11-arm, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)
using Microsoft.Extensions.Configuration;
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient;
Expand Down Expand Up @@ -133,6 +134,92 @@
AssertTransmissionHandler(transmissionHandler, exportClientType, expectedTimeoutMilliseconds, retryStrategy);
}

[Fact]
public void GetHeaders_NoUserAgentInHeaders_ReturnsDefaultUserAgent()
{
var options = new OtlpExporterOptions
{
Headers = "Authorization=Bearer token123",
};

var headers = options.GetHeaders<Dictionary<string, string>>((d, k, v) => d.Add(k, v));
var userAgentHeader = headers.FirstOrDefault(h => h.Key == "User-Agent");

Assert.NotEqual(default(KeyValuePair<string, string>), userAgentHeader);
Assert.StartsWith("OTel-OTLP-Exporter-Dotnet/", userAgentHeader.Value, StringComparison.Ordinal);
}

[Fact]
public void GetHeaders_UserAgentInHeaders_PrependsToDefault()
{
var options = new OtlpExporterOptions
{
Headers = "User-Agent=MyDistribution/1.0.0",
};

var headers = options.GetHeaders<Dictionary<string, string>>((d, k, v) => d.Add(k, v));
var userAgentHeader = headers.FirstOrDefault(h => h.Key == "User-Agent");

Assert.NotEqual(default(KeyValuePair<string, string>), userAgentHeader);
Assert.StartsWith("MyDistribution/1.0.0 OTel-OTLP-Exporter-Dotnet/", userAgentHeader.Value, StringComparison.Ordinal);
}

[Fact]
public void GetHeaders_UserAgentWithWhitespace_TrimmedAndPrepended()
{
var options = new OtlpExporterOptions
{
Headers = "User-Agent= MyService/2.1.0 ",
};

var headers = options.GetHeaders<Dictionary<string, string>>((d, k, v) => d.Add(k, v));
var userAgentHeader = headers.FirstOrDefault(h => h.Key == "User-Agent");

Assert.NotEqual(default(KeyValuePair<string, string>), userAgentHeader);
Assert.StartsWith("MyService/2.1.0 OTel-OTLP-Exporter-Dotnet/", userAgentHeader.Value, StringComparison.Ordinal);
Assert.DoesNotContain(" ", userAgentHeader.Value, StringComparison.Ordinal);
}

[Fact]
public void GetHeaders_UserAgentWithOtherHeaders_PrependsCorrectly()
{
var options = new OtlpExporterOptions
{
Headers = "Authorization=Bearer token,User-Agent=CustomAgent/3.0.0,Content-Type=application/json",
};

var headers = options.GetHeaders<Dictionary<string, string>>((d, k, v) => d.Add(k, v));

// Should have Authorization, Content-Type, and User-Agent (from standard headers with custom prepended)
Assert.Equal(3, headers.Count);
Assert.Contains(headers, h => h.Key == "Authorization" && h.Value == "Bearer token");
Assert.Contains(headers, h => h.Key == "Content-Type" && h.Value == "application/json");

var userAgentHeader = headers.FirstOrDefault(h => h.Key == "User-Agent");
Assert.NotEqual(default(KeyValuePair<string, string>), userAgentHeader);
Assert.StartsWith("CustomAgent/3.0.0 OTel-OTLP-Exporter-Dotnet/", userAgentHeader.Value, StringComparison.Ordinal);
}

[Theory]
[InlineData("")]
[InlineData(" ")]
public void GetHeaders_EmptyOrWhitespaceUserAgent_UsesDefault(string userAgentValue)
{
var options = new OtlpExporterOptions
{
Headers = $"User-Agent={userAgentValue}",
};

var headers = options.GetHeaders<Dictionary<string, string>>((d, k, v) => d.Add(k, v));
var userAgentHeader = headers.FirstOrDefault(h => h.Key == "User-Agent");

Assert.NotEqual(default(KeyValuePair<string, string>), userAgentHeader);
Assert.StartsWith("OTel-OTLP-Exporter-Dotnet/", userAgentHeader.Value, StringComparison.Ordinal);

// Should not have extra spaces or the empty custom prefix
Assert.DoesNotContain(" ", userAgentHeader.Value, StringComparison.Ordinal);
}

private static void AssertTransmissionHandler(OtlpExporterTransmissionHandler transmissionHandler, Type exportClientType, int expectedTimeoutMilliseconds, string? retryStrategy)
{
if (retryStrategy == "in_memory")
Expand Down
Loading