diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
index 5fb2f25602d..78fcdd6b874 100644
--- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
+++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
@@ -13,6 +13,10 @@
Fixes issues building on Apple Silicon (M1).
([#2963](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2963))
+* Fixed issue where the configuration of an OTLP exporter could be changed
+ after instantiation by altering the original `OtlpExporterOptions` provided.
+ ([#3066](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3066))
+
## 1.2.0-rc3
Released 2022-Mar-04
diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/BaseOtlpGrpcExportClient.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/BaseOtlpGrpcExportClient.cs
index 12af999d820..49b60c1a97e 100644
--- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/BaseOtlpGrpcExportClient.cs
+++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/BaseOtlpGrpcExportClient.cs
@@ -14,6 +14,7 @@
// limitations under the License.
//
+using System;
using System.Threading;
using System.Threading.Tasks;
using Grpc.Core;
@@ -35,20 +36,23 @@ protected BaseOtlpGrpcExportClient(OtlpExporterOptions options)
ExporterClientValidation.EnsureUnencryptedSupportIsEnabled(options);
- this.Options = options;
+ this.Endpoint = new UriBuilder(options.Endpoint).Uri;
this.Headers = options.GetMetadataFromHeaders();
+ this.TimeoutMilliseconds = options.TimeoutMilliseconds;
}
- internal OtlpExporterOptions Options { get; }
-
#if NETSTANDARD2_1 || NET5_0_OR_GREATER
internal GrpcChannel Channel { get; set; }
#else
internal Channel Channel { get; set; }
#endif
+ internal Uri Endpoint { get; }
+
internal Metadata Headers { get; }
+ internal int TimeoutMilliseconds { get; }
+
///
public abstract bool SendExportRequest(TRequest request, CancellationToken cancellationToken = default);
diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/BaseOtlpHttpExportClient.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/BaseOtlpHttpExportClient.cs
index 46f8dd5c748..5906b7f7798 100644
--- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/BaseOtlpHttpExportClient.cs
+++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/BaseOtlpHttpExportClient.cs
@@ -14,6 +14,7 @@
// limitations under the License.
//
+using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
@@ -31,15 +32,15 @@ protected BaseOtlpHttpExportClient(OtlpExporterOptions options, HttpClient httpC
Guard.ThrowIfNull(httpClient);
Guard.ThrowIfInvalidTimeout(options.TimeoutMilliseconds);
- this.Options = options;
+ this.Endpoint = new UriBuilder(options.Endpoint).Uri;
this.Headers = options.GetHeaders>((d, k, v) => d.Add(k, v));
this.HttpClient = httpClient;
}
- internal OtlpExporterOptions Options { get; }
-
internal HttpClient HttpClient { get; }
+ internal Uri Endpoint { get; set; }
+
internal IReadOnlyDictionary Headers { get; }
///
@@ -55,7 +56,7 @@ public bool SendExportRequest(TRequest request, CancellationToken cancellationTo
}
catch (HttpRequestException ex)
{
- OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(this.Options.Endpoint, ex);
+ OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(this.Endpoint, ex);
return false;
}
diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcLogExportClient.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcLogExportClient.cs
index aad3a2146fc..469ae690cb6 100644
--- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcLogExportClient.cs
+++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcLogExportClient.cs
@@ -43,7 +43,7 @@ public OtlpGrpcLogExportClient(OtlpExporterOptions options, OtlpCollector.LogsSe
///
public override bool SendExportRequest(OtlpCollector.ExportLogsServiceRequest request, CancellationToken cancellationToken = default)
{
- var deadline = DateTime.UtcNow.AddMilliseconds(this.Options.TimeoutMilliseconds);
+ var deadline = DateTime.UtcNow.AddMilliseconds(this.TimeoutMilliseconds);
try
{
@@ -51,7 +51,7 @@ public override bool SendExportRequest(OtlpCollector.ExportLogsServiceRequest re
}
catch (RpcException ex)
{
- OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(this.Options.Endpoint, ex);
+ OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(this.Endpoint, ex);
return false;
}
diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcMetricsExportClient.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcMetricsExportClient.cs
index 45553cf7f84..a4980147742 100644
--- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcMetricsExportClient.cs
+++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcMetricsExportClient.cs
@@ -43,7 +43,7 @@ public OtlpGrpcMetricsExportClient(OtlpExporterOptions options, OtlpCollector.Me
///
public override bool SendExportRequest(OtlpCollector.ExportMetricsServiceRequest request, CancellationToken cancellationToken = default)
{
- var deadline = DateTime.UtcNow.AddMilliseconds(this.Options.TimeoutMilliseconds);
+ var deadline = DateTime.UtcNow.AddMilliseconds(this.TimeoutMilliseconds);
try
{
@@ -51,7 +51,7 @@ public override bool SendExportRequest(OtlpCollector.ExportMetricsServiceRequest
}
catch (RpcException ex)
{
- OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(this.Options.Endpoint, ex);
+ OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(this.Endpoint, ex);
return false;
}
diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs
index c17f49c4fca..9846d0e1524 100644
--- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs
+++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs
@@ -43,7 +43,7 @@ public OtlpGrpcTraceExportClient(OtlpExporterOptions options, OtlpCollector.Trac
///
public override bool SendExportRequest(OtlpCollector.ExportTraceServiceRequest request, CancellationToken cancellationToken = default)
{
- var deadline = DateTime.UtcNow.AddMilliseconds(this.Options.TimeoutMilliseconds);
+ var deadline = DateTime.UtcNow.AddMilliseconds(this.TimeoutMilliseconds);
try
{
@@ -51,7 +51,7 @@ public override bool SendExportRequest(OtlpCollector.ExportTraceServiceRequest r
}
catch (RpcException ex)
{
- OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(this.Options.Endpoint, ex);
+ OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(this.Endpoint, ex);
return false;
}
diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpHttpMetricsExportClient.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpHttpMetricsExportClient.cs
index 541e32f1b87..9be1ce51d50 100644
--- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpHttpMetricsExportClient.cs
+++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpHttpMetricsExportClient.cs
@@ -38,7 +38,7 @@ internal sealed class OtlpHttpMetricsExportClient : BaseOtlpHttpExportClient