Skip to content

Commit 3d05c14

Browse files
committed
Add base User-Agent string to OtlpExporterOptions
1 parent c1e219d commit 3d05c14

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
@@ -41,6 +41,7 @@ public class OtlpExporterOptions : IOtlpExporterOptions
4141
private int? timeoutMilliseconds;
4242
private Func<HttpClient>? httpClientFactory;
4343
private string? userAgentProductIdentifier;
44+
private string baseUserAgent = $"OTel-OTLP-Exporter-Dotnet/{typeof(OtlpExporterOptions).Assembly.GetName().Version}";
4445

4546
/// <summary>
4647
/// Initializes a new instance of the <see cref="OtlpExporterOptions"/> class.
@@ -70,7 +71,10 @@ internal OtlpExporterOptions(
7071

7172
this.DefaultHttpClientFactory = () =>
7273
{
73-
return new HttpClient { Timeout = TimeSpan.FromMilliseconds(this.TimeoutMilliseconds), };
74+
return new HttpClient
75+
{
76+
Timeout = TimeSpan.FromMilliseconds(this.TimeoutMilliseconds),
77+
};
7478
};
7579

7680
this.BatchExportProcessorOptions = defaultBatchOptions!;
@@ -232,9 +236,6 @@ internal OtlpExporterOptions ApplyDefaults(OtlpExporterOptions defaultExporterOp
232236

233237
private string GetUserAgentString()
234238
{
235-
var assembly = typeof(OtlpExporterOptions).Assembly;
236-
var baseUserAgent = $"OTel-OTLP-Exporter-Dotnet/{assembly.GetPackageVersion()}";
237-
238239
return !string.IsNullOrEmpty(this.userAgentProductIdentifier) ? $"{this.userAgentProductIdentifier} {baseUserAgent}" : baseUserAgent;
239240
}
240241

0 commit comments

Comments
 (0)