Skip to content
Merged
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 @@ -25,6 +25,8 @@ public boolean configure(CamelContext camelContext, Object obj, String name, Obj
switch (ignoreCase ? name.toLowerCase() : name) {
case "camelcontext":
case "camelContext": target.setCamelContext(property(camelContext, org.apache.camel.CamelContext.class, value)); return true;
case "disablecoreprocessors":
case "disableCoreProcessors": target.setDisableCoreProcessors(property(camelContext, boolean.class, value)); return true;
case "excludepatterns":
case "excludePatterns": target.setExcludePatterns(property(camelContext, java.lang.String.class, value)); return true;
case "observationregistry":
Expand All @@ -46,6 +48,8 @@ public Class<?> getOptionType(String name, boolean ignoreCase) {
switch (ignoreCase ? name.toLowerCase() : name) {
case "camelcontext":
case "camelContext": return org.apache.camel.CamelContext.class;
case "disablecoreprocessors":
case "disableCoreProcessors": return boolean.class;
case "excludepatterns":
case "excludePatterns": return java.lang.String.class;
case "observationregistry":
Expand All @@ -68,6 +72,8 @@ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
switch (ignoreCase ? name.toLowerCase() : name) {
case "camelcontext":
case "camelContext": return target.getCamelContext();
case "disablecoreprocessors":
case "disableCoreProcessors": return target.isDisableCoreProcessors();
case "excludepatterns":
case "excludePatterns": return target.getExcludePatterns();
case "observationregistry":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ The configuration properties for the component are:
[width="100%",cols="10%,10%,80%",options="header",]
|=======================================================================
|Option |Default |Description
|`enabled`| false | Turn the tracing on/off.
|`traceProcessors`| false | Trace inner custom processors (i.e., any `process` configured in the route).
|`disableCoreProcessors`| false | Disable any inner core processors (any core DSL processor provided in the route, for example `bean`, `log`, ...).
|`excludePatterns` | | Sets exclude pattern that will disable tracing for those spans that matches the pattern. The variable is a comma separated values of filters to execute (eg, `log*,direct*,setBody*`, ...)
|`traceProcessors` | `false` | Setting this to true will create new spans for each Camel Processors.
Use the excludePattern property to filter out Processors
|`traceHeadersInclusion`| false | Add the generated telemetry `CAMEL_TRACE_ID` and `CAMEL_SPAN_ID` Exchange headers.
|=======================================================================

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ public class BaggageInjectionTest extends MicrometerObservabilityTracerPropagati

@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext ctx = super.createCamelContext();
tst.setTraceProcessors(true);
return super.createCamelContext();
tst.setDisableCoreProcessors(false);

return ctx;
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ public class EnableProcessorsTest extends MicrometerObservabilityTracerPropagati

@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext ctx = super.createCamelContext();
tst.setTraceProcessors(true);
return super.createCamelContext();
tst.setDisableCoreProcessors(false);

return ctx;
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ protected CamelContext createCamelContext() throws Exception {

CamelContextAware.trySetCamelContext(tst, context);
tst.init(context);
tst.setDisableCoreProcessors(true);
return context;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* 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.micrometer.observability;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.sdk.trace.data.SpanData;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.micrometer.observability.CamelOpenTelemetryExtension.OtelTrace;
import org.apache.camel.telemetry.Op;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class SpanBeanTest extends MicrometerObservabilityTracerPropagationTestSupport {

@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext ctx = super.createCamelContext();
tst.setDisableCoreProcessors(false);

return ctx;
}

@Test
void testRouteSingleRequest() throws IOException {
template.request("direct:start", null);
Map<String, OtelTrace> traces = otelExtension.getTraces();
assertEquals(1, traces.size());
checkTrace(traces.values().iterator().next());
}

private void checkTrace(OtelTrace trace) {
List<SpanData> spans = trace.getSpans();
assertEquals(7, spans.size());
SpanData testProducer = spans.get(0);
SpanData direct = spans.get(1);
SpanData innerLog = spans.get(2);
SpanData beanProcessor = spans.get(3);
SpanData customSpan = spans.get(4);
SpanData log = spans.get(5);
SpanData innerToLog = spans.get(6);

// Validate span completion
assertTrue(testProducer.hasEnded());
assertTrue(direct.hasEnded());
assertTrue(innerLog.hasEnded());
assertTrue(beanProcessor.hasEnded());
assertTrue(customSpan.hasEnded());
assertTrue(log.hasEnded());
assertTrue(innerToLog.hasEnded());

// Validate same trace
assertEquals(testProducer.getSpanContext().getTraceId(), direct.getSpanContext().getTraceId());
assertEquals(testProducer.getSpanContext().getTraceId(), direct.getSpanContext().getTraceId());
assertEquals(testProducer.getSpanContext().getTraceId(), innerLog.getSpanContext().getTraceId());
assertEquals(testProducer.getSpanContext().getTraceId(), beanProcessor.getSpanContext().getTraceId());
assertEquals(testProducer.getSpanContext().getTraceId(), customSpan.getSpanContext().getTraceId());
assertEquals(testProducer.getSpanContext().getTraceId(), log.getSpanContext().getTraceId());
assertEquals(testProducer.getSpanContext().getTraceId(), innerToLog.getSpanContext().getTraceId());

// Validate operations
assertEquals(Op.EVENT_RECEIVED.toString(), direct.getAttributes().get(AttributeKey.stringKey("op")));
assertEquals(Op.EVENT_PROCESS.toString(), beanProcessor.getAttributes().get(AttributeKey.stringKey("op")));

// Validate hierarchy
assertFalse(testProducer.getParentSpanContext().isValid());
assertEquals(testProducer.getSpanContext().getSpanId(), direct.getParentSpanContext().getSpanId());
assertEquals(direct.getSpanContext().getSpanId(), beanProcessor.getParentSpanContext().getSpanId());
assertEquals(beanProcessor.getSpanContext().getSpanId(), customSpan.getParentSpanContext().getSpanId());

// Validate custom span
assertEquals("mySpan", customSpan.getName());
}

@Override
protected RoutesBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() {
MyBean myBean = new MyBean();
this.getCamelContext().getRegistry().bind("myBean", myBean);

from("direct:start")
.routeId("start")
.log("A message")
.bean(MyBean.class)
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
// noop
}
})
.to("log:info");
}
};
}

class MyBean {
// NOTE: the commented annotation below would work only when an agent or a runtime framework (quarkus or spring)
// is available. We simulate it creating the Span by hand instead.
//@WithSpan
public void helloWorld() {
io.opentelemetry.api.trace.Span mySpan = otelTracer.spanBuilder("mySpan").startSpan();
// Do the work here
mySpan.end();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ public class SpanCustomizationTest extends MicrometerObservabilityTracerPropagat

@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext ctx = super.createCamelContext();
tst.setTraceProcessors(true);
return super.createCamelContext();
tst.setDisableCoreProcessors(false);

return ctx;
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ public class SpanInjectionTest extends MicrometerObservabilityTracerPropagationT

@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext ctx = super.createCamelContext();
tst.setTraceProcessors(true);
return super.createCamelContext();
tst.setDisableCoreProcessors(false);

return ctx;
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public boolean configure(CamelContext camelContext, Object obj, String name, Obj
switch (ignoreCase ? name.toLowerCase() : name) {
case "camelcontext":
case "camelContext": target.setCamelContext(property(camelContext, org.apache.camel.CamelContext.class, value)); return true;
case "disablecoreprocessors":
case "disableCoreProcessors": target.setDisableCoreProcessors(property(camelContext, boolean.class, value)); return true;
case "excludepatterns":
case "excludePatterns": target.setExcludePatterns(property(camelContext, java.lang.String.class, value)); return true;
case "spanlifecyclemanager":
Expand All @@ -42,6 +44,8 @@ public Class<?> getOptionType(String name, boolean ignoreCase) {
switch (ignoreCase ? name.toLowerCase() : name) {
case "camelcontext":
case "camelContext": return org.apache.camel.CamelContext.class;
case "disablecoreprocessors":
case "disableCoreProcessors": return boolean.class;
case "excludepatterns":
case "excludePatterns": return java.lang.String.class;
case "spanlifecyclemanager":
Expand All @@ -60,6 +64,8 @@ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
switch (ignoreCase ? name.toLowerCase() : name) {
case "camelcontext":
case "camelContext": return target.getCamelContext();
case "disablecoreprocessors":
case "disableCoreProcessors": return target.isDisableCoreProcessors();
case "excludepatterns":
case "excludePatterns": return target.getExcludePatterns();
case "spanlifecyclemanager":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ The configuration properties for the OpenTelemetry2 tracer are:
[width="100%",cols="10%,10%,80%",options="header",]
|=======================================================================
| Option | Default | Description
|`enabled`| false | Turn the tracing on/off.
|`traceProcessors`| false | Trace inner custom processors (i.e., any `process` configured in the route).
|`disableCoreProcessors`| false | Disable any inner core processors (any core DSL processor provided in the route, for example `bean`, `log`, ...).
| `excludePatterns` | | A comma-separated list of patterns (e.g., `log*,direct*,setBody*`) to exclude from tracing. Spans matching these patterns will be disabled.
| `traceProcessors` | `false` | If set to `true`, Camel creates OpenTelemetry Spans for each processor in your routes. You can use `excludePatterns` to filter which processors are traced.
| `traceHeadersInclusion`| `false` | If set to `true`, adds the generated telemetry `CAMEL_TRACE_ID` and `CAMEL_SPAN_ID` Exchange headers.
|=======================================================================

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ protected CamelContext createCamelContext() throws Exception {
OpenTelemetryTracer tst = new OpenTelemetryTracer();
tst.setTracer(otelExtension.getOpenTelemetry().getTracer("traceTest"));
tst.setContextPropagators(otelExtension.getOpenTelemetry().getPropagators());
tst.setDisableCoreProcessors(true);
CamelContext context = super.createCamelContext();
CamelContextAware.trySetCamelContext(tst, context);
tst.init(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected CamelContext createCamelContext() throws Exception {
OpenTelemetryTracer tst = new OpenTelemetryTracer();
tst.setTracer(otelExtension.getOpenTelemetry().getTracer("traceTest"));
tst.setContextPropagators(otelExtension.getOpenTelemetry().getPropagators());
tst.setDisableCoreProcessors(true);
CamelContext context = super.createCamelContext();
CamelContextAware.trySetCamelContext(tst, context);
tst.init(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ protected CamelContext createCamelContext() throws Exception {
OpenTelemetryTracer tst = new OpenTelemetryTracer();
tst.setTracer(otelExtension.getOpenTelemetry().getTracer("traceTest"));
tst.setContextPropagators(otelExtension.getOpenTelemetry().getPropagators());
tst.setDisableCoreProcessors(true);
CamelContext context = super.createCamelContext();
CamelContextAware.trySetCamelContext(tst, context);
tst.init(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ protected CamelContext createCamelContext() throws Exception {
OpenTelemetryTracer tst = new OpenTelemetryTracer();
tst.setTracer(otelExtension.getOpenTelemetry().getTracer("traceTest"));
tst.setContextPropagators(otelExtension.getOpenTelemetry().getPropagators());
tst.setDisableCoreProcessors(true);
CamelContext context = super.createCamelContext();
CamelContextAware.trySetCamelContext(tst, context);
tst.init(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected CamelContext createCamelContext() throws Exception {
tst.setTraceHeadersInclusion(true);
tst.setTracer(otelExtension.getOpenTelemetry().getTracer("traceTest"));
tst.setContextPropagators(otelExtension.getOpenTelemetry().getPropagators());
tst.setDisableCoreProcessors(true);
CamelContextAware.trySetCamelContext(tst, context);
tst.init(context);
return context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected CamelContext createCamelContext() throws Exception {
OpenTelemetryTracer tst = new OpenTelemetryTracer();
tst.setTracer(otelExtension.getOpenTelemetry().getTracer("traceTest"));
tst.setContextPropagators(otelExtension.getOpenTelemetry().getPropagators());
tst.setDisableCoreProcessors(true);
CamelContext context = super.createCamelContext();
CamelContextAware.trySetCamelContext(tst, context);
tst.init(context);
Expand Down
Loading
Loading