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

Adding proxy functionality #6206

Closed
wants to merge 6 commits into from
Closed
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
@@ -1,2 +1,19 @@
Comparing source compatibility of against
No changes.
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder setProxy(io.opentelemetry.sdk.common.export.ProxyOptions)
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder setProxy(io.opentelemetry.sdk.common.export.ProxyOptions)
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder setProxy(io.opentelemetry.sdk.common.export.ProxyOptions)
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder setProxy(io.opentelemetry.sdk.common.export.ProxyOptions)
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder setProxy(io.opentelemetry.sdk.common.export.ProxyOptions)
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder setProxy(io.opentelemetry.sdk.common.export.ProxyOptions)
11 changes: 10 additions & 1 deletion docs/apidiffs/current_vs_latest/opentelemetry-sdk-common.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
Comparing source compatibility of against
No changes.
+++ NEW CLASS: PUBLIC(+) io.opentelemetry.sdk.common.export.ProxyOptions (not serializable)
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
+++ NEW SUPERCLASS: java.lang.Object
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.common.export.ProxyOptions$ProxyOptionsBuilder builder(java.lang.String, int)
+++ NEW METHOD: PUBLIC(+) java.lang.String getHost()
+++ NEW METHOD: PUBLIC(+) int getPort()
+++ NEW CLASS: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.common.export.ProxyOptions$ProxyOptionsBuilder (not serializable)
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
+++ NEW SUPERCLASS: java.lang.Object
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.common.export.ProxyOptions build()
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.opentelemetry.exporter.internal.TlsConfigHelper;
import io.opentelemetry.exporter.internal.compression.Compressor;
import io.opentelemetry.exporter.internal.marshal.Marshaler;
import io.opentelemetry.sdk.common.export.ProxyOptions;
import io.opentelemetry.sdk.common.export.RetryPolicy;
import java.net.URI;
import java.time.Duration;
Expand Down Expand Up @@ -52,6 +53,7 @@
grpcStubFactory;

private long timeoutNanos;
@Nullable private ProxyOptions proxyOptions;
private URI endpoint;
@Nullable private Compressor compressor;
private final Map<String, String> constantHeaders = new HashMap<>();
Expand Down Expand Up @@ -92,6 +94,11 @@
return setTimeout(timeout.toNanos(), TimeUnit.NANOSECONDS);
}

public GrpcExporterBuilder<T> setProxy(ProxyOptions proxyOptions) {
this.proxyOptions = proxyOptions;
return this;

Check warning on line 99 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/grpc/GrpcExporterBuilder.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/grpc/GrpcExporterBuilder.java#L98-L99

Added lines #L98 - L99 were not covered by tests
}

public GrpcExporterBuilder<T> setEndpoint(String endpoint) {
this.endpoint = ExporterBuilderUtil.validateEndpoint(endpoint);
return this;
Expand Down Expand Up @@ -161,6 +168,7 @@
}
copy.meterProviderSupplier = meterProviderSupplier;
copy.grpcChannel = grpcChannel;
copy.proxyOptions = proxyOptions;
return copy;
}

Expand Down Expand Up @@ -194,6 +202,7 @@
compressor,
timeoutNanos,
headerSupplier,
proxyOptions,
grpcChannel,
grpcStubFactory,
retryPolicy,
Expand All @@ -214,6 +223,7 @@
joiner.add("endpoint=" + endpoint.toString());
joiner.add("endpointPath=" + grpcEndpointPath);
joiner.add("timeoutNanos=" + timeoutNanos);
joiner.add("proxyOptions=" + proxyOptions);
joiner.add(
"compressorEncoding="
+ Optional.ofNullable(compressor).map(Compressor::getEncoding).orElse(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.grpc.Channel;
import io.opentelemetry.exporter.internal.compression.Compressor;
import io.opentelemetry.exporter.internal.marshal.Marshaler;
import io.opentelemetry.sdk.common.export.ProxyOptions;
import io.opentelemetry.sdk.common.export.RetryPolicy;
import java.net.URI;
import java.util.List;
Expand Down Expand Up @@ -35,6 +36,7 @@ <T extends Marshaler> GrpcSender<T> createSender(
@Nullable Compressor compressor,
long timeoutNanos,
Supplier<Map<String, List<String>>> headersSupplier,
@Nullable ProxyOptions proxyOptions,
@Nullable Object managedChannel,
Supplier<BiFunction<Channel, String, MarshalerServiceStub<T, ?, ?>>> stubFactory,
@Nullable RetryPolicy retryPolicy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.opentelemetry.exporter.internal.auth.Authenticator;
import io.opentelemetry.exporter.internal.compression.Compressor;
import io.opentelemetry.exporter.internal.marshal.Marshaler;
import io.opentelemetry.sdk.common.export.ProxyOptions;
import io.opentelemetry.sdk.common.export.RetryPolicy;
import java.net.URI;
import java.util.ArrayList;
Expand Down Expand Up @@ -52,6 +53,7 @@
private long timeoutNanos = TimeUnit.SECONDS.toNanos(DEFAULT_TIMEOUT_SECS);
@Nullable private Compressor compressor;
private long connectTimeoutNanos = TimeUnit.SECONDS.toNanos(DEFAULT_CONNECT_TIMEOUT_SECS);
@Nullable private ProxyOptions proxyOptions;
private boolean exportAsJson = false;
private final Map<String, String> constantHeaders = new HashMap<>();
private Supplier<Map<String, String>> headerSupplier = Collections::emptyMap;
Expand Down Expand Up @@ -131,6 +133,11 @@
return this;
}

public HttpExporterBuilder<T> setProxy(ProxyOptions proxyOptions) {
this.proxyOptions = proxyOptions;
return this;

Check warning on line 138 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/http/HttpExporterBuilder.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/http/HttpExporterBuilder.java#L137-L138

Added lines #L137 - L138 were not covered by tests
}

public HttpExporterBuilder<T> exportAsJson() {
this.exportAsJson = true;
return this;
Expand All @@ -152,6 +159,7 @@
}
copy.meterProviderSupplier = meterProviderSupplier;
copy.authenticator = authenticator;
copy.proxyOptions = proxyOptions;
return copy;
}

Expand Down Expand Up @@ -187,6 +195,7 @@
timeoutNanos,
connectTimeoutNanos,
headerSupplier,
proxyOptions,
authenticator,
retryPolicy,
tlsConfigHelper.getSslContext(),
Expand All @@ -205,6 +214,7 @@
joiner.add("type=" + type);
joiner.add("endpoint=" + endpoint);
joiner.add("timeoutNanos=" + timeoutNanos);
joiner.add("proxyOptions=" + proxyOptions);
joiner.add(
"compressorEncoding="
+ Optional.ofNullable(compressor).map(Compressor::getEncoding).orElse(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import io.opentelemetry.exporter.internal.auth.Authenticator;
import io.opentelemetry.exporter.internal.compression.Compressor;
import io.opentelemetry.sdk.common.export.ProxyOptions;
import io.opentelemetry.sdk.common.export.RetryPolicy;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -34,6 +35,7 @@ HttpSender createSender(
long timeoutNanos,
long connectTimeout,
Supplier<Map<String, List<String>>> headerSupplier,
@Nullable ProxyOptions proxyOptions,
@Nullable Authenticator authenticator,
@Nullable RetryPolicy retryPolicy,
@Nullable SSLContext sslContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public void setUp() {
Collections::emptyMap,
null,
null,
null,
null),
MeterProvider::noop);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.opentelemetry.exporter.internal.http.HttpExporterBuilder;
import io.opentelemetry.exporter.internal.otlp.logs.LogsRequestMarshaler;
import io.opentelemetry.exporter.otlp.internal.OtlpUserAgent;
import io.opentelemetry.sdk.common.export.ProxyOptions;
import io.opentelemetry.sdk.common.export.RetryPolicy;
import java.time.Duration;
import java.util.Map;
Expand Down Expand Up @@ -171,6 +172,13 @@
return this;
}

/** Sets the proxy to be used. */
public OtlpHttpLogRecordExporterBuilder setProxy(ProxyOptions proxyOptions) {
requireNonNull(proxyOptions, "proxyHost");
delegate.setProxy(proxyOptions);
return this;

Check warning on line 179 in exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/http/logs/OtlpHttpLogRecordExporterBuilder.java

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/http/logs/OtlpHttpLogRecordExporterBuilder.java#L177-L179

Added lines #L177 - L179 were not covered by tests
}

/**
* Sets the {@link MeterProvider} to use to collect metrics related to export. If not set, uses
* {@link GlobalOpenTelemetry#getMeterProvider()}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.opentelemetry.exporter.internal.http.HttpExporterBuilder;
import io.opentelemetry.exporter.internal.otlp.metrics.MetricsRequestMarshaler;
import io.opentelemetry.exporter.otlp.internal.OtlpUserAgent;
import io.opentelemetry.sdk.common.export.ProxyOptions;
import io.opentelemetry.sdk.common.export.RetryPolicy;
import io.opentelemetry.sdk.metrics.InstrumentType;
import io.opentelemetry.sdk.metrics.export.AggregationTemporalitySelector;
Expand Down Expand Up @@ -215,6 +216,13 @@
return this;
}

/** Sets the proxy to be used. */
public OtlpHttpMetricExporterBuilder setProxy(ProxyOptions proxyOptions) {
requireNonNull(proxyOptions, "proxyOptions");
delegate.setProxy(proxyOptions);
return this;

Check warning on line 223 in exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/http/metrics/OtlpHttpMetricExporterBuilder.java

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/http/metrics/OtlpHttpMetricExporterBuilder.java#L221-L223

Added lines #L221 - L223 were not covered by tests
}

OtlpHttpMetricExporterBuilder exportAsJson() {
delegate.exportAsJson();
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.opentelemetry.exporter.internal.http.HttpExporterBuilder;
import io.opentelemetry.exporter.internal.otlp.traces.TraceRequestMarshaler;
import io.opentelemetry.exporter.otlp.internal.OtlpUserAgent;
import io.opentelemetry.sdk.common.export.ProxyOptions;
import io.opentelemetry.sdk.common.export.RetryPolicy;
import java.time.Duration;
import java.util.Map;
Expand Down Expand Up @@ -172,6 +173,13 @@
return this;
}

/** Sets the proxy to be used. */
public OtlpHttpSpanExporterBuilder setProxy(ProxyOptions proxyOptions) {
requireNonNull(proxyOptions, "proxyOptions");
delegate.setProxy(proxyOptions);
return this;

Check warning on line 180 in exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/http/trace/OtlpHttpSpanExporterBuilder.java

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/http/trace/OtlpHttpSpanExporterBuilder.java#L178-L180

Added lines #L178 - L180 were not covered by tests
}

/**
* Sets the {@link MeterProvider} to use to collect metrics related to export. If not set, uses
* {@link GlobalOpenTelemetry#getMeterProvider()}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.common.export.ProxyOptions;
import io.opentelemetry.sdk.common.export.RetryPolicy;
import io.opentelemetry.sdk.metrics.Aggregation;
import io.opentelemetry.sdk.metrics.InstrumentType;
Expand Down Expand Up @@ -53,6 +54,7 @@
}

/** Invoke the setters with the OTLP configuration for the {@code dataType}. */
@SuppressWarnings("TooManyParameters")
public static void configureOtlpExporterBuilder(
String dataType,
ConfigProperties config,
Expand All @@ -62,7 +64,8 @@
Consumer<Duration> setTimeout,
Consumer<byte[]> setTrustedCertificates,
BiConsumer<byte[], byte[]> setClientTls,
Consumer<RetryPolicy> setRetryPolicy) {
Consumer<RetryPolicy> setRetryPolicy,
Consumer<ProxyOptions> setProxy) {
String protocol = getOtlpProtocol(dataType, config);
boolean isHttpProtobuf = protocol.equals(PROTOCOL_HTTP_PROTOBUF);
URL endpoint =
Expand Down Expand Up @@ -152,6 +155,12 @@
if (retryEnabled) {
setRetryPolicy.accept(RetryPolicy.getDefault());
}

String proxyHost = config.getString("otel.exporter.otlp." + dataType + ".proxy.host");
Integer proxyPort = config.getInt("otel.exporter.otlp." + dataType + ".proxy.port");
if (proxyHost != null && proxyPort != null) {
setProxy.accept(ProxyOptions.builder(proxyHost, proxyPort).build());

Check warning on line 162 in exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpConfigUtil.java

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpConfigUtil.java#L162

Added line #L162 was not covered by tests
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public LogRecordExporter createExporter(ConfigProperties config) {
builder::setTimeout,
builder::setTrustedCertificates,
builder::setClientTls,
builder::setRetryPolicy);
builder::setRetryPolicy,
builder::setProxy);
builder.setMeterProvider(meterProviderRef::get);

return builder.build();
Expand All @@ -67,7 +68,8 @@ public LogRecordExporter createExporter(ConfigProperties config) {
builder::setTimeout,
builder::setTrustedCertificates,
builder::setClientTls,
builder::setRetryPolicy);
builder::setRetryPolicy,
builder::setProxy);
builder.setMeterProvider(meterProviderRef::get);

return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public MetricExporter createExporter(ConfigProperties config) {
builder::setTimeout,
builder::setTrustedCertificates,
builder::setClientTls,
builder::setRetryPolicy);
builder::setRetryPolicy,
builder::setProxy);
OtlpConfigUtil.configureOtlpAggregationTemporality(
config, builder::setAggregationTemporalitySelector);
OtlpConfigUtil.configureOtlpHistogramDefaultAggregation(
Expand All @@ -62,7 +63,8 @@ public MetricExporter createExporter(ConfigProperties config) {
builder::setTimeout,
builder::setTrustedCertificates,
builder::setClientTls,
builder::setRetryPolicy);
builder::setRetryPolicy,
builder::setProxy);
OtlpConfigUtil.configureOtlpAggregationTemporality(
config, builder::setAggregationTemporalitySelector);
OtlpConfigUtil.configureOtlpHistogramDefaultAggregation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public SpanExporter createExporter(ConfigProperties config) {
builder::setTimeout,
builder::setTrustedCertificates,
builder::setClientTls,
builder::setRetryPolicy);
builder::setRetryPolicy,
builder::setProxy);
builder.setMeterProvider(meterProviderRef::get);

return builder.build();
Expand All @@ -66,7 +67,8 @@ public SpanExporter createExporter(ConfigProperties config) {
builder::setTimeout,
builder::setTrustedCertificates,
builder::setClientTls,
builder::setRetryPolicy);
builder::setRetryPolicy,
builder::setProxy);
builder.setMeterProvider(meterProviderRef::get);

return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.opentelemetry.exporter.internal.grpc.GrpcExporterBuilder;
import io.opentelemetry.exporter.internal.otlp.logs.LogsRequestMarshaler;
import io.opentelemetry.exporter.otlp.internal.OtlpUserAgent;
import io.opentelemetry.sdk.common.export.ProxyOptions;
import io.opentelemetry.sdk.common.export.RetryPolicy;
import java.net.URI;
import java.time.Duration;
Expand Down Expand Up @@ -191,6 +192,13 @@
return this;
}

/** Sets the proxy to be used. */
public OtlpGrpcLogRecordExporterBuilder setProxy(ProxyOptions proxyOptions) {
requireNonNull(proxyOptions, "proxyOptions");
delegate.setProxy(proxyOptions);
return this;

Check warning on line 199 in exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/logs/OtlpGrpcLogRecordExporterBuilder.java

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/logs/OtlpGrpcLogRecordExporterBuilder.java#L197-L199

Added lines #L197 - L199 were not covered by tests
}

/**
* Sets the {@link MeterProvider} to use to collect metrics related to export. If not set, uses
* {@link GlobalOpenTelemetry#getMeterProvider()}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.opentelemetry.exporter.internal.grpc.GrpcExporterBuilder;
import io.opentelemetry.exporter.internal.otlp.metrics.MetricsRequestMarshaler;
import io.opentelemetry.exporter.otlp.internal.OtlpUserAgent;
import io.opentelemetry.sdk.common.export.ProxyOptions;
import io.opentelemetry.sdk.common.export.RetryPolicy;
import io.opentelemetry.sdk.metrics.InstrumentType;
import io.opentelemetry.sdk.metrics.export.AggregationTemporalitySelector;
Expand Down Expand Up @@ -235,6 +236,12 @@
return this;
}

/** Sets the proxy to be used. */
public OtlpGrpcMetricExporterBuilder setProxy(ProxyOptions proxyOptions) {
requireNonNull(proxyOptions, "proxyOptions");
return this;

Check warning on line 242 in exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/metrics/OtlpGrpcMetricExporterBuilder.java

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/metrics/OtlpGrpcMetricExporterBuilder.java#L241-L242

Added lines #L241 - L242 were not covered by tests
}

/**
* Constructs a new instance of the exporter based on the builder's values.
*
Expand Down
Loading
Loading