From 6ccff484bc930f393a97f61de3391a8b1967ece6 Mon Sep 17 00:00:00 2001 From: brunobat Date: Thu, 26 Sep 2024 12:50:07 +0100 Subject: [PATCH] Disable instrumentation according with SDK config --- .../InstrumentationProcessor.java | 6 +-- .../OpenTelemetryDisabledSdkTest.java | 48 ++++++++++++++++++- .../tracing/cdi/WithSpanInterceptor.java | 5 +- .../InstrumentationRecorder.java | 20 ++++++-- .../grpc/GrpcTracingClientInterceptor.java | 5 +- .../grpc/GrpcTracingServerInterceptor.java | 5 +- .../restclient/OpenTelemetryClientFilter.java | 13 ++++- .../OpenTelemetryJobInstrumenter.java | 22 +++++---- .../EventBusInstrumenterVertxTracer.java | 17 +++++-- .../vertx/HttpInstrumenterVertxTracer.java | 17 +++++-- .../RedisClientInstrumenterVertxTracer.java | 5 +- .../SqlClientInstrumenterVertxTracer.java | 5 +- 12 files changed, 131 insertions(+), 37 deletions(-) diff --git a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/instrumentation/InstrumentationProcessor.java b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/instrumentation/InstrumentationProcessor.java index c7b2970acbb89..bdbb88e786c94 100644 --- a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/instrumentation/InstrumentationProcessor.java +++ b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/instrumentation/InstrumentationProcessor.java @@ -5,7 +5,6 @@ import java.util.Optional; import java.util.function.BooleanSupplier; -import java.util.function.Consumer; import org.eclipse.microprofile.config.Config; import org.eclipse.microprofile.config.ConfigProvider; @@ -34,7 +33,6 @@ import io.quarkus.resteasy.reactive.server.spi.PreExceptionMapperHandlerBuildItem; import io.quarkus.resteasy.reactive.spi.CustomContainerRequestFilterBuildItem; import io.quarkus.vertx.core.deployment.VertxOptionsConsumerBuildItem; -import io.vertx.core.VertxOptions; @BuildSteps(onlyIf = TracerEnabled.class) public class InstrumentationProcessor { @@ -112,9 +110,7 @@ VertxOptionsConsumerBuildItem vertxTracingMetricsOptions(InstrumentationRecorder @Record(ExecutionTime.RUNTIME_INIT) VertxOptionsConsumerBuildItem vertxTracingOptions( InstrumentationRecorder recorder) { - Consumer vertxTracingOptions; - vertxTracingOptions = recorder.getVertxTracingOptions(); - return new VertxOptionsConsumerBuildItem(vertxTracingOptions, LIBRARY_AFTER); + return new VertxOptionsConsumerBuildItem(recorder.getVertxTracingOptions(), LIBRARY_AFTER); } // RESTEasy and Vert.x web diff --git a/extensions/opentelemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/OpenTelemetryDisabledSdkTest.java b/extensions/opentelemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/OpenTelemetryDisabledSdkTest.java index d77a2f14dbbb2..015bff58543fc 100644 --- a/extensions/opentelemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/OpenTelemetryDisabledSdkTest.java +++ b/extensions/opentelemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/OpenTelemetryDisabledSdkTest.java @@ -1,17 +1,22 @@ package io.quarkus.opentelemetry.deployment; +import static org.junit.jupiter.api.Assertions.assertFalse; + import jakarta.inject.Inject; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig; import io.quarkus.opentelemetry.runtime.exporter.otlp.tracing.LateBoundBatchSpanProcessor; +import io.quarkus.opentelemetry.runtime.tracing.intrumentation.vertx.HttpInstrumenterVertxTracer; import io.quarkus.test.QuarkusUnitTest; +import io.vertx.core.spi.observability.HttpRequest; +import io.vertx.core.spi.observability.HttpResponse; -@Disabled("Not implemented") public class OpenTelemetryDisabledSdkTest { @RegisterExtension @@ -25,9 +30,48 @@ public class OpenTelemetryDisabledSdkTest { @Inject OpenTelemetry openTelemetry; + @Inject + OTelRuntimeConfig runtimeConfig; + @Test void testNoTracer() { // The OTel API doesn't provide a clear way to check if a tracer is an effective NOOP tracer. Assertions.assertTrue(batchSpanProcessor.isDelegateNull(), "BatchSpanProcessor delegate must not be set"); } + + @Test + void noReceiveRequestInstrumenter() { + HttpInstrumenterVertxTracer instrumenter = new HttpInstrumenterVertxTracer(openTelemetry, runtimeConfig); + + Instrumenter receiveRequestInstrumenter = instrumenter.getReceiveRequestInstrumenter(); + assertFalse(receiveRequestInstrumenter.shouldStart(null, null), + "Instrumenter must not start, if it does, it will throw an exception because of the null objects we are passing"); + } + + @Test + void noReceiveResponseInstrumenter() { + HttpInstrumenterVertxTracer instrumenter = new HttpInstrumenterVertxTracer(openTelemetry, runtimeConfig); + + Instrumenter receiveRequestInstrumenter = instrumenter.getReceiveResponseInstrumenter(); + assertFalse(receiveRequestInstrumenter.shouldStart(null, null), + "Instrumenter must not start, if it does, it will throw an exception because of the null objects we are passing"); + } + + @Test + void noSendRequestInstrumenter() { + HttpInstrumenterVertxTracer instrumenter = new HttpInstrumenterVertxTracer(openTelemetry, runtimeConfig); + + Instrumenter receiveRequestInstrumenter = instrumenter.getSendRequestInstrumenter(); + assertFalse(receiveRequestInstrumenter.shouldStart(null, null), + "Instrumenter must not start, if it does, it will throw an exception because of the null objects we are passing"); + } + + @Test + void noSendResponseInstrumenter() { + HttpInstrumenterVertxTracer instrumenter = new HttpInstrumenterVertxTracer(openTelemetry, runtimeConfig); + + Instrumenter receiveRequestInstrumenter = instrumenter.getSendResponseInstrumenter(); + assertFalse(receiveRequestInstrumenter.shouldStart(null, null), + "Instrumenter must not start, if it does, it will throw an exception because of the null objects we are passing"); + } } diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/cdi/WithSpanInterceptor.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/cdi/WithSpanInterceptor.java index 4e56bbdf4b0ea..0050a849d4adb 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/cdi/WithSpanInterceptor.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/cdi/WithSpanInterceptor.java @@ -28,6 +28,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.quarkus.arc.ArcInvocationContext; +import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig; import io.smallrye.mutiny.Multi; import io.smallrye.mutiny.Uni; import io.smallrye.mutiny.tuples.Functions; @@ -38,12 +39,14 @@ public class WithSpanInterceptor { private final Instrumenter instrumenter; - public WithSpanInterceptor(final OpenTelemetry openTelemetry) { + public WithSpanInterceptor(final OpenTelemetry openTelemetry, final OTelRuntimeConfig runtimeConfig) { InstrumenterBuilder builder = Instrumenter.builder( openTelemetry, INSTRUMENTATION_NAME, new MethodRequestSpanNameExtractor()); + builder.setEnabled(!runtimeConfig.sdkDisabled()); + MethodSpanAttributesExtractor attributesExtractor = MethodSpanAttributesExtractor.create( MethodRequest::getMethod, new WithSpanParameterAttributeNamesExtractor(), diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/InstrumentationRecorder.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/InstrumentationRecorder.java index 40aac71c43e0b..3b846e98189cf 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/InstrumentationRecorder.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/InstrumentationRecorder.java @@ -33,8 +33,13 @@ public InstrumentationRecorder(RuntimeValue config) { this.config = config; } + /* RUNTIME INIT */ @RuntimeInit public Consumer getVertxTracingOptions() { + if (config.getValue().sdkDisabled()) { + return vertxOptions -> { + }; + } TracingOptions tracingOptions = new TracingOptions() .setFactory(FACTORY); return vertxOptions -> vertxOptions.setTracingOptions(tracingOptions); @@ -44,25 +49,30 @@ public Consumer getVertxTracingOptions() { @RuntimeInit public void setupVertxTracer(BeanContainer beanContainer, boolean sqlClientAvailable, boolean redisClientAvailable) { + + if (config.getValue().sdkDisabled()) { + return; + } + OpenTelemetry openTelemetry = beanContainer.beanInstance(OpenTelemetry.class); List> tracers = new ArrayList<>(4); if (config.getValue().instrument().vertxHttp()) { - tracers.add(new HttpInstrumenterVertxTracer(openTelemetry)); + tracers.add(new HttpInstrumenterVertxTracer(openTelemetry, config.getValue())); } if (config.getValue().instrument().vertxEventBus()) { - tracers.add(new EventBusInstrumenterVertxTracer(openTelemetry)); + tracers.add(new EventBusInstrumenterVertxTracer(openTelemetry, config.getValue())); } if (sqlClientAvailable && config.getValue().instrument().vertxSqlClient()) { - tracers.add(new SqlClientInstrumenterVertxTracer(openTelemetry)); + tracers.add(new SqlClientInstrumenterVertxTracer(openTelemetry, config.getValue())); } if (redisClientAvailable && config.getValue().instrument().vertxRedisClient()) { - tracers.add(new RedisClientInstrumenterVertxTracer(openTelemetry)); + tracers.add(new RedisClientInstrumenterVertxTracer(openTelemetry, config.getValue())); } OpenTelemetryVertxTracer openTelemetryVertxTracer = new OpenTelemetryVertxTracer(tracers); FACTORY.getVertxTracerDelegator().setDelegate(openTelemetryVertxTracer); } - /* RUNTIME INIT */ + /* STATIC INIT */ public Consumer getVertxTracingMetricsOptions() { MetricsOptions metricsOptions = new MetricsOptions() .setEnabled(true) diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/grpc/GrpcTracingClientInterceptor.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/grpc/GrpcTracingClientInterceptor.java index 1901857ccdd01..4681ef04aac88 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/grpc/GrpcTracingClientInterceptor.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/grpc/GrpcTracingClientInterceptor.java @@ -21,6 +21,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; import io.quarkus.grpc.GlobalInterceptor; +import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig; @Singleton @GlobalInterceptor @@ -28,7 +29,7 @@ public class GrpcTracingClientInterceptor implements ClientInterceptor { private final OpenTelemetry openTelemetry; private final Instrumenter instrumenter; - public GrpcTracingClientInterceptor(final OpenTelemetry openTelemetry) { + public GrpcTracingClientInterceptor(final OpenTelemetry openTelemetry, final OTelRuntimeConfig runtimeConfig) { this.openTelemetry = openTelemetry; InstrumenterBuilder builder = Instrumenter.builder( @@ -36,6 +37,8 @@ public GrpcTracingClientInterceptor(final OpenTelemetry openTelemetry) { INSTRUMENTATION_NAME, new GrpcSpanNameExtractor()); + builder.setEnabled(!runtimeConfig.sdkDisabled()); + builder.addAttributesExtractor(RpcClientAttributesExtractor.create(GrpcAttributesGetter.INSTANCE)) .addAttributesExtractor(new GrpcStatusCodeExtractor()) .setSpanStatusExtractor(new GrpcSpanStatusExtractor()); diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/grpc/GrpcTracingServerInterceptor.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/grpc/GrpcTracingServerInterceptor.java index 7d728a0e1c13c..021eafd46aa76 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/grpc/GrpcTracingServerInterceptor.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/grpc/GrpcTracingServerInterceptor.java @@ -29,18 +29,21 @@ import io.opentelemetry.instrumentation.api.semconv.network.ServerAttributesExtractor; import io.opentelemetry.instrumentation.api.semconv.network.ServerAttributesGetter; import io.quarkus.grpc.GlobalInterceptor; +import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig; @Singleton @GlobalInterceptor public class GrpcTracingServerInterceptor implements ServerInterceptor { private final Instrumenter instrumenter; - public GrpcTracingServerInterceptor(final OpenTelemetry openTelemetry) { + public GrpcTracingServerInterceptor(final OpenTelemetry openTelemetry, final OTelRuntimeConfig runtimeConfig) { InstrumenterBuilder builder = Instrumenter.builder( openTelemetry, INSTRUMENTATION_NAME, new GrpcSpanNameExtractor()); + builder.setEnabled(!runtimeConfig.sdkDisabled()); + GrpcServerNetworkAttributesGetter getter = new GrpcServerNetworkAttributesGetter(); builder.addAttributesExtractor(RpcServerAttributesExtractor.create(GrpcAttributesGetter.INSTANCE)) diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/restclient/OpenTelemetryClientFilter.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/restclient/OpenTelemetryClientFilter.java index c3ea205f6c2cf..be5263c5f98a9 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/restclient/OpenTelemetryClientFilter.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/restclient/OpenTelemetryClientFilter.java @@ -15,6 +15,8 @@ import jakarta.ws.rs.core.UriBuilder; import jakarta.ws.rs.ext.Provider; +import org.eclipse.microprofile.config.ConfigProvider; + import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.trace.Span; @@ -29,6 +31,8 @@ import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; import io.quarkus.arc.Unremovable; import io.quarkus.opentelemetry.runtime.QuarkusContextStorage; +import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig; +import io.smallrye.config.SmallRyeConfig; /** * A client filter for the JAX-RS Client and MicroProfile REST Client that records OpenTelemetry data. This is only used @@ -56,11 +60,14 @@ public class OpenTelemetryClientFilter implements ClientRequestFilter, ClientRes // RESTEasy requires no-arg constructor for CDI injection: https://issues.redhat.com/browse/RESTEASY-1538 // In Reactive Rest Client this is the constructor called. In the classic is the next one with injection. public OpenTelemetryClientFilter() { - this(GlobalOpenTelemetry.get()); + this(GlobalOpenTelemetry.get(), + ConfigProvider.getConfig() + .unwrap(SmallRyeConfig.class) + .getConfigMapping(OTelRuntimeConfig.class)); } @Inject - public OpenTelemetryClientFilter(final OpenTelemetry openTelemetry) { + public OpenTelemetryClientFilter(final OpenTelemetry openTelemetry, final OTelRuntimeConfig runtimeConfig) { ClientAttributesExtractor clientAttributesExtractor = new ClientAttributesExtractor(); InstrumenterBuilder builder = Instrumenter.builder( @@ -68,6 +75,8 @@ public OpenTelemetryClientFilter(final OpenTelemetry openTelemetry) { INSTRUMENTATION_NAME, HttpSpanNameExtractor.create(clientAttributesExtractor)); + builder.setEnabled(!runtimeConfig.sdkDisabled()); + this.instrumenter = builder .setSpanStatusExtractor(HttpSpanStatusExtractor.create(clientAttributesExtractor)) .addAttributesExtractor(HttpClientAttributesExtractor.create( diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/scheduler/OpenTelemetryJobInstrumenter.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/scheduler/OpenTelemetryJobInstrumenter.java index 1456bce5beafd..12e88f7666171 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/scheduler/OpenTelemetryJobInstrumenter.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/scheduler/OpenTelemetryJobInstrumenter.java @@ -11,6 +11,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; +import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig; import io.quarkus.scheduler.spi.JobInstrumenter; @Singleton @@ -18,7 +19,7 @@ public class OpenTelemetryJobInstrumenter implements JobInstrumenter { private final Instrumenter instrumenter; - public OpenTelemetryJobInstrumenter(OpenTelemetry openTelemetry) { + public OpenTelemetryJobInstrumenter(final OpenTelemetry openTelemetry, final OTelRuntimeConfig runtimeConfig) { InstrumenterBuilder instrumenterBuilder = Instrumenter.builder( openTelemetry, "io.quarkus.opentelemetry", new SpanNameExtractor() { @@ -27,6 +28,9 @@ public String extract(JobInstrumentationContext context) { return context.getSpanName(); } }); + + instrumenterBuilder.setEnabled(!runtimeConfig.sdkDisabled()); + instrumenterBuilder.setErrorCauseExtractor(new ErrorCauseExtractor() { @Override public Throwable extract(Throwable throwable) { @@ -39,13 +43,15 @@ public Throwable extract(Throwable throwable) { @Override public CompletionStage instrument(JobInstrumentationContext instrumentationContext) { Context parentCtx = Context.current(); - Context context = instrumenter.start(parentCtx, instrumentationContext); - try (Scope scope = context.makeCurrent()) { - return instrumentationContext - .executeJob() - .whenComplete( - (result, throwable) -> instrumenter.end(context, instrumentationContext, null, throwable)); + if (instrumenter.shouldStart(parentCtx, instrumentationContext)) { + Context context = instrumenter.start(parentCtx, instrumentationContext); + try (Scope scope = context.makeCurrent()) { + return instrumentationContext + .executeJob() + .whenComplete( + (result, throwable) -> instrumenter.end(context, instrumentationContext, null, throwable)); + } } + return instrumentationContext.executeJob(); } - } diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/EventBusInstrumenterVertxTracer.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/EventBusInstrumenterVertxTracer.java index e3aff4e8e2383..eb7e3fe6e16c1 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/EventBusInstrumenterVertxTracer.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/EventBusInstrumenterVertxTracer.java @@ -11,6 +11,7 @@ import io.opentelemetry.instrumentation.api.incubator.semconv.messaging.MessagingSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; +import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig; import io.vertx.core.eventbus.Message; import io.vertx.core.spi.tracing.TagExtractor; @@ -19,9 +20,9 @@ public class EventBusInstrumenterVertxTracer implements InstrumenterVertxTracer< private final Instrumenter consumerInstrumenter; private final Instrumenter producerInstrumenter; - public EventBusInstrumenterVertxTracer(final OpenTelemetry openTelemetry) { - this.consumerInstrumenter = getConsumerInstrumenter(openTelemetry); - this.producerInstrumenter = getProducerInstrumenter(openTelemetry); + public EventBusInstrumenterVertxTracer(final OpenTelemetry openTelemetry, final OTelRuntimeConfig runtimeConfig) { + this.consumerInstrumenter = getConsumerInstrumenter(openTelemetry, runtimeConfig); + this.producerInstrumenter = getProducerInstrumenter(openTelemetry, runtimeConfig); } @Override @@ -49,11 +50,14 @@ public Instrumenter getReceiveResponseInstrumenter() { return producerInstrumenter; } - private static Instrumenter getConsumerInstrumenter(final OpenTelemetry openTelemetry) { + private static Instrumenter getConsumerInstrumenter(final OpenTelemetry openTelemetry, + final OTelRuntimeConfig runtimeConfig) { InstrumenterBuilder serverBuilder = Instrumenter.builder( openTelemetry, INSTRUMENTATION_NAME, MessagingSpanNameExtractor.create(EventBusAttributesGetter.INSTANCE, RECEIVE)); + serverBuilder.setEnabled(!runtimeConfig.sdkDisabled()); + return serverBuilder .addAttributesExtractor(MessagingAttributesExtractor.create(EventBusAttributesGetter.INSTANCE, RECEIVE)) .buildConsumerInstrumenter(new TextMapGetter<>() { @@ -72,11 +76,14 @@ public String get(final Message message, final String key) { }); } - private static Instrumenter getProducerInstrumenter(final OpenTelemetry openTelemetry) { + private static Instrumenter getProducerInstrumenter(final OpenTelemetry openTelemetry, + final OTelRuntimeConfig runtimeConfig) { InstrumenterBuilder serverBuilder = Instrumenter.builder( openTelemetry, INSTRUMENTATION_NAME, MessagingSpanNameExtractor.create(EventBusAttributesGetter.INSTANCE, PUBLISH)); + serverBuilder.setEnabled(!runtimeConfig.sdkDisabled()); + return serverBuilder .addAttributesExtractor(MessagingAttributesExtractor.create(EventBusAttributesGetter.INSTANCE, PUBLISH)) .buildProducerInstrumenter((message, key, value) -> { diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/HttpInstrumenterVertxTracer.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/HttpInstrumenterVertxTracer.java index d8974c1c69215..2d1d7c68a1273 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/HttpInstrumenterVertxTracer.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/HttpInstrumenterVertxTracer.java @@ -30,6 +30,7 @@ import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteBiGetter; import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; +import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig; import io.smallrye.common.vertx.VertxContext; import io.vertx.core.Context; import io.vertx.core.MultiMap; @@ -51,9 +52,9 @@ public class HttpInstrumenterVertxTracer implements InstrumenterVertxTracer serverInstrumenter; private final Instrumenter clientInstrumenter; - public HttpInstrumenterVertxTracer(final OpenTelemetry openTelemetry) { - serverInstrumenter = getServerInstrumenter(openTelemetry); - clientInstrumenter = getClientInstrumenter(openTelemetry); + public HttpInstrumenterVertxTracer(final OpenTelemetry openTelemetry, final OTelRuntimeConfig runtimeConfig) { + serverInstrumenter = getServerInstrumenter(openTelemetry, runtimeConfig); + clientInstrumenter = getClientInstrumenter(openTelemetry, runtimeConfig); } @Override @@ -136,7 +137,8 @@ public HttpRequest writableHeaders( return WriteHeadersHttpRequest.request(request, headers); } - private static Instrumenter getServerInstrumenter(final OpenTelemetry openTelemetry) { + static Instrumenter getServerInstrumenter(final OpenTelemetry openTelemetry, + final OTelRuntimeConfig runtimeConfig) { ServerAttributesExtractor serverAttributesExtractor = new ServerAttributesExtractor(); InstrumenterBuilder serverBuilder = Instrumenter.builder( @@ -144,6 +146,8 @@ private static Instrumenter getServerInstrumenter(fin INSTRUMENTATION_NAME, HttpSpanNameExtractor.create(serverAttributesExtractor)); + serverBuilder.setEnabled(!runtimeConfig.sdkDisabled()); + return serverBuilder .setSpanStatusExtractor(HttpSpanStatusExtractor.create(serverAttributesExtractor)) .addAttributesExtractor( @@ -153,7 +157,8 @@ private static Instrumenter getServerInstrumenter(fin .buildServerInstrumenter(new HttpRequestTextMapGetter()); } - private static Instrumenter getClientInstrumenter(final OpenTelemetry openTelemetry) { + static Instrumenter getClientInstrumenter(final OpenTelemetry openTelemetry, + final OTelRuntimeConfig runtimeConfig) { ServerAttributesExtractor serverAttributesExtractor = new ServerAttributesExtractor(); HttpClientAttributesExtractor httpClientAttributesExtractor = new HttpClientAttributesExtractor(); @@ -162,6 +167,8 @@ private static Instrumenter getClientInstrumenter(fin INSTRUMENTATION_NAME, new ClientSpanNameExtractor(httpClientAttributesExtractor)); + clientBuilder.setEnabled(!runtimeConfig.sdkDisabled()); + return clientBuilder .setSpanStatusExtractor(HttpSpanStatusExtractor.create(serverAttributesExtractor)) .addAttributesExtractor( diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/RedisClientInstrumenterVertxTracer.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/RedisClientInstrumenterVertxTracer.java index 06c5db88ee48c..a27b7dbd2e475 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/RedisClientInstrumenterVertxTracer.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/RedisClientInstrumenterVertxTracer.java @@ -16,6 +16,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; import io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil; import io.opentelemetry.semconv.SemanticAttributes; +import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig; import io.vertx.core.Context; import io.vertx.core.spi.tracing.SpanKind; import io.vertx.core.spi.tracing.TagExtractor; @@ -25,12 +26,14 @@ public class RedisClientInstrumenterVertxTracer implements InstrumenterVertxTracer { private final Instrumenter redisClientInstrumenter; - public RedisClientInstrumenterVertxTracer(final OpenTelemetry openTelemetry) { + public RedisClientInstrumenterVertxTracer(final OpenTelemetry openTelemetry, final OTelRuntimeConfig runtimeConfig) { InstrumenterBuilder clientInstrumenterBuilder = Instrumenter.builder( openTelemetry, INSTRUMENTATION_NAME, DbClientSpanNameExtractor.create(RedisClientAttributesGetter.INSTANCE)); + clientInstrumenterBuilder.setEnabled(!runtimeConfig.sdkDisabled()); + this.redisClientInstrumenter = clientInstrumenterBuilder .addAttributesExtractor(DbClientAttributesExtractor.create(RedisClientAttributesGetter.INSTANCE)) .addAttributesExtractor(RedisClientAttributesExtractor.INSTANCE) diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/SqlClientInstrumenterVertxTracer.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/SqlClientInstrumenterVertxTracer.java index 527459568968b..8ed7e16332d59 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/SqlClientInstrumenterVertxTracer.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/SqlClientInstrumenterVertxTracer.java @@ -10,6 +10,7 @@ import io.opentelemetry.instrumentation.api.incubator.semconv.db.SqlClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; +import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig; import io.vertx.core.Context; import io.vertx.core.spi.tracing.SpanKind; import io.vertx.core.spi.tracing.TagExtractor; @@ -19,13 +20,15 @@ public class SqlClientInstrumenterVertxTracer implements InstrumenterVertxTracer { private final Instrumenter sqlClientInstrumenter; - public SqlClientInstrumenterVertxTracer(final OpenTelemetry openTelemetry) { + public SqlClientInstrumenterVertxTracer(final OpenTelemetry openTelemetry, final OTelRuntimeConfig runtimeConfig) { SqlClientAttributesGetter sqlClientAttributesGetter = new SqlClientAttributesGetter(); InstrumenterBuilder serverBuilder = Instrumenter.builder( openTelemetry, INSTRUMENTATION_NAME, DbClientSpanNameExtractor.create(sqlClientAttributesGetter)); + serverBuilder.setEnabled(!runtimeConfig.sdkDisabled()); + this.sqlClientInstrumenter = serverBuilder .addAttributesExtractor(SqlClientAttributesExtractor.create(sqlClientAttributesGetter)) .buildClientInstrumenter((queryTrace, key, value) -> {