From 7804e670d5fb4cb749745cde840767556035ac34 Mon Sep 17 00:00:00 2001 From: Adriano Machado <60320+ammachado@users.noreply.github.com> Date: Wed, 14 Aug 2024 17:10:50 -0400 Subject: [PATCH] Refactoring tracing interfaces to `camel-api` and `camel-support` This allows moving the span decorators closer to the components. --- .../MicrometerObservationTracer.java | 2 +- .../opentelemetry/OpenTelemetryTracer.java | 2 +- .../java/org/apache/camel/tracing/Tracer.java | 22 ++++-- .../decorators/AbstractHttpSpanDecorator.java | 1 + .../AbstractMessagingSpanDecorator.java | 5 +- .../tracing/decorators/CqlSpanDecorator.java | 1 + .../decorators/DirectSpanDecorator.java | 2 + .../decorators/DisruptorSpanDecorator.java | 2 + .../decorators/DisruptorvmSpanDecorator.java | 2 + .../ElasticsearchSpanDecorator.java | 1 + .../tracing/decorators/FileSpanDecorator.java | 1 + .../tracing/decorators/JdbcSpanDecorator.java | 1 + .../tracing/decorators/LogSpanDecorator.java | 2 + .../decorators/MongoDBSpanDecorator.java | 1 + .../tracing/decorators/SedaSpanDecorator.java | 2 + .../tracing/decorators/SqlSpanDecorator.java | 1 + .../decorators/TimerSpanDecorator.java | 1 + .../camel/tracing/ActiveSpanManagerTest.java | 19 ++--- .../AbstractHttpSpanDecoratorTest.java | 6 +- .../AbstractMessagingSpanDecoratorTest.java | 6 +- .../AzureServiceBusSpanDecoratorTest.java | 4 +- .../decorators/CqlSpanDecoratorTest.java | 6 +- .../ElasticsearchSpanDecoratorTest.java | 4 +- .../decorators/JdbcSpanDecoratorTest.java | 4 +- .../decorators/KafkaSpanDecoratorTest.java | 6 +- .../decorators/MongoDBSpanDecoratorTest.java | 5 +- .../decorators/RestSpanDecoratorTest.java | 4 +- .../decorators/SqlSpanDecoratorTest.java | 4 +- components/pom.xml | 2 +- .../org/apache/camel/ExchangePropertyKey.java | 2 + .../apache/camel/tracing/ExtractAdapter.java | 15 ++++ .../apache/camel/tracing/InjectAdapter.java | 3 + .../org/apache/camel/tracing/SpanAdapter.java | 74 ++++++++++++++++++- .../apache/camel/tracing/SpanDecorator.java | 27 +++---- .../org/apache/camel/tracing/SpanKind.java | 3 + .../java/org/apache/camel/tracing/Tag.java | 0 .../apache/camel/tracing/TagConstants.java | 0 core/camel-support/pom.xml | 6 ++ .../AbstractInternalSpanDecorator.java | 2 +- .../decorators/AbstractSpanDecorator.java | 22 +----- .../decorators/InMemorySpanAdapter.java | 36 ++++----- .../CamelHeadersExtractAdapter.java | 2 +- .../CamelHeadersInjectAdapter.java | 2 +- .../CamelMessagingHeadersExtractAdapter.java | 2 +- .../CamelMessagingHeadersInjectAdapter.java | 2 +- .../decorators/AbstractSpanDecoratorTest.java | 7 +- ...melMessagingHeadersExtractAdapterTest.java | 4 +- ...amelMessagingHeadersInjectAdapterTest.java | 4 +- 48 files changed, 216 insertions(+), 116 deletions(-) rename {components/camel-tracing => core/camel-api}/src/main/java/org/apache/camel/tracing/ExtractAdapter.java (74%) rename {components/camel-tracing => core/camel-api}/src/main/java/org/apache/camel/tracing/InjectAdapter.java (93%) rename {components/camel-tracing => core/camel-api}/src/main/java/org/apache/camel/tracing/SpanAdapter.java (59%) rename {components/camel-tracing => core/camel-api}/src/main/java/org/apache/camel/tracing/SpanDecorator.java (89%) rename {components/camel-tracing => core/camel-api}/src/main/java/org/apache/camel/tracing/SpanKind.java (95%) rename {components/camel-tracing => core/camel-api}/src/main/java/org/apache/camel/tracing/Tag.java (100%) rename {components/camel-tracing => core/camel-api}/src/main/java/org/apache/camel/tracing/TagConstants.java (100%) rename {components/camel-tracing/src/main/java/org/apache/camel => core/camel-support/src/main/java/org/apache/camel/support}/tracing/decorators/AbstractInternalSpanDecorator.java (95%) rename {components/camel-tracing/src/main/java/org/apache/camel => core/camel-support/src/main/java/org/apache/camel/support}/tracing/decorators/AbstractSpanDecorator.java (92%) rename components/camel-tracing/src/test/java/org/apache/camel/tracing/MockSpanAdapter.java => core/camel-support/src/main/java/org/apache/camel/support/tracing/decorators/InMemorySpanAdapter.java (78%) rename {components/camel-tracing/src/main/java/org/apache/camel/tracing/propagation => core/camel-support/src/main/java/org/apache/camel/support/tracing/propagators}/CamelHeadersExtractAdapter.java (96%) rename {components/camel-tracing/src/main/java/org/apache/camel/tracing/propagation => core/camel-support/src/main/java/org/apache/camel/support/tracing/propagators}/CamelHeadersInjectAdapter.java (96%) rename {components/camel-tracing/src/main/java/org/apache/camel/tracing/propagation => core/camel-support/src/main/java/org/apache/camel/support/tracing/propagators}/CamelMessagingHeadersExtractAdapter.java (97%) rename {components/camel-tracing/src/main/java/org/apache/camel/tracing/propagation => core/camel-support/src/main/java/org/apache/camel/support/tracing/propagators}/CamelMessagingHeadersInjectAdapter.java (97%) rename {components/camel-tracing/src/test/java/org/apache/camel => core/camel-support/src/test/java/org/apache/camel/support}/tracing/decorators/AbstractSpanDecoratorTest.java (95%) rename {components/camel-tracing/src/test/java/org/apache/camel/tracing/propagation => core/camel-support/src/test/java/org/apache/camel/support/tracing/propagators}/CamelMessagingHeadersExtractAdapterTest.java (95%) rename {components/camel-tracing/src/test/java/org/apache/camel/tracing/propagation => core/camel-support/src/test/java/org/apache/camel/support/tracing/propagators}/CamelMessagingHeadersInjectAdapterTest.java (93%) 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 06690fb2f65ff..5d2ee3eab1b37 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 @@ -29,12 +29,12 @@ import org.apache.camel.Message; import org.apache.camel.api.management.ManagedResource; import org.apache.camel.support.CamelContextHelper; +import org.apache.camel.support.tracing.decorators.AbstractInternalSpanDecorator; import org.apache.camel.tracing.ExtractAdapter; import org.apache.camel.tracing.InjectAdapter; import org.apache.camel.tracing.SpanAdapter; import org.apache.camel.tracing.SpanDecorator; import org.apache.camel.tracing.SpanKind; -import org.apache.camel.tracing.decorators.AbstractInternalSpanDecorator; @ManagedResource(description = "MicrometerObservationTracer") public class MicrometerObservationTracer extends org.apache.camel.tracing.Tracer { diff --git a/components/camel-opentelemetry/src/main/java/org/apache/camel/opentelemetry/OpenTelemetryTracer.java b/components/camel-opentelemetry/src/main/java/org/apache/camel/opentelemetry/OpenTelemetryTracer.java index 8df31fe332982..3d59ab7baa3bf 100644 --- a/components/camel-opentelemetry/src/main/java/org/apache/camel/opentelemetry/OpenTelemetryTracer.java +++ b/components/camel-opentelemetry/src/main/java/org/apache/camel/opentelemetry/OpenTelemetryTracer.java @@ -32,11 +32,11 @@ import org.apache.camel.spi.Configurer; import org.apache.camel.spi.annotations.JdkService; import org.apache.camel.support.CamelContextHelper; +import org.apache.camel.support.tracing.decorators.AbstractInternalSpanDecorator; import org.apache.camel.tracing.ExtractAdapter; import org.apache.camel.tracing.InjectAdapter; import org.apache.camel.tracing.SpanAdapter; import org.apache.camel.tracing.SpanDecorator; -import org.apache.camel.tracing.decorators.AbstractInternalSpanDecorator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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 f011dfce6689c..72d1b9d8c6e34 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 @@ -42,6 +42,7 @@ import org.apache.camel.support.RoutePolicySupport; import org.apache.camel.support.service.ServiceHelper; import org.apache.camel.support.service.ServiceSupport; +import org.apache.camel.support.tracing.decorators.AbstractSpanDecorator; import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.StringHelper; import org.slf4j.Logger; @@ -49,10 +50,22 @@ public abstract class Tracer extends ServiceSupport implements CamelTracingService, RoutePolicyFactory, StaticService { protected static final Map DECORATORS = new HashMap<>(); - static final AutoCloseable NOOP_CLOSEABLE = () -> { - }; private static final Logger LOG = LoggerFactory.getLogger(Tracer.class); + private static final SpanDecorator DEFAULT_SPAN_DECORATOR = new AbstractSpanDecorator() { + + @Override + public String getComponent() { + return null; + } + + @Override + public String getComponentClassName() { + return null; + } + + }; + static { ServiceLoader.load(SpanDecorator.class).forEach(d -> { SpanDecorator existing = DECORATORS.get(d.getComponent()); @@ -202,7 +215,7 @@ protected SpanDecorator getSpanDecorator(Endpoint endpoint) { .orElse(null); } if (sd == null) { - sd = SpanDecorator.DEFAULT; + sd = DEFAULT_SPAN_DECORATOR; } return sd; @@ -282,8 +295,7 @@ public void notify(CamelEvent event) throws Exception { } private boolean shouldExclude(SpanDecorator sd, Exchange exchange, Endpoint endpoint) { - return !sd.newSpan() - || isExcluded(exchange, endpoint); + return !sd.newSpan() || isExcluded(exchange, endpoint); } } diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractHttpSpanDecorator.java b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractHttpSpanDecorator.java index 9de3987a4b809..abcdf4e654f27 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractHttpSpanDecorator.java +++ b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractHttpSpanDecorator.java @@ -19,6 +19,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; import org.apache.camel.Message; +import org.apache.camel.support.tracing.decorators.AbstractSpanDecorator; import org.apache.camel.tracing.SpanAdapter; import org.apache.camel.tracing.TagConstants; diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractMessagingSpanDecorator.java b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractMessagingSpanDecorator.java index 9477ccc5e79d4..8d82ad2b212e0 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractMessagingSpanDecorator.java +++ b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractMessagingSpanDecorator.java @@ -20,13 +20,14 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; +import org.apache.camel.support.tracing.decorators.AbstractSpanDecorator; +import org.apache.camel.support.tracing.propagators.CamelMessagingHeadersExtractAdapter; +import org.apache.camel.support.tracing.propagators.CamelMessagingHeadersInjectAdapter; import org.apache.camel.tracing.ExtractAdapter; import org.apache.camel.tracing.InjectAdapter; import org.apache.camel.tracing.SpanAdapter; import org.apache.camel.tracing.SpanKind; import org.apache.camel.tracing.TagConstants; -import org.apache.camel.tracing.propagation.CamelMessagingHeadersExtractAdapter; -import org.apache.camel.tracing.propagation.CamelMessagingHeadersInjectAdapter; public abstract class AbstractMessagingSpanDecorator extends AbstractSpanDecorator { diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/CqlSpanDecorator.java b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/CqlSpanDecorator.java index 18e27aa8a6981..f434af08dffd6 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/CqlSpanDecorator.java +++ b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/CqlSpanDecorator.java @@ -21,6 +21,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; +import org.apache.camel.support.tracing.decorators.AbstractSpanDecorator; import org.apache.camel.tracing.SpanAdapter; import org.apache.camel.tracing.TagConstants; diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/DirectSpanDecorator.java b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/DirectSpanDecorator.java index 67ae5858896dd..a226c44b37db7 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/DirectSpanDecorator.java +++ b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/DirectSpanDecorator.java @@ -16,6 +16,8 @@ */ package org.apache.camel.tracing.decorators; +import org.apache.camel.support.tracing.decorators.AbstractInternalSpanDecorator; + public class DirectSpanDecorator extends AbstractInternalSpanDecorator { @Override diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/DisruptorSpanDecorator.java b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/DisruptorSpanDecorator.java index d254ec9eae751..92cd603e478a6 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/DisruptorSpanDecorator.java +++ b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/DisruptorSpanDecorator.java @@ -16,6 +16,8 @@ */ package org.apache.camel.tracing.decorators; +import org.apache.camel.support.tracing.decorators.AbstractInternalSpanDecorator; + public class DisruptorSpanDecorator extends AbstractInternalSpanDecorator { @Override diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/DisruptorvmSpanDecorator.java b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/DisruptorvmSpanDecorator.java index 967a38fc78483..adc2dfe7dbfa4 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/DisruptorvmSpanDecorator.java +++ b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/DisruptorvmSpanDecorator.java @@ -16,6 +16,8 @@ */ package org.apache.camel.tracing.decorators; +import org.apache.camel.support.tracing.decorators.AbstractInternalSpanDecorator; + public class DisruptorvmSpanDecorator extends AbstractInternalSpanDecorator { @Override diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/ElasticsearchSpanDecorator.java b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/ElasticsearchSpanDecorator.java index b0f7332591918..7163a2fb05ea8 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/ElasticsearchSpanDecorator.java +++ b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/ElasticsearchSpanDecorator.java @@ -20,6 +20,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; +import org.apache.camel.support.tracing.decorators.AbstractSpanDecorator; import org.apache.camel.tracing.SpanAdapter; import org.apache.camel.tracing.TagConstants; diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/FileSpanDecorator.java b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/FileSpanDecorator.java index ec8dadb98486c..fdd5b3196afef 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/FileSpanDecorator.java +++ b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/FileSpanDecorator.java @@ -18,6 +18,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; +import org.apache.camel.support.tracing.decorators.AbstractSpanDecorator; import org.apache.camel.tracing.SpanAdapter; import org.apache.camel.tracing.TagConstants; diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/JdbcSpanDecorator.java b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/JdbcSpanDecorator.java index 0c90fc0089e6a..953ea562981f6 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/JdbcSpanDecorator.java +++ b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/JdbcSpanDecorator.java @@ -18,6 +18,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; +import org.apache.camel.support.tracing.decorators.AbstractSpanDecorator; import org.apache.camel.tracing.SpanAdapter; import org.apache.camel.tracing.TagConstants; diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/LogSpanDecorator.java b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/LogSpanDecorator.java index 8117c26460717..9464d6f49ccc9 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/LogSpanDecorator.java +++ b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/LogSpanDecorator.java @@ -16,6 +16,8 @@ */ package org.apache.camel.tracing.decorators; +import org.apache.camel.support.tracing.decorators.AbstractSpanDecorator; + public class LogSpanDecorator extends AbstractSpanDecorator { @Override diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/MongoDBSpanDecorator.java b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/MongoDBSpanDecorator.java index 5e3b5fa5e526a..7a361a435fcc2 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/MongoDBSpanDecorator.java +++ b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/MongoDBSpanDecorator.java @@ -20,6 +20,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; +import org.apache.camel.support.tracing.decorators.AbstractSpanDecorator; import org.apache.camel.tracing.SpanAdapter; import org.apache.camel.tracing.TagConstants; diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/SedaSpanDecorator.java b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/SedaSpanDecorator.java index b8c0924e69433..6011730f6857e 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/SedaSpanDecorator.java +++ b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/SedaSpanDecorator.java @@ -16,6 +16,8 @@ */ package org.apache.camel.tracing.decorators; +import org.apache.camel.support.tracing.decorators.AbstractInternalSpanDecorator; + public class SedaSpanDecorator extends AbstractInternalSpanDecorator { @Override diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/SqlSpanDecorator.java b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/SqlSpanDecorator.java index 9935c959e8c11..d9bdd1fbc3c5d 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/SqlSpanDecorator.java +++ b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/SqlSpanDecorator.java @@ -18,6 +18,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; +import org.apache.camel.support.tracing.decorators.AbstractSpanDecorator; import org.apache.camel.tracing.SpanAdapter; import org.apache.camel.tracing.TagConstants; diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/TimerSpanDecorator.java b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/TimerSpanDecorator.java index 9c3c8fc137210..d37f0978ac6c9 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/TimerSpanDecorator.java +++ b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/TimerSpanDecorator.java @@ -18,6 +18,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; +import org.apache.camel.support.tracing.decorators.AbstractSpanDecorator; public class TimerSpanDecorator extends AbstractSpanDecorator { diff --git a/components/camel-tracing/src/test/java/org/apache/camel/tracing/ActiveSpanManagerTest.java b/components/camel-tracing/src/test/java/org/apache/camel/tracing/ActiveSpanManagerTest.java index b19798d812a6d..48cfd91400cb3 100644 --- a/components/camel-tracing/src/test/java/org/apache/camel/tracing/ActiveSpanManagerTest.java +++ b/components/camel-tracing/src/test/java/org/apache/camel/tracing/ActiveSpanManagerTest.java @@ -17,6 +17,7 @@ package org.apache.camel.tracing; import org.apache.camel.Exchange; +import org.apache.camel.support.tracing.decorators.InMemorySpanAdapter; import org.apache.camel.test.junit5.ExchangeTestSupport; import org.junit.jupiter.api.Test; import org.slf4j.MDC; @@ -40,7 +41,7 @@ void testNoSpan() { @Test void testCurrentSpan() { Exchange exchange = createExchange(); - MockSpanAdapter span = MockSpanAdapter.buildSpan("test"); + InMemorySpanAdapter span = InMemorySpanAdapter.buildSpan("test"); ActiveSpanManager.activate(exchange, span); assertTrue(span.isCurrent()); assertEquals(span, ActiveSpanManager.getSpan(exchange)); @@ -53,7 +54,7 @@ void testCurrentSpan() { @Test void testSEndScope() { Exchange exchange = createExchange(); - MockSpanAdapter span = MockSpanAdapter.buildSpan("test"); + InMemorySpanAdapter span = InMemorySpanAdapter.buildSpan("test"); ActiveSpanManager.activate(exchange, span); assertTrue(span.isCurrent()); @@ -67,9 +68,9 @@ void testSEndScope() { @Test void testCreateChild() { Exchange exchange = createExchange(); - SpanAdapter parent = MockSpanAdapter.buildSpan("parent"); + SpanAdapter parent = InMemorySpanAdapter.buildSpan("parent"); ActiveSpanManager.activate(exchange, parent); - SpanAdapter child = MockSpanAdapter.buildSpan("child"); + SpanAdapter child = InMemorySpanAdapter.buildSpan("child"); ActiveSpanManager.activate(exchange, child); assertEquals(child, ActiveSpanManager.getSpan(exchange)); @@ -80,7 +81,7 @@ void testCreateChild() { @Test void testIsolatedConcurrentExchanges() { Exchange exchange = createExchange(); - SpanAdapter parent = MockSpanAdapter.buildSpan("parent"); + SpanAdapter parent = InMemorySpanAdapter.buildSpan("parent"); ActiveSpanManager.activate(exchange, parent); Exchange path1 = exchange.copy(); @@ -90,10 +91,10 @@ void testIsolatedConcurrentExchanges() { assertEquals(parent, ActiveSpanManager.getSpan(path1)); assertEquals(parent, ActiveSpanManager.getSpan(path2)); - SpanAdapter child1 = MockSpanAdapter.buildSpan("child1"); + SpanAdapter child1 = InMemorySpanAdapter.buildSpan("child1"); ActiveSpanManager.activate(path1, child1); - SpanAdapter child2 = MockSpanAdapter.buildSpan("child2"); + SpanAdapter child2 = InMemorySpanAdapter.buildSpan("child2"); ActiveSpanManager.activate(path2, child2); ActiveSpanManager.deactivate(path2); @@ -108,7 +109,7 @@ void testMDCSupport() { Exchange exchange = createExchange(); exchange.getContext().setUseMDCLogging(true); - MockSpanAdapter parent = MockSpanAdapter.buildSpan("parent"); + InMemorySpanAdapter parent = InMemorySpanAdapter.buildSpan("parent"); parent.setTraceId("0"); parent.setSpanId("1"); @@ -121,7 +122,7 @@ void testMDCSupport() { assertEquals("1", MDC.get(ActiveSpanManager.MDC_SPAN_ID)); // 1 and 2 after activating child1 - MockSpanAdapter child1 = MockSpanAdapter.buildSpan("child1"); + InMemorySpanAdapter child1 = InMemorySpanAdapter.buildSpan("child1"); child1.setTraceId("1"); child1.setSpanId("2"); ActiveSpanManager.activate(exchange, child1); diff --git a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/AbstractHttpSpanDecoratorTest.java b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/AbstractHttpSpanDecoratorTest.java index fc04663312fa7..f78748522294f 100644 --- a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/AbstractHttpSpanDecoratorTest.java +++ b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/AbstractHttpSpanDecoratorTest.java @@ -19,7 +19,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; import org.apache.camel.Message; -import org.apache.camel.tracing.MockSpanAdapter; +import org.apache.camel.support.tracing.decorators.InMemorySpanAdapter; import org.apache.camel.tracing.SpanDecorator; import org.apache.camel.tracing.TagConstants; import org.junit.jupiter.api.Test; @@ -155,7 +155,7 @@ public String getComponentClassName() { } }; - MockSpanAdapter span = new MockSpanAdapter(); + InMemorySpanAdapter span = new InMemorySpanAdapter(); decorator.pre(span, exchange, endpoint); @@ -282,7 +282,7 @@ public String getComponentClassName() { } }; - MockSpanAdapter span = new MockSpanAdapter(); + InMemorySpanAdapter span = new InMemorySpanAdapter(); decorator.post(span, exchange, null); diff --git a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/AbstractMessagingSpanDecoratorTest.java b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/AbstractMessagingSpanDecoratorTest.java index b5a3a9374edac..22c1dc1326e32 100644 --- a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/AbstractMessagingSpanDecoratorTest.java +++ b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/AbstractMessagingSpanDecoratorTest.java @@ -18,7 +18,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; -import org.apache.camel.tracing.MockSpanAdapter; +import org.apache.camel.support.tracing.decorators.InMemorySpanAdapter; import org.apache.camel.tracing.SpanDecorator; import org.apache.camel.tracing.TagConstants; import org.junit.jupiter.api.Test; @@ -67,7 +67,7 @@ public String getComponentClassName() { } }; - MockSpanAdapter span = new MockSpanAdapter(); + InMemorySpanAdapter span = new InMemorySpanAdapter(); decorator.pre(span, null, endpoint); @@ -99,7 +99,7 @@ public String getMessageId(Exchange exchange) { } }; - MockSpanAdapter span = new MockSpanAdapter(); + InMemorySpanAdapter span = new InMemorySpanAdapter(); decorator.pre(span, exchange, endpoint); diff --git a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/AzureServiceBusSpanDecoratorTest.java b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/AzureServiceBusSpanDecoratorTest.java index 9594bd2cb4793..c4be2a983b16a 100644 --- a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/AzureServiceBusSpanDecoratorTest.java +++ b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/AzureServiceBusSpanDecoratorTest.java @@ -22,7 +22,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; import org.apache.camel.Message; -import org.apache.camel.tracing.MockSpanAdapter; +import org.apache.camel.support.tracing.decorators.InMemorySpanAdapter; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -79,7 +79,7 @@ public void testPre() { AbstractMessagingSpanDecorator decorator = new AzureServiceBusSpanDecorator(); - MockSpanAdapter span = new MockSpanAdapter(); + InMemorySpanAdapter span = new InMemorySpanAdapter(); decorator.pre(span, exchange, endpoint); diff --git a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/CqlSpanDecoratorTest.java b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/CqlSpanDecoratorTest.java index 0dcf9ad3c832a..d7031056b153b 100644 --- a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/CqlSpanDecoratorTest.java +++ b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/CqlSpanDecoratorTest.java @@ -19,7 +19,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; import org.apache.camel.Message; -import org.apache.camel.tracing.MockSpanAdapter; +import org.apache.camel.support.tracing.decorators.InMemorySpanAdapter; import org.apache.camel.tracing.SpanDecorator; import org.apache.camel.tracing.TagConstants; import org.junit.jupiter.api.Test; @@ -45,7 +45,7 @@ public void testPreCqlFromUri() { SpanDecorator decorator = new CqlSpanDecorator(); - MockSpanAdapter span = new MockSpanAdapter(); + InMemorySpanAdapter span = new InMemorySpanAdapter(); decorator.pre(span, exchange, endpoint); @@ -68,7 +68,7 @@ public void testPreCqlFromHeader() { SpanDecorator decorator = new CqlSpanDecorator(); - MockSpanAdapter span = new MockSpanAdapter(); + InMemorySpanAdapter span = new InMemorySpanAdapter(); decorator.pre(span, exchange, endpoint); diff --git a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/ElasticsearchSpanDecoratorTest.java b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/ElasticsearchSpanDecoratorTest.java index acd81b46bbbdc..9513db74226e2 100644 --- a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/ElasticsearchSpanDecoratorTest.java +++ b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/ElasticsearchSpanDecoratorTest.java @@ -19,7 +19,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; import org.apache.camel.Message; -import org.apache.camel.tracing.MockSpanAdapter; +import org.apache.camel.support.tracing.decorators.InMemorySpanAdapter; import org.apache.camel.tracing.SpanDecorator; import org.apache.camel.tracing.TagConstants; import org.junit.jupiter.api.Test; @@ -58,7 +58,7 @@ public void testPre() { SpanDecorator decorator = new ElasticsearchSpanDecorator(); - MockSpanAdapter span = new MockSpanAdapter(); + InMemorySpanAdapter span = new InMemorySpanAdapter(); decorator.pre(span, exchange, endpoint); diff --git a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/JdbcSpanDecoratorTest.java b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/JdbcSpanDecoratorTest.java index ac24d49ac9899..69bc9c70e404b 100644 --- a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/JdbcSpanDecoratorTest.java +++ b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/JdbcSpanDecoratorTest.java @@ -19,7 +19,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; import org.apache.camel.Message; -import org.apache.camel.tracing.MockSpanAdapter; +import org.apache.camel.support.tracing.decorators.InMemorySpanAdapter; import org.apache.camel.tracing.SpanDecorator; import org.apache.camel.tracing.TagConstants; import org.junit.jupiter.api.Test; @@ -43,7 +43,7 @@ public void testPre() { SpanDecorator decorator = new JdbcSpanDecorator(); - MockSpanAdapter span = new MockSpanAdapter(); + InMemorySpanAdapter span = new InMemorySpanAdapter(); decorator.pre(span, exchange, endpoint); diff --git a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/KafkaSpanDecoratorTest.java b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/KafkaSpanDecoratorTest.java index e3091143dd54a..53ce8f77886ec 100644 --- a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/KafkaSpanDecoratorTest.java +++ b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/KafkaSpanDecoratorTest.java @@ -19,7 +19,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; import org.apache.camel.Message; -import org.apache.camel.tracing.MockSpanAdapter; +import org.apache.camel.support.tracing.decorators.InMemorySpanAdapter; import org.apache.camel.tracing.SpanDecorator; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -76,7 +76,7 @@ public void testPreOffsetAndPartitionAsStringHeader() { SpanDecorator decorator = new KafkaSpanDecorator(); - MockSpanAdapter span = new MockSpanAdapter(); + InMemorySpanAdapter span = new InMemorySpanAdapter(); decorator.pre(span, exchange, endpoint); @@ -102,7 +102,7 @@ public void testPrePartitionAsIntegerHeaderAndOffsetAsLongHeader() { SpanDecorator decorator = new KafkaSpanDecorator(); - MockSpanAdapter span = new MockSpanAdapter(); + InMemorySpanAdapter span = new InMemorySpanAdapter(); decorator.pre(span, exchange, endpoint); diff --git a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/MongoDBSpanDecoratorTest.java b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/MongoDBSpanDecoratorTest.java index a6982d6e33545..a9dc2b5f6de51 100644 --- a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/MongoDBSpanDecoratorTest.java +++ b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/MongoDBSpanDecoratorTest.java @@ -19,7 +19,8 @@ import java.util.Map; import org.apache.camel.Endpoint; -import org.apache.camel.tracing.MockSpanAdapter; +import org.apache.camel.support.tracing.decorators.AbstractSpanDecorator; +import org.apache.camel.support.tracing.decorators.InMemorySpanAdapter; import org.apache.camel.tracing.SpanDecorator; import org.apache.camel.tracing.TagConstants; import org.junit.jupiter.api.Test; @@ -60,7 +61,7 @@ public void testPre() { SpanDecorator decorator = new MongoDBSpanDecorator(); - MockSpanAdapter span = new MockSpanAdapter(); + InMemorySpanAdapter span = new InMemorySpanAdapter(); decorator.pre(span, null, endpoint); diff --git a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/RestSpanDecoratorTest.java b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/RestSpanDecoratorTest.java index 54ba0f2961eab..cbfdf6a6d02da 100644 --- a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/RestSpanDecoratorTest.java +++ b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/RestSpanDecoratorTest.java @@ -21,7 +21,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; import org.apache.camel.Message; -import org.apache.camel.tracing.MockSpanAdapter; +import org.apache.camel.support.tracing.decorators.InMemorySpanAdapter; import org.apache.camel.tracing.SpanDecorator; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -84,7 +84,7 @@ protected void testParameter(String paramName, Object paramValue) { SpanDecorator decorator = new RestSpanDecorator(); - MockSpanAdapter span = new MockSpanAdapter(); + InMemorySpanAdapter span = new InMemorySpanAdapter(); decorator.pre(span, exchange, endpoint); diff --git a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/SqlSpanDecoratorTest.java b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/SqlSpanDecoratorTest.java index b9f0bf5252c16..4230ebd6e81ac 100644 --- a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/SqlSpanDecoratorTest.java +++ b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/SqlSpanDecoratorTest.java @@ -19,7 +19,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; import org.apache.camel.Message; -import org.apache.camel.tracing.MockSpanAdapter; +import org.apache.camel.support.tracing.decorators.InMemorySpanAdapter; import org.apache.camel.tracing.SpanDecorator; import org.apache.camel.tracing.TagConstants; import org.junit.jupiter.api.Test; @@ -43,7 +43,7 @@ public void testPre() { SpanDecorator decorator = new SqlSpanDecorator(); - MockSpanAdapter span = new MockSpanAdapter(); + InMemorySpanAdapter span = new InMemorySpanAdapter(); decorator.pre(span, exchange, endpoint); diff --git a/components/pom.xml b/components/pom.xml index 4e3f0a949a63c..ab7896bd0bfd7 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -275,7 +275,7 @@ camel-snakeyaml camel-snmp camel-soap - camel-solr + camel-solr camel-splunk camel-splunk-hec camel-spring-batch diff --git a/core/camel-api/src/main/java/org/apache/camel/ExchangePropertyKey.java b/core/camel-api/src/main/java/org/apache/camel/ExchangePropertyKey.java index da612e93348e1..a70dd526f6594 100644 --- a/core/camel-api/src/main/java/org/apache/camel/ExchangePropertyKey.java +++ b/core/camel-api/src/main/java/org/apache/camel/ExchangePropertyKey.java @@ -88,6 +88,8 @@ public String getName() { public static ExchangePropertyKey asExchangePropertyKey(String name) { switch (name) { + case Exchange.ACTIVE_SPAN: + return ACTIVE_SPAN; case Exchange.AGGREGATED_COMPLETED_BY: return AGGREGATED_COMPLETED_BY; case Exchange.AGGREGATED_CORRELATION_KEY: diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/ExtractAdapter.java b/core/camel-api/src/main/java/org/apache/camel/tracing/ExtractAdapter.java similarity index 74% rename from components/camel-tracing/src/main/java/org/apache/camel/tracing/ExtractAdapter.java rename to core/camel-api/src/main/java/org/apache/camel/tracing/ExtractAdapter.java index 680a816062fdd..cd916680ee6b0 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/ExtractAdapter.java +++ b/core/camel-api/src/main/java/org/apache/camel/tracing/ExtractAdapter.java @@ -20,10 +20,25 @@ import java.util.Map; import java.util.Set; +/** + * An adapter to extract tracing attributes from a tracing span. + */ public interface ExtractAdapter { + + /** + * Extract an iterator of attributes from the current tracing span. + */ Iterator> iterator(); + /** + * Extract an attribute from the current tracing span. + * + * @param key the attribute key + */ Object get(String key); + /** + * Get the attribute keys for the current tracing span. + */ Set keys(); } diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/InjectAdapter.java b/core/camel-api/src/main/java/org/apache/camel/tracing/InjectAdapter.java similarity index 93% rename from components/camel-tracing/src/main/java/org/apache/camel/tracing/InjectAdapter.java rename to core/camel-api/src/main/java/org/apache/camel/tracing/InjectAdapter.java index c7f0069f0293f..70779a49f9ff3 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/InjectAdapter.java +++ b/core/camel-api/src/main/java/org/apache/camel/tracing/InjectAdapter.java @@ -16,6 +16,9 @@ */ package org.apache.camel.tracing; +/** + * An adapter to inject tracing attributes into a tracing span. + */ public interface InjectAdapter { /** diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/SpanAdapter.java b/core/camel-api/src/main/java/org/apache/camel/tracing/SpanAdapter.java similarity index 59% rename from components/camel-tracing/src/main/java/org/apache/camel/tracing/SpanAdapter.java rename to core/camel-api/src/main/java/org/apache/camel/tracing/SpanAdapter.java index e3239ce912685..9aebf74eaa038 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/SpanAdapter.java +++ b/core/camel-api/src/main/java/org/apache/camel/tracing/SpanAdapter.java @@ -18,10 +18,23 @@ import java.util.Map; +/** + * An adapter to allow Camel to interact with different tracing technologies. + */ public interface SpanAdapter { + /** + * Sets the operation name of the span. + * + * @param component the component name. + */ void setComponent(String component); + /** + * Sets this span as an error span. + * + * @param error true if this span is an error span. + */ void setError(boolean error); /** @@ -40,10 +53,28 @@ default void setTag(Tag key, Number value) { setTag(key.getAttribute(), value); } + /** + * Sets a tag on the span. + * + * @param key the tag key + * @param value the tag value + */ void setTag(String key, String value); + /** + * Sets a tag on the span. + * + * @param key the tag key + * @param value the tag value + */ void setTag(String key, Number value); + /** + * Sets a tag on the span. + * + * @param key the tag key + * @param value the tag value + */ void setTag(String key, Boolean value); /** @@ -62,25 +93,66 @@ default void setLowCardinalityTag(Tag key, Number value) { setLowCardinalityTag(key.getAttribute(), value); } + /** + * @deprecated use {@link #setLowCardinalityTag(String, Boolean)} instead. + */ + @Deprecated + default void setLowCardinalityTag(Tag key, Boolean value) { + setLowCardinalityTag(key.getAttribute(), value); + } + + /** + * Sets a low cardinality tag on the span. + * + * @param key the tag key + * @param value the tag value + */ default void setLowCardinalityTag(String key, String value) { setTag(key, value); } + /** + * Sets a low cardinality tag on the span. + * + * @param key the tag key + * @param value the tag value + */ default void setLowCardinalityTag(String key, Number value) { setTag(key, value); } + /** + * Sets a low cardinality tag on the span. + * + * @param key the tag key + * @param value the tag value + */ default void setLowCardinalityTag(String key, Boolean value) { setTag(key, value); } + /** + * Add log messages to a span. + * + * @param log the log messages + */ void log(Map log); + /** + * Get the current trace id. + */ String traceId(); + /** + * Get the current span id. + */ String spanId(); + /** + * Makes the current span the active span. + */ default AutoCloseable makeCurrent() { - return Tracer.NOOP_CLOSEABLE; + return () -> { + }; } } diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/SpanDecorator.java b/core/camel-api/src/main/java/org/apache/camel/tracing/SpanDecorator.java similarity index 89% rename from components/camel-tracing/src/main/java/org/apache/camel/tracing/SpanDecorator.java rename to core/camel-api/src/main/java/org/apache/camel/tracing/SpanDecorator.java index 39cfe2bf0450a..08dad06f65cdc 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/SpanDecorator.java +++ b/core/camel-api/src/main/java/org/apache/camel/tracing/SpanDecorator.java @@ -20,7 +20,6 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; -import org.apache.camel.tracing.decorators.AbstractSpanDecorator; /** * This interface represents a decorator specific to the component/endpoint being instrumented. @@ -30,27 +29,15 @@ public interface SpanDecorator { /* Prefix for camel component tag */ String CAMEL_COMPONENT = "camel-"; - SpanDecorator DEFAULT = new AbstractSpanDecorator() { - - @Override - public String getComponent() { - return null; - } - - @Override - public String getComponentClassName() { - return null; - } - - }; - /** * This method indicates whether the component associated with the SpanDecorator should result in a new span being * created. * * @return Whether a new span should be created */ - boolean newSpan(); + default boolean newSpan() { + return true; + } /** * The camel component name associated with the decorator. @@ -100,14 +87,18 @@ public String getComponentClassName() { * * @return The kind */ - SpanKind getInitiatorSpanKind(); + default SpanKind getInitiatorSpanKind() { + return SpanKind.SPAN_KIND_CLIENT; + } /** * This method returns the 'span.kind' value for use when the component is receiving a communication. * * @return The kind */ - SpanKind getReceiverSpanKind(); + default SpanKind getReceiverSpanKind() { + return SpanKind.SPAN_KIND_SERVER; + } /** * This method returns the map to be used for header extraction when the component is receiving a communication. diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/SpanKind.java b/core/camel-api/src/main/java/org/apache/camel/tracing/SpanKind.java similarity index 95% rename from components/camel-tracing/src/main/java/org/apache/camel/tracing/SpanKind.java rename to core/camel-api/src/main/java/org/apache/camel/tracing/SpanKind.java index f2afa79518815..0b5bd8fc03287 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/SpanKind.java +++ b/core/camel-api/src/main/java/org/apache/camel/tracing/SpanKind.java @@ -16,6 +16,9 @@ */ package org.apache.camel.tracing; +/** + * Represents the kind of tracing span. + */ public enum SpanKind { SPAN_KIND_CLIENT, SPAN_KIND_SERVER, diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/Tag.java b/core/camel-api/src/main/java/org/apache/camel/tracing/Tag.java similarity index 100% rename from components/camel-tracing/src/main/java/org/apache/camel/tracing/Tag.java rename to core/camel-api/src/main/java/org/apache/camel/tracing/Tag.java diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/TagConstants.java b/core/camel-api/src/main/java/org/apache/camel/tracing/TagConstants.java similarity index 100% rename from components/camel-tracing/src/main/java/org/apache/camel/tracing/TagConstants.java rename to core/camel-api/src/main/java/org/apache/camel/tracing/TagConstants.java diff --git a/core/camel-support/pom.xml b/core/camel-support/pom.xml index 69c348a78aea0..62201d9b96d5b 100644 --- a/core/camel-support/pom.xml +++ b/core/camel-support/pom.xml @@ -71,6 +71,12 @@ junit-jupiter test + + org.mockito + mockito-core + ${mockito-version} + test + diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractInternalSpanDecorator.java b/core/camel-support/src/main/java/org/apache/camel/support/tracing/decorators/AbstractInternalSpanDecorator.java similarity index 95% rename from components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractInternalSpanDecorator.java rename to core/camel-support/src/main/java/org/apache/camel/support/tracing/decorators/AbstractInternalSpanDecorator.java index a0c08a91b523a..e0f92a1860631 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractInternalSpanDecorator.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/tracing/decorators/AbstractInternalSpanDecorator.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.tracing.decorators; +package org.apache.camel.support.tracing.decorators; import org.apache.camel.Endpoint; import org.apache.camel.Exchange; diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractSpanDecorator.java b/core/camel-support/src/main/java/org/apache/camel/support/tracing/decorators/AbstractSpanDecorator.java similarity index 92% rename from components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractSpanDecorator.java rename to core/camel-support/src/main/java/org/apache/camel/support/tracing/decorators/AbstractSpanDecorator.java index 9cd7def4da6b6..6d1579b278458 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractSpanDecorator.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/tracing/decorators/AbstractSpanDecorator.java @@ -14,21 +14,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.tracing.decorators; +package org.apache.camel.support.tracing.decorators; import java.util.*; import org.apache.camel.Endpoint; import org.apache.camel.Exchange; import org.apache.camel.spi.EndpointServiceLocation; +import org.apache.camel.support.tracing.propagators.CamelHeadersExtractAdapter; +import org.apache.camel.support.tracing.propagators.CamelHeadersInjectAdapter; import org.apache.camel.tracing.ExtractAdapter; import org.apache.camel.tracing.InjectAdapter; import org.apache.camel.tracing.SpanAdapter; import org.apache.camel.tracing.SpanDecorator; -import org.apache.camel.tracing.SpanKind; import org.apache.camel.tracing.TagConstants; -import org.apache.camel.tracing.propagation.CamelHeadersExtractAdapter; -import org.apache.camel.tracing.propagation.CamelHeadersInjectAdapter; import org.apache.camel.util.StringHelper; import org.apache.camel.util.URISupport; @@ -83,11 +82,6 @@ private static String getSchemeName(Endpoint endpoint) { return StringHelper.before(endpoint.getEndpointUri(), ":"); } - @Override - public boolean newSpan() { - return true; - } - @Override public String getOperationName(Exchange exchange, Endpoint endpoint) { // OpenTracing aims to use low cardinality operation names. Ideally, a @@ -155,16 +149,6 @@ public void post(SpanAdapter span, Exchange exchange, Endpoint endpoint) { } } - @Override - public SpanKind getInitiatorSpanKind() { - return SpanKind.SPAN_KIND_CLIENT; - } - - @Override - public SpanKind getReceiverSpanKind() { - return SpanKind.SPAN_KIND_SERVER; - } - @Override public ExtractAdapter getExtractAdapter(final Map map, boolean encoding) { // no encoding supported per default diff --git a/components/camel-tracing/src/test/java/org/apache/camel/tracing/MockSpanAdapter.java b/core/camel-support/src/main/java/org/apache/camel/support/tracing/decorators/InMemorySpanAdapter.java similarity index 78% rename from components/camel-tracing/src/test/java/org/apache/camel/tracing/MockSpanAdapter.java rename to core/camel-support/src/main/java/org/apache/camel/support/tracing/decorators/InMemorySpanAdapter.java index 383e7b91b4751..275de71366a0a 100644 --- a/components/camel-tracing/src/test/java/org/apache/camel/tracing/MockSpanAdapter.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/tracing/decorators/InMemorySpanAdapter.java @@ -14,14 +14,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.tracing; +package org.apache.camel.support.tracing.decorators; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -public class MockSpanAdapter implements SpanAdapter { +import org.apache.camel.tracing.SpanAdapter; +import org.apache.camel.tracing.Tag; +import org.apache.camel.tracing.TagConstants; + +/** + * In memory implementation of {@link SpanAdapter} used for testing and mocking. + */ +public class InMemorySpanAdapter implements SpanAdapter { private final List logEntries = new ArrayList<>(); private final Map tags = new HashMap<>(); @@ -29,12 +36,12 @@ public class MockSpanAdapter implements SpanAdapter { private String spanId; private boolean isCurrent; - static long nowMicros() { + public static long nowMicros() { return System.currentTimeMillis() * 1000; } - static MockSpanAdapter buildSpan(String operation) { - return new MockSpanAdapter().setOperation(operation); + public static InMemorySpanAdapter buildSpan(String operation) { + return new InMemorySpanAdapter().setOperation(operation); } public Map tags() { @@ -102,25 +109,10 @@ public boolean isCurrent() { return this.isCurrent; } - public static final class LogEntry { - private final long timestampMicros; - private final Map fields; - - public LogEntry(long timestampMicros, Map fields) { - this.timestampMicros = timestampMicros; - this.fields = fields; - } - - public long timestampMicros() { - return timestampMicros; - } - - public Map fields() { - return fields; - } + public record LogEntry(long timestampMicros, Map fields) { } - public MockSpanAdapter setOperation(String operation) { + public InMemorySpanAdapter setOperation(String operation) { return this; } diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/propagation/CamelHeadersExtractAdapter.java b/core/camel-support/src/main/java/org/apache/camel/support/tracing/propagators/CamelHeadersExtractAdapter.java similarity index 96% rename from components/camel-tracing/src/main/java/org/apache/camel/tracing/propagation/CamelHeadersExtractAdapter.java rename to core/camel-support/src/main/java/org/apache/camel/support/tracing/propagators/CamelHeadersExtractAdapter.java index 2e9007b02790b..c375b94d56860 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/propagation/CamelHeadersExtractAdapter.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/tracing/propagators/CamelHeadersExtractAdapter.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.tracing.propagation; +package org.apache.camel.support.tracing.propagators; import java.util.Iterator; import java.util.Map; diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/propagation/CamelHeadersInjectAdapter.java b/core/camel-support/src/main/java/org/apache/camel/support/tracing/propagators/CamelHeadersInjectAdapter.java similarity index 96% rename from components/camel-tracing/src/main/java/org/apache/camel/tracing/propagation/CamelHeadersInjectAdapter.java rename to core/camel-support/src/main/java/org/apache/camel/support/tracing/propagators/CamelHeadersInjectAdapter.java index 25ef941780d74..3be84c3eb8d1e 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/propagation/CamelHeadersInjectAdapter.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/tracing/propagators/CamelHeadersInjectAdapter.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.tracing.propagation; +package org.apache.camel.support.tracing.propagators; import java.util.Map; diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/propagation/CamelMessagingHeadersExtractAdapter.java b/core/camel-support/src/main/java/org/apache/camel/support/tracing/propagators/CamelMessagingHeadersExtractAdapter.java similarity index 97% rename from components/camel-tracing/src/main/java/org/apache/camel/tracing/propagation/CamelMessagingHeadersExtractAdapter.java rename to core/camel-support/src/main/java/org/apache/camel/support/tracing/propagators/CamelMessagingHeadersExtractAdapter.java index b80c5164c388c..e3d90781679d8 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/propagation/CamelMessagingHeadersExtractAdapter.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/tracing/propagators/CamelMessagingHeadersExtractAdapter.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.tracing.propagation; +package org.apache.camel.support.tracing.propagators; import java.nio.charset.StandardCharsets; import java.util.Iterator; diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/propagation/CamelMessagingHeadersInjectAdapter.java b/core/camel-support/src/main/java/org/apache/camel/support/tracing/propagators/CamelMessagingHeadersInjectAdapter.java similarity index 97% rename from components/camel-tracing/src/main/java/org/apache/camel/tracing/propagation/CamelMessagingHeadersInjectAdapter.java rename to core/camel-support/src/main/java/org/apache/camel/support/tracing/propagators/CamelMessagingHeadersInjectAdapter.java index 88fbb4cec786b..7263ab3ad1f6f 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/propagation/CamelMessagingHeadersInjectAdapter.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/tracing/propagators/CamelMessagingHeadersInjectAdapter.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.tracing.propagation; +package org.apache.camel.support.tracing.propagators; import java.util.Map; diff --git a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/AbstractSpanDecoratorTest.java b/core/camel-support/src/test/java/org/apache/camel/support/tracing/decorators/AbstractSpanDecoratorTest.java similarity index 95% rename from components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/AbstractSpanDecoratorTest.java rename to core/camel-support/src/test/java/org/apache/camel/support/tracing/decorators/AbstractSpanDecoratorTest.java index d017a210cb62c..200bc4f23fffc 100644 --- a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/AbstractSpanDecoratorTest.java +++ b/core/camel-support/src/test/java/org/apache/camel/support/tracing/decorators/AbstractSpanDecoratorTest.java @@ -14,11 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.tracing.decorators; +package org.apache.camel.support.tracing.decorators; import org.apache.camel.Endpoint; import org.apache.camel.Exchange; -import org.apache.camel.tracing.MockSpanAdapter; import org.apache.camel.tracing.SpanDecorator; import org.apache.camel.tracing.TagConstants; import org.junit.jupiter.api.Test; @@ -72,7 +71,7 @@ public String getComponentClassName() { } }; - MockSpanAdapter span = new MockSpanAdapter(); + InMemorySpanAdapter span = new InMemorySpanAdapter(); decorator.pre(span, null, endpoint); @@ -103,7 +102,7 @@ public String getComponentClassName() { } }; - MockSpanAdapter span = new MockSpanAdapter(); + InMemorySpanAdapter span = new InMemorySpanAdapter(); decorator.post(span, exchange, null); diff --git a/components/camel-tracing/src/test/java/org/apache/camel/tracing/propagation/CamelMessagingHeadersExtractAdapterTest.java b/core/camel-support/src/test/java/org/apache/camel/support/tracing/propagators/CamelMessagingHeadersExtractAdapterTest.java similarity index 95% rename from components/camel-tracing/src/test/java/org/apache/camel/tracing/propagation/CamelMessagingHeadersExtractAdapterTest.java rename to core/camel-support/src/test/java/org/apache/camel/support/tracing/propagators/CamelMessagingHeadersExtractAdapterTest.java index 8cc6ba92ac6ab..c307d6f1f1b15 100644 --- a/components/camel-tracing/src/test/java/org/apache/camel/tracing/propagation/CamelMessagingHeadersExtractAdapterTest.java +++ b/core/camel-support/src/test/java/org/apache/camel/support/tracing/propagators/CamelMessagingHeadersExtractAdapterTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.tracing.propagation; +package org.apache.camel.support.tracing.propagators; import java.util.HashMap; import java.util.Iterator; @@ -23,7 +23,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.apache.camel.tracing.propagation.CamelMessagingHeadersInjectAdapter.JMS_DASH; +import static org.apache.camel.support.tracing.propagators.CamelMessagingHeadersInjectAdapter.JMS_DASH; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; diff --git a/components/camel-tracing/src/test/java/org/apache/camel/tracing/propagation/CamelMessagingHeadersInjectAdapterTest.java b/core/camel-support/src/test/java/org/apache/camel/support/tracing/propagators/CamelMessagingHeadersInjectAdapterTest.java similarity index 93% rename from components/camel-tracing/src/test/java/org/apache/camel/tracing/propagation/CamelMessagingHeadersInjectAdapterTest.java rename to core/camel-support/src/test/java/org/apache/camel/support/tracing/propagators/CamelMessagingHeadersInjectAdapterTest.java index 48d02a667328c..67cfff7622236 100644 --- a/components/camel-tracing/src/test/java/org/apache/camel/tracing/propagation/CamelMessagingHeadersInjectAdapterTest.java +++ b/core/camel-support/src/test/java/org/apache/camel/support/tracing/propagators/CamelMessagingHeadersInjectAdapterTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.tracing.propagation; +package org.apache.camel.support.tracing.propagators; import java.util.HashMap; import java.util.Map; @@ -22,7 +22,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.apache.camel.tracing.propagation.CamelMessagingHeadersInjectAdapter.JMS_DASH; +import static org.apache.camel.support.tracing.propagators.CamelMessagingHeadersInjectAdapter.JMS_DASH; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull;