This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new cb4557166e Add traceProcessors option to OpenTelemetry extension
cb4557166e is described below
commit cb4557166e4930b1b993df996c01fff522c0dc2a
Author: James Netherton <[email protected]>
AuthorDate: Mon Jun 3 14:34:33 2024 +0100
Add traceProcessors option to OpenTelemetry extension
Fixes #6143
---
.../pages/reference/extensions/opentelemetry.adoc | 12 +++--
.../deployment/OpenTelemetryEnabledTest.java | 14 +++++-
.../opentelemetry/CamelOpenTelemetryConfig.java | 11 ++++-
.../opentelemetry/OpenTelemetryTracerProducer.java | 8 +++
.../opentelemetry/it/OpenTelemetryTest.java | 20 ++------
.../opentelemetry/it/OpenTelemetryTestHelper.java | 39 +++++++++++++++
.../it/OpenTelemetryTraceProcessorsIT.java | 23 +++++++++
.../it/OpenTelemetryTraceProcessorsTest.java | 57 ++++++++++++++++++++++
.../it/TraceProcessorsTestProfile.java | 28 +++++++++++
9 files changed, 190 insertions(+), 22 deletions(-)
diff --git a/docs/modules/ROOT/pages/reference/extensions/opentelemetry.adoc
b/docs/modules/ROOT/pages/reference/extensions/opentelemetry.adoc
index 84982456b6..7fd7861c8b 100644
--- a/docs/modules/ROOT/pages/reference/extensions/opentelemetry.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/opentelemetry.adoc
@@ -120,15 +120,15 @@ There is more information about CDI instrumentation in
the https://quarkus.io/gu
| Configuration property | Type | Default
-|icon:lock[title=Fixed at build time]
[[quarkus.camel.opentelemetry.encoding]]`link:#quarkus.camel.opentelemetry.encoding[quarkus.camel.opentelemetry.encoding]`
+|
[[quarkus.camel.opentelemetry.encoding]]`link:#quarkus.camel.opentelemetry.encoding[quarkus.camel.opentelemetry.encoding]`
Sets whether header names need to be encoded. Can be useful in situations
where OpenTelemetry propagators potentially set header name values in formats
that are not compatible with the target system. E.g for JMS where the
specification mandates header names are valid Java identifiers.
| `boolean`
| `false`
-|icon:lock[title=Fixed at build time]
[[quarkus.camel.opentelemetry.exclude-patterns]]`link:#quarkus.camel.opentelemetry.exclude-patterns[quarkus.camel.opentelemetry.exclude-patterns]`
+|
[[quarkus.camel.opentelemetry.exclude-patterns]]`link:#quarkus.camel.opentelemetry.exclude-patterns[quarkus.camel.opentelemetry.exclude-patterns]`
-Sets whether to disable tracing for endpoint URIs that match the given comma
separated patterns. The pattern can take the following forms:
+Sets whether to disable tracing for endpoint URIs or Processor ids that match
the given comma separated patterns. The pattern can take the following forms:
@@ -143,6 +143,12 @@ Sets whether to disable tracing for endpoint URIs that
match the given comma sep
3. A regular expression matching the endpoint URI. E.g
platform-http:/prefix/.++*++
| `string`
|
+
+|
[[quarkus.camel.opentelemetry.trace-processors]]`link:#quarkus.camel.opentelemetry.trace-processors[quarkus.camel.opentelemetry.trace-processors]`
+
+Sets whether to create new OpenTelemetry spans for each Camel Processor. Use
the excludePatterns property to filter out Processors.
+| `boolean`
+| `false`
|===
[.configuration-legend]
diff --git
a/extensions/opentelemetry/deployment/src/test/java/org/apache/camel/quarkus/component/opentelemetry/deployment/OpenTelemetryEnabledTest.java
b/extensions/opentelemetry/deployment/src/test/java/org/apache/camel/quarkus/component/opentelemetry/deployment/OpenTelemetryEnabledTest.java
index 57ab28369e..dfbda06121 100644
---
a/extensions/opentelemetry/deployment/src/test/java/org/apache/camel/quarkus/component/opentelemetry/deployment/OpenTelemetryEnabledTest.java
+++
b/extensions/opentelemetry/deployment/src/test/java/org/apache/camel/quarkus/component/opentelemetry/deployment/OpenTelemetryEnabledTest.java
@@ -23,18 +23,25 @@ import jakarta.inject.Inject;
import org.apache.camel.CamelContext;
import org.apache.camel.opentelemetry.CamelQuarkusOpenTelemetryTracer;
import org.apache.camel.opentelemetry.OpenTelemetryTracer;
+import org.apache.camel.opentelemetry.OpenTelemetryTracingStrategy;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class OpenTelemetryEnabledTest {
+ private static final String EXCLUDE_PATTERNS =
"platform-http:*,platform-http:/prefix/.*";
+
@RegisterExtension
static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
+ .overrideConfigKey("quarkus.camel.opentelemetry.encoding", "true")
+ .overrideConfigKey("quarkus.camel.opentelemetry.exclude-patterns",
EXCLUDE_PATTERNS)
+ .overrideConfigKey("quarkus.camel.opentelemetry.trace-processors",
"true")
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));
@Inject
@@ -45,7 +52,10 @@ public class OpenTelemetryEnabledTest {
Set<OpenTelemetryTracer> tracers =
context.getRegistry().findByType(OpenTelemetryTracer.class);
assertEquals(1, tracers.size());
- OpenTelemetryTracer factory = tracers.iterator().next();
- assertTrue(factory instanceof CamelQuarkusOpenTelemetryTracer);
+ OpenTelemetryTracer tracer = tracers.iterator().next();
+ assertInstanceOf(CamelQuarkusOpenTelemetryTracer.class, tracer);
+ assertInstanceOf(OpenTelemetryTracingStrategy.class,
tracer.getTracingStrategy());
+ assertTrue(tracer.isEncoding());
+ assertEquals(EXCLUDE_PATTERNS, tracer.getExcludePatterns());
}
}
diff --git
a/extensions/opentelemetry/runtime/src/main/java/org/apache/camel/quarkus/component/opentelemetry/CamelOpenTelemetryConfig.java
b/extensions/opentelemetry/runtime/src/main/java/org/apache/camel/quarkus/component/opentelemetry/CamelOpenTelemetryConfig.java
index dd0670842f..7ea9cb3759 100644
---
a/extensions/opentelemetry/runtime/src/main/java/org/apache/camel/quarkus/component/opentelemetry/CamelOpenTelemetryConfig.java
+++
b/extensions/opentelemetry/runtime/src/main/java/org/apache/camel/quarkus/component/opentelemetry/CamelOpenTelemetryConfig.java
@@ -22,7 +22,7 @@ import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
-@ConfigRoot(name = "camel.opentelemetry", phase =
ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
+@ConfigRoot(name = "camel.opentelemetry", phase = ConfigPhase.RUN_TIME)
public final class CamelOpenTelemetryConfig {
/**
@@ -34,7 +34,7 @@ public final class CamelOpenTelemetryConfig {
public boolean encoding;
/**
- * Sets whether to disable tracing for endpoint URIs that match the given
+ * Sets whether to disable tracing for endpoint URIs or Processor ids that
match the given
* comma separated patterns. The pattern can take the following
* forms:
* <p>
@@ -49,4 +49,11 @@ public final class CamelOpenTelemetryConfig {
*/
@ConfigItem
public Optional<String> excludePatterns;
+
+ /**
+ * Sets whether to create new OpenTelemetry spans for each Camel
Processor. Use the excludePatterns
+ * property to filter out Processors.
+ */
+ @ConfigItem(defaultValue = "false")
+ public boolean traceProcessors;
}
diff --git
a/extensions/opentelemetry/runtime/src/main/java/org/apache/camel/quarkus/component/opentelemetry/OpenTelemetryTracerProducer.java
b/extensions/opentelemetry/runtime/src/main/java/org/apache/camel/quarkus/component/opentelemetry/OpenTelemetryTracerProducer.java
index ff44a1aaf6..0e1b61983c 100644
---
a/extensions/opentelemetry/runtime/src/main/java/org/apache/camel/quarkus/component/opentelemetry/OpenTelemetryTracerProducer.java
+++
b/extensions/opentelemetry/runtime/src/main/java/org/apache/camel/quarkus/component/opentelemetry/OpenTelemetryTracerProducer.java
@@ -23,6 +23,7 @@ import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import org.apache.camel.opentelemetry.CamelQuarkusOpenTelemetryTracer;
import org.apache.camel.opentelemetry.OpenTelemetryTracer;
+import org.apache.camel.opentelemetry.OpenTelemetryTracingStrategy;
@Singleton
public class OpenTelemetryTracerProducer {
@@ -43,6 +44,13 @@ public class OpenTelemetryTracerProducer {
if (config.excludePatterns.isPresent()) {
openTelemetryTracer.setExcludePatterns(config.excludePatterns.get());
}
+
+ if (config.traceProcessors) {
+ OpenTelemetryTracingStrategy tracingStrategy = new
OpenTelemetryTracingStrategy(openTelemetryTracer);
+ tracingStrategy.setPropagateContext(true);
+ openTelemetryTracer.setTracingStrategy(tracingStrategy);
+ }
+
openTelemetryTracer.setEncoding(config.encoding);
}
return openTelemetryTracer;
diff --git
a/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryTest.java
b/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryTest.java
index b4cd23ddf4..91dd3c4fee 100644
---
a/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryTest.java
+++
b/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryTest.java
@@ -27,6 +27,7 @@ import io.restassured.RestAssured;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
+import static
org.apache.camel.quarkus.component.opentelemetry.it.OpenTelemetryTestHelper.getSpans;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -86,8 +87,8 @@ class OpenTelemetryTest {
List<Map<String, String>> spans = getSpans();
assertEquals(3, spans.size());
assertEquals(spans.get(0).get("parentId"), spans.get(1).get("spanId"));
- assertEquals(spans.get(1).get("kind"), SpanKind.CLIENT.name());
- assertEquals(spans.get(2).get("kind"), SpanKind.SERVER.name());
+ assertEquals(SpanKind.CLIENT.name(), spans.get(1).get("kind"));
+ assertEquals(SpanKind.SERVER.name(), spans.get(2).get("kind"));
}
@Test
@@ -104,8 +105,8 @@ class OpenTelemetryTest {
assertEquals(4, spans.size());
assertEquals(spans.get(0).get("parentId"),
spans.get(1).get("parentId"));
assertEquals(spans.get(1).get("parentId"), spans.get(2).get("spanId"));
- assertEquals(spans.get(2).get("kind"), SpanKind.CLIENT.name());
- assertEquals(spans.get(3).get("kind"), SpanKind.SERVER.name());
+ assertEquals(SpanKind.CLIENT.name(), spans.get(2).get("kind"));
+ assertEquals(SpanKind.SERVER.name(), spans.get(3).get("kind"));
}
@Test
@@ -141,15 +142,4 @@ class OpenTelemetryTest {
assertEquals(spans.get(5).get("parentId"), "0000000000000000");
assertEquals(spans.get(5).get("code.function"), "jdbcQuery");
}
-
- private List<Map<String, String>> getSpans() {
- return RestAssured.given()
- .get("/opentelemetry/exporter/spans")
- .then()
- .statusCode(200)
- .extract()
- .body()
- .jsonPath()
- .get();
- }
}
diff --git
a/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryTestHelper.java
b/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryTestHelper.java
new file mode 100644
index 0000000000..85a0f36e4b
--- /dev/null
+++
b/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryTestHelper.java
@@ -0,0 +1,39 @@
+/*
+ * 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.quarkus.component.opentelemetry.it;
+
+import java.util.List;
+import java.util.Map;
+
+import io.restassured.RestAssured;
+
+class OpenTelemetryTestHelper {
+ private OpenTelemetryTestHelper() {
+ // Utility class
+ }
+
+ static List<Map<String, String>> getSpans() {
+ return RestAssured.given()
+ .get("/opentelemetry/exporter/spans")
+ .then()
+ .statusCode(200)
+ .extract()
+ .body()
+ .jsonPath()
+ .get();
+ }
+}
diff --git
a/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryTraceProcessorsIT.java
b/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryTraceProcessorsIT.java
new file mode 100644
index 0000000000..e25053d12f
--- /dev/null
+++
b/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryTraceProcessorsIT.java
@@ -0,0 +1,23 @@
+/*
+ * 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.quarkus.component.opentelemetry.it;
+
+import io.quarkus.test.junit.QuarkusIntegrationTest;
+
+@QuarkusIntegrationTest
+class OpenTelemetryTraceProcessorsIT extends OpenTelemetryTraceProcessorsTest {
+}
diff --git
a/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryTraceProcessorsTest.java
b/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryTraceProcessorsTest.java
new file mode 100644
index 0000000000..365b1e33b8
--- /dev/null
+++
b/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryTraceProcessorsTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.quarkus.component.opentelemetry.it;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import io.opentelemetry.api.trace.SpanKind;
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.TestProfile;
+import io.restassured.RestAssured;
+import org.junit.jupiter.api.Test;
+
+import static
org.apache.camel.quarkus.component.opentelemetry.it.OpenTelemetryTestHelper.getSpans;
+import static org.awaitility.Awaitility.await;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+@TestProfile(TraceProcessorsTestProfile.class)
+@QuarkusTest
+class OpenTelemetryTraceProcessorsTest {
+ @Test
+ void traceProcessors() {
+ RestAssured.get("/opentelemetry/trace")
+ .then()
+ .statusCode(200)
+ .body(equalTo("Traced direct:start"));
+
+ // Verify the span hierarchy is JAX-RS Service -> Direct Endpoint ->
SetBody
+ await().atMost(30, TimeUnit.SECONDS).pollDelay(50,
TimeUnit.MILLISECONDS).until(() -> getSpans().size() == 4);
+ List<Map<String, String>> spans = getSpans();
+ assertEquals(4, spans.size());
+ assertEquals(SpanKind.INTERNAL.name(), spans.get(0).get("kind"));
+ assertEquals("camel-setBody", spans.get(0).get("component"));
+ assertEquals(spans.get(1).get("spanId"), spans.get(0).get("parentId"));
+ assertEquals(SpanKind.INTERNAL.name(), spans.get(1).get("kind"));
+ assertEquals(spans.get(2).get("spanId"), spans.get(1).get("parentId"));
+ assertEquals(SpanKind.CLIENT.name(), spans.get(2).get("kind"));
+ assertEquals(spans.get(3).get("spanId"), spans.get(2).get("parentId"));
+ assertEquals(SpanKind.SERVER.name(), spans.get(3).get("kind"));
+ }
+}
diff --git
a/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/TraceProcessorsTestProfile.java
b/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/TraceProcessorsTestProfile.java
new file mode 100644
index 0000000000..20dfeeb527
--- /dev/null
+++
b/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/TraceProcessorsTestProfile.java
@@ -0,0 +1,28 @@
+/*
+ * 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.quarkus.component.opentelemetry.it;
+
+import java.util.Map;
+
+import io.quarkus.test.junit.QuarkusTestProfile;
+
+public class TraceProcessorsTestProfile implements QuarkusTestProfile {
+ @Override
+ public Map<String, String> getConfigOverrides() {
+ return Map.of("quarkus.camel.opentelemetry.trace-processors", "true");
+ }
+}