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

Polish OtlpGrpcSpanExporter creation #34637

Merged
merged 2 commits into from
Jul 10, 2023
Merged
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
@@ -1,12 +1,9 @@
package io.quarkus.opentelemetry.runtime.exporter.otlp;

import static io.quarkus.opentelemetry.runtime.OpenTelemetryUtil.convertKeyValueListToMap;
import static io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterRuntimeConfig.DEFAULT_GRPC_BASE_URI;
import static io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterTracesConfig.Protocol.HTTP_PROTOBUF;

import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

import jakarta.enterprise.inject.Any;
import jakarta.enterprise.inject.spi.CDI;
Expand All @@ -17,7 +14,6 @@
import io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig;
import io.quarkus.opentelemetry.runtime.config.runtime.exporter.CompressionType;
import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterRuntimeConfig;
import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.annotations.Recorder;
Expand Down Expand Up @@ -88,28 +84,33 @@ private OtlpGrpcSpanExporter createOtlpGrpcSpanExporter(OtlpExporterRuntimeConfi
// FIXME TLS Support. Was not available before but will be available soon.
// exporterRuntimeConfig.traces.certificate.ifPresent(exporterBuilder::setTrustedCertificates);
// exporterRuntimeConfig.client.ifPresent(exporterBuilder::setClientTls);
exporterRuntimeConfig.traces().headers().ifPresent(new Consumer<List<String>>() {
@Override
public void accept(final List<String> headers) {
for (Map.Entry<String, String> entry : convertKeyValueListToMap(headers).entrySet()) {
String key = entry.getKey();
String value = entry.getValue();

if (exporterRuntimeConfig.traces().headers().isPresent()) {
List<String> headers = exporterRuntimeConfig.traces().headers().get();
if (!headers.isEmpty()) {
for (String header : headers) {
if (header.isEmpty()) {
continue;
}
String[] parts = header.split("=", 2);
String key = parts[0].trim();
String value = parts[1].trim();
exporterBuilder.addHeader(key, value);
}
}
});
exporterRuntimeConfig.traces().compression()
.ifPresent(new Consumer<CompressionType>() {
@Override
public void accept(CompressionType compression) {
exporterBuilder.setCompression(compression.getValue());
}
});
}

if (!exporterRuntimeConfig.traces().protocol().orElse("").equals(HTTP_PROTOBUF)) {
throw new IllegalStateException("Only the GRPC Exporter is currently supported. " +
"Please check `otel.exporter.otlp.traces.protocol` property");
if (exporterRuntimeConfig.traces().compression().isPresent()) {
exporterBuilder.setCompression(exporterRuntimeConfig.traces().compression().get().getValue());
}

if (exporterRuntimeConfig.traces().protocol().isPresent()) {
if (!exporterRuntimeConfig.traces().protocol().get().equals(HTTP_PROTOBUF)) {
throw new IllegalStateException("Only the GRPC Exporter is currently supported. " +
"Please check `quarkus.otel.exporter.otlp.traces.protocol` property");
}
}

return exporterBuilder.build();
}
}