You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/03/14 14:04:22 UTC
camel git commit: Add messaging span decorators
Repository: camel
Updated Branches:
refs/heads/master 3e56a4f2a -> 689d3c8f0
Add messaging span decorators
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/689d3c8f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/689d3c8f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/689d3c8f
Branch: refs/heads/master
Commit: 689d3c8f09e60e9d18af29f5ea8dcf68fe7daf8f
Parents: 3e56a4f
Author: Gary Brown <ga...@brownuk.com>
Authored: Fri Mar 10 15:40:12 2017 +0000
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 14 15:02:28 2017 +0100
----------------------------------------------------------------------
.../camel/opentracing/OpenTracingTracer.java | 4 +-
.../apache/camel/opentracing/SpanDecorator.java | 16 ++++
.../AbstractMessagingSpanDecorator.java | 76 ++++++++++++++++
.../decorators/AbstractSpanDecorator.java | 27 ++++++
.../decorators/AmqpSpanDecorator.java | 26 ++++++
.../decorators/AwsSnsSpanDecorator.java | 35 +++++++
.../decorators/AwsSqsSpanDecorator.java | 35 +++++++
.../decorators/CometdSpanDecorator.java | 37 ++++++++
.../decorators/CometdsSpanDecorator.java | 26 ++++++
.../decorators/IronmqSpanDecorator.java | 35 +++++++
.../decorators/JmsSpanDecorator.java | 35 +++++++
.../decorators/KafkaSpanDecorator.java | 82 +++++++++++++++++
.../decorators/MongoDBSpanDecorator.java | 17 ----
.../decorators/MqttSpanDecorator.java | 46 ++++++++++
.../decorators/PahoSpanDecorator.java | 26 ++++++
.../decorators/RabbitmqSpanDecorator.java | 39 ++++++++
.../decorators/SjmsSpanDecorator.java | 26 ++++++
.../org.apache.camel.opentracing.SpanDecorator | 12 +++
.../AbstractMessagingSpanDecoratorTest.java | 96 ++++++++++++++++++++
.../decorators/AwsSnsSpanDecoratorTest.java | 42 +++++++++
.../decorators/AwsSqsSpanDecoratorTest.java | 42 +++++++++
.../decorators/CometdSpanDecoratorTest.java | 37 ++++++++
.../decorators/IronmqSpanDecoratorTest.java | 42 +++++++++
.../decorators/JmsSpanDecoratorTest.java | 42 +++++++++
.../decorators/KafkaSpanDecoratorTest.java | 92 +++++++++++++++++++
.../decorators/MqttSpanDecoratorTest.java | 60 ++++++++++++
.../decorators/RabbitmqSpanDecoratorTest.java | 41 +++++++++
27 files changed, 1075 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/OpenTracingTracer.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/OpenTracingTracer.java b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/OpenTracingTracer.java
index 9a3e34e..6f709f2 100644
--- a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/OpenTracingTracer.java
+++ b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/OpenTracingTracer.java
@@ -167,7 +167,7 @@ public class OpenTracingTracer extends ServiceSupport implements RoutePolicyFact
SpanManager.ManagedSpan parent = spanManager.current();
SpanDecorator sd = getSpanDecorator(ese.getEndpoint());
SpanBuilder spanBuilder = tracer.buildSpan(sd.getOperationName(ese.getExchange(), ese.getEndpoint()))
- .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);
+ .withTag(Tags.SPAN_KIND.getKey(), sd.getInitiatorSpanKind());
// Temporary workaround to avoid adding 'null' span as a parent
if (parent != null && parent.getSpan() != null) {
spanBuilder.asChildOf(parent.getSpan());
@@ -216,7 +216,7 @@ public class OpenTracingTracer extends ServiceSupport implements RoutePolicyFact
Span span = tracer.buildSpan(sd.getOperationName(exchange, route.getEndpoint()))
.asChildOf(tracer.extract(Format.Builtin.TEXT_MAP,
new CamelHeadersExtractAdapter(exchange.getIn().getHeaders())))
- .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
+ .withTag(Tags.SPAN_KIND.getKey(), sd.getReceiverSpanKind())
.start();
sd.pre(span, exchange, route.getEndpoint());
spanManager.activate(span);
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/SpanDecorator.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/SpanDecorator.java b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/SpanDecorator.java
index 1ffeac2..5d0445a 100644
--- a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/SpanDecorator.java
+++ b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/SpanDecorator.java
@@ -76,4 +76,20 @@ public interface SpanDecorator {
*/
void post(Span span, Exchange exchange, Endpoint endpoint);
+ /**
+ * This method returns the 'span.kind' value for use when the component
+ * is initiating a communication.
+ *
+ * @return The kind
+ */
+ String getInitiatorSpanKind();
+
+ /**
+ * This method returns the 'span.kind' value for use when the component
+ * is receiving a communication.
+ *
+ * @return The kind
+ */
+ String getReceiverSpanKind();
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AbstractMessagingSpanDecorator.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AbstractMessagingSpanDecorator.java b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AbstractMessagingSpanDecorator.java
new file mode 100644
index 0000000..25c8377
--- /dev/null
+++ b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AbstractMessagingSpanDecorator.java
@@ -0,0 +1,76 @@
+/**
+ * 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.opentracing.decorators;
+
+import io.opentracing.Span;
+import io.opentracing.tag.Tags;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+
+public abstract class AbstractMessagingSpanDecorator extends AbstractSpanDecorator {
+
+ public static final String MESSAGE_BUS_ID = "message_bus.id";
+
+ @Override
+ public String getOperationName(Exchange exchange, Endpoint endpoint) {
+ // Use the destination name
+ return getDestination(exchange, endpoint);
+ }
+
+ @Override
+ public void pre(Span span, Exchange exchange, Endpoint endpoint) {
+ super.pre(span, exchange, endpoint);
+
+ span.setTag(Tags.MESSAGE_BUS_DESTINATION.getKey(), getDestination(exchange, endpoint));
+
+ String messageId = (String)getMessageId(exchange);
+ if (messageId != null) {
+ span.setTag(MESSAGE_BUS_ID, messageId);
+ }
+ }
+
+ /**
+ * This method identifies the destination from the supplied exchange and/or endpoint.
+ *
+ * @param exchange The exchange
+ * @param endpoint The endpoint
+ * @return The message bus destination
+ */
+ protected String getDestination(Exchange exchange, Endpoint endpoint) {
+ return stripSchemeAndOptions(endpoint);
+ }
+
+ @Override
+ public String getInitiatorSpanKind() {
+ return "producer";
+ }
+
+ @Override
+ public String getReceiverSpanKind() {
+ return "consumer";
+ }
+
+ /**
+ * This method identifies the message id for the messaging exchange.
+ *
+ * @return The message id, or null if no id exists for the exchange
+ */
+ protected String getMessageId(Exchange exchange) {
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AbstractSpanDecorator.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AbstractSpanDecorator.java b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AbstractSpanDecorator.java
index b87238b..55efc4c 100644
--- a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AbstractSpanDecorator.java
+++ b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AbstractSpanDecorator.java
@@ -17,6 +17,7 @@
package org.apache.camel.opentracing.decorators;
import java.net.URI;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -84,4 +85,30 @@ public abstract class AbstractSpanDecorator implements SpanDecorator {
}
}
+ @Override
+ public String getInitiatorSpanKind() {
+ return Tags.SPAN_KIND_CLIENT;
+ }
+
+ @Override
+ public String getReceiverSpanKind() {
+ return Tags.SPAN_KIND_SERVER;
+ }
+
+ public static Map<String, String> toQueryParameters(String uri) {
+ int index = uri.indexOf('?');
+ if (index != -1) {
+ String queryString = uri.substring(index + 1);
+ Map<String, String> map = new HashMap<>();
+ for (String param : queryString.split("&")) {
+ String[] parts = param.split("=");
+ if (parts.length == 2) {
+ map.put(parts[0], parts[1]);
+ }
+ }
+ return map;
+ }
+ return Collections.emptyMap();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AmqpSpanDecorator.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AmqpSpanDecorator.java b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AmqpSpanDecorator.java
new file mode 100644
index 0000000..bce692e
--- /dev/null
+++ b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AmqpSpanDecorator.java
@@ -0,0 +1,26 @@
+/**
+ * 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.opentracing.decorators;
+
+public class AmqpSpanDecorator extends AbstractMessagingSpanDecorator {
+
+ @Override
+ public String getComponent() {
+ return "amqp";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AwsSnsSpanDecorator.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AwsSnsSpanDecorator.java b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AwsSnsSpanDecorator.java
new file mode 100644
index 0000000..acf608b
--- /dev/null
+++ b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AwsSnsSpanDecorator.java
@@ -0,0 +1,35 @@
+/**
+ * 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.opentracing.decorators;
+
+import org.apache.camel.Exchange;
+
+public class AwsSnsSpanDecorator extends AbstractMessagingSpanDecorator {
+
+ public static final String CAMEL_AWS_SNS_MESSAGE_ID = "CamelAwsSnsMessageId";
+
+ @Override
+ public String getComponent() {
+ return "aws-sns";
+ }
+
+ @Override
+ protected String getMessageId(Exchange exchange) {
+ return (String)exchange.getIn().getHeader(CAMEL_AWS_SNS_MESSAGE_ID);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AwsSqsSpanDecorator.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AwsSqsSpanDecorator.java b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AwsSqsSpanDecorator.java
new file mode 100644
index 0000000..0811c45
--- /dev/null
+++ b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/AwsSqsSpanDecorator.java
@@ -0,0 +1,35 @@
+/**
+ * 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.opentracing.decorators;
+
+import org.apache.camel.Exchange;
+
+public class AwsSqsSpanDecorator extends AbstractMessagingSpanDecorator {
+
+ public static final String CAMEL_AWS_SQS_MESSAGE_ID = "CamelAwsSqsMessageId";
+
+ @Override
+ public String getComponent() {
+ return "aws-sqs";
+ }
+
+ @Override
+ protected String getMessageId(Exchange exchange) {
+ return (String)exchange.getIn().getHeader(CAMEL_AWS_SQS_MESSAGE_ID);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/CometdSpanDecorator.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/CometdSpanDecorator.java b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/CometdSpanDecorator.java
new file mode 100644
index 0000000..3eabe05
--- /dev/null
+++ b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/CometdSpanDecorator.java
@@ -0,0 +1,37 @@
+/**
+ * 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.opentracing.decorators;
+
+import java.net.URI;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+
+public class CometdSpanDecorator extends AbstractMessagingSpanDecorator {
+
+ @Override
+ public String getComponent() {
+ return "cometd";
+ }
+
+ @Override
+ protected String getDestination(Exchange exchange, Endpoint endpoint) {
+ // Extract path, and remove leading '/'
+ return URI.create(endpoint.getEndpointUri()).getPath().substring(1);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/CometdsSpanDecorator.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/CometdsSpanDecorator.java b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/CometdsSpanDecorator.java
new file mode 100644
index 0000000..f700d2a
--- /dev/null
+++ b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/CometdsSpanDecorator.java
@@ -0,0 +1,26 @@
+/**
+ * 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.opentracing.decorators;
+
+public class CometdsSpanDecorator extends CometdSpanDecorator {
+
+ @Override
+ public String getComponent() {
+ return "cometds";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/IronmqSpanDecorator.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/IronmqSpanDecorator.java b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/IronmqSpanDecorator.java
new file mode 100644
index 0000000..75858bd
--- /dev/null
+++ b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/IronmqSpanDecorator.java
@@ -0,0 +1,35 @@
+/**
+ * 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.opentracing.decorators;
+
+import org.apache.camel.Exchange;
+
+public class IronmqSpanDecorator extends AbstractMessagingSpanDecorator {
+
+ public static final String CAMEL_IRON_MQ_MESSAGE_ID = "CamelIronMQMessageId";
+
+ @Override
+ public String getComponent() {
+ return "ironmq";
+ }
+
+ @Override
+ protected String getMessageId(Exchange exchange) {
+ return (String)exchange.getIn().getHeader(CAMEL_IRON_MQ_MESSAGE_ID);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/JmsSpanDecorator.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/JmsSpanDecorator.java b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/JmsSpanDecorator.java
new file mode 100644
index 0000000..cfe25bc
--- /dev/null
+++ b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/JmsSpanDecorator.java
@@ -0,0 +1,35 @@
+/**
+ * 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.opentracing.decorators;
+
+import org.apache.camel.Exchange;
+
+public class JmsSpanDecorator extends AbstractMessagingSpanDecorator {
+
+ public static final String JMS_MESSAGE_ID = "JMSMessageID";
+
+ @Override
+ public String getComponent() {
+ return "jms";
+ }
+
+ @Override
+ protected String getMessageId(Exchange exchange) {
+ return (String)exchange.getIn().getHeader(JMS_MESSAGE_ID);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/KafkaSpanDecorator.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/KafkaSpanDecorator.java b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/KafkaSpanDecorator.java
new file mode 100644
index 0000000..ecc9279
--- /dev/null
+++ b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/KafkaSpanDecorator.java
@@ -0,0 +1,82 @@
+/**
+ * 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.opentracing.decorators;
+
+import java.util.Map;
+
+import io.opentracing.Span;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+
+public class KafkaSpanDecorator extends AbstractMessagingSpanDecorator {
+
+ public static final String KAFKA_PARTITION_TAG = "kafka.partition";
+ public static final String KAFKA_PARTITION_KEY_TAG = "kafka.partition.key";
+ public static final String KAFKA_KEY_TAG = "kafka.key";
+ public static final String KAFKA_OFFSET_TAG = "kafka.offset";
+
+ /**
+ * Constants copied from {@link org.apache.camel.component.kafka.KafkaConstants}
+ */
+ protected static final String PARTITION_KEY = "kafka.PARTITION_KEY";
+ protected static final String PARTITION = "kafka.PARTITION";
+ protected static final String KEY = "kafka.KEY";
+ protected static final String TOPIC = "kafka.TOPIC";
+ protected static final String OFFSET = "kafka.OFFSET";
+
+ @Override
+ public String getComponent() {
+ return "kafka";
+ }
+
+ @Override
+ public String getDestination(Exchange exchange, Endpoint endpoint) {
+ String topic = (String)exchange.getIn().getHeader(TOPIC);
+ if (topic == null) {
+ Map<String, String> queryParameters = toQueryParameters(endpoint.getEndpointUri());
+ topic = queryParameters.get("topic");
+ }
+ return topic != null ? topic : super.getDestination(exchange, endpoint);
+ }
+
+ @Override
+ public void pre(Span span, Exchange exchange, Endpoint endpoint) {
+ super.pre(span, exchange, endpoint);
+
+ String partition = (String)exchange.getIn().getHeader(PARTITION);
+ if (partition != null) {
+ span.setTag(KAFKA_PARTITION_TAG, partition);
+ }
+
+ String partitionKey = (String)exchange.getIn().getHeader(PARTITION_KEY);
+ if (partitionKey != null) {
+ span.setTag(KAFKA_PARTITION_KEY_TAG, partitionKey);
+ }
+
+ String key = (String)exchange.getIn().getHeader(KEY);
+ if (key != null) {
+ span.setTag(KAFKA_KEY_TAG, key);
+ }
+
+ String offset = (String)exchange.getIn().getHeader(OFFSET);
+ if (offset != null) {
+ span.setTag(KAFKA_OFFSET_TAG, offset);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/MongoDBSpanDecorator.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/MongoDBSpanDecorator.java b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/MongoDBSpanDecorator.java
index a6da0b8..1139e68 100644
--- a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/MongoDBSpanDecorator.java
+++ b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/MongoDBSpanDecorator.java
@@ -16,8 +16,6 @@
*/
package org.apache.camel.opentracing.decorators;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.Map;
import io.opentracing.Span;
@@ -57,19 +55,4 @@ public class MongoDBSpanDecorator extends AbstractSpanDecorator {
span.setTag(Tags.DB_STATEMENT.getKey(), queryParameters.toString());
}
- public static Map<String, String> toQueryParameters(String uri) {
- int index = uri.indexOf('?');
- if (index != -1) {
- String queryString = uri.substring(index + 1);
- Map<String, String> map = new HashMap<>();
- for (String param : queryString.split("&")) {
- String[] parts = param.split("=");
- if (parts.length == 2) {
- map.put(parts[0], parts[1]);
- }
- }
- return map;
- }
- return Collections.emptyMap();
- }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/MqttSpanDecorator.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/MqttSpanDecorator.java b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/MqttSpanDecorator.java
new file mode 100644
index 0000000..4bee69a
--- /dev/null
+++ b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/MqttSpanDecorator.java
@@ -0,0 +1,46 @@
+/**
+ * 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.opentracing.decorators;
+
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+
+public class MqttSpanDecorator extends AbstractMessagingSpanDecorator {
+
+ @Override
+ public String getComponent() {
+ return "mqtt";
+ }
+
+ @Override
+ public String getOperationName(Exchange exchange, Endpoint endpoint) {
+ return stripSchemeAndOptions(endpoint);
+ }
+
+ @Override
+ protected String getDestination(Exchange exchange, Endpoint endpoint) {
+ Map<String, String> queryParameters = toQueryParameters(endpoint.getEndpointUri());
+ String destination = queryParameters.get("subscribeTopicNames");
+ if (destination == null) {
+ destination = queryParameters.get("publishTopicName");
+ }
+ return destination;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/PahoSpanDecorator.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/PahoSpanDecorator.java b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/PahoSpanDecorator.java
new file mode 100644
index 0000000..b970fd8
--- /dev/null
+++ b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/PahoSpanDecorator.java
@@ -0,0 +1,26 @@
+/**
+ * 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.opentracing.decorators;
+
+public class PahoSpanDecorator extends AbstractMessagingSpanDecorator {
+
+ @Override
+ public String getComponent() {
+ return "paho";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/RabbitmqSpanDecorator.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/RabbitmqSpanDecorator.java b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/RabbitmqSpanDecorator.java
new file mode 100644
index 0000000..f26c4d2
--- /dev/null
+++ b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/RabbitmqSpanDecorator.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.opentracing.decorators;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+
+public class RabbitmqSpanDecorator extends AbstractMessagingSpanDecorator {
+
+ /**
+ * Constants copied from {@link org.apache.camel.component.rabbitmq.RabbitMQConstants}
+ */
+ protected static final String EXCHANGE_NAME = "rabbitmq.EXCHANGE_NAME";
+
+ @Override
+ public String getComponent() {
+ return "rabbitmq";
+ }
+
+ @Override
+ public String getDestination(Exchange exchange, Endpoint endpoint) {
+ return (String)exchange.getIn().getHeader(EXCHANGE_NAME);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/SjmsSpanDecorator.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/SjmsSpanDecorator.java b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/SjmsSpanDecorator.java
new file mode 100644
index 0000000..efe29e7
--- /dev/null
+++ b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/decorators/SjmsSpanDecorator.java
@@ -0,0 +1,26 @@
+/**
+ * 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.opentracing.decorators;
+
+public class SjmsSpanDecorator extends AbstractMessagingSpanDecorator {
+
+ @Override
+ public String getComponent() {
+ return "sjms";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/main/resources/META-INF/services/org.apache.camel.opentracing.SpanDecorator
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/main/resources/META-INF/services/org.apache.camel.opentracing.SpanDecorator b/components/camel-opentracing/src/main/resources/META-INF/services/org.apache.camel.opentracing.SpanDecorator
index 137835e..68af6ca 100644
--- a/components/camel-opentracing/src/main/resources/META-INF/services/org.apache.camel.opentracing.SpanDecorator
+++ b/components/camel-opentracing/src/main/resources/META-INF/services/org.apache.camel.opentracing.SpanDecorator
@@ -16,17 +16,29 @@
#
org.apache.camel.opentracing.decorators.AhcSpanDecorator
+org.apache.camel.opentracing.decorators.AmqpSpanDecorator
+org.apache.camel.opentracing.decorators.AwsSqsSpanDecorator
+org.apache.camel.opentracing.decorators.AwsSnsSpanDecorator
+org.apache.camel.opentracing.decorators.CometdSpanDecorator
+org.apache.camel.opentracing.decorators.CometdsSpanDecorator
org.apache.camel.opentracing.decorators.DirectSpanDecorator
org.apache.camel.opentracing.decorators.Http4SpanDecorator
org.apache.camel.opentracing.decorators.HttpSpanDecorator
+org.apache.camel.opentracing.decorators.IronmqSpanDecorator
org.apache.camel.opentracing.decorators.JdbcSpanDecorator
org.apache.camel.opentracing.decorators.JettySpanDecorator
+org.apache.camel.opentracing.decorators.JmsSpanDecorator
+org.apache.camel.opentracing.decorators.KafkaSpanDecorator
org.apache.camel.opentracing.decorators.MongoDBSpanDecorator
+org.apache.camel.opentracing.decorators.MqttSpanDecorator
org.apache.camel.opentracing.decorators.NettyHttp4SpanDecorator
org.apache.camel.opentracing.decorators.NettyHttpSpanDecorator
+org.apache.camel.opentracing.decorators.PahoSpanDecorator
+org.apache.camel.opentracing.decorators.RabbitmqSpanDecorator
org.apache.camel.opentracing.decorators.RestletSpanDecorator
org.apache.camel.opentracing.decorators.SedaSpanDecorator
org.apache.camel.opentracing.decorators.ServletSpanDecorator
+org.apache.camel.opentracing.decorators.SjmsSpanDecorator
org.apache.camel.opentracing.decorators.SqlSpanDecorator
org.apache.camel.opentracing.decorators.TimerSpanDecorator
org.apache.camel.opentracing.decorators.UndertowSpanDecorator
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/AbstractMessagingSpanDecoratorTest.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/AbstractMessagingSpanDecoratorTest.java b/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/AbstractMessagingSpanDecoratorTest.java
new file mode 100644
index 0000000..3a694b3
--- /dev/null
+++ b/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/AbstractMessagingSpanDecoratorTest.java
@@ -0,0 +1,96 @@
+/**
+ * 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.opentracing.decorators;
+
+import io.opentracing.mock.MockSpan;
+import io.opentracing.mock.MockTracer;
+import io.opentracing.tag.Tags;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.opentracing.SpanDecorator;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.junit.Assert.assertEquals;
+
+public class AbstractMessagingSpanDecoratorTest {
+
+ @Test
+ public void testOperationName() {
+ Endpoint endpoint = Mockito.mock(Endpoint.class);
+
+ Mockito.when(endpoint.getEndpointUri()).thenReturn("jms://MyQueue?hello=world");
+
+ SpanDecorator decorator = new AbstractMessagingSpanDecorator() {
+ @Override
+ public String getComponent() {
+ return null;
+ }
+ };
+
+ assertEquals("MyQueue", decorator.getOperationName(null, endpoint));
+ }
+
+ @Test
+ public void testPreMessageBusDestination() {
+ Endpoint endpoint = Mockito.mock(Endpoint.class);
+
+ Mockito.when(endpoint.getEndpointUri()).thenReturn("jms://MyQueue?hello=world");
+
+ SpanDecorator decorator = new AbstractMessagingSpanDecorator() {
+ @Override
+ public String getComponent() {
+ return null;
+ }
+ };
+
+ MockTracer tracer = new MockTracer();
+ MockSpan span = (MockSpan)tracer.buildSpan("TestSpan").start();
+
+ decorator.pre(span, null, endpoint);
+
+ assertEquals("MyQueue", span.tags().get(Tags.MESSAGE_BUS_DESTINATION.getKey()));
+ }
+
+ @Test
+ public void testPreMessageId() {
+ String messageId = "abcd";
+ Endpoint endpoint = Mockito.mock(Endpoint.class);
+ Exchange exchange = Mockito.mock(Exchange.class);
+
+ Mockito.when(endpoint.getEndpointUri()).thenReturn("test");
+
+ SpanDecorator decorator = new AbstractMessagingSpanDecorator() {
+ @Override
+ public String getComponent() {
+ return null;
+ }
+ @Override
+ public String getMessageId(Exchange exchange) {
+ return messageId;
+ }
+ };
+
+ MockTracer tracer = new MockTracer();
+ MockSpan span = (MockSpan)tracer.buildSpan("TestSpan").start();
+
+ decorator.pre(span, exchange, endpoint);
+
+ assertEquals(messageId, span.tags().get(AwsSqsSpanDecorator.MESSAGE_BUS_ID));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/AwsSnsSpanDecoratorTest.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/AwsSnsSpanDecoratorTest.java b/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/AwsSnsSpanDecoratorTest.java
new file mode 100644
index 0000000..eb8f8db
--- /dev/null
+++ b/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/AwsSnsSpanDecoratorTest.java
@@ -0,0 +1,42 @@
+/**
+ * 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.opentracing.decorators;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.junit.Assert.assertEquals;
+
+public class AwsSnsSpanDecoratorTest {
+
+ @Test
+ public void testGetMessageId() {
+ String messageId = "abcd";
+ Exchange exchange = Mockito.mock(Exchange.class);
+ Message message = Mockito.mock(Message.class);
+
+ Mockito.when(exchange.getIn()).thenReturn(message);
+ Mockito.when(message.getHeader(AwsSnsSpanDecorator.CAMEL_AWS_SNS_MESSAGE_ID)).thenReturn(messageId);
+
+ AwsSnsSpanDecorator decorator = new AwsSnsSpanDecorator();
+
+ assertEquals(messageId, decorator.getMessageId(exchange));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/AwsSqsSpanDecoratorTest.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/AwsSqsSpanDecoratorTest.java b/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/AwsSqsSpanDecoratorTest.java
new file mode 100644
index 0000000..2f527d4
--- /dev/null
+++ b/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/AwsSqsSpanDecoratorTest.java
@@ -0,0 +1,42 @@
+/**
+ * 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.opentracing.decorators;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.junit.Assert.assertEquals;
+
+public class AwsSqsSpanDecoratorTest {
+
+ @Test
+ public void testGetMessageId() {
+ String messageId = "abcd";
+ Exchange exchange = Mockito.mock(Exchange.class);
+ Message message = Mockito.mock(Message.class);
+
+ Mockito.when(exchange.getIn()).thenReturn(message);
+ Mockito.when(message.getHeader(AwsSqsSpanDecorator.CAMEL_AWS_SQS_MESSAGE_ID)).thenReturn(messageId);
+
+ AwsSqsSpanDecorator decorator = new AwsSqsSpanDecorator();
+
+ assertEquals(messageId, decorator.getMessageId(exchange));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/CometdSpanDecoratorTest.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/CometdSpanDecoratorTest.java b/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/CometdSpanDecoratorTest.java
new file mode 100644
index 0000000..a1dda42
--- /dev/null
+++ b/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/CometdSpanDecoratorTest.java
@@ -0,0 +1,37 @@
+/**
+ * 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.opentracing.decorators;
+
+import org.apache.camel.Endpoint;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.junit.Assert.assertEquals;
+
+public class CometdSpanDecoratorTest {
+
+ @Test
+ public void testGetDestination() {
+ Endpoint endpoint = Mockito.mock(Endpoint.class);
+
+ Mockito.when(endpoint.getEndpointUri()).thenReturn("cometd://localhost:8080/MyQueue?hello=world");
+
+ CometdSpanDecorator decorator = new CometdSpanDecorator();
+
+ assertEquals("MyQueue", decorator.getDestination(null, endpoint));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/IronmqSpanDecoratorTest.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/IronmqSpanDecoratorTest.java b/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/IronmqSpanDecoratorTest.java
new file mode 100644
index 0000000..5f58ccd
--- /dev/null
+++ b/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/IronmqSpanDecoratorTest.java
@@ -0,0 +1,42 @@
+/**
+ * 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.opentracing.decorators;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.junit.Assert.assertEquals;
+
+public class IronmqSpanDecoratorTest {
+
+ @Test
+ public void testGetMessageId() {
+ String messageId = "abcd";
+ Exchange exchange = Mockito.mock(Exchange.class);
+ Message message = Mockito.mock(Message.class);
+
+ Mockito.when(exchange.getIn()).thenReturn(message);
+ Mockito.when(message.getHeader(IronmqSpanDecorator.CAMEL_IRON_MQ_MESSAGE_ID)).thenReturn(messageId);
+
+ IronmqSpanDecorator decorator = new IronmqSpanDecorator();
+
+ assertEquals(messageId, decorator.getMessageId(exchange));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/JmsSpanDecoratorTest.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/JmsSpanDecoratorTest.java b/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/JmsSpanDecoratorTest.java
new file mode 100644
index 0000000..bd7e008
--- /dev/null
+++ b/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/JmsSpanDecoratorTest.java
@@ -0,0 +1,42 @@
+/**
+ * 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.opentracing.decorators;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.junit.Assert.assertEquals;
+
+public class JmsSpanDecoratorTest {
+
+ @Test
+ public void testGetMessageId() {
+ String messageId = "abcd";
+ Exchange exchange = Mockito.mock(Exchange.class);
+ Message message = Mockito.mock(Message.class);
+
+ Mockito.when(exchange.getIn()).thenReturn(message);
+ Mockito.when(message.getHeader(JmsSpanDecorator.JMS_MESSAGE_ID)).thenReturn(messageId);
+
+ JmsSpanDecorator decorator = new JmsSpanDecorator();
+
+ assertEquals(messageId, decorator.getMessageId(exchange));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/KafkaSpanDecoratorTest.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/KafkaSpanDecoratorTest.java b/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/KafkaSpanDecoratorTest.java
new file mode 100644
index 0000000..b3eda9c
--- /dev/null
+++ b/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/KafkaSpanDecoratorTest.java
@@ -0,0 +1,92 @@
+/**
+ * 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.opentracing.decorators;
+
+import io.opentracing.mock.MockSpan;
+import io.opentracing.mock.MockTracer;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.opentracing.SpanDecorator;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.junit.Assert.assertEquals;
+
+public class KafkaSpanDecoratorTest {
+
+ @Test
+ public void testGetDestinationHeaderTopic() {
+ Exchange exchange = Mockito.mock(Exchange.class);
+ Message message = Mockito.mock(Message.class);
+
+ Mockito.when(exchange.getIn()).thenReturn(message);
+ Mockito.when(message.getHeader(KafkaSpanDecorator.TOPIC)).thenReturn("test");
+
+ KafkaSpanDecorator decorator = new KafkaSpanDecorator();
+
+ assertEquals("test", decorator.getDestination(exchange, null));
+ }
+
+ @Test
+ public void testGetDestinationNoHeaderTopic() {
+ Exchange exchange = Mockito.mock(Exchange.class);
+ Message message = Mockito.mock(Message.class);
+ Endpoint endpoint = Mockito.mock(Endpoint.class);
+
+ Mockito.when(exchange.getIn()).thenReturn(message);
+ Mockito.when(endpoint.getEndpointUri())
+ .thenReturn("kafka:localhost:9092?topic=test&groupId=testing&consumersCount=1");
+
+ KafkaSpanDecorator decorator = new KafkaSpanDecorator();
+
+ assertEquals("test", decorator.getDestination(exchange, endpoint));
+ }
+
+ @Test
+ public void testPre() {
+ String testKey = "TestKey";
+ String testOffset = "TestOffset";
+ String testPartition = "TestPartition";
+ String testPartitionKey = "TestPartitionKey";
+
+ Endpoint endpoint = Mockito.mock(Endpoint.class);
+ Exchange exchange = Mockito.mock(Exchange.class);
+ Message message = Mockito.mock(Message.class);
+
+ Mockito.when(endpoint.getEndpointUri()).thenReturn("test");
+ Mockito.when(exchange.getIn()).thenReturn(message);
+ Mockito.when(message.getHeader(KafkaSpanDecorator.KEY)).thenReturn(testKey);
+ Mockito.when(message.getHeader(KafkaSpanDecorator.OFFSET)).thenReturn(testOffset);
+ Mockito.when(message.getHeader(KafkaSpanDecorator.PARTITION)).thenReturn(testPartition);
+ Mockito.when(message.getHeader(KafkaSpanDecorator.PARTITION_KEY)).thenReturn(testPartitionKey);
+
+ SpanDecorator decorator = new KafkaSpanDecorator();
+
+ MockTracer tracer = new MockTracer();
+ MockSpan span = tracer.buildSpan("TestSpan").start();
+
+ decorator.pre(span, exchange, endpoint);
+
+ assertEquals(testKey, span.tags().get(KafkaSpanDecorator.KAFKA_KEY_TAG));
+ assertEquals(testOffset, span.tags().get(KafkaSpanDecorator.KAFKA_OFFSET_TAG));
+ assertEquals(testPartition, span.tags().get(KafkaSpanDecorator.KAFKA_PARTITION_TAG));
+ assertEquals(testPartitionKey, span.tags().get(KafkaSpanDecorator.KAFKA_PARTITION_KEY_TAG));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/MqttSpanDecoratorTest.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/MqttSpanDecoratorTest.java b/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/MqttSpanDecoratorTest.java
new file mode 100644
index 0000000..d10682a
--- /dev/null
+++ b/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/MqttSpanDecoratorTest.java
@@ -0,0 +1,60 @@
+/**
+ * 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.opentracing.decorators;
+
+import org.apache.camel.Endpoint;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.junit.Assert.assertEquals;
+
+public class MqttSpanDecoratorTest {
+
+ @Test
+ public void testGetOperationName() {
+ Endpoint endpoint = Mockito.mock(Endpoint.class);
+
+ Mockito.when(endpoint.getEndpointUri()).thenReturn("mqtt://hello?publishTopicName=world");
+
+ MqttSpanDecorator decorator = new MqttSpanDecorator();
+
+ assertEquals("hello", decorator.getOperationName(null, endpoint));
+ }
+
+ @Test
+ public void testGetDestinationPublish() {
+ Endpoint endpoint = Mockito.mock(Endpoint.class);
+
+ Mockito.when(endpoint.getEndpointUri()).thenReturn("mqtt://hello?publishTopicName=world");
+
+ MqttSpanDecorator decorator = new MqttSpanDecorator();
+
+ assertEquals("world", decorator.getDestination(null, endpoint));
+ }
+
+ @Test
+ public void testGetDestinationSubscribe() {
+ Endpoint endpoint = Mockito.mock(Endpoint.class);
+
+ Mockito.when(endpoint.getEndpointUri()).thenReturn("mqtt://hello?subscribeTopicNames=world");
+
+ MqttSpanDecorator decorator = new MqttSpanDecorator();
+
+ assertEquals("world", decorator.getDestination(null, endpoint));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/689d3c8f/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/RabbitmqSpanDecoratorTest.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/RabbitmqSpanDecoratorTest.java b/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/RabbitmqSpanDecoratorTest.java
new file mode 100644
index 0000000..cb99557
--- /dev/null
+++ b/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/decorators/RabbitmqSpanDecoratorTest.java
@@ -0,0 +1,41 @@
+/**
+ * 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.opentracing.decorators;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.junit.Assert.assertEquals;
+
+public class RabbitmqSpanDecoratorTest {
+
+ @Test
+ public void testGetDestinationHeaderTopic() {
+ Exchange exchange = Mockito.mock(Exchange.class);
+ Message message = Mockito.mock(Message.class);
+
+ Mockito.when(exchange.getIn()).thenReturn(message);
+ Mockito.when(message.getHeader(RabbitmqSpanDecorator.EXCHANGE_NAME)).thenReturn("test");
+
+ RabbitmqSpanDecorator decorator = new RabbitmqSpanDecorator();
+
+ assertEquals("test", decorator.getDestination(exchange, null));
+ }
+
+}