apache / camel-quarkus

Apache Camel Quarkus
https://camel.apache.org
Apache License 2.0
257 stars 192 forks source link

Camel OpenTelemetry enabled when quarkus.otel.sdk.disabled=true #6814

Closed aka-peter closed 13 hours ago

aka-peter commented 1 day ago

Bug description

Camel OpenTelemetry seems to be enabled even if quarkus.otel.sdk.disabled=true.

Log line:

2024-11-21 16:31:53,659 INFO  [org.apa.cam.ope.OpenTelemetryTracer] (Quarkus Main Thread) OpenTelemetryTracer enabled using instrumentation-name: camel

This triggers a problem for the configuration below where there are issues with GlobalOpenTelemetry.set being called although it should be disabled. No problems with otel sdk enabled (or mongodb tracing disabled).

quarkus create app --extension=quarkus-config-yaml,camel-quarkus-scheduler,camel-quarkus-direct,camel-quarkus-opentelemetry,camel-quarkus-mongodb && cd code-with-quarkus
cat <<EOF >> src/main/resources/application.yml 
quarkus:
  otel:
    sdk:
      disabled: true
    traces:
      enabled: true
    metrics:
      enabled: true
    logs:
      enabled: true
  mongodb:
    metrics:
      enabled: true
    tracing:
      enabled: true
EOF
cat <<EOF > src/main/java/org/acme/GreetingApp.java 
package org.acme;

import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
import org.apache.camel.component.mongodb.MongoDbOperation;
import jakarta.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class GreetingApp extends EndpointRouteBuilder {

    @Override
    public void configure() throws Exception {
        from(scheduler("repeat").delay(5000).repeatCount(1000).includeMetadata(true))
                        .log("\${headers}").to(direct("count"));
        from(direct("count")).to(
                        mongodb("mongoClient").database("mydb").collection("mycoll").operation(MongoDbOperation.count))
                        .log("\${body}");
    }
}
EOF
quarkus dev

Log:

2024-11-21 16:31:53,536 INFO  [org.apa.cam.qua.cor.CamelBootstrapRecorder] (Quarkus Main Thread) Apache Camel Quarkus 3.16.0 is starting
2024-11-21 16:31:53,536 INFO  [org.apa.cam.mai.MainSupport] (Quarkus Main Thread) Apache Camel (Main) 4.8.1 is starting
2024-11-21 16:31:53,540 INFO  [org.apa.cam.mai.ProfileConfigurer] (Quarkus Main Thread) The application is starting with profile: dev
2024-11-21 16:31:53,648 INFO  [io.ope.api.GlobalOpenTelemetry] (Quarkus Main Thread) AutoConfiguredOpenTelemetrySdk found on classpath but automatic configuration is disabled. To enable, run your JVM with -Dotel.java.global-autoconfigure.enabled=true
(com.mongodb.client.MongoClient_h1_G0-d2ADp3y2Tmh2-WKjUlre0_Synthetic_ClientProxy) found in the registry
2024-11-21 16:31:53,652 INFO  [org.apa.cam.sup.LifecycleStrategySupport] (Quarkus Main Thread) Autowired property: mongoConnection on component: mongodb as exactly one instance of type: com.mongodb.client.MongoClient (com.mongodb.client.MongoClient_h1_G0-d2ADp3y2Tmh2-WKjUlre0_Synthetic_ClientProxy) found in the registry
2024-11-21 16:31:53,657 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (Quarkus Main Thread) Apache Camel 4.8.1 (camel-1) is starting
2024-11-21 16:31:53,659 INFO  [org.apa.cam.ope.OpenTelemetryTracer] (Quarkus Main Thread) OpenTelemetryTracer enabled using instrumentation-name: camel
2024-11-21 16:31:53,659 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (Quarkus Main Thread) Using ThreadPoolFactory: org.apache.camel.quarkus.component.opentelemetry.patch.OpenTelemetryInstrumentedThreadPoolFactory@2c0bf219
2024-11-21

2024-11-21 16:31:53,660 INFO  [org.apa.cam.com.mon.MongoDbEndpoint] (Quarkus Main Thread) Initialising MongoDb endpoint: mongodb://mongoClient?collection=mycoll&database=mydb&operation=count
2024-11-21 16:31:53,695 INFO  [io.ope.sdk.aut.AutoConfiguredOpenTelemetrySdkBuilder] (Quarkus Main Thread) Error encountered during autoconfiguration. Closing partially configured components.
2024-11-21 16:31:53,695 ERROR [org.apa.cam.imp.eng.AbstractCamelContext] (Quarkus Main Thread) Error starting CamelContext (camel-1) due to exception thrown: Failed to start route route2 because of jakarta.enterprise.inject.CreationException: Error creating synthetic bean [h1_G0-d2ADp3y2Tmh2-WKjUlre0]: jakarta.enterprise.inject.CreationException: Error creating synthetic bean [Le6zQbzkojAYO_OiKIQWJf4lGa4]: io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException: Unexpected configuration error: org.apache.camel.FailedToStartRouteException: Failed to start route route2 because of jakarta.enterprise.inject.CreationException: Error creating synthetic bean [h1_G0-d2ADp3y2Tmh2-WKjUlre0]: jakarta.enterprise.inject.CreationException: Error creating synthetic bean [Le6zQbzkojAYO_OiKIQWJf4lGa4]: io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException: Unexpected configuration error
    at org.apache.camel.impl.engine.RouteService.warmUp(RouteService.java:125)
    at org.apache.camel.impl.engine.InternalRouteStartupManager.doWarmUpRoutes(InternalRouteStartupManager.java:327)
    at org.apache.camel.impl.engine.InternalRouteStartupManager.safelyStartRouteServices(InternalRouteStartupManager.java:198)
    at org.apache.camel.impl.engine.InternalRouteStartupManager.doStartOrResumeRoutes(InternalRouteStartupManager.java:132)
    at org.apache.camel.impl.engine.AbstractCamelContext.doStartCamel(AbstractCamelContext.java:2898)
    at org.apache.camel.impl.engine.AbstractCamelContext.doStartContext(AbstractCamelContext.java:2528)
    at org.apache.camel.impl.engine.AbstractCamelContext.doStart(AbstractCamelContext.java:2483)
    at org.apache.camel.support.service.BaseService.start(BaseService.java:123)
    at org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2087)
    at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:211)
    at org.apache.camel.quarkus.main.CamelMain.doStart(CamelMain.java:91)
    at org.apache.camel.support.service.BaseService.start(BaseService.java:123)
    at org.apache.camel.quarkus.main.CamelMain.startEngine(CamelMain.java:137)
    at org.apache.camel.quarkus.main.CamelMainRuntime.start(CamelMainRuntime.java:49)
    at org.apache.camel.quarkus.core.CamelBootstrapRecorder.start(CamelBootstrapRecorder.java:45)
    at io.quarkus.deployment.steps.CamelBootstrapProcessor$boot173480958.deploy_0(Unknown Source)
    at io.quarkus.deployment.steps.CamelBootstrapProcessor$boot173480958.deploy(Unknown Source)
    at io.quarkus.runner.ApplicationImpl.doStart(Unknown Source)
    at io.quarkus.runtime.Application.start(Application.java:101)
    at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:121)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:71)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:44)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:124)
    at io.quarkus.runner.GeneratedMain.main(Unknown Source)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at io.quarkus.runner.bootstrap.StartupActionImpl$1.run(StartupActionImpl.java:116)
    at java.base/java.lang.Thread.run(Thread.java:1575)
Caused by: org.apache.camel.RuntimeCamelException: jakarta.enterprise.inject.CreationException: Error creating synthetic bean [h1_G0-d2ADp3y2Tmh2-WKjUlre0]: jakarta.enterprise.inject.CreationException: Error creating synthetic bean [Le6zQbzkojAYO_OiKIQWJf4lGa4]: io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException: Unexpected configuration error
    at org.apache.camel.RuntimeCamelException.wrapRuntimeCamelException(RuntimeCamelException.java:53)
    at org.apache.camel.support.ChildServiceSupport.start(ChildServiceSupport.java:68)
    at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:126)
    at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113)
    at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:153)
    at org.apache.camel.impl.engine.DefaultChannel.doStart(DefaultChannel.java:130)
    at org.apache.camel.support.service.BaseService.start(BaseService.java:123)
    at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:126)
    at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113)
    at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:139)
    at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:115)
    at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:153)
    at org.apache.camel.processor.Pipeline.doStart(Pipeline.java:205)
    at org.apache.camel.support.service.BaseService.start(BaseService.java:123)
    at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:126)
    at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113)
    at org.apache.camel.support.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:89)
    at org.apache.camel.support.service.BaseService.start(BaseService.java:123)
    at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:126)
    at org.apache.camel.impl.engine.RouteService.startChildServices(RouteService.java:408)
    at org.apache.camel.impl.engine.RouteService.doWarmUp(RouteService.java:202)
    at org.apache.camel.impl.engine.RouteService.warmUp(RouteService.java:123)
    ... 27 more
Caused by: jakarta.enterprise.inject.CreationException: Error creating synthetic bean [h1_G0-d2ADp3y2Tmh2-WKjUlre0]: jakarta.enterprise.inject.CreationException: Error creating synthetic bean [Le6zQbzkojAYO_OiKIQWJf4lGa4]: io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException: Unexpected configuration error
    at com.mongodb.client.MongoClient_h1_G0-d2ADp3y2Tmh2-WKjUlre0_Synthetic_Bean.doCreate(Unknown Source)
    at com.mongodb.client.MongoClient_h1_G0-d2ADp3y2Tmh2-WKjUlre0_Synthetic_Bean.create(Unknown Source)
    at com.mongodb.client.MongoClient_h1_G0-d2ADp3y2Tmh2-WKjUlre0_Synthetic_Bean.create(Unknown Source)
    at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:119)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:38)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:35)
    at io.quarkus.arc.generator.Default_jakarta_enterprise_context_ApplicationScoped_ContextInstances.c7(Unknown Source)
    at io.quarkus.arc.generator.Default_jakarta_enterprise_context_ApplicationScoped_ContextInstances.computeIfAbsent(Unknown Source)
    at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:35)
    at io.quarkus.arc.impl.ClientProxies.getApplicationScopedDelegate(ClientProxies.java:21)
    at com.mongodb.client.MongoClient_h1_G0-d2ADp3y2Tmh2-WKjUlre0_Synthetic_ClientProxy.arc$delegate(Unknown Source)
    at com.mongodb.client.MongoClient_h1_G0-d2ADp3y2Tmh2-WKjUlre0_Synthetic_ClientProxy.getDatabase(Unknown Source)
    at org.apache.camel.component.mongodb.MongoDbEndpoint.initializeConnection(MongoDbEndpoint.java:343)
    at org.apache.camel.component.mongodb.MongoDbEndpoint.createProducer(MongoDbEndpoint.java:235)
    at org.apache.camel.support.DefaultEndpoint.createAsyncProducer(DefaultEndpoint.java:198)
    at org.apache.camel.processor.SendProcessor.doStart(SendProcessor.java:313)
    at org.apache.camel.support.service.BaseService.start(BaseService.java:123)
    at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:126)
    at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113)
    at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:153)
    at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler.doStart(RedeliveryErrorHandler.java:1668)
    at org.apache.camel.support.ChildServiceSupport.start(ChildServiceSupport.java:61)
    ... 47 more
Caused by: jakarta.enterprise.inject.CreationException: Error creating synthetic bean [Le6zQbzkojAYO_OiKIQWJf4lGa4]: io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException: Unexpected configuration error
    at io.opentelemetry.api.OpenTelemetry_Le6zQbzkojAYO_OiKIQWJf4lGa4_Synthetic_Bean.doCreate(Unknown Source)
    at io.opentelemetry.api.OpenTelemetry_Le6zQbzkojAYO_OiKIQWJf4lGa4_Synthetic_Bean.create(Unknown Source)
    at io.opentelemetry.api.OpenTelemetry_Le6zQbzkojAYO_OiKIQWJf4lGa4_Synthetic_Bean.create(Unknown Source)
    at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:119)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:38)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:35)
    at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:32)
    at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
    at io.quarkus.arc.impl.ComputingCacheContextInstances.computeIfAbsent(ComputingCacheContextInstances.java:19)
    at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:35)
    at io.opentelemetry.api.OpenTelemetry_Le6zQbzkojAYO_OiKIQWJf4lGa4_Synthetic_Bean.get(Unknown Source)
    at io.opentelemetry.api.OpenTelemetry_Le6zQbzkojAYO_OiKIQWJf4lGa4_Synthetic_Bean.get(Unknown Source)
    at io.quarkus.mongodb.tracing.MongoTracingCommandListener_Bean.doCreate(Unknown Source)
    at io.quarkus.mongodb.tracing.MongoTracingCommandListener_Bean.create(Unknown Source)
    at io.quarkus.mongodb.tracing.MongoTracingCommandListener_Bean.create(Unknown Source)
    at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:119)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:38)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:35)
    at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:32)
    at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
    at io.quarkus.arc.impl.ComputingCacheContextInstances.computeIfAbsent(ComputingCacheContextInstances.java:19)
    at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:35)
    at io.quarkus.mongodb.tracing.MongoTracingCommandListener_Bean.get(Unknown Source)
    at io.quarkus.mongodb.tracing.MongoTracingCommandListener_Bean.get(Unknown Source)
    at io.quarkus.arc.impl.InstanceImpl.getBeanInstance(InstanceImpl.java:325)
    at io.quarkus.arc.impl.InstanceImpl$InstanceIterator.next(InstanceImpl.java:363)
    at io.quarkus.mongodb.runtime.MongoClients.createMongoConfiguration(MongoClients.java:285)
    at io.quarkus.mongodb.runtime.MongoClients.createMongoClient(MongoClients.java:128)
    at io.quarkus.mongodb.runtime.MongoClientRecorder.lambda$mongoClientSupplier$0(MongoClientRecorder.java:66)
    at io.quarkus.mongodb.runtime.MongoClientRecorder$MongoClientSupplier.get(MongoClientRecorder.java:60)
    at io.quarkus.arc.runtime.ArcRecorder$4.apply(ArcRecorder.java:137)
    at io.quarkus.arc.runtime.ArcRecorder$4.apply(ArcRecorder.java:134)
    at com.mongodb.client.MongoClient_h1_G0-d2ADp3y2Tmh2-WKjUlre0_Synthetic_Bean.createSynthetic(Unknown Source)
    ... 69 more
Caused by: io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException: Unexpected configuration error
    at io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder.build(AutoConfiguredOpenTelemetrySdkBuilder.java:525)
    at io.quarkus.opentelemetry.runtime.OpenTelemetryRecorder$1.apply(OpenTelemetryRecorder.java:68)
    at io.quarkus.opentelemetry.runtime.OpenTelemetryRecorder$1.apply(OpenTelemetryRecorder.java:54)
    at io.opentelemetry.api.OpenTelemetry_Le6zQbzkojAYO_OiKIQWJf4lGa4_Synthetic_Bean.createSynthetic(Unknown Source)
    ... 102 more
Caused by: java.lang.IllegalStateException: GlobalOpenTelemetry.set has already been called. GlobalOpenTelemetry.set must be called only once before any calls to GlobalOpenTelemetry.get. If you are using the OpenTelemetrySdk, use OpenTelemetrySdkBuilder.buildAndRegisterGlobal instead. Previous invocation set to cause of this exception.
    at io.opentelemetry.api.GlobalOpenTelemetry.set(GlobalOpenTelemetry.java:107)
    at io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder.maybeSetAsGlobal(AutoConfiguredOpenTelemetrySdkBuilder.java:589)
    at io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder.build(AutoConfiguredOpenTelemetrySdkBuilder.java:506)
    ... 105 more
Caused by: java.lang.Throwable
    at io.opentelemetry.api.GlobalOpenTelemetry.set(GlobalOpenTelemetry.java:115)
    at io.opentelemetry.api.GlobalOpenTelemetry.get(GlobalOpenTelemetry.java:85)
    at org.apache.camel.opentelemetry.OpenTelemetryTracer.initContextPropagators(OpenTelemetryTracer.java:136)
    at org.apache.camel.tracing.Tracer.doInit(Tracer.java:174)
    at org.apache.camel.support.service.BaseService.init(BaseService.java:85)
    at org.apache.camel.support.service.ServiceHelper.initService(ServiceHelper.java:84)
    at org.apache.camel.impl.engine.InternalServiceManager.doAddService(InternalServiceManager.java:146)
    at org.apache.camel.impl.engine.AbstractCamelContext.addService(AbstractCamelContext.java:1364)
    at org.apache.camel.tracing.Tracer.init(Tracer.java:153)
    at org.apache.camel.tracing.Tracer.createRoutePolicy(Tracer.java:142)
    at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:275)
    at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:86)
    at org.apache.camel.impl.DefaultModelReifierFactory.createRoute(DefaultModelReifierFactory.java:49)
    at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:726)
    at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:592)
    at org.apache.camel.impl.engine.AbstractCamelContext.doInit(AbstractCamelContext.java:2433)
    at org.apache.camel.quarkus.core.FastCamelContext.doInit(FastCamelContext.java:195)
    at org.apache.camel.support.service.BaseService.init(BaseService.java:85)
    at org.apache.camel.impl.engine.AbstractCamelContext.init(AbstractCamelContext.java:2068)
    at org.apache.camel.support.service.BaseService.start(BaseService.java:115)
    ... 20 more
jamesnetherton commented 13 hours ago

Thanks for the reproducer instructions 👍.

The issue should be fixed in Camel Qurakus >= 3.17.0.

There is a (somewhat terrible) workaround:

@ApplicationScoped
public class OtelSdkDisabledCamelWorkaround {
    @Produces
    OpenTelemetryTracer disableCamelOpenTelemetryTracer() {
        return null;
    }
}