Skip to content

Commit 765648d

Browse files
jaydelucatrask
andauthored
Add Camel jms test and update metadata (#15027)
Co-authored-by: Trask Stalnaker <[email protected]>
1 parent 26ed070 commit 765648d

File tree

4 files changed

+152
-0
lines changed

4 files changed

+152
-0
lines changed

docs/instrumentation-list.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,7 +2143,14 @@ libraries:
21432143
- name: camel-2.20
21442144
description: |
21452145
This instrumentation enables tracing for Apache Camel 2.x applications by generating spans for each route execution. For Camel versions 3.5 and newer, users should instead use the native 'camel-opentelemetry' component provided directly by the Camel project.
2146+
semantic_conventions:
2147+
- HTTP_CLIENT_SPANS
2148+
- HTTP_SERVER_SPANS
2149+
- DATABASE_CLIENT_SPANS
2150+
- MESSAGING_SPANS
21462151
library_link: https://camel.apache.org/
2152+
features:
2153+
- HTTP_ROUTE
21472154
source_path: instrumentation/camel-2.20
21482155
scope:
21492156
name: io.opentelemetry.camel-2.20
@@ -2173,6 +2180,12 @@ libraries:
21732180
type: LONG
21742181
- name: url.full
21752182
type: STRING
2183+
- span_kind: CONSUMER
2184+
attributes:
2185+
- name: messaging.destination.name
2186+
type: STRING
2187+
- name: messaging.message.id
2188+
type: STRING
21762189
- span_kind: INTERNAL
21772190
attributes:
21782191
- name: http.request.method
@@ -2183,6 +2196,10 @@ libraries:
21832196
type: STRING
21842197
- name: url.full
21852198
type: STRING
2199+
- span_kind: PRODUCER
2200+
attributes:
2201+
- name: messaging.destination.name
2202+
type: STRING
21862203
- span_kind: SERVER
21872204
attributes:
21882205
- name: http.request.method
@@ -2209,6 +2226,14 @@ libraries:
22092226
type: LONG
22102227
- name: url.full
22112228
type: STRING
2229+
- span_kind: CONSUMER
2230+
attributes:
2231+
- name: camel.uri
2232+
type: STRING
2233+
- name: messaging.destination.name
2234+
type: STRING
2235+
- name: messaging.message.id
2236+
type: STRING
22122237
- span_kind: INTERNAL
22132238
attributes:
22142239
- name: camel.uri
@@ -2221,6 +2246,12 @@ libraries:
22212246
type: STRING
22222247
- name: url.full
22232248
type: STRING
2249+
- span_kind: PRODUCER
2250+
attributes:
2251+
- name: camel.uri
2252+
type: STRING
2253+
- name: messaging.destination.name
2254+
type: STRING
22242255
- span_kind: SERVER
22252256
attributes:
22262257
- name: camel.uri
@@ -2247,6 +2278,12 @@ libraries:
22472278
type: LONG
22482279
- name: url.full
22492280
type: STRING
2281+
- span_kind: CONSUMER
2282+
attributes:
2283+
- name: messaging.destination.name
2284+
type: STRING
2285+
- name: messaging.message.id
2286+
type: STRING
22502287
- span_kind: INTERNAL
22512288
attributes:
22522289
- name: http.request.method
@@ -2257,6 +2294,10 @@ libraries:
22572294
type: STRING
22582295
- name: url.full
22592296
type: STRING
2297+
- span_kind: PRODUCER
2298+
attributes:
2299+
- name: messaging.destination.name
2300+
type: STRING
22602301
- span_kind: SERVER
22612302
attributes:
22622303
- name: http.request.method

instrumentation/camel-2.20/javaagent/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ dependencies {
4343
testImplementation("org.apache.camel:camel-undertow:$camelversion")
4444
testImplementation("org.apache.camel:camel-aws:$camelversion")
4545
testImplementation("org.apache.camel:camel-cassandraql:$camelversion")
46+
testImplementation("org.apache.camel:camel-jms:$camelversion")
47+
testImplementation("org.apache.activemq:activemq-broker:5.16.5")
4648

4749
testImplementation("org.springframework.boot:spring-boot-starter-test:1.5.17.RELEASE")
4850
testImplementation("org.springframework.boot:spring-boot-starter:1.5.17.RELEASE")
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.apachecamel;
7+
8+
import static io.opentelemetry.api.common.AttributeKey.stringKey;
9+
import static io.opentelemetry.javaagent.instrumentation.apachecamel.ExperimentalTest.experimental;
10+
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
11+
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
12+
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME;
13+
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_MESSAGE_ID;
14+
15+
import io.opentelemetry.api.trace.SpanKind;
16+
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
17+
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
18+
import javax.jms.ConnectionFactory;
19+
import org.apache.activemq.ActiveMQConnectionFactory;
20+
import org.apache.activemq.broker.BrokerService;
21+
import org.apache.camel.CamelContext;
22+
import org.apache.camel.ProducerTemplate;
23+
import org.apache.camel.builder.RouteBuilder;
24+
import org.apache.camel.component.jms.JmsComponent;
25+
import org.apache.camel.impl.DefaultCamelContext;
26+
import org.junit.jupiter.api.AfterAll;
27+
import org.junit.jupiter.api.BeforeAll;
28+
import org.junit.jupiter.api.Test;
29+
import org.junit.jupiter.api.extension.RegisterExtension;
30+
31+
class JmsCamelTest {
32+
33+
@RegisterExtension
34+
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
35+
36+
private static BrokerService broker;
37+
private static CamelContext camelContext;
38+
39+
@BeforeAll
40+
static void setUp() throws Exception {
41+
broker = new BrokerService();
42+
broker.setPersistent(false);
43+
broker.setUseJmx(false);
44+
broker.addConnector("vm://localhost");
45+
broker.start();
46+
47+
camelContext = new DefaultCamelContext();
48+
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
49+
camelContext.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
50+
51+
camelContext.addRoutes(
52+
new RouteBuilder() {
53+
@Override
54+
public void configure() {
55+
from("direct:input").to("jms:queue:testQueue");
56+
from("jms:queue:testQueue").to("mock:result");
57+
}
58+
});
59+
60+
camelContext.start();
61+
testing.clearData();
62+
}
63+
64+
@AfterAll
65+
static void tearDown() throws Exception {
66+
if (camelContext != null) {
67+
camelContext.stop();
68+
}
69+
if (broker != null) {
70+
broker.stop();
71+
}
72+
}
73+
74+
@Test
75+
void testJmsProducerAndConsumer() {
76+
ProducerTemplate template = camelContext.createProducerTemplate();
77+
template.sendBody("direct:input", "test message");
78+
79+
testing.waitAndAssertTraces(
80+
trace ->
81+
trace.hasSpansSatisfyingExactly(
82+
span -> span.hasName("input").hasKind(SpanKind.INTERNAL).hasNoParent(),
83+
span ->
84+
span.hasName("queue:testQueue")
85+
.hasKind(SpanKind.PRODUCER)
86+
.hasParent(trace.getSpan(0))
87+
.hasAttributesSatisfyingExactly(
88+
equalTo(MESSAGING_DESTINATION_NAME, "queue:testQueue"),
89+
equalTo(stringKey("camel.uri"), experimental("jms://queue:testQueue"))),
90+
span ->
91+
span.hasName("queue:testQueue")
92+
.hasKind(SpanKind.CONSUMER)
93+
.hasParent(trace.getSpan(1))
94+
.hasAttributesSatisfyingExactly(
95+
equalTo(MESSAGING_DESTINATION_NAME, "queue:testQueue"),
96+
equalTo(stringKey("camel.uri"), experimental("jms://queue:testQueue")),
97+
satisfies(
98+
MESSAGING_MESSAGE_ID,
99+
stringAssert -> stringAssert.isInstanceOf(String.class))),
100+
span -> span.hasName("mock").hasKind(SpanKind.CLIENT).hasParent(trace.getSpan(2))));
101+
}
102+
}

instrumentation/camel-2.20/metadata.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ description: >
22
This instrumentation enables tracing for Apache Camel 2.x applications by generating spans for
33
each route execution. For Camel versions 3.5 and newer, users should instead use the native
44
'camel-opentelemetry' component provided directly by the Camel project.
5+
semantic_conventions:
6+
- HTTP_CLIENT_SPANS
7+
- HTTP_SERVER_SPANS
8+
- DATABASE_CLIENT_SPANS
9+
- MESSAGING_SPANS
10+
features:
11+
- HTTP_ROUTE
512
library_link: https://camel.apache.org/
613
configurations:
714
- name: otel.instrumentation.camel.experimental-span-attributes

0 commit comments

Comments
 (0)