Skip to content

Commit d9401e4

Browse files
authored
Merge pull request #34637 from geoand/OtlpGrpcSpanExporter-polish
Polish OtlpGrpcSpanExporter creation
2 parents b71789b + b3f0bd2 commit d9401e4

File tree

1 file changed

+22
-21
lines changed
  • extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp

1 file changed

+22
-21
lines changed

extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorder.java

+22-21
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package io.quarkus.opentelemetry.runtime.exporter.otlp;
22

3-
import static io.quarkus.opentelemetry.runtime.OpenTelemetryUtil.convertKeyValueListToMap;
43
import static io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterRuntimeConfig.DEFAULT_GRPC_BASE_URI;
54
import static io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterTracesConfig.Protocol.HTTP_PROTOBUF;
65

76
import java.util.List;
8-
import java.util.Map;
9-
import java.util.function.Consumer;
107

118
import jakarta.enterprise.inject.Any;
129
import jakarta.enterprise.inject.spi.CDI;
@@ -17,7 +14,6 @@
1714
import io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder;
1815
import io.opentelemetry.sdk.trace.export.SpanExporter;
1916
import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig;
20-
import io.quarkus.opentelemetry.runtime.config.runtime.exporter.CompressionType;
2117
import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterRuntimeConfig;
2218
import io.quarkus.runtime.LaunchMode;
2319
import io.quarkus.runtime.annotations.Recorder;
@@ -88,28 +84,33 @@ private OtlpGrpcSpanExporter createOtlpGrpcSpanExporter(OtlpExporterRuntimeConfi
8884
// FIXME TLS Support. Was not available before but will be available soon.
8985
// exporterRuntimeConfig.traces.certificate.ifPresent(exporterBuilder::setTrustedCertificates);
9086
// exporterRuntimeConfig.client.ifPresent(exporterBuilder::setClientTls);
91-
exporterRuntimeConfig.traces().headers().ifPresent(new Consumer<List<String>>() {
92-
@Override
93-
public void accept(final List<String> headers) {
94-
for (Map.Entry<String, String> entry : convertKeyValueListToMap(headers).entrySet()) {
95-
String key = entry.getKey();
96-
String value = entry.getValue();
87+
88+
if (exporterRuntimeConfig.traces().headers().isPresent()) {
89+
List<String> headers = exporterRuntimeConfig.traces().headers().get();
90+
if (!headers.isEmpty()) {
91+
for (String header : headers) {
92+
if (header.isEmpty()) {
93+
continue;
94+
}
95+
String[] parts = header.split("=", 2);
96+
String key = parts[0].trim();
97+
String value = parts[1].trim();
9798
exporterBuilder.addHeader(key, value);
9899
}
99100
}
100-
});
101-
exporterRuntimeConfig.traces().compression()
102-
.ifPresent(new Consumer<CompressionType>() {
103-
@Override
104-
public void accept(CompressionType compression) {
105-
exporterBuilder.setCompression(compression.getValue());
106-
}
107-
});
101+
}
108102

109-
if (!exporterRuntimeConfig.traces().protocol().orElse("").equals(HTTP_PROTOBUF)) {
110-
throw new IllegalStateException("Only the GRPC Exporter is currently supported. " +
111-
"Please check `otel.exporter.otlp.traces.protocol` property");
103+
if (exporterRuntimeConfig.traces().compression().isPresent()) {
104+
exporterBuilder.setCompression(exporterRuntimeConfig.traces().compression().get().getValue());
112105
}
106+
107+
if (exporterRuntimeConfig.traces().protocol().isPresent()) {
108+
if (!exporterRuntimeConfig.traces().protocol().get().equals(HTTP_PROTOBUF)) {
109+
throw new IllegalStateException("Only the GRPC Exporter is currently supported. " +
110+
"Please check `quarkus.otel.exporter.otlp.traces.protocol` property");
111+
}
112+
}
113+
113114
return exporterBuilder.build();
114115
}
115116
}

0 commit comments

Comments
 (0)