Skip to content

Commit

Permalink
Revert supplier accepting list
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg committed Dec 7, 2023
1 parent 719750d commit b8b5d8e
Show file tree
Hide file tree
Showing 19 changed files with 40 additions and 67 deletions.
12 changes: 6 additions & 6 deletions docs/apidiffs/current_vs_latest/opentelemetry-exporter-otlp.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
Comparing source compatibility of against
*** 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 setHeaders(java.util.function.Supplier<java.util.Map<java.lang.String,java.util.List<java.lang.String>>>)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder setHeaders(java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.String>>)
*** 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 setHeaders(java.util.function.Supplier<java.util.Map<java.lang.String,java.util.List<java.lang.String>>>)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder setHeaders(java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.String>>)
*** 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 setHeaders(java.util.function.Supplier<java.util.Map<java.lang.String,java.util.List<java.lang.String>>>)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder setHeaders(java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.String>>)
*** 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 setHeaders(java.util.function.Supplier<java.util.Map<java.lang.String,java.util.List<java.lang.String>>>)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder setHeaders(java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.String>>)
*** 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 setHeaders(java.util.function.Supplier<java.util.Map<java.lang.String,java.util.List<java.lang.String>>>)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder setHeaders(java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.String>>)
*** 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 setHeaders(java.util.function.Supplier<java.util.Map<java.lang.String,java.util.List<java.lang.String>>>)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder setHeaders(java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.String>>)
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public class GrpcExporterBuilder<T extends Marshaler> {
private long timeoutNanos;
private URI endpoint;
private boolean compressionEnabled = false;
private final Map<String, List<String>> constantHeaders = new HashMap<>();
private Supplier<Map<String, List<String>>> headerSupplier = Collections::emptyMap;
private final Map<String, String> constantHeaders = new HashMap<>();
private Supplier<Map<String, String>> headerSupplier = Collections::emptyMap;
private TlsConfigHelper tlsConfigHelper = new TlsConfigHelper();
@Nullable private RetryPolicy retryPolicy;
private Supplier<MeterProvider> meterProviderSupplier = GlobalOpenTelemetry::getMeterProvider;
Expand Down Expand Up @@ -118,12 +118,11 @@ public GrpcExporterBuilder<T> setSslContext(
}

public GrpcExporterBuilder<T> addConstantHeader(String key, String value) {
constantHeaders.computeIfAbsent(key, unused -> new ArrayList<>()).add(value);
constantHeaders.put(key, value);
return this;
}

public GrpcExporterBuilder<T> setHeadersSupplier(
Supplier<Map<String, List<String>>> headerSupplier) {
public GrpcExporterBuilder<T> setHeadersSupplier(Supplier<Map<String, String>> headerSupplier) {
this.headerSupplier = headerSupplier;
return this;
}
Expand Down Expand Up @@ -167,15 +166,16 @@ public GrpcExporter<T> build() {
Supplier<Map<String, List<String>>> headerSupplier =
() -> {
Map<String, List<String>> result = new HashMap<>();
Map<String, List<String>> supplierResult = this.headerSupplier.get();
Map<String, String> supplierResult = this.headerSupplier.get();
if (supplierResult != null) {
result.putAll(supplierResult);
supplierResult.forEach(
(key, value) -> result.put(key, Collections.singletonList(value)));
}
constantHeaders.forEach(
(key, value) ->
result.merge(
key,
value,
Collections.singletonList(value),
(v1, v2) -> {
List<String> merged = new ArrayList<>(v1);
merged.addAll(v2);
Expand Down Expand Up @@ -215,7 +215,7 @@ public String toString(boolean includePrefixAndSuffix) {
joiner.add("compressionEnabled=" + compressionEnabled);
StringJoiner headersJoiner = new StringJoiner(", ", "Headers{", "}");
constantHeaders.forEach((key, value) -> headersJoiner.add(key + "=OBFUSCATED"));
Map<String, List<String>> headers = headerSupplier.get();
Map<String, String> headers = headerSupplier.get();
if (headers != null) {
headers.forEach((key, value) -> headersJoiner.add(key + "=OBFUSCATED"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public final class HttpExporterBuilder<T extends Marshaler> {
private long timeoutNanos = TimeUnit.SECONDS.toNanos(DEFAULT_TIMEOUT_SECS);
private boolean compressionEnabled = false;
private boolean exportAsJson = false;
private final Map<String, List<String>> constantHeaders = new HashMap<>();
private Supplier<Map<String, List<String>>> headerSupplier = Collections::emptyMap;
private final Map<String, String> constantHeaders = new HashMap<>();
private Supplier<Map<String, String>> headerSupplier = Collections::emptyMap;

private TlsConfigHelper tlsConfigHelper = new TlsConfigHelper();
@Nullable private RetryPolicy retryPolicy;
Expand Down Expand Up @@ -86,12 +86,11 @@ public HttpExporterBuilder<T> setCompression(String compressionMethod) {
}

public HttpExporterBuilder<T> addConstantHeaders(String key, String value) {
constantHeaders.computeIfAbsent(key, unused -> new ArrayList<>()).add(value);
constantHeaders.put(key, value);
return this;
}

public HttpExporterBuilder<T> setHeadersSupplier(
Supplier<Map<String, List<String>>> headerSupplier) {
public HttpExporterBuilder<T> setHeadersSupplier(Supplier<Map<String, String>> headerSupplier) {
this.headerSupplier = headerSupplier;
return this;
}
Expand Down Expand Up @@ -155,15 +154,16 @@ public HttpExporter<T> build() {
Supplier<Map<String, List<String>>> headerSupplier =
() -> {
Map<String, List<String>> result = new HashMap<>();
Map<String, List<String>> supplierResult = this.headerSupplier.get();
Map<String, String> supplierResult = this.headerSupplier.get();
if (supplierResult != null) {
result.putAll(supplierResult);
supplierResult.forEach(
(key, value) -> result.put(key, Collections.singletonList(value)));
}
constantHeaders.forEach(
(key, value) ->
result.merge(
key,
value,
Collections.singletonList(value),
(v1, v2) -> {
List<String> merged = new ArrayList<>(v1);
merged.addAll(v2);
Expand Down Expand Up @@ -202,7 +202,7 @@ public String toString(boolean includePrefixAndSuffix) {
joiner.add("exportAsJson=" + exportAsJson);
StringJoiner headersJoiner = new StringJoiner(", ", "Headers{", "}");
constantHeaders.forEach((key, value) -> headersJoiner.add(key + "=OBFUSCATED"));
Map<String, List<String>> headers = headerSupplier.get();
Map<String, String> headers = headerSupplier.get();
if (headers != null) {
headers.forEach((key, value) -> headersJoiner.add(key + "=OBFUSCATED"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import io.opentelemetry.exporter.otlp.internal.OtlpUserAgent;
import io.opentelemetry.sdk.common.export.RetryPolicy;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
Expand Down Expand Up @@ -98,8 +97,7 @@ public OtlpHttpLogRecordExporterBuilder addHeader(String key, String value) {
* Set the supplier of headers to add to requests. If a key from the map collides with a constant
* from {@link #addHeader(String, String)}, the values from both are included.
*/
public OtlpHttpLogRecordExporterBuilder setHeaders(
Supplier<Map<String, List<String>>> headerSupplier) {
public OtlpHttpLogRecordExporterBuilder setHeaders(Supplier<Map<String, String>> headerSupplier) {
delegate.setHeadersSupplier(headerSupplier);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import io.opentelemetry.sdk.metrics.export.DefaultAggregationSelector;
import io.opentelemetry.sdk.metrics.export.MetricExporter;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
Expand Down Expand Up @@ -110,8 +109,7 @@ public OtlpHttpMetricExporterBuilder addHeader(String key, String value) {
* Set the supplier of headers to add to requests. If a key from the map collides with a constant
* from {@link #addHeader(String, String)}, the values from both are included.
*/
public OtlpHttpMetricExporterBuilder setHeaders(
Supplier<Map<String, List<String>>> headerSupplier) {
public OtlpHttpMetricExporterBuilder setHeaders(Supplier<Map<String, String>> headerSupplier) {
delegate.setHeadersSupplier(headerSupplier);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import io.opentelemetry.exporter.otlp.internal.OtlpUserAgent;
import io.opentelemetry.sdk.common.export.RetryPolicy;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
Expand Down Expand Up @@ -98,8 +97,7 @@ public OtlpHttpSpanExporterBuilder addHeader(String key, String value) {
* Set the supplier of headers to add to requests. If a key from the map collides with a constant
* from {@link #addHeader(String, String)}, the values from both are included.
*/
public OtlpHttpSpanExporterBuilder setHeaders(
Supplier<Map<String, List<String>>> headerSupplier) {
public OtlpHttpSpanExporterBuilder setHeaders(Supplier<Map<String, String>> headerSupplier) {
delegate.setHeadersSupplier(headerSupplier);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import io.opentelemetry.sdk.common.export.RetryPolicy;
import java.net.URI;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
Expand Down Expand Up @@ -172,8 +171,7 @@ public OtlpGrpcLogRecordExporterBuilder addHeader(String key, String value) {
* from {@link #addHeader(String, String)}, the values from both are included. Applicable only if
* {@link OtlpGrpcLogRecordExporterBuilder#setChannel(ManagedChannel)} is not used to set channel.
*/
public OtlpGrpcLogRecordExporterBuilder setHeaders(
Supplier<Map<String, List<String>>> headerSupplier) {
public OtlpGrpcLogRecordExporterBuilder setHeaders(Supplier<Map<String, String>> headerSupplier) {
delegate.setHeadersSupplier(headerSupplier);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.opentelemetry.sdk.metrics.export.MetricExporter;
import java.net.URI;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
Expand Down Expand Up @@ -185,8 +184,7 @@ public OtlpGrpcMetricExporterBuilder addHeader(String key, String value) {
* from {@link #addHeader(String, String)}, the values from both are included. Applicable only if
* {@link OtlpGrpcMetricExporterBuilder#setChannel(ManagedChannel)} is not used to set channel.
*/
public OtlpGrpcMetricExporterBuilder setHeaders(
Supplier<Map<String, List<String>>> headerSupplier) {
public OtlpGrpcMetricExporterBuilder setHeaders(Supplier<Map<String, String>> headerSupplier) {
delegate.setHeadersSupplier(headerSupplier);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import io.opentelemetry.sdk.common.export.RetryPolicy;
import java.net.URI;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
Expand Down Expand Up @@ -169,8 +168,7 @@ public OtlpGrpcSpanExporterBuilder addHeader(String key, String value) {
* from {@link #addHeader(String, String)}, the values from both are included. Applicable only if
* {@link OtlpGrpcSpanExporterBuilder#setChannel(ManagedChannel)} is not used to set channel.
*/
public OtlpGrpcSpanExporterBuilder setHeaders(
Supplier<Map<String, List<String>>> headerSupplier) {
public OtlpGrpcSpanExporterBuilder setHeaders(Supplier<Map<String, String>> headerSupplier) {
delegate.setHeadersSupplier(headerSupplier);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,7 @@ void withHeaders() {
exporterBuilder()
.setEndpoint(server.httpUri().toString())
.addHeader("key1", "value1")
.setHeaders(
() ->
Collections.singletonMap(
"key2", Collections.singletonList("value" + count.incrementAndGet())))
.setHeaders(() -> Collections.singletonMap("key2", "value" + count.incrementAndGet()))
.build();
try {
// Export twice to ensure header supplier gets invoked twice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,7 @@ void withHeaders() {
exporterBuilder()
.setEndpoint(server.httpUri() + path)
.addHeader("key1", "value1")
.setHeaders(
() ->
Collections.singletonMap(
"key2", Collections.singletonList("value" + count.incrementAndGet())))
.setHeaders(() -> Collections.singletonMap("key2", "value" + count.incrementAndGet()))
.build();
try {
// Export twice to ensure header supplier gets invoked twice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import io.opentelemetry.sdk.common.export.RetryPolicy;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
Expand Down Expand Up @@ -57,7 +56,7 @@ public TelemetryExporterBuilder<LogRecordData> addHeader(String key, String valu

@Override
public TelemetryExporterBuilder<LogRecordData> setHeaders(
Supplier<Map<String, List<String>>> headerSupplier) {
Supplier<Map<String, String>> headerSupplier) {
builder.setHeaders(headerSupplier);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import io.opentelemetry.sdk.common.export.RetryPolicy;
import io.opentelemetry.sdk.metrics.data.MetricData;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
Expand Down Expand Up @@ -57,7 +56,7 @@ public TelemetryExporterBuilder<MetricData> addHeader(String key, String value)

@Override
public TelemetryExporterBuilder<MetricData> setHeaders(
Supplier<Map<String, List<String>>> headerSupplier) {
Supplier<Map<String, String>> headerSupplier) {
builder.setHeaders(headerSupplier);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import io.opentelemetry.sdk.common.export.RetryPolicy;
import io.opentelemetry.sdk.trace.data.SpanData;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
Expand Down Expand Up @@ -58,7 +57,7 @@ public TelemetryExporterBuilder<SpanData> addHeader(String key, String value) {

@Override
public TelemetryExporterBuilder<SpanData> setHeaders(
Supplier<Map<String, List<String>>> headerSupplier) {
Supplier<Map<String, String>> headerSupplier) {
builder.setHeaders(headerSupplier);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import io.opentelemetry.sdk.common.export.RetryPolicy;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
Expand Down Expand Up @@ -58,7 +57,7 @@ public TelemetryExporterBuilder<LogRecordData> addHeader(String key, String valu

@Override
public TelemetryExporterBuilder<LogRecordData> setHeaders(
Supplier<Map<String, List<String>>> headerSupplier) {
Supplier<Map<String, String>> headerSupplier) {
builder.setHeaders(headerSupplier);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import io.opentelemetry.sdk.common.export.RetryPolicy;
import io.opentelemetry.sdk.metrics.data.MetricData;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
Expand Down Expand Up @@ -57,7 +56,7 @@ public TelemetryExporterBuilder<MetricData> addHeader(String key, String value)

@Override
public TelemetryExporterBuilder<MetricData> setHeaders(
Supplier<Map<String, List<String>>> headerSupplier) {
Supplier<Map<String, String>> headerSupplier) {
builder.setHeaders(headerSupplier);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import io.opentelemetry.sdk.common.export.RetryPolicy;
import io.opentelemetry.sdk.trace.data.SpanData;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
Expand Down Expand Up @@ -57,7 +56,7 @@ public TelemetryExporterBuilder<SpanData> addHeader(String key, String value) {

@Override
public TelemetryExporterBuilder<SpanData> setHeaders(
Supplier<Map<String, List<String>>> headerSupplier) {
Supplier<Map<String, String>> headerSupplier) {
builder.setHeaders(headerSupplier);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.net.URI;
import java.time.Duration;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
Expand Down Expand Up @@ -92,8 +91,7 @@ public TelemetryExporterBuilder<T> addHeader(String key, String value) {
}

@Override
public TelemetryExporterBuilder<T> setHeaders(
Supplier<Map<String, List<String>>> headerSupplier) {
public TelemetryExporterBuilder<T> setHeaders(Supplier<Map<String, String>> headerSupplier) {
delegate.setHeaders(headerSupplier);
return this;
}
Expand Down
Loading

0 comments on commit b8b5d8e

Please sign in to comment.