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

Add OtlpGrpc{Signal}Exporter#toBuilder() methods #5680

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 @@ -8,3 +8,12 @@ Comparing source compatibility of against
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder toBuilder()
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder toBuilder()
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder toBuilder()
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder toBuilder()
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class GrpcExporterBuilder<T extends Marshaler> {
private URI endpoint;
private boolean compressionEnabled = false;
private final Map<String, String> headers = new HashMap<>();
private final TlsConfigHelper tlsConfigHelper = new TlsConfigHelper();
private TlsConfigHelper tlsConfigHelper = new TlsConfigHelper();
@Nullable private RetryPolicy retryPolicy;
private Supplier<MeterProvider> meterProviderSupplier = GlobalOpenTelemetry::getMeterProvider;

Expand Down Expand Up @@ -132,6 +132,30 @@ public GrpcExporterBuilder<T> setMeterProvider(MeterProvider meterProvider) {
return this;
}

@SuppressWarnings("BuilderReturnThis")
public GrpcExporterBuilder<T> copy() {
GrpcExporterBuilder<T> copy =
new GrpcExporterBuilder<>(
exporterName,
type,
TimeUnit.NANOSECONDS.toSeconds(timeoutNanos),
endpoint,
grpcStubFactory,
grpcEndpointPath);

copy.timeoutNanos = timeoutNanos;
copy.endpoint = endpoint;
copy.compressionEnabled = compressionEnabled;
copy.headers.putAll(headers);
copy.tlsConfigHelper = tlsConfigHelper.copy();
if (retryPolicy != null) {
copy.retryPolicy = retryPolicy.toBuilder().build();
}
copy.meterProviderSupplier = meterProviderSupplier;
copy.grpcChannel = grpcChannel;
return copy;
}

public GrpcExporter<T> build() {
if (grpcChannel != null) {
return new UpstreamGrpcExporterFactory().buildWithChannel((Channel) grpcChannel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.exporter.otlp.logs;

import io.opentelemetry.exporter.internal.grpc.GrpcExporter;
import io.opentelemetry.exporter.internal.grpc.GrpcExporterBuilder;
import io.opentelemetry.exporter.internal.otlp.logs.LogsRequestMarshaler;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.logs.data.LogRecordData;
Expand All @@ -21,6 +22,7 @@
@ThreadSafe
public final class OtlpGrpcLogRecordExporter implements LogRecordExporter {

private final GrpcExporterBuilder<LogsRequestMarshaler> builder;
private final GrpcExporter<LogsRequestMarshaler> delegate;

/**
Expand All @@ -44,10 +46,22 @@ public static OtlpGrpcLogRecordExporterBuilder builder() {
return new OtlpGrpcLogRecordExporterBuilder();
}

OtlpGrpcLogRecordExporter(GrpcExporter<LogsRequestMarshaler> delegate) {
OtlpGrpcLogRecordExporter(
GrpcExporterBuilder<LogsRequestMarshaler> builder,
GrpcExporter<LogsRequestMarshaler> delegate) {
this.builder = builder;
this.delegate = delegate;
}

/**
* Returns a builder with configuration values equal to those for this exporter.
*
* <p>IMPORTANT: Be sure to {@link #shutdown()} this instance if it will no longer be used.
*/
public OtlpGrpcLogRecordExporterBuilder toBuilder() {
return new OtlpGrpcLogRecordExporterBuilder(builder.copy());
}

/**
* Submits all the given logs in a single batch to the OpenTelemetry collector.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,20 @@ public final class OtlpGrpcLogRecordExporterBuilder {
// Visible for testing
final GrpcExporterBuilder<LogsRequestMarshaler> delegate;

OtlpGrpcLogRecordExporterBuilder(GrpcExporterBuilder<LogsRequestMarshaler> delegate) {
this.delegate = delegate;
OtlpUserAgent.addUserAgentHeader(delegate::addHeader);
}

OtlpGrpcLogRecordExporterBuilder() {
delegate =
this(
GrpcExporter.builder(
"otlp",
"log",
DEFAULT_TIMEOUT_SECS,
DEFAULT_ENDPOINT,
() -> MarshalerLogsServiceGrpc::newFutureStub,
GRPC_ENDPOINT_PATH);
OtlpUserAgent.addUserAgentHeader(delegate::addHeader);
GRPC_ENDPOINT_PATH));
}

/**
Expand Down Expand Up @@ -186,6 +190,6 @@ public OtlpGrpcLogRecordExporterBuilder setMeterProvider(MeterProvider meterProv
* @return a new exporter's instance
*/
public OtlpGrpcLogRecordExporter build() {
return new OtlpGrpcLogRecordExporter(delegate.build());
return new OtlpGrpcLogRecordExporter(delegate, delegate.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.exporter.otlp.metrics;

import io.opentelemetry.exporter.internal.grpc.GrpcExporter;
import io.opentelemetry.exporter.internal.grpc.GrpcExporterBuilder;
import io.opentelemetry.exporter.internal.otlp.metrics.MetricsRequestMarshaler;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.metrics.Aggregation;
Expand All @@ -26,6 +27,7 @@
@ThreadSafe
public final class OtlpGrpcMetricExporter implements MetricExporter {

private final GrpcExporterBuilder<MetricsRequestMarshaler> builder;
private final GrpcExporter<MetricsRequestMarshaler> delegate;
private final AggregationTemporalitySelector aggregationTemporalitySelector;
private final DefaultAggregationSelector defaultAggregationSelector;
Expand All @@ -52,14 +54,25 @@ public static OtlpGrpcMetricExporterBuilder builder() {
}

OtlpGrpcMetricExporter(
GrpcExporterBuilder<MetricsRequestMarshaler> builder,
GrpcExporter<MetricsRequestMarshaler> delegate,
AggregationTemporalitySelector aggregationTemporalitySelector,
DefaultAggregationSelector defaultAggregationSelector) {
this.builder = builder;
this.delegate = delegate;
this.aggregationTemporalitySelector = aggregationTemporalitySelector;
this.defaultAggregationSelector = defaultAggregationSelector;
}

/**
* Returns a builder with configuration values equal to those for this exporter.
*
* <p>IMPORTANT: Be sure to {@link #shutdown()} this instance if it will no longer be used.
*/
public OtlpGrpcMetricExporterBuilder toBuilder() {
return new OtlpGrpcMetricExporterBuilder(builder.copy());
}

@Override
public AggregationTemporality getAggregationTemporality(InstrumentType instrumentType) {
return aggregationTemporalitySelector.getAggregationTemporality(instrumentType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,21 @@ public final class OtlpGrpcMetricExporterBuilder {
private DefaultAggregationSelector defaultAggregationSelector =
DefaultAggregationSelector.getDefault();

OtlpGrpcMetricExporterBuilder(GrpcExporterBuilder<MetricsRequestMarshaler> delegate) {
this.delegate = delegate;
delegate.setMeterProvider(MeterProvider.noop());
OtlpUserAgent.addUserAgentHeader(delegate::addHeader);
}

OtlpGrpcMetricExporterBuilder() {
delegate =
this(
GrpcExporter.builder(
"otlp",
"metric",
DEFAULT_TIMEOUT_SECS,
DEFAULT_ENDPOINT,
() -> MarshalerMetricsServiceGrpc::newFutureStub,
GRPC_ENDPOINT_PATH);
delegate.setMeterProvider(MeterProvider.noop());
OtlpUserAgent.addUserAgentHeader(delegate::addHeader);
GRPC_ENDPOINT_PATH));
}

/**
Expand Down Expand Up @@ -221,6 +225,6 @@ public OtlpGrpcMetricExporterBuilder setRetryPolicy(RetryPolicy retryPolicy) {
*/
public OtlpGrpcMetricExporter build() {
return new OtlpGrpcMetricExporter(
delegate.build(), aggregationTemporalitySelector, defaultAggregationSelector);
delegate, delegate.build(), aggregationTemporalitySelector, defaultAggregationSelector);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.exporter.otlp.trace;

import io.opentelemetry.exporter.internal.grpc.GrpcExporter;
import io.opentelemetry.exporter.internal.grpc.GrpcExporterBuilder;
import io.opentelemetry.exporter.internal.otlp.traces.TraceRequestMarshaler;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.trace.data.SpanData;
Expand All @@ -17,6 +18,7 @@
@ThreadSafe
public final class OtlpGrpcSpanExporter implements SpanExporter {

private final GrpcExporterBuilder<TraceRequestMarshaler> builder;
private final GrpcExporter<TraceRequestMarshaler> delegate;

/**
Expand All @@ -40,10 +42,22 @@ public static OtlpGrpcSpanExporterBuilder builder() {
return new OtlpGrpcSpanExporterBuilder();
}

OtlpGrpcSpanExporter(GrpcExporter<TraceRequestMarshaler> delegate) {
OtlpGrpcSpanExporter(
GrpcExporterBuilder<TraceRequestMarshaler> builder,
GrpcExporter<TraceRequestMarshaler> delegate) {
this.builder = builder;
this.delegate = delegate;
}

/**
* Returns a builder with configuration values equal to those for this exporter.
*
* <p>IMPORTANT: Be sure to {@link #shutdown()} this instance if it will no longer be used.
*/
public OtlpGrpcSpanExporterBuilder toBuilder() {
return new OtlpGrpcSpanExporterBuilder(builder.copy());
}

/**
* Submits all the given spans in a single batch to the OpenTelemetry collector.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,20 @@ public final class OtlpGrpcSpanExporterBuilder {
// Visible for testing
final GrpcExporterBuilder<TraceRequestMarshaler> delegate;

OtlpGrpcSpanExporterBuilder(GrpcExporterBuilder<TraceRequestMarshaler> delegate) {
this.delegate = delegate;
OtlpUserAgent.addUserAgentHeader(delegate::addHeader);
}

OtlpGrpcSpanExporterBuilder() {
delegate =
this(
GrpcExporter.builder(
"otlp",
"span",
DEFAULT_TIMEOUT_SECS,
DEFAULT_ENDPOINT,
() -> MarshalerTraceServiceGrpc::newFutureStub,
GRPC_ENDPOINT_PATH);
OtlpUserAgent.addUserAgentHeader(delegate::addHeader);
GRPC_ENDPOINT_PATH));
}

/**
Expand Down Expand Up @@ -183,6 +187,6 @@ public OtlpGrpcSpanExporterBuilder setMeterProvider(MeterProvider meterProvider)
* @return a new exporter's instance
*/
public OtlpGrpcSpanExporter build() {
return new OtlpGrpcSpanExporter(delegate.build());
return new OtlpGrpcSpanExporter(delegate, delegate.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.opentelemetry.exporter.internal.otlp.logs.ResourceLogsMarshaler;
import io.opentelemetry.exporter.otlp.testing.internal.AbstractGrpcTelemetryExporterTest;
import io.opentelemetry.exporter.otlp.testing.internal.FakeTelemetryUtil;
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporter;
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporterBuilder;
import io.opentelemetry.proto.logs.v1.ResourceLogs;
import io.opentelemetry.sdk.logs.data.LogRecordData;
Expand All @@ -38,6 +39,13 @@ protected TelemetryExporterBuilder<LogRecordData> exporterBuilder() {
return TelemetryExporterBuilder.wrap(OtlpGrpcLogRecordExporter.builder());
}

@Override
protected TelemetryExporterBuilder<LogRecordData> toBuilder(
TelemetryExporter<LogRecordData> exporter) {
return TelemetryExporterBuilder.wrap(
((OtlpGrpcLogRecordExporter) exporter.unwrap()).toBuilder());
}

@Override
protected LogRecordData generateFakeTelemetry() {
return FakeTelemetryUtil.generateFakeLogRecordData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.opentelemetry.exporter.internal.otlp.metrics.ResourceMetricsMarshaler;
import io.opentelemetry.exporter.otlp.testing.internal.AbstractGrpcTelemetryExporterTest;
import io.opentelemetry.exporter.otlp.testing.internal.FakeTelemetryUtil;
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporter;
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporterBuilder;
import io.opentelemetry.proto.metrics.v1.ResourceMetrics;
import io.opentelemetry.sdk.metrics.Aggregation;
Expand Down Expand Up @@ -89,6 +90,11 @@ protected TelemetryExporterBuilder<MetricData> exporterBuilder() {
return TelemetryExporterBuilder.wrap(OtlpGrpcMetricExporter.builder());
}

@Override
protected TelemetryExporterBuilder<MetricData> toBuilder(TelemetryExporter<MetricData> exporter) {
return TelemetryExporterBuilder.wrap(((OtlpGrpcMetricExporter) exporter.unwrap()).toBuilder());
}

@Override
protected MetricData generateFakeTelemetry() {
return FakeTelemetryUtil.generateFakeMetricData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.opentelemetry.exporter.internal.otlp.traces.ResourceSpansMarshaler;
import io.opentelemetry.exporter.otlp.testing.internal.AbstractGrpcTelemetryExporterTest;
import io.opentelemetry.exporter.otlp.testing.internal.FakeTelemetryUtil;
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporter;
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporterBuilder;
import io.opentelemetry.proto.trace.v1.ResourceSpans;
import io.opentelemetry.sdk.trace.data.SpanData;
Expand All @@ -37,6 +38,11 @@ protected TelemetryExporterBuilder<SpanData> exporterBuilder() {
return TelemetryExporterBuilder.wrap(OtlpGrpcSpanExporter.builder());
}

@Override
protected TelemetryExporterBuilder<SpanData> toBuilder(TelemetryExporter<SpanData> exporter) {
return TelemetryExporterBuilder.wrap(((OtlpGrpcSpanExporter) exporter.unwrap()).toBuilder());
}

@Override
protected SpanData generateFakeTelemetry() {
return FakeTelemetryUtil.generateFakeSpanData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.opentelemetry.exporter.otlp.testing.internal.AbstractGrpcTelemetryExporterTest;
import io.opentelemetry.exporter.otlp.testing.internal.FakeTelemetryUtil;
import io.opentelemetry.exporter.otlp.testing.internal.ManagedChannelTelemetryExporterBuilder;
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporter;
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporterBuilder;
import io.opentelemetry.proto.logs.v1.ResourceLogs;
import io.opentelemetry.sdk.logs.data.LogRecordData;
Expand Down Expand Up @@ -46,6 +47,13 @@ protected TelemetryExporterBuilder<LogRecordData> exporterBuilder() {
TelemetryExporterBuilder.wrap(OtlpGrpcLogRecordExporter.builder()));
}

@Override
protected TelemetryExporterBuilder<LogRecordData> toBuilder(
TelemetryExporter<LogRecordData> exporter) {
return TelemetryExporterBuilder.wrap(
((OtlpGrpcLogRecordExporter) exporter.unwrap()).toBuilder());
}

@Override
protected LogRecordData generateFakeTelemetry() {
return FakeTelemetryUtil.generateFakeLogRecordData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.opentelemetry.exporter.otlp.testing.internal.AbstractGrpcTelemetryExporterTest;
import io.opentelemetry.exporter.otlp.testing.internal.FakeTelemetryUtil;
import io.opentelemetry.exporter.otlp.testing.internal.ManagedChannelTelemetryExporterBuilder;
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporter;
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporterBuilder;
import io.opentelemetry.proto.metrics.v1.ResourceMetrics;
import io.opentelemetry.sdk.metrics.data.MetricData;
Expand Down Expand Up @@ -46,6 +47,11 @@ protected TelemetryExporterBuilder<MetricData> exporterBuilder() {
TelemetryExporterBuilder.wrap(OtlpGrpcMetricExporter.builder()));
}

@Override
protected TelemetryExporterBuilder<MetricData> toBuilder(TelemetryExporter<MetricData> exporter) {
return TelemetryExporterBuilder.wrap(((OtlpGrpcMetricExporter) exporter.unwrap()).toBuilder());
}

@Override
protected MetricData generateFakeTelemetry() {
return FakeTelemetryUtil.generateFakeMetricData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.opentelemetry.exporter.otlp.testing.internal.AbstractGrpcTelemetryExporterTest;
import io.opentelemetry.exporter.otlp.testing.internal.FakeTelemetryUtil;
import io.opentelemetry.exporter.otlp.testing.internal.ManagedChannelTelemetryExporterBuilder;
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporter;
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporterBuilder;
import io.opentelemetry.proto.trace.v1.ResourceSpans;
import io.opentelemetry.sdk.trace.data.SpanData;
Expand Down Expand Up @@ -46,6 +47,11 @@ protected TelemetryExporterBuilder<SpanData> exporterBuilder() {
TelemetryExporterBuilder.wrap(OtlpGrpcSpanExporter.builder()));
}

@Override
protected TelemetryExporterBuilder<SpanData> toBuilder(TelemetryExporter<SpanData> exporter) {
return TelemetryExporterBuilder.wrap(((OtlpGrpcSpanExporter) exporter.unwrap()).toBuilder());
}

@Override
protected SpanData generateFakeTelemetry() {
return FakeTelemetryUtil.generateFakeSpanData();
Expand Down
Loading