You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "squakez (via GitHub)" <gi...@apache.org> on 2026/05/11 10:38:17 UTC
[PR] chore(components): specify custom span nesting in opentelemetry [camel]
squakez opened a new pull request, #23120:
URL: https://github.com/apache/camel/pull/23120
As we have moved the scope only for Processors, any call to the endpoint, which generates an event is not providing the scope. This is needed by custom span to nest the execution under the specific processor. Added some test and documentation to clarify this architecture constraint.
# Description
<!--
- Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
-->
# Target
- [ ] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch)
# Tracking
- [ ] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it).
<!--
# *Note*: trivial changes like, typos, minor documentation fixes and other small items do not require a JIRA issue. In this case your pull request should address just this issue, without pulling in other changes.
-->
# Apache Camel coding standards and style
- [ ] I checked that each commit in the pull request has a meaningful subject line and body.
<!--
If you're unsure, you can format the pull request title like `[CAMEL-XXX] Fixes bug in camel-file component`, where you replace `CAMEL-XXX` with the appropriate JIRA issue.
-->
- [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes.
<!--
You can run the aforementioned command in your module so that the build auto-formats your code. This will also be verified as part of the checks and your PR may be rejected if if there are uncommited changes after running `mvn clean install -DskipTests`.
You can learn more about the contribution guidelines at https://github.com/apache/camel/blob/main/CONTRIBUTING.md
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] chore(components): specify custom span nesting in opentelemetry [camel]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #23120:
URL: https://github.com/apache/camel/pull/23120#discussion_r3224058471
##########
components/camel-opentelemetry2/src/test/java/org/apache/camel/opentelemetry2/SpanToBeanTest.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.opentelemetry2;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import io.opentelemetry.api.trace.Span;
+import io.opentelemetry.api.trace.Tracer;
+import io.opentelemetry.sdk.trace.data.SpanData;
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.opentelemetry2.CamelOpenTelemetryExtension.OtelTrace;
+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 SpanToBeanTest extends OpenTelemetryTracerTestSupport {
+
+ Tracer tracer = otelExtension.getOpenTelemetry().getTracer("spanInjection");
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ OpenTelemetryTracer tst = new OpenTelemetryTracer();
+ tst.setTracer(tracer);
+ tst.setContextPropagators(otelExtension.getOpenTelemetry().getPropagators());
+ CamelContext context = super.createCamelContext();
+ CamelContextAware.trySetCamelContext(tst, context);
+ tst.init(context);
+ return context;
+ }
+
+ @Test
+ void testRouteSingleRequest() throws IOException {
+ template.sendBody("direct:start", "my-body");
+ 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(8, spans.size());
+ SpanData testProducer = spans.get(0);
+ SpanData direct = spans.get(1);
+ SpanData innerLog = spans.get(2);
+ SpanData beanTo = spans.get(3);
+ SpanData beanProcessor = spans.get(4);
+ SpanData beanMethod = spans.get(5);
+ SpanData log = spans.get(6);
+ SpanData innerToLog = spans.get(7);
+
+ // Validate span completion
+ assertTrue(testProducer.hasEnded());
+ assertTrue(direct.hasEnded());
+ assertTrue(innerLog.hasEnded());
+ assertTrue(beanProcessor.hasEnded());
Review Comment:
`beanTo` is declared on line 66 but its completion is not validated here — all other 7 spans are checked. Looks like an oversight.
```suggestion
assertTrue(beanTo.hasEnded());
assertTrue(beanProcessor.hasEnded());
```
##########
components/camel-opentelemetry2/src/test/java/org/apache/camel/opentelemetry2/SpanToBeanTest.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.opentelemetry2;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import io.opentelemetry.api.trace.Span;
+import io.opentelemetry.api.trace.Tracer;
+import io.opentelemetry.sdk.trace.data.SpanData;
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.opentelemetry2.CamelOpenTelemetryExtension.OtelTrace;
+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 SpanToBeanTest extends OpenTelemetryTracerTestSupport {
+
+ Tracer tracer = otelExtension.getOpenTelemetry().getTracer("spanInjection");
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ OpenTelemetryTracer tst = new OpenTelemetryTracer();
+ tst.setTracer(tracer);
+ tst.setContextPropagators(otelExtension.getOpenTelemetry().getPropagators());
+ CamelContext context = super.createCamelContext();
+ CamelContextAware.trySetCamelContext(tst, context);
+ tst.init(context);
+ return context;
+ }
+
+ @Test
+ void testRouteSingleRequest() throws IOException {
+ template.sendBody("direct:start", "my-body");
+ 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(8, spans.size());
+ SpanData testProducer = spans.get(0);
+ SpanData direct = spans.get(1);
+ SpanData innerLog = spans.get(2);
+ SpanData beanTo = spans.get(3);
+ SpanData beanProcessor = spans.get(4);
+ SpanData beanMethod = spans.get(5);
+ SpanData log = spans.get(6);
+ SpanData innerToLog = spans.get(7);
+
+ // Validate span completion
+ assertTrue(testProducer.hasEnded());
+ assertTrue(direct.hasEnded());
+ assertTrue(innerLog.hasEnded());
+ assertTrue(beanProcessor.hasEnded());
+ assertTrue(beanMethod.hasEnded());
+ assertTrue(log.hasEnded());
+ assertTrue(innerToLog.hasEnded());
+
+ // Validate same trace
+ assertEquals(testProducer.getSpanContext().getTraceId(), direct.getSpanContext().getTraceId());
+ assertEquals(testProducer.getSpanContext().getTraceId(), innerLog.getSpanContext().getTraceId());
+ assertEquals(testProducer.getSpanContext().getTraceId(), beanTo.getSpanContext().getTraceId());
+ assertEquals(testProducer.getSpanContext().getTraceId(), beanProcessor.getSpanContext().getTraceId());
+ assertEquals(testProducer.getSpanContext().getTraceId(), beanMethod.getSpanContext().getTraceId());
+ assertEquals(testProducer.getSpanContext().getTraceId(), log.getSpanContext().getTraceId());
+ assertEquals(testProducer.getSpanContext().getTraceId(), innerToLog.getSpanContext().getTraceId());
+
+ // Validate hierarchy
+ assertFalse(testProducer.getParentSpanContext().isValid());
+
+ assertEquals(testProducer.getSpanContext().getSpanId(), direct.getParentSpanContext().getSpanId());
+ assertEquals(direct.getSpanContext().getSpanId(), innerLog.getParentSpanContext().getSpanId());
+ assertEquals(direct.getSpanContext().getSpanId(), beanTo.getParentSpanContext().getSpanId());
+ assertEquals(beanTo.getSpanContext().getSpanId(), beanProcessor.getParentSpanContext().getSpanId());
+ // NOTE: the bean method belongs to the component ("to") node.
+ assertEquals(beanTo.getSpanContext().getSpanId(), beanMethod.getParentSpanContext().getSpanId());
+ assertEquals(direct.getSpanContext().getSpanId(), log.getParentSpanContext().getSpanId());
+ assertEquals(log.getSpanContext().getSpanId(), innerToLog.getParentSpanContext().getSpanId());
+ }
+
+ @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")
+ .to("bean:myBean")
+ .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() {
+ Span mySpan = tracer.spanBuilder("helloworld").startSpan();
+ System.out.println("*** " + mySpan);
Review Comment:
Looks like leftover debug output — please remove.
```suggestion
```
##########
components/camel-telemetry/src/test/java/org/apache/camel/telemetry/SpanToBeanTest.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.telemetry;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+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.telemetry.mock.MockSpanAdapter;
+import org.apache.camel.telemetry.mock.MockTrace;
+import org.apache.camel.telemetry.mock.MockTracer;
+import org.apache.camel.test.junit6.ExchangeTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+public class SpanToBeanTest extends ExchangeTestSupport {
+
+ MockTracer mockTracer;
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ this.mockTracer = new MockTracer();
+ CamelContextAware.trySetCamelContext(mockTracer, context);
+ mockTracer.init(context);
+ return context;
+ }
+
+ @Test
+ void testProcessorsTraceRequest() {
+ template.sendBody("direct:start", "my-body");
+ Map<String, MockTrace> traces = mockTracer.traces();
+ assertEquals(1, traces.size());
+ checkTrace(traces.values().iterator().next());
+ }
+
+ private void checkTrace(MockTrace trace) {
+ List<Span> spans = trace.spans();
+ assertEquals(8, spans.size());
+ // Cast to implementation object to be able to
+ // inspect the status of the Span.
+ MockSpanAdapter testProducer = (MockSpanAdapter) spans.get(0);
+ MockSpanAdapter direct = (MockSpanAdapter) spans.get(1);
+ MockSpanAdapter innerLog = (MockSpanAdapter) spans.get(2);
+ MockSpanAdapter toBean = (MockSpanAdapter) spans.get(3);
+ MockSpanAdapter bean = (MockSpanAdapter) spans.get(4);
+ MockSpanAdapter beanMethod = (MockSpanAdapter) spans.get(5);
+ MockSpanAdapter log = (MockSpanAdapter) spans.get(6);
+ MockSpanAdapter innerToLog = (MockSpanAdapter) spans.get(7);
+
+ // Validate span completion
+ assertEquals("true", testProducer.getTag("isDone"));
+ assertEquals("true", direct.getTag("isDone"));
+ assertEquals("true", innerLog.getTag("isDone"));
+ assertEquals("true", toBean.getTag("isDone"));
+ assertEquals("true", bean.getTag("isDone"));
+ assertEquals("true", beanMethod.getTag("isDone"));
+ assertEquals("true", log.getTag("isDone"));
+ assertEquals("true", innerToLog.getTag("isDone"));
+
+ // Validate same trace
+ assertEquals(testProducer.getTag("traceid"), direct.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), innerLog.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), log.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), toBean.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), bean.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), beanMethod.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), innerToLog.getTag("traceid"));
+
+ // Validate op
+ assertEquals(Op.EVENT_RECEIVED.toString(), direct.getTag("op"));
+
+ // Validate hierarchy
+ assertNull(testProducer.getTag("parentSpan"));
+ assertEquals(testProducer.getTag("spanid"), direct.getTag("parentSpan"));
+ assertEquals(direct.getTag("spanid"), innerLog.getTag("parentSpan"));
+ assertEquals(direct.getTag("spanid"), log.getTag("parentSpan"));
+ assertEquals(direct.getTag("spanid"), toBean.getTag("parentSpan"));
+ assertEquals(toBean.getTag("spanid"), bean.getTag("parentSpan"));
+ assertEquals(bean.getTag("spanid"), beanMethod.getTag("parentSpan"));
+ assertEquals(log.getTag("spanid"), innerToLog.getTag("parentSpan"));
+
+ // Validate operations
+ assertEquals(Op.EVENT_SENT.toString(), testProducer.getTag("op"));
+ assertEquals(Op.EVENT_RECEIVED.toString(), direct.getTag("op"));
+
+ // Validate message logging
+ assertEquals("A message", innerLog.logEntries().get(0).fields().get("message"));
+ assertEquals(
+ "Exchange[ExchangePattern: InOnly, BodyType: String, Body: my-body]",
+ innerToLog.logEntries().get(0).fields().get("message"));
+ }
+
+ @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")
+ .to("bean:myBean")
+ .process(new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader("operation", "fake");
+ }
+ })
Review Comment:
Nit: this `.process(...)` step is present in the telemetry test but absent from the otel2 equivalent. It doesn't produce a span and only sets a header that isn't asserted anywhere. Removing it would keep the routes identical across modules and make the behavioral difference (span nesting) easier to compare side-by-side.
##########
components/camel-telemetry/src/test/java/org/apache/camel/telemetry/SpanToBeanTest.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.telemetry;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+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.telemetry.mock.MockSpanAdapter;
+import org.apache.camel.telemetry.mock.MockTrace;
+import org.apache.camel.telemetry.mock.MockTracer;
+import org.apache.camel.test.junit6.ExchangeTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+public class SpanToBeanTest extends ExchangeTestSupport {
+
+ MockTracer mockTracer;
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ this.mockTracer = new MockTracer();
+ CamelContextAware.trySetCamelContext(mockTracer, context);
+ mockTracer.init(context);
+ return context;
+ }
+
+ @Test
+ void testProcessorsTraceRequest() {
+ template.sendBody("direct:start", "my-body");
+ Map<String, MockTrace> traces = mockTracer.traces();
+ assertEquals(1, traces.size());
+ checkTrace(traces.values().iterator().next());
+ }
+
+ private void checkTrace(MockTrace trace) {
+ List<Span> spans = trace.spans();
+ assertEquals(8, spans.size());
+ // Cast to implementation object to be able to
+ // inspect the status of the Span.
+ MockSpanAdapter testProducer = (MockSpanAdapter) spans.get(0);
+ MockSpanAdapter direct = (MockSpanAdapter) spans.get(1);
+ MockSpanAdapter innerLog = (MockSpanAdapter) spans.get(2);
+ MockSpanAdapter toBean = (MockSpanAdapter) spans.get(3);
+ MockSpanAdapter bean = (MockSpanAdapter) spans.get(4);
+ MockSpanAdapter beanMethod = (MockSpanAdapter) spans.get(5);
+ MockSpanAdapter log = (MockSpanAdapter) spans.get(6);
+ MockSpanAdapter innerToLog = (MockSpanAdapter) spans.get(7);
+
+ // Validate span completion
+ assertEquals("true", testProducer.getTag("isDone"));
+ assertEquals("true", direct.getTag("isDone"));
+ assertEquals("true", innerLog.getTag("isDone"));
+ assertEquals("true", toBean.getTag("isDone"));
+ assertEquals("true", bean.getTag("isDone"));
+ assertEquals("true", beanMethod.getTag("isDone"));
+ assertEquals("true", log.getTag("isDone"));
+ assertEquals("true", innerToLog.getTag("isDone"));
+
+ // Validate same trace
+ assertEquals(testProducer.getTag("traceid"), direct.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), innerLog.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), log.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), toBean.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), bean.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), beanMethod.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), innerToLog.getTag("traceid"));
+
+ // Validate op
+ assertEquals(Op.EVENT_RECEIVED.toString(), direct.getTag("op"));
+
+ // Validate hierarchy
+ assertNull(testProducer.getTag("parentSpan"));
+ assertEquals(testProducer.getTag("spanid"), direct.getTag("parentSpan"));
+ assertEquals(direct.getTag("spanid"), innerLog.getTag("parentSpan"));
+ assertEquals(direct.getTag("spanid"), log.getTag("parentSpan"));
+ assertEquals(direct.getTag("spanid"), toBean.getTag("parentSpan"));
+ assertEquals(toBean.getTag("spanid"), bean.getTag("parentSpan"));
+ assertEquals(bean.getTag("spanid"), beanMethod.getTag("parentSpan"));
Review Comment:
Nit: this asserts `beanMethod` is parented to the **bean processor** span, while the equivalent assertion in `camel-opentelemetry2` `SpanToBeanTest` (line 98) asserts the parent is the **endpoint** span (`beanTo`).
The difference is because the mock here explicitly reads the parent from exchange storage (`SpanStorageManagerExchange().peek(exchange)` → gets the processor), whereas the otel2 test uses implicit OTel context propagation (→ gets the endpoint scope). This is actually the core behavioral difference the documentation describes.
A short comment here noting *why* the hierarchy differs from the otel2 test would help future readers who compare the two.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] chore(components): specify custom span nesting in opentelemetry [camel]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #23120:
URL: https://github.com/apache/camel/pull/23120#issuecomment-4420382096
:star2: Thank you for your contribution to the Apache Camel project! :star2:
:robot: CI automation will test this PR automatically.
:camel: Apache Camel Committers, please review the following items:
* First-time contributors **require MANUAL approval** for the GitHub Actions to run
* You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot although they are normally detected and executed by CI.
* You can label PRs using `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
* Build and test logs are available in the summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary.
:warning: Be careful when sharing logs. Review their contents before sharing them publicly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] chore(components): specify custom span nesting in opentelemetry [camel]
Posted by "squakez (via GitHub)" <gi...@apache.org>.
squakez commented on PR #23120:
URL: https://github.com/apache/camel/pull/23120#issuecomment-4419870464
@davsclaus @oscerd I need you to please have a look at this one. Please, advise if the documentation explaining the design constraint is wrong or should be reworded.
Also, I wonder if this analysis is overlooking something. I understand that when we configure, for example, a bean to be called as an endpoint, then, the execution "converts" it as an event. Is there any possibility to have it as a regular processor and make the otel component to intercept it in the "InterceptStrategy" instead?
Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] chore(components): specify custom span nesting in opentelemetry [camel]
Posted by "squakez (via GitHub)" <gi...@apache.org>.
squakez commented on code in PR #23120:
URL: https://github.com/apache/camel/pull/23120#discussion_r3224560634
##########
components/camel-telemetry/src/test/java/org/apache/camel/telemetry/SpanToBeanTest.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.telemetry;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+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.telemetry.mock.MockSpanAdapter;
+import org.apache.camel.telemetry.mock.MockTrace;
+import org.apache.camel.telemetry.mock.MockTracer;
+import org.apache.camel.test.junit6.ExchangeTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+public class SpanToBeanTest extends ExchangeTestSupport {
+
+ MockTracer mockTracer;
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ this.mockTracer = new MockTracer();
+ CamelContextAware.trySetCamelContext(mockTracer, context);
+ mockTracer.init(context);
+ return context;
+ }
+
+ @Test
+ void testProcessorsTraceRequest() {
+ template.sendBody("direct:start", "my-body");
+ Map<String, MockTrace> traces = mockTracer.traces();
+ assertEquals(1, traces.size());
+ checkTrace(traces.values().iterator().next());
+ }
+
+ private void checkTrace(MockTrace trace) {
+ List<Span> spans = trace.spans();
+ assertEquals(8, spans.size());
+ // Cast to implementation object to be able to
+ // inspect the status of the Span.
+ MockSpanAdapter testProducer = (MockSpanAdapter) spans.get(0);
+ MockSpanAdapter direct = (MockSpanAdapter) spans.get(1);
+ MockSpanAdapter innerLog = (MockSpanAdapter) spans.get(2);
+ MockSpanAdapter toBean = (MockSpanAdapter) spans.get(3);
+ MockSpanAdapter bean = (MockSpanAdapter) spans.get(4);
+ MockSpanAdapter beanMethod = (MockSpanAdapter) spans.get(5);
+ MockSpanAdapter log = (MockSpanAdapter) spans.get(6);
+ MockSpanAdapter innerToLog = (MockSpanAdapter) spans.get(7);
+
+ // Validate span completion
+ assertEquals("true", testProducer.getTag("isDone"));
+ assertEquals("true", direct.getTag("isDone"));
+ assertEquals("true", innerLog.getTag("isDone"));
+ assertEquals("true", toBean.getTag("isDone"));
+ assertEquals("true", bean.getTag("isDone"));
+ assertEquals("true", beanMethod.getTag("isDone"));
+ assertEquals("true", log.getTag("isDone"));
+ assertEquals("true", innerToLog.getTag("isDone"));
+
+ // Validate same trace
+ assertEquals(testProducer.getTag("traceid"), direct.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), innerLog.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), log.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), toBean.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), bean.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), beanMethod.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), innerToLog.getTag("traceid"));
+
+ // Validate op
+ assertEquals(Op.EVENT_RECEIVED.toString(), direct.getTag("op"));
+
+ // Validate hierarchy
+ assertNull(testProducer.getTag("parentSpan"));
+ assertEquals(testProducer.getTag("spanid"), direct.getTag("parentSpan"));
+ assertEquals(direct.getTag("spanid"), innerLog.getTag("parentSpan"));
+ assertEquals(direct.getTag("spanid"), log.getTag("parentSpan"));
+ assertEquals(direct.getTag("spanid"), toBean.getTag("parentSpan"));
+ assertEquals(toBean.getTag("spanid"), bean.getTag("parentSpan"));
+ assertEquals(bean.getTag("spanid"), beanMethod.getTag("parentSpan"));
+ assertEquals(log.getTag("spanid"), innerToLog.getTag("parentSpan"));
+
+ // Validate operations
+ assertEquals(Op.EVENT_SENT.toString(), testProducer.getTag("op"));
+ assertEquals(Op.EVENT_RECEIVED.toString(), direct.getTag("op"));
+
+ // Validate message logging
+ assertEquals("A message", innerLog.logEntries().get(0).fields().get("message"));
+ assertEquals(
+ "Exchange[ExchangePattern: InOnly, BodyType: String, Body: my-body]",
+ innerToLog.logEntries().get(0).fields().get("message"));
+ }
+
+ @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")
+ .to("bean:myBean")
+ .process(new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader("operation", "fake");
+ }
+ })
Review Comment:
It's on purpose. We are excluding by default the custom processors, reason why a span is not generated. I will include the process in the otel2 test as well to make it even.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] chore(components): specify custom span nesting in opentelemetry [camel]
Posted by "squakez (via GitHub)" <gi...@apache.org>.
squakez merged PR #23120:
URL: https://github.com/apache/camel/pull/23120
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] chore(components): specify custom span nesting in opentelemetry [camel]
Posted by "squakez (via GitHub)" <gi...@apache.org>.
squakez commented on code in PR #23120:
URL: https://github.com/apache/camel/pull/23120#discussion_r3224553738
##########
components/camel-telemetry/src/test/java/org/apache/camel/telemetry/SpanToBeanTest.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.telemetry;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+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.telemetry.mock.MockSpanAdapter;
+import org.apache.camel.telemetry.mock.MockTrace;
+import org.apache.camel.telemetry.mock.MockTracer;
+import org.apache.camel.test.junit6.ExchangeTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+public class SpanToBeanTest extends ExchangeTestSupport {
+
+ MockTracer mockTracer;
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ this.mockTracer = new MockTracer();
+ CamelContextAware.trySetCamelContext(mockTracer, context);
+ mockTracer.init(context);
+ return context;
+ }
+
+ @Test
+ void testProcessorsTraceRequest() {
+ template.sendBody("direct:start", "my-body");
+ Map<String, MockTrace> traces = mockTracer.traces();
+ assertEquals(1, traces.size());
+ checkTrace(traces.values().iterator().next());
+ }
+
+ private void checkTrace(MockTrace trace) {
+ List<Span> spans = trace.spans();
+ assertEquals(8, spans.size());
+ // Cast to implementation object to be able to
+ // inspect the status of the Span.
+ MockSpanAdapter testProducer = (MockSpanAdapter) spans.get(0);
+ MockSpanAdapter direct = (MockSpanAdapter) spans.get(1);
+ MockSpanAdapter innerLog = (MockSpanAdapter) spans.get(2);
+ MockSpanAdapter toBean = (MockSpanAdapter) spans.get(3);
+ MockSpanAdapter bean = (MockSpanAdapter) spans.get(4);
+ MockSpanAdapter beanMethod = (MockSpanAdapter) spans.get(5);
+ MockSpanAdapter log = (MockSpanAdapter) spans.get(6);
+ MockSpanAdapter innerToLog = (MockSpanAdapter) spans.get(7);
+
+ // Validate span completion
+ assertEquals("true", testProducer.getTag("isDone"));
+ assertEquals("true", direct.getTag("isDone"));
+ assertEquals("true", innerLog.getTag("isDone"));
+ assertEquals("true", toBean.getTag("isDone"));
+ assertEquals("true", bean.getTag("isDone"));
+ assertEquals("true", beanMethod.getTag("isDone"));
+ assertEquals("true", log.getTag("isDone"));
+ assertEquals("true", innerToLog.getTag("isDone"));
+
+ // Validate same trace
+ assertEquals(testProducer.getTag("traceid"), direct.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), innerLog.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), log.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), toBean.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), bean.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), beanMethod.getTag("traceid"));
+ assertEquals(testProducer.getTag("traceid"), innerToLog.getTag("traceid"));
+
+ // Validate op
+ assertEquals(Op.EVENT_RECEIVED.toString(), direct.getTag("op"));
+
+ // Validate hierarchy
+ assertNull(testProducer.getTag("parentSpan"));
+ assertEquals(testProducer.getTag("spanid"), direct.getTag("parentSpan"));
+ assertEquals(direct.getTag("spanid"), innerLog.getTag("parentSpan"));
+ assertEquals(direct.getTag("spanid"), log.getTag("parentSpan"));
+ assertEquals(direct.getTag("spanid"), toBean.getTag("parentSpan"));
+ assertEquals(toBean.getTag("spanid"), bean.getTag("parentSpan"));
+ assertEquals(bean.getTag("spanid"), beanMethod.getTag("parentSpan"));
Review Comment:
I don't think it's needed. It is explained in the otel2 test, where, as we miss the possibility to get properly the scope, the span belongs to the endpoint directly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] chore(components): specify custom span nesting in opentelemetry [camel]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #23120:
URL: https://github.com/apache/camel/pull/23120#issuecomment-4420629172
<!-- ci-tested-modules -->
:test_tube: **CI tested the following changed modules:**
- `components/camel-opentelemetry2`
- `components/camel-telemetry`
<details><summary>All tested modules (12 modules)</summary>
- Camel :: Common Telemetry
- Camel :: JBang :: MCP
- Camel :: JBang :: Plugin :: Route Parser
- Camel :: JBang :: Plugin :: TUI
- Camel :: JBang :: Plugin :: Validate
- Camel :: Launcher :: Container
- Camel :: Micrometer :: Observability 2
- Camel :: Observability Services
- Camel :: Opentelemetry 2
- Camel :: Telemetry :: Dev
- Camel :: YAML DSL :: Validator
- Camel :: YAML DSL :: Validator Maven Plugin
</details>
---
:gear: [View full build and test results](https://github.com/apache/camel/actions/runs/25665123003)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org