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

[otlp] UseOtlpExporter cross-cutting extension #5400

Merged
merged 61 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
b060f51
OtlpExporter cross-cutting registration extension rough draft.
CodeBlanch Feb 24, 2024
c729fd7
Tweaks and evolving design.
CodeBlanch Feb 26, 2024
fbd97d9
Merge remote-tracking branch 'upstream/main' into otlp-crosscutting-e…
CodeBlanch Feb 28, 2024
ab87eb0
First compiling version.
CodeBlanch Feb 28, 2024
0e9709e
Tweaks.
CodeBlanch Feb 28, 2024
a19a81f
Add concept of weight to BaseProcessor.
CodeBlanch Feb 28, 2024
7e1cffb
Merge remote-tracking branch 'upstream/main' into otlp-crosscutting-e…
CodeBlanch Mar 6, 2024
77e550c
Updates based on discussion.
CodeBlanch Mar 6, 2024
ef6652b
Tweak processor pipeline weight design.
CodeBlanch Mar 7, 2024
ea8d6a1
Revert OtlpExporterOptionsBase refactor to shrink the diff of changes.
CodeBlanch Mar 7, 2024
5512bc7
Merge branch 'main' into otlp-crosscutting-extension
CodeBlanch Mar 7, 2024
b3d9db4
Reduce changes shown on diff.
CodeBlanch Mar 7, 2024
75111d2
Tweaks.
CodeBlanch Mar 7, 2024
c2db100
Code review.
CodeBlanch Mar 7, 2024
cb83c0e
Merge remote-tracking branch 'upstream/main' into otlp-crosscutting-e…
CodeBlanch Mar 7, 2024
1506a34
Merge remote-tracking branch 'upstream/main' into otlp-crosscutting-e…
CodeBlanch Mar 7, 2024
8c896a3
Merge from main.
CodeBlanch Mar 8, 2024
d55e488
Merge from main.
CodeBlanch Mar 8, 2024
2a1046a
Merge from main.
CodeBlanch Mar 8, 2024
15e0272
Merge from main.
CodeBlanch Mar 11, 2024
24cbc81
Merge fixes.
CodeBlanch Mar 11, 2024
2e7811d
Tweaks and fixes.
CodeBlanch Mar 11, 2024
7bdf936
Merge from main.
CodeBlanch Mar 11, 2024
71c56e6
Revert order changes.
CodeBlanch Mar 11, 2024
aa84a40
Tweak.
CodeBlanch Mar 11, 2024
4ba37bb
Tweak.
CodeBlanch Mar 11, 2024
7f3c3cb
API files.
CodeBlanch Mar 11, 2024
ded0687
Bug fix.
CodeBlanch Mar 11, 2024
bc27254
Make processor pipeline weight a constant.
CodeBlanch Mar 11, 2024
57cbc99
Tweak.
CodeBlanch Mar 11, 2024
356628e
Bug fix.
CodeBlanch Mar 12, 2024
3493219
Add tests.
CodeBlanch Mar 12, 2024
15ac47b
CHANGELOG update.
CodeBlanch Mar 12, 2024
f275ea2
Merge branch 'main' into otlp-crosscutting-extension
CodeBlanch Mar 12, 2024
c80c86f
Lint.
CodeBlanch Mar 12, 2024
74f24fe
Warning cleanup.
CodeBlanch Mar 12, 2024
ef38a9d
Warning cleanup.
CodeBlanch Mar 12, 2024
e767069
Docfx fix.
CodeBlanch Mar 12, 2024
f515cc0
Integration test fixes.
CodeBlanch Mar 12, 2024
b145007
Code review.
CodeBlanch Mar 12, 2024
16e0741
JSON config comment update.
CodeBlanch Mar 12, 2024
6f2c8e0
Code review.
CodeBlanch Mar 12, 2024
b75f139
Code review.
CodeBlanch Mar 12, 2024
0faac1a
CHANGELOG tweak.
CodeBlanch Mar 12, 2024
4bef0ef
Ctor tweak.
CodeBlanch Mar 13, 2024
956f537
Test tweaks.
CodeBlanch Mar 13, 2024
2c1cc37
Tweaked exposed overloads and refactored code.
CodeBlanch Mar 13, 2024
e577dc3
Test fixes.
CodeBlanch Mar 13, 2024
c4fe57c
Assert fix.
CodeBlanch Mar 13, 2024
084188a
Add XML docs to capture current naming behaviors.
CodeBlanch Mar 13, 2024
c0d8ba3
Tweak namespace.
CodeBlanch Mar 13, 2024
cc33b5a
Merge branch 'main' into otlp-crosscutting-extension
CodeBlanch Mar 13, 2024
c11e4a2
Warning cleanup.
CodeBlanch Mar 13, 2024
4f06ab8
Code review.
CodeBlanch Mar 13, 2024
cd7ca4e
Remove UseOtlpExporter overload which only changes protocol.
CodeBlanch Mar 13, 2024
01dba40
Code review.
CodeBlanch Mar 13, 2024
5dac98b
Merge from main.
CodeBlanch Mar 13, 2024
1c3258c
Cleanup and refactoring.
CodeBlanch Mar 13, 2024
ed09c06
Code review.
CodeBlanch Mar 13, 2024
31f7759
Refactor spec env var code and add test coverage for UseOtlpExporter …
CodeBlanch Mar 14, 2024
c3e0e37
Add a test collection for tests which modify envvars.
CodeBlanch Mar 14, 2024
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 @@ -106,7 +106,7 @@ internal static IOpenTelemetryBuilder UseOtlpExporter(
string? name = null,
IConfiguration? configuration = null,
Action<OtlpExporterBuilder>? configure = null,
bool addToEndOfPipeline = true)
ProcessorPipelineWeight processorPipelineWeight = ProcessorPipelineWeight.PipelineExporter)
{
Guard.ThrowIfNull(builder);

Expand All @@ -119,12 +119,12 @@ internal static IOpenTelemetryBuilder UseOtlpExporter(

configure?.Invoke(otlpBuilder);

UseOtlpExporterInternal(builder, name, addToEndOfPipeline);
UseOtlpExporterInternal(builder, name, processorPipelineWeight);

return builder;
}

private static void UseOtlpExporterInternal(IOpenTelemetryBuilder builder, string? name, bool addToEndOfPipeline)
private static void UseOtlpExporterInternal(IOpenTelemetryBuilder builder, string? name, ProcessorPipelineWeight processorPipelineWeight)
{
builder
.WithLogging()
Expand Down Expand Up @@ -159,12 +159,12 @@ private static void UseOtlpExporterInternal(IOpenTelemetryBuilder builder, strin

var processor = OtlpLogExporterHelperExtensions.BuildOtlpLogExporter(
sp,
builderOptions.LoggingOptions.ApplyDefaults(builderOptions.DefaultOptions),
builderOptions.LoggingOptionsInstance.ApplyDefaults(builderOptions.DefaultOptionsInstance),
builderOptions.LogRecordExportProcessorOptions ?? throw new NotSupportedException(),
utpilla marked this conversation as resolved.
Show resolved Hide resolved
builderOptions.SdkLimitOptions,
builderOptions.ExperimentalOptions);

processor.Weight = addToEndOfPipeline ? int.MaxValue : 0;
processor.PipelineWeight = processorPipelineWeight;

logging.AddProcessor(processor);
});
Expand All @@ -181,7 +181,7 @@ private static void UseOtlpExporterInternal(IOpenTelemetryBuilder builder, strin

metrics.AddReader(
OtlpMetricExporterExtensions.BuildOtlpExporterMetricReader(
builderOptions.MetricsOptions.ApplyDefaults(builderOptions.DefaultOptions),
builderOptions.MetricsOptionsInstance.ApplyDefaults(builderOptions.DefaultOptionsInstance),
builderOptions.MetricReaderOptions ?? throw new NotSupportedException(),
sp));
});
Expand All @@ -199,13 +199,13 @@ private static void UseOtlpExporterInternal(IOpenTelemetryBuilder builder, strin
var processorOptions = builderOptions.ActivityExportProcessorOptions ?? throw new NotSupportedException();

var processor = OtlpTraceExporterHelperExtensions.BuildOtlpExporterProcessor(
builderOptions.TracingOptions.ApplyDefaults(builderOptions.DefaultOptions),
builderOptions.TracingOptionsInstance.ApplyDefaults(builderOptions.DefaultOptionsInstance),
builderOptions.SdkLimitOptions,
processorOptions.ExportProcessorType,
processorOptions.BatchExportProcessorOptions,
sp);

processor.Weight = addToEndOfPipeline ? int.MaxValue : 0;
processor.PipelineWeight = processorPipelineWeight;

tracing.AddProcessor(processor);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public OtlpExporterBuilder SetSignalsToConfigure(OtlpExporterSignals signalsToCo
}

public OtlpExporterBuilder ConfigureDefaultExporterOptions(
Action<OtlpExporterOptionsBase> configure)
Action<IOtlpExporterOptions> configure)
{
Guard.ThrowIfNull(configure);

Expand All @@ -57,7 +57,7 @@ public OtlpExporterBuilder ConfigureDefaultExporterOptions(
}

public OtlpExporterBuilder ConfigureLoggingExporterOptions(
Action<OtlpExporterOptionsBase> configure)
Action<IOtlpExporterOptions> configure)
{
Guard.ThrowIfNull(configure);

Expand All @@ -77,7 +77,7 @@ public OtlpExporterBuilder ConfigureLoggingProcessorOptions(
}

public OtlpExporterBuilder ConfigureMetricsExporterOptions(
Action<OtlpExporterOptionsBase> configure)
Action<IOtlpExporterOptions> configure)
{
Guard.ThrowIfNull(configure);

Expand All @@ -97,7 +97,7 @@ public OtlpExporterBuilder ConfigureMetricsReaderOptions(
}

public OtlpExporterBuilder ConfigureTracingExporterOptions(
Action<OtlpExporterOptionsBase> configure)
Action<IOtlpExporterOptions> configure)
{
Guard.ThrowIfNull(configure);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ internal sealed class OtlpExporterBuilderOptions
internal readonly MetricReaderOptions? MetricReaderOptions;
internal readonly ActivityExportProcessorOptions? ActivityExportProcessorOptions;

internal readonly OtlpExporterOptions DefaultOptionsInstance;
internal readonly OtlpExporterOptions LoggingOptionsInstance;
internal readonly OtlpExporterOptions MetricsOptionsInstance;
internal readonly OtlpExporterOptions TracingOptionsInstance;

public OtlpExporterBuilderOptions(
IConfiguration configuration,
SdkLimitOptions sdkLimitOptions,
Expand All @@ -38,22 +43,24 @@ public OtlpExporterBuilderOptions(
this.MetricReaderOptions = metricReaderOptions;
this.ActivityExportProcessorOptions = activityExportProcessorOptions;

this.DefaultOptions = new OtlpExporterOptionsBase(configuration!, OtlpExporterSignals.None);
var defaultBatchOptions = this.ActivityExportProcessorOptions!.BatchExportProcessorOptions;

this.DefaultOptionsInstance = new OtlpExporterOptions(configuration!, OtlpExporterSignals.None, defaultBatchOptions);

this.LoggingOptions = new OtlpExporterOptionsBase(configuration!, OtlpExporterSignals.Logs);
this.LoggingOptionsInstance = new OtlpExporterOptions(configuration!, OtlpExporterSignals.Logs, defaultBatchOptions);

this.MetricsOptions = new OtlpExporterOptionsBase(configuration!, OtlpExporterSignals.Metrics);
this.MetricsOptionsInstance = new OtlpExporterOptions(configuration!, OtlpExporterSignals.Metrics, defaultBatchOptions);

this.TracingOptions = new OtlpExporterOptionsBase(configuration!, OtlpExporterSignals.Traces);
this.TracingOptionsInstance = new OtlpExporterOptions(configuration!, OtlpExporterSignals.Traces, defaultBatchOptions);
}

public OtlpExporterSignals Signals { get; set; } = OtlpExporterSignals.All;

public OtlpExporterOptionsBase DefaultOptions { get; }
public IOtlpExporterOptions DefaultOptions => this.DefaultOptionsInstance;

public OtlpExporterOptionsBase LoggingOptions { get; }
public IOtlpExporterOptions LoggingOptions => this.LoggingOptionsInstance;

public OtlpExporterOptionsBase MetricsOptions { get; }
public IOtlpExporterOptions MetricsOptions => this.MetricsOptionsInstance;

public OtlpExporterOptionsBase TracingOptions { get; }
public IOtlpExporterOptions TracingOptions => this.TracingOptionsInstance;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#nullable enable

#if NETFRAMEWORK
using System.Net.Http;
#endif

namespace OpenTelemetry.Exporter;

/// <summary>
/// Describes the OpenTelemetry Protocol (OTLP) exporter options shared by all
/// signals.
/// </summary>
internal interface IOtlpExporterOptions
utpilla marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// Gets or sets the the OTLP transport protocol.
/// </summary>
OtlpExportProtocol Protocol { get; set; }

/// <summary>
/// Gets or sets the target to which the exporter is going to send
/// telemetry.
/// </summary>
/// <remarks>
/// Notes:
/// <list type="bullet">
/// <item><see cref="Endpoint"/> must be a valid <see cref="Uri"/> with
/// scheme (http or https) and host, and may contain a port and path.</item>
/// <item>The default value is based on the <see cref="Protocol"/> property:
/// <list type="bullet">
/// <item><c>http://localhost:4317</c> for <see
/// cref="OtlpExportProtocol.Grpc"/>.</item>
/// <item><c>http://localhost:4318</c> for <see
/// cref="OtlpExportProtocol.HttpProtobuf"/></item>.
/// </list>
/// </item>
/// </list>
/// </remarks>
Uri Endpoint { get; set; }

/// <summary>
/// Gets or sets optional headers for the connection.
/// </summary>
/// <remarks>
/// Note: Refer to the <see
/// href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#specifying-headers-via-environment-variables">
/// OpenTelemetry Specification</see> for details on the format of <see
/// cref="Headers"/>.
/// </remarks>
string? Headers { get; set; }

/// <summary>
/// Gets or sets the max waiting time (in milliseconds) for the backend to
/// process each batch. Default value: <c>10000</c>.
/// </summary>
int TimeoutMilliseconds { get; set; }

/// <summary>
/// Gets or sets the factory function called to create the <see
/// cref="HttpClient"/> instance that will be used at runtime to
/// transmit telemetry over HTTP. The returned instance will be reused
/// for all export invocations.
/// </summary>
/// <remarks>
/// Notes:
/// <list type="bullet">
/// <item>This is only invoked for the <see
/// cref="OtlpExportProtocol.HttpProtobuf"/> protocol.</item>
/// <item>The default behavior when using tracing registration extensions is
/// if an <a
/// href="https://docs.microsoft.com/dotnet/api/system.net.http.ihttpclientfactory">IHttpClientFactory</a>
/// instance can be resolved through the application <see
/// cref="IServiceProvider"/> then an <see cref="HttpClient"/> will be
/// created through the factory with the name "OtlpTraceExporter" otherwise
/// an <see cref="HttpClient"/> will be instantiated directly.</item>
/// <item>The default behavior when using metrics registration extensions is
/// if an <a
/// href="https://docs.microsoft.com/dotnet/api/system.net.http.ihttpclientfactory">IHttpClientFactory</a>
/// instance can be resolved through the application <see
/// cref="IServiceProvider"/> then an <see cref="HttpClient"/> will be
/// created through the factory with the name "OtlpMetricExporter" otherwise
/// an <see cref="HttpClient"/> will be instantiated directly.</item>
/// <item>
/// The default behavior when using logging registration extensions is an
/// <see cref="HttpClient"/> will be instantiated directly. <a
/// href="https://docs.microsoft.com/dotnet/api/system.net.http.ihttpclientfactory">IHttpClientFactory</a>
/// is not currently supported for logging.
/// </item>
/// </list>
/// </remarks>
Func<HttpClient> HttpClientFactory { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal abstract class BaseOtlpGrpcExportClient<TRequest> : IExportClient<TRequ
{
protected static readonly ExportClientGrpcResponse SuccessExportResponse = new ExportClientGrpcResponse(success: true, deadlineUtc: null, exception: null);

protected BaseOtlpGrpcExportClient(OtlpExporterOptionsBase options)
protected BaseOtlpGrpcExportClient(OtlpExporterOptions options)
{
Guard.ThrowIfNull(options);
Guard.ThrowIfInvalidTimeout(options.TimeoutMilliseconds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal abstract class BaseOtlpHttpExportClient<TRequest> : IExportClient<TRequ
{
private static readonly ExportClientHttpResponse SuccessExportResponse = new ExportClientHttpResponse(success: true, deadlineUtc: null, response: null, exception: null);

protected BaseOtlpHttpExportClient(OtlpExporterOptionsBase options, HttpClient httpClient, string signalPath)
protected BaseOtlpHttpExportClient(OtlpExporterOptions options, HttpClient httpClient, string signalPath)
{
Guard.ThrowIfNull(options);
Guard.ThrowIfNull(httpClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClie

internal static class ExporterClientValidation
{
internal static void EnsureUnencryptedSupportIsEnabled(OtlpExporterOptionsBase options)
internal static void EnsureUnencryptedSupportIsEnabled(OtlpExporterOptions options)
{
var version = Environment.Version;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal sealed class OtlpGrpcLogExportClient : BaseOtlpGrpcExportClient<OtlpCol
{
private readonly OtlpCollector.LogsService.LogsServiceClient logsClient;

public OtlpGrpcLogExportClient(OtlpExporterOptionsBase options, OtlpCollector.LogsService.LogsServiceClient logsServiceClient = null)
public OtlpGrpcLogExportClient(OtlpExporterOptions options, OtlpCollector.LogsService.LogsServiceClient logsServiceClient = null)
: base(options)
{
if (logsServiceClient != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal sealed class OtlpGrpcMetricsExportClient : BaseOtlpGrpcExportClient<Otl
{
private readonly OtlpCollector.MetricsService.MetricsServiceClient metricsClient;

public OtlpGrpcMetricsExportClient(OtlpExporterOptionsBase options, OtlpCollector.MetricsService.MetricsServiceClient metricsServiceClient = null)
public OtlpGrpcMetricsExportClient(OtlpExporterOptions options, OtlpCollector.MetricsService.MetricsServiceClient metricsServiceClient = null)
: base(options)
{
if (metricsServiceClient != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal sealed class OtlpGrpcTraceExportClient : BaseOtlpGrpcExportClient<OtlpC
{
private readonly OtlpCollector.TraceService.TraceServiceClient traceClient;

public OtlpGrpcTraceExportClient(OtlpExporterOptionsBase options, OtlpCollector.TraceService.TraceServiceClient traceServiceClient = null)
public OtlpGrpcTraceExportClient(OtlpExporterOptions options, OtlpCollector.TraceService.TraceServiceClient traceServiceClient = null)
: base(options)
{
if (traceServiceClient != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal sealed class OtlpHttpLogExportClient : BaseOtlpHttpExportClient<OtlpCol
internal const string MediaContentType = "application/x-protobuf";
private const string LogsExportPath = "v1/logs";

public OtlpHttpLogExportClient(OtlpExporterOptionsBase options, HttpClient httpClient)
public OtlpHttpLogExportClient(OtlpExporterOptions options, HttpClient httpClient)
: base(options, httpClient, LogsExportPath)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal sealed class OtlpHttpMetricsExportClient : BaseOtlpHttpExportClient<Otl
internal const string MediaContentType = "application/x-protobuf";
private const string MetricsExportPath = "v1/metrics";

public OtlpHttpMetricsExportClient(OtlpExporterOptionsBase options, HttpClient httpClient)
public OtlpHttpMetricsExportClient(OtlpExporterOptions options, HttpClient httpClient)
: base(options, httpClient, MetricsExportPath)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal sealed class OtlpHttpTraceExportClient : BaseOtlpHttpExportClient<OtlpC
internal const string MediaContentType = "application/x-protobuf";
private const string TracesExportPath = "v1/traces";

public OtlpHttpTraceExportClient(OtlpExporterOptionsBase options, HttpClient httpClient)
public OtlpHttpTraceExportClient(OtlpExporterOptions options, HttpClient httpClient)
: base(options, httpClient, TracesExportPath)
{
}
Expand Down
Loading
Loading