This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch otel in repository https://gitbox.apache.org/repos/asf/camel.git
commit dda8534dad84858511735588b14f23725ccd62af Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sun Nov 5 11:48:34 2023 +0100 CAMEL-20083: camel-opentelemtry - Make it easier to configure for camel-main --- .../camel/observation/AttributeProcessor.java | 12 +--------- .../observation/MicrometerObservationTracer.java | 2 +- .../SetCorrelationContextProcessor.java | 3 --- .../main/java/org/apache/camel/tracing/Tracer.java | 4 ++-- .../org/apache/camel/spi/CamelTracingService.java | 27 ++++++++++++++++++++++ .../org/apache/camel/main/BaseMainSupport.java | 14 +++++++---- 6 files changed, 41 insertions(+), 21 deletions(-) diff --git a/components/camel-observation/src/main/java/org/apache/camel/observation/AttributeProcessor.java b/components/camel-observation/src/main/java/org/apache/camel/observation/AttributeProcessor.java index c551908aa4a..cdca8f440ca 100644 --- a/components/camel-observation/src/main/java/org/apache/camel/observation/AttributeProcessor.java +++ b/components/camel-observation/src/main/java/org/apache/camel/observation/AttributeProcessor.java @@ -30,7 +30,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * A processor which adds a attribute on the active {@link Observation} with an {@link org.apache.camel.Expression} + * A processor which adds an attribute on the active {@link Observation} with an {@link org.apache.camel.Expression} */ public class AttributeProcessor extends AsyncProcessorSupport implements Traceable, IdAware, RouteIdAware { @@ -99,16 +99,6 @@ public class AttributeProcessor extends AsyncProcessorSupport implements Traceab return expression; } - @Override - protected void doStart() throws Exception { - // noop - } - - @Override - protected void doStop() throws Exception { - // noop - } - @Override public String toString() { return id; diff --git a/components/camel-observation/src/main/java/org/apache/camel/observation/MicrometerObservationTracer.java b/components/camel-observation/src/main/java/org/apache/camel/observation/MicrometerObservationTracer.java index aa5baec9d4f..74f90818965 100644 --- a/components/camel-observation/src/main/java/org/apache/camel/observation/MicrometerObservationTracer.java +++ b/components/camel-observation/src/main/java/org/apache/camel/observation/MicrometerObservationTracer.java @@ -160,7 +160,7 @@ public class MicrometerObservationTracer extends org.apache.camel.tracing.Tracer @Override protected void initContextPropagators() { - + // noop } private static Observation getParentObservation(SpanAdapter parentObservation) { diff --git a/components/camel-observation/src/main/java/org/apache/camel/observation/SetCorrelationContextProcessor.java b/components/camel-observation/src/main/java/org/apache/camel/observation/SetCorrelationContextProcessor.java index 80d329ffafa..9d2d86cde84 100644 --- a/components/camel-observation/src/main/java/org/apache/camel/observation/SetCorrelationContextProcessor.java +++ b/components/camel-observation/src/main/java/org/apache/camel/observation/SetCorrelationContextProcessor.java @@ -28,9 +28,6 @@ import org.apache.camel.util.ObjectHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * @author rvargasp - */ public class SetCorrelationContextProcessor extends AsyncProcessorSupport implements Traceable, IdAware, RouteIdAware { private static final Logger LOG = LoggerFactory.getLogger(SetCorrelationContextProcessor.class); diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/Tracer.java b/components/camel-tracing/src/main/java/org/apache/camel/tracing/Tracer.java index 1b9c5297112..3afbeae663f 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/Tracer.java +++ b/components/camel-tracing/src/main/java/org/apache/camel/tracing/Tracer.java @@ -23,7 +23,6 @@ import java.util.ServiceLoader; import java.util.Set; import org.apache.camel.CamelContext; -import org.apache.camel.CamelContextAware; import org.apache.camel.Component; import org.apache.camel.Endpoint; import org.apache.camel.Exchange; @@ -33,6 +32,7 @@ import org.apache.camel.RuntimeCamelException; import org.apache.camel.StaticService; import org.apache.camel.spi.CamelEvent; import org.apache.camel.spi.CamelLogger; +import org.apache.camel.spi.CamelTracingService; import org.apache.camel.spi.InterceptStrategy; import org.apache.camel.spi.LogListener; import org.apache.camel.spi.RoutePolicy; @@ -48,7 +48,7 @@ import org.apache.camel.util.StringHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public abstract class Tracer extends ServiceSupport implements RoutePolicyFactory, StaticService, CamelContextAware { +public abstract class Tracer extends ServiceSupport implements CamelTracingService, RoutePolicyFactory, StaticService { protected static final Map<String, SpanDecorator> DECORATORS = new HashMap<>(); static final AutoCloseable NOOP_CLOSEABLE = () -> { }; diff --git a/core/camel-api/src/generated/java/org/apache/camel/spi/CamelTracingService.java b/core/camel-api/src/generated/java/org/apache/camel/spi/CamelTracingService.java new file mode 100644 index 00000000000..e71ebc047fe --- /dev/null +++ b/core/camel-api/src/generated/java/org/apache/camel/spi/CamelTracingService.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.spi; + +import org.apache.camel.CamelContextAware; +import org.apache.camel.Service; + +/** + * A Camel tracing service is a factory for telemetry tracers. + */ +public interface CamelTracingService extends Service, CamelContextAware { + +} diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java index 734356576c6..f00d66c107e 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java @@ -84,6 +84,7 @@ import org.apache.camel.support.scan.PackageScanHelper; import org.apache.camel.support.service.BaseService; import org.apache.camel.support.startup.BacklogStartupStepRecorder; import org.apache.camel.support.startup.LoggingStartupStepRecorder; +import org.apache.camel.spi.CamelTracingService; import org.apache.camel.util.FileUtil; import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.OrderedLocationProperties; @@ -2023,6 +2024,9 @@ public abstract class BaseMainSupport extends BaseService { private static CamelSagaService resolveLraSagaService(CamelContext camelContext) throws Exception { // lookup in service registry first CamelSagaService answer = camelContext.getRegistry().findSingleByType(CamelSagaService.class); + if (answer == null) { + answer = camelContext.hasService(CamelSagaService.class); + } if (answer == null) { answer = camelContext.getCamelContextExtension().getBootstrapFactoryFinder() .newInstance("lra-saga-service", CamelSagaService.class) @@ -2032,13 +2036,15 @@ public abstract class BaseMainSupport extends BaseService { return answer; } - private static Service resolveOtelService(CamelContext camelContext) throws Exception { + private static CamelTracingService resolveOtelService(CamelContext camelContext) throws Exception { // lookup in service registry first - // TODO: We need a Tracing SPI to be able to identify this (lookup in registry / service on camel context) - Service answer = camelContext.getRegistry().lookupByNameAndType("OpenTelemetryTracer", Service.class); + CamelTracingService answer = camelContext.getRegistry().findSingleByType(CamelTracingService.class); + if (answer == null) { + answer = camelContext.hasService(CamelTracingService.class); + } if (answer == null) { answer = camelContext.getCamelContextExtension().getBootstrapFactoryFinder() - .newInstance("opentelemetry-tracer", Service.class) + .newInstance("opentelemetry-tracer", CamelTracingService.class) .orElseThrow(() -> new IllegalArgumentException( "Cannot find OpenTelemetryTracer on classpath. Add camel-opentelemetry to classpath.")); }