This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karaf.git
The following commit(s) were added to refs/heads/main by this push:
new 37418b472 feat(#768): add camel-opentelemetry2 integration test (#769)
37418b472 is described below
commit 37418b4721017d54064ac3f105e5b84f2b46b36b
Author: François de Parscau <[email protected]>
AuthorDate: Mon Nov 30 13:27:48 2026 +0100
feat(#768): add camel-opentelemetry2 integration test (#769)
Install the camel-opentelemetry2 feature in Karaf, start OpenTelemetryTracer
on the supplied context and check that a custom span and the Camel spans are
exported through an in-memory exporter.
Co-authored-by: Claude Sonnet 5.5 <[email protected]>
---
.gitignore | 1 +
tests/features/camel-opentelemetry2/pom.xml | 76 ++++++++++++
.../test/CamelOpentelemetry2RouteSupplier.java | 128 +++++++++++++++++++++
.../camel/itest/CamelOpentelemetry2ITest.java | 61 ++++++++++
tests/features/pom.xml | 1 +
5 files changed, 267 insertions(+)
diff --git a/.gitignore b/.gitignore
index 5d69a553e..74252bb17 100644
--- a/.gitignore
+++ b/.gitignore
@@ -25,3 +25,4 @@ components/camel-cxf/activemq-data
*.swp
.flattened-pom.xml
.java-version
+**/.resolved-pom.xml
\ No newline at end of file
diff --git a/tests/features/camel-opentelemetry2/pom.xml
b/tests/features/camel-opentelemetry2/pom.xml
new file mode 100644
index 000000000..e262638f2
--- /dev/null
+++ b/tests/features/camel-opentelemetry2/pom.xml
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel.karaf</groupId>
+ <artifactId>camel-karaf-features-test</artifactId>
+ <version>4.22.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-opentelemetry2-test</artifactId>
+ <name>Apache Camel :: Karaf :: Tests :: Features :: OpenTelemetry2</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-opentelemetry2</artifactId>
+ <version>${camel-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.opentelemetry</groupId>
+ <artifactId>opentelemetry-api</artifactId>
+ <version>${opentelemetry-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.opentelemetry</groupId>
+ <artifactId>opentelemetry-context</artifactId>
+ <version>${opentelemetry-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.opentelemetry</groupId>
+ <artifactId>opentelemetry-sdk</artifactId>
+ <version>${opentelemetry-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.opentelemetry</groupId>
+ <artifactId>opentelemetry-sdk-common</artifactId>
+ <version>${opentelemetry-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.opentelemetry</groupId>
+ <artifactId>opentelemetry-sdk-trace</artifactId>
+ <version>${opentelemetry-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>../../../src/main/resources</directory>
+ <filtering>false</filtering>
+ </resource>
+ </resources>
+ </build>
+
+</project>
\ No newline at end of file
diff --git
a/tests/features/camel-opentelemetry2/src/main/java/org/apache/karaf/camel/test/CamelOpentelemetry2RouteSupplier.java
b/tests/features/camel-opentelemetry2/src/main/java/org/apache/karaf/camel/test/CamelOpentelemetry2RouteSupplier.java
new file mode 100644
index 000000000..a030e0478
--- /dev/null
+++
b/tests/features/camel-opentelemetry2/src/main/java/org/apache/karaf/camel/test/CamelOpentelemetry2RouteSupplier.java
@@ -0,0 +1,128 @@
+/*
+ * 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.karaf.camel.test;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import io.opentelemetry.api.common.AttributeKey;
+import io.opentelemetry.api.trace.Span;
+import io.opentelemetry.api.trace.Tracer;
+import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator;
+import io.opentelemetry.context.propagation.ContextPropagators;
+import io.opentelemetry.sdk.OpenTelemetrySdk;
+import io.opentelemetry.sdk.common.CompletableResultCode;
+import io.opentelemetry.sdk.trace.SdkTracerProvider;
+import io.opentelemetry.sdk.trace.data.SpanData;
+import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
+import io.opentelemetry.sdk.trace.export.SpanExporter;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.opentelemetry2.OpenTelemetryTracer;
+import
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier;
+import org.apache.karaf.camel.itests.CamelRouteSupplier;
+import org.osgi.service.component.annotations.Component;
+
+@Component(name = "karaf-camel-opentelemetry2-test", immediate = true, service
= CamelRouteSupplier.class)
+public class CamelOpentelemetry2RouteSupplier extends
AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
+
+ public static final String CUSTOM_SPAN_NAME = "karaf-custom-span";
+ public static final String CUSTOM_ATTRIBUTE = "karaf.test.attribute";
+ public static final String CUSTOM_ATTRIBUTE_VALUE = "karaf-value";
+ public static final String TRACER_STARTED = "tracer-started";
+ public static final String TRACER_MISSING = "tracer-missing";
+
+ /** Spans finished so far, filled by the in-memory exporter below. */
+ private static final List<SpanData> EXPORTED_SPANS = new
CopyOnWriteArrayList<>();
+
+ private static final SpanExporter IN_MEMORY_EXPORTER = new SpanExporter() {
+ @Override
+ public CompletableResultCode export(Collection<SpanData> spans) {
+ EXPORTED_SPANS.addAll(spans);
+ return CompletableResultCode.ofSuccess();
+ }
+
+ @Override
+ public CompletableResultCode flush() {
+ return CompletableResultCode.ofSuccess();
+ }
+
+ @Override
+ public CompletableResultCode shutdown() {
+ return CompletableResultCode.ofSuccess();
+ }
+ };
+
+ private Tracer otelTracer;
+
+ /**
+ * Names of the spans exported so far. Only JDK types are exposed so the
test probe bundle
+ * does not need to import any OpenTelemetry package.
+ */
+ public static List<String> exportedSpanNames() {
+ return EXPORTED_SPANS.stream().map(SpanData::getName).toList();
+ }
+
+ /** Value of the custom attribute on the exported custom span, or null if
it was not exported. */
+ public static String exportedCustomAttribute() {
+ return EXPORTED_SPANS.stream()
+ .filter(s -> CUSTOM_SPAN_NAME.equals(s.getName()))
+ .map(s ->
s.getAttributes().get(AttributeKey.stringKey(CUSTOM_ATTRIBUTE)))
+ .findFirst()
+ .orElse(null);
+ }
+
+ @Override
+ public void configure(CamelContext camelContext) {
+ EXPORTED_SPANS.clear();
+ SdkTracerProvider provider = SdkTracerProvider.builder()
+
.addSpanProcessor(SimpleSpanProcessor.create(IN_MEMORY_EXPORTER))
+ .build();
+ ContextPropagators propagators =
ContextPropagators.create(W3CTraceContextPropagator.getInstance());
+ OpenTelemetrySdk sdk = OpenTelemetrySdk.builder()
+ .setTracerProvider(provider)
+ .setPropagators(propagators)
+ .build();
+ otelTracer = sdk.getTracer("camel");
+
+ // OpenTelemetryTracer looks these up by type in the registry (instead
of GlobalOpenTelemetry)
+ camelContext.getRegistry().bind("otelTracer", otelTracer);
+ camelContext.getRegistry().bind("otelPropagators", propagators);
+
+ OpenTelemetryTracer tracer = new OpenTelemetryTracer();
+ tracer.init(camelContext);
+ }
+
+ @Override
+ protected boolean consumerEnabled() {
+ return false;
+ }
+
+ @Override
+ protected void configureProducer(RouteBuilder builder, RouteDefinition
producerRoute) {
+ producerRoute.process(exchange -> {
+ Span span = otelTracer.spanBuilder(CUSTOM_SPAN_NAME)
+ .setAttribute(AttributeKey.stringKey(CUSTOM_ATTRIBUTE),
CUSTOM_ATTRIBUTE_VALUE)
+ .startSpan();
+ span.end();
+ exchange.getMessage().setBody(
+
exchange.getContext().hasService(OpenTelemetryTracer.class) != null
+ ? TRACER_STARTED : TRACER_MISSING);
+ }).toF("mock:%s", getResultMockName());
+ }
+}
diff --git
a/tests/features/camel-opentelemetry2/src/test/java/org/apache/karaf/camel/itest/CamelOpentelemetry2ITest.java
b/tests/features/camel-opentelemetry2/src/test/java/org/apache/karaf/camel/itest/CamelOpentelemetry2ITest.java
new file mode 100644
index 000000000..964c34bc7
--- /dev/null
+++
b/tests/features/camel-opentelemetry2/src/test/java/org/apache/karaf/camel/itest/CamelOpentelemetry2ITest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.karaf.camel.itest;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteITest;
+import org.apache.karaf.camel.test.CamelOpentelemetry2RouteSupplier;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class CamelOpentelemetry2ITest extends
AbstractCamelSingleFeatureResultMockBasedRouteITest {
+
+ @Override
+ public void configureMock(MockEndpoint mock) {
+
mock.expectedBodiesReceived(CamelOpentelemetry2RouteSupplier.TRACER_STARTED);
+ }
+
+ @Test
+ public void testResultMock() throws Exception {
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testCustomSpanIsExported() {
+ await().atMost(20, TimeUnit.SECONDS).untilAsserted(() -> {
+ assertTrue("custom span not exported",
+ CamelOpentelemetry2RouteSupplier.exportedSpanNames()
+
.contains(CamelOpentelemetry2RouteSupplier.CUSTOM_SPAN_NAME));
+
assertEquals(CamelOpentelemetry2RouteSupplier.CUSTOM_ATTRIBUTE_VALUE,
+
CamelOpentelemetry2RouteSupplier.exportedCustomAttribute());
+ });
+ // the Camel tracer must also have produced its own spans for the route
+ await().atMost(20, TimeUnit.SECONDS).untilAsserted(() ->
assertTrue("no Camel span exported",
+ CamelOpentelemetry2RouteSupplier.exportedSpanNames().stream()
+ .anyMatch(n ->
!CamelOpentelemetry2RouteSupplier.CUSTOM_SPAN_NAME.equals(n))));
+ }
+}
diff --git a/tests/features/pom.xml b/tests/features/pom.xml
index 3c446c577..3dfb92dda 100644
--- a/tests/features/pom.xml
+++ b/tests/features/pom.xml
@@ -106,6 +106,7 @@
<module>camel-netty-http</module>
<module>camel-mail</module>
<module>camel-olingo2</module>
+ <module>camel-opentelemetry2</module>
<module>camel-paho-mqtt5</module>
<module>camel-quartz</module>
<module>camel-saxon</module>