From 47c212c76d73e47dfab7b24997d06e00e6e05810 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Mon, 10 Jul 2023 10:14:26 +0300 Subject: [PATCH 1/2] Reduce overhead of creating OtlpGrpcSpanExporter --- .../runtime/exporter/otlp/OtlpRecorder.java | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorder.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorder.java index 414032b18ea3d..1bb7fcc3f21ea 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorder.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorder.java @@ -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; @@ -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; @@ -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>() { - @Override - public void accept(final List headers) { - for (Map.Entry entry : convertKeyValueListToMap(headers).entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); + + if (exporterRuntimeConfig.traces().headers().isPresent()) { + List 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() { - @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 `otel.exporter.otlp.traces.protocol` property"); + } + } + return exporterBuilder.build(); } } From b3f0bd292e0c4f3f6f2c1364f802488379bfec60 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Mon, 10 Jul 2023 10:15:28 +0300 Subject: [PATCH 2/2] Use proper property name in warning about OtlpGrpcSpanExporter protocol --- .../opentelemetry/runtime/exporter/otlp/OtlpRecorder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorder.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorder.java index 1bb7fcc3f21ea..088bd5ec4849c 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorder.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorder.java @@ -107,7 +107,7 @@ private OtlpGrpcSpanExporter createOtlpGrpcSpanExporter(OtlpExporterRuntimeConfi 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 `otel.exporter.otlp.traces.protocol` property"); + "Please check `quarkus.otel.exporter.otlp.traces.protocol` property"); } }