Skip to content

Commit 5336b6b

Browse files
committed
Common MessageWriter abstraction
1 parent ee21659 commit 5336b6b

File tree

32 files changed

+142
-185
lines changed

32 files changed

+142
-185
lines changed

docs/apidiffs/current_vs_latest/opentelemetry-exporter-common.txt

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,17 @@ Comparing source compatibility of opentelemetry-exporter-common-1.58.0-SNAPSHOT.
99
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
1010
+++ NEW SUPERCLASS: java.lang.Object
1111
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.exporter.compressor.Compressor getInstance()
12-
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.exporter.grpc.GrpcMessageWriter (not serializable)
13-
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
14-
+++ NEW SUPERCLASS: java.lang.Object
15-
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) int getContentLength()
16-
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) void writeMessage(java.io.OutputStream)
17-
+++ NEW EXCEPTION: java.io.IOException
1812
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.exporter.grpc.GrpcResponse (not serializable)
1913
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
2014
+++ NEW SUPERCLASS: java.lang.Object
21-
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) byte[] getResponseMessage()
15+
+++ NEW METHOD: PUBLIC(+) byte[] getResponseMessage()
2216
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.exporter.grpc.GrpcStatusCode getStatusCode()
2317
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.String getStatusDescription()
2418
+++ NEW ANNOTATION: javax.annotation.Nullable
2519
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.exporter.grpc.GrpcSender (not serializable)
2620
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
2721
+++ NEW SUPERCLASS: java.lang.Object
28-
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) void send(io.opentelemetry.exporter.grpc.GrpcMessageWriter, java.util.function.Consumer<io.opentelemetry.exporter.grpc.GrpcResponse>, java.util.function.Consumer<java.lang.Throwable>)
22+
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) void send(io.opentelemetry.exporter.marshal.MessageWriter, java.util.function.Consumer<io.opentelemetry.exporter.grpc.GrpcResponse>, java.util.function.Consumer<java.lang.Throwable>)
2923
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.common.CompletableResultCode shutdown()
3024
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.exporter.grpc.GrpcSenderConfig (not serializable)
3125
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
@@ -76,22 +70,16 @@ Comparing source compatibility of opentelemetry-exporter-common-1.58.0-SNAPSHOT.
7670
+++ NEW METHOD: PUBLIC(+) int getValue()
7771
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.exporter.grpc.GrpcStatusCode valueOf(java.lang.String)
7872
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.exporter.grpc.GrpcStatusCode[] values()
79-
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.exporter.http.HttpRequestBodyWriter (not serializable)
80-
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
81-
+++ NEW SUPERCLASS: java.lang.Object
82-
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) int contentLength()
83-
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) void writeRequestBody(java.io.OutputStream)
84-
+++ NEW EXCEPTION: java.io.IOException
8573
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.exporter.http.HttpResponse (not serializable)
8674
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
8775
+++ NEW SUPERCLASS: java.lang.Object
88-
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) byte[] getResponseBody()
76+
+++ NEW METHOD: PUBLIC(+) byte[] getResponseBody()
8977
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) int getStatusCode()
9078
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.String getStatusMessage()
9179
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.exporter.http.HttpSender (not serializable)
9280
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
9381
+++ NEW SUPERCLASS: java.lang.Object
94-
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) void send(io.opentelemetry.exporter.http.HttpRequestBodyWriter, java.util.function.Consumer<io.opentelemetry.exporter.http.HttpResponse>, java.util.function.Consumer<java.lang.Throwable>)
82+
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) void send(io.opentelemetry.exporter.marshal.MessageWriter, java.util.function.Consumer<io.opentelemetry.exporter.http.HttpResponse>, java.util.function.Consumer<java.lang.Throwable>)
9583
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.common.CompletableResultCode shutdown()
9684
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.exporter.http.HttpSenderConfig (not serializable)
9785
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
@@ -117,3 +105,9 @@ Comparing source compatibility of opentelemetry-exporter-common-1.58.0-SNAPSHOT.
117105
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
118106
+++ NEW SUPERCLASS: java.lang.Object
119107
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.exporter.http.HttpSender createSender(io.opentelemetry.exporter.http.HttpSenderConfig)
108+
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.exporter.marshal.MessageWriter (not serializable)
109+
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
110+
+++ NEW SUPERCLASS: java.lang.Object
111+
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) int getContentLength()
112+
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) void writeMessage(java.io.OutputStream)
113+
+++ NEW EXCEPTION: java.io.IOException

exporters/common/src/main/java/io/opentelemetry/exporter/grpc/GrpcMessageWriter.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

exporters/common/src/main/java/io/opentelemetry/exporter/grpc/GrpcResponse.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55

66
package io.opentelemetry.exporter.grpc;
77

8+
import io.opentelemetry.exporter.marshal.MessageWriter;
89
import java.util.function.Consumer;
910
import javax.annotation.Nullable;
1011
import javax.annotation.concurrent.Immutable;
1112

1213
/**
1314
* A gRPC response.
1415
*
15-
* @see GrpcSender#send(GrpcMessageWriter, Consumer, Consumer)
16+
* @see GrpcSender#send(MessageWriter, Consumer, Consumer)
1617
*/
1718
@Immutable
1819
public interface GrpcResponse {
@@ -26,5 +27,7 @@ public interface GrpcResponse {
2627

2728
/** The gRPC response message bytes. */
2829
@SuppressWarnings("mutable")
29-
byte[] getResponseMessage();
30+
default byte[] getResponseMessage() {
31+
return new byte[0];
32+
}
3033
}

exporters/common/src/main/java/io/opentelemetry/exporter/grpc/GrpcSender.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.opentelemetry.exporter.grpc;
77

8+
import io.opentelemetry.exporter.marshal.MessageWriter;
89
import io.opentelemetry.sdk.common.CompletableResultCode;
910
import java.util.function.Consumer;
1011

@@ -31,9 +32,7 @@ public interface GrpcSender {
3132
* @param onError the callback to invoke when the gRPC call could not be executed
3233
*/
3334
void send(
34-
GrpcMessageWriter messageWriter,
35-
Consumer<GrpcResponse> onResponse,
36-
Consumer<Throwable> onError);
35+
MessageWriter messageWriter, Consumer<GrpcResponse> onResponse, Consumer<Throwable> onError);
3736

3837
/** Shutdown the sender. */
3938
CompletableResultCode shutdown();

exporters/common/src/main/java/io/opentelemetry/exporter/grpc/GrpcSenderConfig.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.exporter.grpc;
77

88
import io.opentelemetry.exporter.compressor.Compressor;
9+
import io.opentelemetry.exporter.marshal.MessageWriter;
910
import io.opentelemetry.sdk.common.export.RetryPolicy;
1011
import java.io.OutputStream;
1112
import java.net.URI;
@@ -41,8 +42,8 @@ public interface GrpcSenderConfig {
4142
/**
4243
* The compressor, or {@code null} if no compression is used. If present, {@link
4344
* Compressor#compress(OutputStream)} must be applied to {@link
44-
* GrpcMessageWriter#writeMessage(OutputStream)} when {@link GrpcSender#send(GrpcMessageWriter,
45-
* Consumer, Consumer)} is called and {@link Compressor#getEncoding()} must be set as the {@code
45+
* MessageWriter#writeMessage(OutputStream)} when {@link GrpcSender#send(MessageWriter, Consumer,
46+
* Consumer)} is called and {@link Compressor#getEncoding()} must be set as the {@code
4647
* grpc-encoding}.
4748
*/
4849
@Nullable

exporters/common/src/main/java/io/opentelemetry/exporter/http/HttpRequestBodyWriter.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

exporters/common/src/main/java/io/opentelemetry/exporter/http/HttpResponse.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
package io.opentelemetry.exporter.http;
77

8+
import io.opentelemetry.exporter.marshal.MessageWriter;
89
import java.util.function.Consumer;
910
import javax.annotation.concurrent.Immutable;
1011

1112
/**
1213
* A HTTP response.
1314
*
14-
* @see HttpSender#send(HttpRequestBodyWriter, Consumer, Consumer)
15+
* @see HttpSender#send(MessageWriter, Consumer, Consumer)
1516
*/
1617
@Immutable
1718
public interface HttpResponse {
@@ -23,5 +24,8 @@ public interface HttpResponse {
2324
String getStatusMessage();
2425

2526
/** The HTTP response body bytes. */
26-
byte[] getResponseBody();
27+
@SuppressWarnings("mutable")
28+
default byte[] getResponseBody() {
29+
return new byte[0];
30+
}
2731
}

exporters/common/src/main/java/io/opentelemetry/exporter/http/HttpSender.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.opentelemetry.exporter.http;
77

8+
import io.opentelemetry.exporter.marshal.MessageWriter;
89
import io.opentelemetry.sdk.common.CompletableResultCode;
910
import java.util.function.Consumer;
1011

@@ -26,14 +27,12 @@ public interface HttpSender {
2627
* called when the request could not be executed due to cancellation, connectivity problems, or
2728
* timeout.
2829
*
29-
* @param requestBodyWriter the request body writer
30+
* @param messageWriter the request body message writer
3031
* @param onResponse the callback to invoke with the HTTP response
3132
* @param onError the callback to invoke when the HTTP request could not be executed
3233
*/
3334
void send(
34-
HttpRequestBodyWriter requestBodyWriter,
35-
Consumer<HttpResponse> onResponse,
36-
Consumer<Throwable> onError);
35+
MessageWriter messageWriter, Consumer<HttpResponse> onResponse, Consumer<Throwable> onError);
3736

3837
/** Shutdown the sender. */
3938
CompletableResultCode shutdown();

exporters/common/src/main/java/io/opentelemetry/exporter/http/HttpSenderConfig.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.exporter.http;
77

88
import io.opentelemetry.exporter.compressor.Compressor;
9+
import io.opentelemetry.exporter.marshal.MessageWriter;
910
import io.opentelemetry.sdk.common.export.ProxyOptions;
1011
import io.opentelemetry.sdk.common.export.RetryPolicy;
1112
import java.io.OutputStream;
@@ -36,9 +37,9 @@ public interface HttpSenderConfig {
3637
/**
3738
* The compressor, or {@code null} if no compression is used. If present, {@link
3839
* Compressor#compress(OutputStream)} must be applied to {@link
39-
* HttpRequestBodyWriter#writeRequestBody(OutputStream)} when {@link
40-
* HttpSender#send(HttpRequestBodyWriter, Consumer, Consumer)} is called and {@link
41-
* Compressor#getEncoding()} must be set as the {@code Content-Encoding} header.
40+
* MessageWriter#writeMessage(OutputStream)} when {@link HttpSender#send(MessageWriter, Consumer,
41+
* Consumer)} is called and {@link Compressor#getEncoding()} must be set as the {@code
42+
* Content-Encoding} header.
4243
*/
4344
@Nullable
4445
Compressor getCompressor();

exporters/common/src/main/java/io/opentelemetry/exporter/internal/grpc/GrpcExporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public CompletableResultCode export(Marshaler exportRequest, int numItems) {
6767
CompletableResultCode result = new CompletableResultCode();
6868

6969
grpcSender.send(
70-
exportRequest.toGrpcRequestBodyWriter(),
70+
exportRequest.toMessageWriter(false),
7171
grpcResponse -> onResponse(result, metricRecording, grpcResponse),
7272
throwable -> onError(result, metricRecording, throwable));
7373

0 commit comments

Comments
 (0)