Skip to content

Commit d2db75d

Browse files
committed
Move standard component types to enum
1 parent 32943e1 commit d2db75d

File tree

25 files changed

+275
-175
lines changed

25 files changed

+275
-175
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import io.opentelemetry.api.common.Attributes;
1212
import io.opentelemetry.api.metrics.MeterProvider;
13-
import io.opentelemetry.exporter.internal.metrics.ExporterMetrics;
1413
import io.opentelemetry.exporter.internal.metrics.ExporterInstrumentation;
1514
import io.opentelemetry.exporter.internal.FailedExportException;
1615
import io.opentelemetry.exporter.internal.marshal.Marshaler;
@@ -46,24 +45,22 @@ public final class GrpcExporter<T extends Marshaler> {
4645
private final ExporterInstrumentation exporterMetrics;
4746

4847
public GrpcExporter(
49-
String legacyExporterName,
50-
ExporterMetrics.Signal type,
5148
GrpcSender<T> grpcSender,
5249
InternalTelemetrySchemaVersion internalTelemetrySchemaVersion,
5350
ComponentId componentId,
51+
ComponentId.StandardExporterType exporterType,
5452
Supplier<MeterProvider> meterProviderSupplier,
5553
Attributes healthMetricAttributes) {
56-
this.type = type.toString();
54+
this.type = exporterType.signal().toString();
5755
this.grpcSender = grpcSender;
5856
this.exporterMetrics =
5957
new ExporterInstrumentation(
6058
internalTelemetrySchemaVersion,
6159
meterProviderSupplier,
62-
type,
6360
componentId,
64-
healthMetricAttributes,
65-
legacyExporterName,
66-
"grpc");
61+
exporterType,
62+
healthMetricAttributes
63+
);
6764
}
6865

6966
public CompletableResultCode export(T exportRequest, int numItems) {

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

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import io.opentelemetry.api.internal.ConfigUtil;
1212
import io.opentelemetry.api.metrics.MeterProvider;
1313
import io.opentelemetry.exporter.internal.ExporterBuilderUtil;
14-
import io.opentelemetry.exporter.internal.metrics.ExporterMetrics;
1514
import io.opentelemetry.exporter.internal.ServerAttributesUtil;
1615
import io.opentelemetry.exporter.internal.TlsConfigHelper;
1716
import io.opentelemetry.exporter.internal.compression.Compressor;
@@ -52,9 +51,7 @@ public class GrpcExporterBuilder<T extends Marshaler> {
5251

5352
private static final Logger LOGGER = Logger.getLogger(GrpcExporterBuilder.class.getName());
5453

55-
private final String legacyExporterName;
56-
private final ExporterMetrics.Signal signal;
57-
private final String componentType;
54+
private final ComponentId.StandardExporterType exporterType;
5855
private final String grpcEndpointPath;
5956
private final Supplier<BiFunction<Channel, String, MarshalerServiceStub<T, ?, ?>>>
6057
grpcStubFactory;
@@ -77,16 +74,12 @@ public class GrpcExporterBuilder<T extends Marshaler> {
7774
@Nullable private Object grpcChannel;
7875

7976
public GrpcExporterBuilder(
80-
String legacyExporterName,
81-
ExporterMetrics.Signal signal,
82-
String componentType,
77+
ComponentId.StandardExporterType exporterType,
8378
long defaultTimeoutSecs,
8479
URI defaultEndpoint,
8580
Supplier<BiFunction<Channel, String, MarshalerServiceStub<T, ?, ?>>> grpcStubFactory,
8681
String grpcEndpointPath) {
87-
this.legacyExporterName = legacyExporterName;
88-
this.signal = signal;
89-
this.componentType = componentType;
82+
this.exporterType = exporterType;
9083
this.grpcEndpointPath = grpcEndpointPath;
9184
timeoutNanos = TimeUnit.SECONDS.toNanos(defaultTimeoutSecs);
9285
endpoint = defaultEndpoint;
@@ -179,9 +172,7 @@ public GrpcExporterBuilder<T> setExecutorService(ExecutorService executorService
179172
public GrpcExporterBuilder<T> copy() {
180173
GrpcExporterBuilder<T> copy =
181174
new GrpcExporterBuilder<>(
182-
legacyExporterName,
183-
signal,
184-
componentType,
175+
exporterType,
185176
TimeUnit.NANOSECONDS.toSeconds(timeoutNanos),
186177
endpoint,
187178
grpcStubFactory,
@@ -245,11 +236,10 @@ public GrpcExporter<T> build() {
245236
LOGGER.log(Level.FINE, "Using GrpcSender: " + grpcSender.getClass().getName());
246237

247238
return new GrpcExporter<>(
248-
legacyExporterName,
249-
signal,
250239
grpcSender,
251240
internalTelemetrySchemaVersion,
252-
ComponentId.generateLazy(componentType),
241+
ComponentId.generateLazy(exporterType),
242+
exporterType,
253243
meterProviderSupplier,
254244
ServerAttributesUtil.extractServerAttributes(endpoint));
255245
}
@@ -259,8 +249,7 @@ public String toString(boolean includePrefixAndSuffix) {
259249
includePrefixAndSuffix
260250
? new StringJoiner(", ", "GrpcExporterBuilder{", "}")
261251
: new StringJoiner(", ");
262-
joiner.add("exporterName=" + legacyExporterName);
263-
joiner.add("type=" + signal);
252+
joiner.add("exporterType=" + exporterType.toString());
264253
joiner.add("endpoint=" + endpoint.toString());
265254
joiner.add("endpointPath=" + grpcEndpointPath);
266255
joiner.add("timeoutNanos=" + timeoutNanos);

exporters/common/src/main/java/io/opentelemetry/exporter/internal/http/HttpExporter.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import io.opentelemetry.api.common.Attributes;
99
import io.opentelemetry.api.metrics.MeterProvider;
10-
import io.opentelemetry.exporter.internal.metrics.ExporterMetrics;
1110
import io.opentelemetry.exporter.internal.metrics.ExporterInstrumentation;
1211
import io.opentelemetry.exporter.internal.FailedExportException;
1312
import io.opentelemetry.exporter.internal.grpc.GrpcExporterUtil;
@@ -43,26 +42,22 @@ public final class HttpExporter<T extends Marshaler> {
4342
private final ExporterInstrumentation exporterMetrics;
4443

4544
public HttpExporter(
46-
String legacyExporterName,
47-
ExporterMetrics.Signal type,
4845
ComponentId componentId,
4946
HttpSender httpSender,
5047
Supplier<MeterProvider> meterProviderSupplier,
5148
InternalTelemetrySchemaVersion internalTelemetrySchemaVersion,
52-
boolean exportAsJson,
49+
ComponentId.StandardExporterType exporterType,
5350
Attributes healthMetricAttributes) {
54-
this.type = type.toString();
51+
this.type = exporterType.signal().toString();
5552
this.httpSender = httpSender;
56-
// TODO: extract server.address and server.port here
5753
this.exporterMetrics =
5854
new ExporterInstrumentation(
5955
internalTelemetrySchemaVersion,
6056
meterProviderSupplier,
61-
type,
6257
componentId,
63-
healthMetricAttributes,
64-
legacyExporterName,
65-
exportAsJson ? "http-json" : "http");
58+
exporterType,
59+
healthMetricAttributes
60+
);
6661
}
6762

6863
public CompletableResultCode export(T exportRequest, int numItems) {

exporters/common/src/main/java/io/opentelemetry/exporter/internal/http/HttpExporterBuilder.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import io.opentelemetry.api.internal.ConfigUtil;
1010
import io.opentelemetry.api.metrics.MeterProvider;
1111
import io.opentelemetry.exporter.internal.ExporterBuilderUtil;
12-
import io.opentelemetry.exporter.internal.metrics.ExporterMetrics;
1312
import io.opentelemetry.exporter.internal.ServerAttributesUtil;
1413
import io.opentelemetry.exporter.internal.TlsConfigHelper;
1514
import io.opentelemetry.exporter.internal.compression.Compressor;
@@ -49,9 +48,7 @@ public final class HttpExporterBuilder<T extends Marshaler> {
4948

5049
private static final Logger LOGGER = Logger.getLogger(HttpExporterBuilder.class.getName());
5150

52-
private final String exporterName;
53-
private final ExporterMetrics.Signal signal;
54-
private String componentType;
51+
private ComponentId.StandardExporterType exporterType;
5552

5653
private String endpoint;
5754

@@ -71,13 +68,9 @@ public final class HttpExporterBuilder<T extends Marshaler> {
7168
@Nullable private ExecutorService executorService;
7269

7370
public HttpExporterBuilder(
74-
String exporterName,
75-
ExporterMetrics.Signal signal,
76-
String componentType,
71+
ComponentId.StandardExporterType exporterType,
7772
String defaultEndpoint) {
78-
this.exporterName = exporterName;
79-
this.signal = signal;
80-
this.componentType = componentType;
73+
this.exporterType = exporterType;
8174

8275
endpoint = defaultEndpoint;
8376
}
@@ -141,11 +134,6 @@ public HttpExporterBuilder<T> setInternalTelemetry(
141134
return this;
142135
}
143136

144-
public HttpExporterBuilder<T> setComponentType(String componentType) {
145-
this.componentType = componentType;
146-
return this;
147-
}
148-
149137
public HttpExporterBuilder<T> setRetryPolicy(@Nullable RetryPolicy retryPolicy) {
150138
this.retryPolicy = retryPolicy;
151139
return this;
@@ -168,13 +156,28 @@ public HttpExporterBuilder<T> setExecutorService(ExecutorService executorService
168156

169157
public HttpExporterBuilder<T> exportAsJson() {
170158
this.exportAsJson = true;
159+
exporterType = mapToJsonTypeIfPossible(exporterType);
171160
return this;
172161
}
173162

163+
private static ComponentId.StandardExporterType mapToJsonTypeIfPossible(
164+
ComponentId.StandardExporterType componentType) {
165+
switch (componentType) {
166+
case OTLP_HTTP_SPAN_EXPORTER:
167+
return ComponentId.StandardExporterType.OTLP_HTTP_JSON_SPAN_EXPORTER;
168+
case OTLP_HTTP_LOG_EXPORTER:
169+
return ComponentId.StandardExporterType.OTLP_HTTP_JSON_LOG_EXPORTER;
170+
case OTLP_HTTP_METRIC_EXPORTER:
171+
return ComponentId.StandardExporterType.OTLP_HTTP_JSON_METRIC_EXPORTER;
172+
default:
173+
return componentType;
174+
}
175+
}
176+
174177
@SuppressWarnings("BuilderReturnThis")
175178
public HttpExporterBuilder<T> copy() {
176179
HttpExporterBuilder<T> copy =
177-
new HttpExporterBuilder<>(exporterName, signal, componentType, endpoint);
180+
new HttpExporterBuilder<>(exporterType, endpoint);
178181
copy.endpoint = endpoint;
179182
copy.timeoutNanos = timeoutNanos;
180183
copy.connectTimeoutNanos = connectTimeoutNanos;
@@ -234,13 +237,11 @@ public HttpExporter<T> build() {
234237
LOGGER.log(Level.FINE, "Using HttpSender: " + httpSender.getClass().getName());
235238

236239
return new HttpExporter<>(
237-
exporterName,
238-
signal,
239-
ComponentId.generateLazy(componentType),
240+
ComponentId.generateLazy(exporterType),
240241
httpSender,
241242
meterProviderSupplier,
242243
internalTelemetrySchemaVersion,
243-
exportAsJson,
244+
exporterType,
244245
ServerAttributesUtil.extractServerAttributes(endpoint));
245246
}
246247

@@ -249,8 +250,7 @@ public String toString(boolean includePrefixAndSuffix) {
249250
includePrefixAndSuffix
250251
? new StringJoiner(", ", "HttpExporterBuilder{", "}")
251252
: new StringJoiner(", ");
252-
joiner.add("exporterName=" + exporterName);
253-
joiner.add("type=" + signal);
253+
joiner.add("exporterType=" + exporterType);
254254
joiner.add("endpoint=" + endpoint);
255255
joiner.add("timeoutNanos=" + timeoutNanos);
256256
joiner.add("proxyOptions=" + proxyOptions);

exporters/common/src/main/java/io/opentelemetry/exporter/internal/metrics/ExporterInstrumentation.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,20 @@ public class ExporterInstrumentation implements ExporterMetrics {
2323
public ExporterInstrumentation(
2424
InternalTelemetrySchemaVersion schema,
2525
Supplier<MeterProvider> meterProviderSupplier,
26-
ExporterMetrics.Signal signal,
2726
ComponentId componentId,
28-
@Nullable Attributes additionalAttributes,
29-
String legacyExporterName,
30-
String legacyTransportName) {
27+
ComponentId.StandardExporterType exporterType,
28+
@Nullable Attributes additionalAttributes) {
3129

3230
switch (schema) {
3331
case DISABLED:
3432
implementation = NoopExporterMetrics.INSTANCE;
3533
break;
3634
case LEGACY:
37-
implementation =
38-
new LegacyExporterMetrics(
39-
meterProviderSupplier,
40-
legacyExporterName,
41-
signal,
42-
legacyTransportName);
35+
implementation = LegacyExporterMetrics.isSupportedType(exporterType) ? new LegacyExporterMetrics(meterProviderSupplier,exporterType) : NoopExporterMetrics.INSTANCE;
4336
break;
4437
case V1_33:
4538
case LATEST:
46-
implementation = new SemConvExporterMetrics(meterProviderSupplier, signal, componentId, additionalAttributes == null ? Attributes.empty() : additionalAttributes);
39+
implementation = new SemConvExporterMetrics(meterProviderSupplier, exporterType.signal(), componentId, additionalAttributes == null ? Attributes.empty() : additionalAttributes);
4740
break;
4841
default:
4942
throw new IllegalStateException("Unhandled case: " + schema);

exporters/common/src/main/java/io/opentelemetry/exporter/internal/metrics/ExporterMetrics.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@
99
*/
1010
public interface ExporterMetrics {
1111

12-
/**
13-
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
14-
* any time.
15-
*/
16-
enum Signal {
17-
SPAN, METRIC, LOG
18-
}
19-
2012
Recording startRecordingExport(int itemCount);
2113

2214
/**

exporters/common/src/main/java/io/opentelemetry/exporter/internal/metrics/LegacyExporterMetrics.java

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import io.opentelemetry.api.metrics.LongCounter;
1414
import io.opentelemetry.api.metrics.Meter;
1515
import io.opentelemetry.api.metrics.MeterProvider;
16+
import io.opentelemetry.sdk.internal.ComponentId;
1617
import java.util.function.Supplier;
1718
import javax.annotation.Nullable;
1819

@@ -42,18 +43,35 @@ public class LegacyExporterMetrics implements ExporterMetrics {
4243

4344
LegacyExporterMetrics(
4445
Supplier<MeterProvider> meterProviderSupplier,
45-
String exporterName,
46-
Signal signal,
47-
String transportName) {
46+
ComponentId.StandardExporterType exporterType
47+
) {
4848
this.meterProviderSupplier = meterProviderSupplier;
49-
this.exporterName = exporterName;
50-
this.transportName = transportName;
51-
this.seenAttrs = Attributes.builder().put(ATTRIBUTE_KEY_TYPE, getTypeString(signal)).build();
49+
this.exporterName = getExporterName(exporterType);
50+
this.transportName = getTransportName(exporterType);
51+
this.seenAttrs = Attributes.builder().put(ATTRIBUTE_KEY_TYPE, getTypeString(exporterType.signal())).build();
5252
this.successAttrs = this.seenAttrs.toBuilder().put(ATTRIBUTE_KEY_SUCCESS, true).build();
5353
this.failedAttrs = this.seenAttrs.toBuilder().put(ATTRIBUTE_KEY_SUCCESS, false).build();
5454
}
5555

56-
private static String getTypeString(Signal signal) {
56+
public static boolean isSupportedType(ComponentId.StandardExporterType exporterType) {
57+
switch (exporterType) {
58+
case OTLP_GRPC_SPAN_EXPORTER:
59+
case OTLP_HTTP_SPAN_EXPORTER:
60+
case OTLP_HTTP_JSON_SPAN_EXPORTER:
61+
case ZIPKIN_HTTP_SPAN_EXPORTER:
62+
case ZIPKIN_HTTP_JSON_SPAN_EXPORTER:
63+
case OTLP_GRPC_LOG_EXPORTER:
64+
case OTLP_HTTP_LOG_EXPORTER:
65+
case OTLP_HTTP_JSON_LOG_EXPORTER:
66+
case OTLP_GRPC_METRIC_EXPORTER:
67+
case OTLP_HTTP_METRIC_EXPORTER:
68+
case OTLP_HTTP_JSON_METRIC_EXPORTER:
69+
return true;
70+
}
71+
return false;
72+
}
73+
74+
private static String getTypeString(ComponentId.StandardExporterType.Signal signal) {
5775
switch (signal) {
5876
case SPAN:
5977
return "span";
@@ -62,7 +80,46 @@ private static String getTypeString(Signal signal) {
6280
case METRIC:
6381
return "metric";
6482
}
65-
throw new IllegalArgumentException("Unhandled case: " + signal);
83+
throw new IllegalArgumentException("Unhandled signal type: " + signal);
84+
}
85+
86+
private static String getExporterName(ComponentId.StandardExporterType exporterType) {
87+
switch (exporterType) {
88+
case OTLP_GRPC_SPAN_EXPORTER:
89+
case OTLP_HTTP_SPAN_EXPORTER:
90+
case OTLP_HTTP_JSON_SPAN_EXPORTER:
91+
case OTLP_GRPC_LOG_EXPORTER:
92+
case OTLP_HTTP_LOG_EXPORTER:
93+
case OTLP_HTTP_JSON_LOG_EXPORTER:
94+
case OTLP_GRPC_METRIC_EXPORTER:
95+
case OTLP_HTTP_METRIC_EXPORTER:
96+
case OTLP_HTTP_JSON_METRIC_EXPORTER:
97+
return "otlp";
98+
case ZIPKIN_HTTP_SPAN_EXPORTER:
99+
case ZIPKIN_HTTP_JSON_SPAN_EXPORTER:
100+
return "zipkin";
101+
}
102+
throw new IllegalArgumentException("Not a supported exporter type: " + exporterType);
103+
}
104+
105+
private static String getTransportName(ComponentId.StandardExporterType exporterType) {
106+
switch (exporterType) {
107+
case OTLP_GRPC_SPAN_EXPORTER:
108+
case OTLP_GRPC_LOG_EXPORTER:
109+
case OTLP_GRPC_METRIC_EXPORTER:
110+
return "grpc";
111+
case OTLP_HTTP_SPAN_EXPORTER:
112+
case OTLP_HTTP_LOG_EXPORTER:
113+
case OTLP_HTTP_METRIC_EXPORTER:
114+
case ZIPKIN_HTTP_SPAN_EXPORTER:
115+
return "http";
116+
case OTLP_HTTP_JSON_SPAN_EXPORTER:
117+
case OTLP_HTTP_JSON_LOG_EXPORTER:
118+
case OTLP_HTTP_JSON_METRIC_EXPORTER:
119+
case ZIPKIN_HTTP_JSON_SPAN_EXPORTER:
120+
return "http-json";
121+
}
122+
throw new IllegalArgumentException("Not a supported exporter type: " + exporterType);
66123
}
67124

68125
/** Record number of records seen. */

0 commit comments

Comments
 (0)