forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly construct instance of LateBoundBatchSpanProcessor
This is now done entirely in a CDI producer method which is then fully initialized when OpenTelemetry autoconfigures itself Fixes: quarkusio#29987
- Loading branch information
Showing
11 changed files
with
117 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
...src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerIdGeneratorBuildItem.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
...nt/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerProviderBuildItem.java
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
...nt/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerResourceBuildItem.java
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
...c/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerSpanExportersBuildItem.java
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
.../main/java/io/quarkus/opentelemetry/deployment/tracing/TracerSpanProcessorsBuildItem.java
This file was deleted.
Oops, something went wrong.
103 changes: 101 additions & 2 deletions
103
...me/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpExporterProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,113 @@ | ||
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.Instance; | ||
import jakarta.enterprise.inject.Produces; | ||
import jakarta.inject.Singleton; | ||
|
||
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; | ||
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder; | ||
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; | ||
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; | ||
|
||
@Deprecated | ||
@Singleton | ||
public class OtlpExporterProvider { | ||
|
||
@Produces | ||
@Singleton | ||
public LateBoundBatchSpanProcessor batchSpanProcessorForOtlp() { | ||
return new LateBoundBatchSpanProcessor(); | ||
public LateBoundBatchSpanProcessor batchSpanProcessorForOtlp(OTelRuntimeConfig otelRuntimeConfig, | ||
OtlpExporterRuntimeConfig exporterRuntimeConfig, | ||
Instance<SpanExporter> spanExporters) { | ||
var result = new LateBoundBatchSpanProcessor(); | ||
|
||
if (otelRuntimeConfig.sdkDisabled()) { | ||
return result; | ||
} | ||
|
||
String endpoint = resolveEndpoint(exporterRuntimeConfig).trim(); | ||
|
||
// Only create the OtlpGrpcSpanExporter if an endpoint was set in runtime config | ||
if (endpoint.length() > 0) { | ||
try { | ||
// CDI exporter was already added to a processor by OTEL | ||
if (spanExporters.isUnsatisfied()) { | ||
var spanExporter = createOtlpGrpcSpanExporter(exporterRuntimeConfig, endpoint); | ||
|
||
BatchSpanProcessorBuilder processorBuilder = BatchSpanProcessor.builder(spanExporter); | ||
|
||
processorBuilder.setScheduleDelay(otelRuntimeConfig.bsp().scheduleDelay()); | ||
processorBuilder.setMaxQueueSize(otelRuntimeConfig.bsp().maxQueueSize()); | ||
processorBuilder.setMaxExportBatchSize(otelRuntimeConfig.bsp().maxExportBatchSize()); | ||
processorBuilder.setExporterTimeout(otelRuntimeConfig.bsp().exportTimeout()); | ||
// processorBuilder.setMeterProvider() // TODO add meter provider to span processor. | ||
|
||
result.setBatchSpanProcessorDelegate(processorBuilder.build()); | ||
} | ||
} catch (IllegalArgumentException iae) { | ||
throw new IllegalStateException("Unable to install OTLP Exporter", iae); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
static String resolveEndpoint(final OtlpExporterRuntimeConfig runtimeConfig) { | ||
String endpoint = runtimeConfig.traces().legacyEndpoint() | ||
.filter(OtlpExporterProvider::excludeDefaultEndpoint) | ||
.orElse(runtimeConfig.traces().endpoint() | ||
.filter(OtlpExporterProvider::excludeDefaultEndpoint) | ||
.orElse(runtimeConfig.endpoint() | ||
.filter(OtlpExporterProvider::excludeDefaultEndpoint) | ||
.orElse(DEFAULT_GRPC_BASE_URI))); | ||
return endpoint.trim(); | ||
} | ||
|
||
private static boolean excludeDefaultEndpoint(String endpoint) { | ||
return !DEFAULT_GRPC_BASE_URI.equals(endpoint); | ||
} | ||
|
||
private OtlpGrpcSpanExporter createOtlpGrpcSpanExporter(OtlpExporterRuntimeConfig exporterRuntimeConfig, String endpoint) { | ||
OtlpGrpcSpanExporterBuilder exporterBuilder = OtlpGrpcSpanExporter.builder() | ||
.setEndpoint(endpoint) | ||
.setTimeout(exporterRuntimeConfig.traces().timeout()); | ||
|
||
// 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(); | ||
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"); | ||
} | ||
return exporterBuilder.build(); | ||
} | ||
} |
Oops, something went wrong.