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

Do not allow changes to OTLP exporter configuration after instantiation #3066

Merged
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 @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.
// </copyright>

using System;
using System.Threading;
using System.Threading.Tasks;
using Grpc.Core;
Expand All @@ -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; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: internal readonly?

Copy link
Member

@reyang reyang Mar 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind, I see that it only has "get"


internal Metadata Headers { get; }

internal int TimeoutMilliseconds { get; }

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

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

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
Expand All @@ -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/>
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down