Skip to content

Commit

Permalink
Do not allow changes to OTLP exporter configuration after instantiati…
Browse files Browse the repository at this point in the history
…on (#3066)
  • Loading branch information
alanwest authored Mar 18, 2022
1 parent ea5d11d commit 45964ca
Showing 8 changed files with 24 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
// limitations under the License.
// </copyright>

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; }

/// <inheritdoc/>
public abstract bool SendExportRequest(TRequest request, CancellationToken cancellationToken = default);

Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
// limitations under the License.
// </copyright>

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<Dictionary<string, string>>((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<string, string> Headers { get; }

/// <inheritdoc/>
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -43,15 +43,15 @@ public OtlpGrpcLogExportClient(OtlpExporterOptions options, OtlpCollector.LogsSe
/// <inheritdoc/>
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
{
this.logsClient.Export(request, headers: this.Headers, deadline: deadline);
}
catch (RpcException ex)
{
OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(this.Options.Endpoint, ex);
OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(this.Endpoint, ex);

return false;
}
Original file line number Diff line number Diff line change
@@ -43,15 +43,15 @@ public OtlpGrpcMetricsExportClient(OtlpExporterOptions options, OtlpCollector.Me
/// <inheritdoc/>
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
{
this.metricsClient.Export(request, headers: this.Headers, deadline: deadline);
}
catch (RpcException ex)
{
OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(this.Options.Endpoint, ex);
OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(this.Endpoint, ex);

return false;
}
Original file line number Diff line number Diff line change
@@ -43,15 +43,15 @@ public OtlpGrpcTraceExportClient(OtlpExporterOptions options, OtlpCollector.Trac
/// <inheritdoc/>
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
{
this.traceClient.Export(request, headers: this.Headers, deadline: deadline);
}
catch (RpcException ex)
{
OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(this.Options.Endpoint, ex);
OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(this.Endpoint, ex);

return false;
}
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ internal sealed class OtlpHttpMetricsExportClient : BaseOtlpHttpExportClient<Otl
public OtlpHttpMetricsExportClient(OtlpExporterOptions options, HttpClient httpClient)
: base(options, httpClient)
{
this.exportMetricsUri = this.Options.Endpoint;
this.exportMetricsUri = this.Endpoint;
}

protected override HttpRequestMessage CreateHttpRequest(OtlpCollector.ExportMetricsServiceRequest exportRequest)
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ internal sealed class OtlpHttpTraceExportClient : BaseOtlpHttpExportClient<OtlpC
public OtlpHttpTraceExportClient(OtlpExporterOptions options, HttpClient httpClient)
: base(options, httpClient)
{
this.exportTracesUri = this.Options.Endpoint;
this.exportTracesUri = this.Endpoint;
}

protected override HttpRequestMessage CreateHttpRequest(OtlpCollector.ExportTraceServiceRequest exportRequest)

0 comments on commit 45964ca

Please sign in to comment.