Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring tracing interfaces to camel-api and camel-support #15163

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,30 @@
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;
import org.slf4j.LoggerFactory;

public abstract class Tracer extends ServiceSupport implements CamelTracingService, RoutePolicyFactory, StaticService {
protected static final Map<String, SpanDecorator> 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());
Expand Down Expand Up @@ -202,7 +215,7 @@ protected SpanDecorator getSpanDecorator(Endpoint endpoint) {
.orElse(null);
}
if (sd == null) {
sd = SpanDecorator.DEFAULT;
sd = DEFAULT_SPAN_DECORATOR;
}

return sd;
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.camel.tracing.decorators;

import org.apache.camel.support.tracing.decorators.AbstractInternalSpanDecorator;

public class DirectSpanDecorator extends AbstractInternalSpanDecorator {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.camel.tracing.decorators;

import org.apache.camel.support.tracing.decorators.AbstractInternalSpanDecorator;

public class DisruptorSpanDecorator extends AbstractInternalSpanDecorator {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.camel.tracing.decorators;

import org.apache.camel.support.tracing.decorators.AbstractInternalSpanDecorator;

public class DisruptorvmSpanDecorator extends AbstractInternalSpanDecorator {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.camel.tracing.decorators;

import org.apache.camel.support.tracing.decorators.AbstractSpanDecorator;

public class LogSpanDecorator extends AbstractSpanDecorator {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.camel.tracing.decorators;

import org.apache.camel.support.tracing.decorators.AbstractInternalSpanDecorator;

public class SedaSpanDecorator extends AbstractInternalSpanDecorator {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand All @@ -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());

Expand All @@ -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));

Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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");

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -155,7 +155,7 @@ public String getComponentClassName() {
}
};

MockSpanAdapter span = new MockSpanAdapter();
InMemorySpanAdapter span = new InMemorySpanAdapter();

decorator.pre(span, exchange, endpoint);

Expand Down Expand Up @@ -282,7 +282,7 @@ public String getComponentClassName() {
}
};

MockSpanAdapter span = new MockSpanAdapter();
InMemorySpanAdapter span = new InMemorySpanAdapter();

decorator.post(span, exchange, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,7 +67,7 @@ public String getComponentClassName() {
}
};

MockSpanAdapter span = new MockSpanAdapter();
InMemorySpanAdapter span = new InMemorySpanAdapter();

decorator.pre(span, null, endpoint);

Expand Down Expand Up @@ -99,7 +99,7 @@ public String getMessageId(Exchange exchange) {
}
};

MockSpanAdapter span = new MockSpanAdapter();
InMemorySpanAdapter span = new InMemorySpanAdapter();

decorator.pre(span, exchange, endpoint);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -79,7 +79,7 @@ public void testPre() {

AbstractMessagingSpanDecorator decorator = new AzureServiceBusSpanDecorator();

MockSpanAdapter span = new MockSpanAdapter();
InMemorySpanAdapter span = new InMemorySpanAdapter();

decorator.pre(span, exchange, endpoint);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,7 +45,7 @@ public void testPreCqlFromUri() {

SpanDecorator decorator = new CqlSpanDecorator();

MockSpanAdapter span = new MockSpanAdapter();
InMemorySpanAdapter span = new InMemorySpanAdapter();

decorator.pre(span, exchange, endpoint);

Expand All @@ -68,7 +68,7 @@ public void testPreCqlFromHeader() {

SpanDecorator decorator = new CqlSpanDecorator();

MockSpanAdapter span = new MockSpanAdapter();
InMemorySpanAdapter span = new InMemorySpanAdapter();

decorator.pre(span, exchange, endpoint);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,7 +58,7 @@ public void testPre() {

SpanDecorator decorator = new ElasticsearchSpanDecorator();

MockSpanAdapter span = new MockSpanAdapter();
InMemorySpanAdapter span = new InMemorySpanAdapter();

decorator.pre(span, exchange, endpoint);

Expand Down
Loading
Loading