Skip to content

Commit 176f5f5

Browse files
committed
Add OpenTelemetry distributed tracing support
New activemq-opentelemetry module that instruments the broker using the OpenTelemetry API. The plugin traces send (PRODUCER), dispatch (CONSUMER), and acknowledge (INTERNAL) operations with W3C TraceContext propagation and standard OTel messaging semantic conventions. Depends on opentelemetry-api only; users bring their own SDK and exporter at runtime. Included in the distribution with example configuration.
1 parent 8ffd468 commit 176f5f5

10 files changed

Lines changed: 809 additions & 0 deletions

File tree

activemq-opentelemetry/pom.xml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<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/maven-v4_0_0.xsd">
19+
20+
<modelVersion>4.0.0</modelVersion>
21+
22+
<parent>
23+
<groupId>org.apache.activemq</groupId>
24+
<artifactId>activemq-parent</artifactId>
25+
<version>6.3.0-SNAPSHOT</version>
26+
</parent>
27+
28+
<artifactId>activemq-opentelemetry</artifactId>
29+
<packaging>bundle</packaging>
30+
<name>ActiveMQ :: OpenTelemetry</name>
31+
<description>ActiveMQ OpenTelemetry tracing support</description>
32+
33+
<dependencies>
34+
35+
<!-- =============================== -->
36+
<!-- Required Dependencies -->
37+
<!-- =============================== -->
38+
<dependency>
39+
<groupId>${project.groupId}</groupId>
40+
<artifactId>activemq-broker</artifactId>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>io.opentelemetry</groupId>
45+
<artifactId>opentelemetry-api</artifactId>
46+
</dependency>
47+
<dependency>
48+
<groupId>io.opentelemetry</groupId>
49+
<artifactId>opentelemetry-context</artifactId>
50+
</dependency>
51+
52+
<!-- =============================== -->
53+
<!-- Testing Dependencies -->
54+
<!-- =============================== -->
55+
<dependency>
56+
<groupId>${project.groupId}</groupId>
57+
<artifactId>activemq-kahadb-store</artifactId>
58+
<scope>test</scope>
59+
</dependency>
60+
<dependency>
61+
<groupId>${project.groupId}</groupId>
62+
<artifactId>activemq-broker</artifactId>
63+
<type>test-jar</type>
64+
<scope>test</scope>
65+
</dependency>
66+
<dependency>
67+
<groupId>io.opentelemetry</groupId>
68+
<artifactId>opentelemetry-sdk-testing</artifactId>
69+
<scope>test</scope>
70+
</dependency>
71+
<dependency>
72+
<groupId>io.opentelemetry</groupId>
73+
<artifactId>opentelemetry-sdk</artifactId>
74+
<scope>test</scope>
75+
</dependency>
76+
<dependency>
77+
<groupId>junit</groupId>
78+
<artifactId>junit</artifactId>
79+
<scope>test</scope>
80+
</dependency>
81+
<dependency>
82+
<groupId>org.apache.logging.log4j</groupId>
83+
<artifactId>log4j-slf4j2-impl</artifactId>
84+
<scope>test</scope>
85+
</dependency>
86+
<dependency>
87+
<groupId>org.apache.logging.log4j</groupId>
88+
<artifactId>log4j-core</artifactId>
89+
<scope>test</scope>
90+
</dependency>
91+
</dependencies>
92+
93+
<build>
94+
<plugins>
95+
<plugin>
96+
<groupId>org.apache.felix</groupId>
97+
<artifactId>maven-bundle-plugin</artifactId>
98+
<extensions>true</extensions>
99+
<configuration>
100+
<instructions>
101+
<Bundle-SymbolicName>org.apache.activemq.opentelemetry</Bundle-SymbolicName>
102+
<Export-Package>org.apache.activemq.broker.util.opentelemetry*;version=${project.version};-noimport:=true;-split-package:=merge-first</Export-Package>
103+
<Import-Package>
104+
org.apache.activemq*;version=${project.version};resolution:=optional,
105+
io.opentelemetry.*;resolution:=optional,
106+
*
107+
</Import-Package>
108+
<_noee>true</_noee>
109+
</instructions>
110+
</configuration>
111+
</plugin>
112+
</plugins>
113+
</build>
114+
115+
</project>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.activemq.broker.util.opentelemetry;
18+
19+
import java.io.IOException;
20+
import java.util.Collections;
21+
22+
import io.opentelemetry.context.propagation.TextMapGetter;
23+
import org.apache.activemq.command.Message;
24+
25+
public class ActiveMQMessageTextMapGetter implements TextMapGetter<Message> {
26+
27+
public static final ActiveMQMessageTextMapGetter INSTANCE = new ActiveMQMessageTextMapGetter();
28+
29+
@Override
30+
public Iterable<String> keys(Message message) {
31+
try {
32+
if (message.getProperties() != null) {
33+
return message.getProperties().keySet();
34+
}
35+
} catch (IOException e) {
36+
// ignore
37+
}
38+
return Collections.emptyList();
39+
}
40+
41+
@Override
42+
public String get(Message message, String key) {
43+
try {
44+
Object value = message.getProperty(key);
45+
if (value instanceof String) {
46+
return (String) value;
47+
}
48+
} catch (IOException e) {
49+
// ignore
50+
}
51+
return null;
52+
}
53+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.activemq.broker.util.opentelemetry;
18+
19+
import java.io.IOException;
20+
21+
import io.opentelemetry.context.propagation.TextMapSetter;
22+
import org.apache.activemq.command.Message;
23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
25+
26+
public class ActiveMQMessageTextMapSetter implements TextMapSetter<Message> {
27+
28+
private static final Logger LOG = LoggerFactory.getLogger(ActiveMQMessageTextMapSetter.class);
29+
30+
public static final ActiveMQMessageTextMapSetter INSTANCE = new ActiveMQMessageTextMapSetter();
31+
32+
@Override
33+
public void set(Message message, String key, String value) {
34+
try {
35+
message.setProperty(key, value);
36+
message.setMarshalledProperties(null);
37+
} catch (IOException e) {
38+
LOG.warn("Failed to set trace context property '{}' on message", key, e);
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)