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 2016/03/29 14:45:08 UTC

[01/12] camel git commit: CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.

Repository: camel
Updated Branches:
  refs/heads/master d1c3bbfe5 -> f8ef4eb1a


CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b48915a7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b48915a7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b48915a7

Branch: refs/heads/master
Commit: b48915a71d80dc45f797ea4590390668408cbff8
Parents: 4b1737a
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 29 14:15:54 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 29 14:41:54 2016 +0200

----------------------------------------------------------------------
 .../camel/zipkin/ZipkinEventNotifier.java       | 109 ++++++++++++++++---
 .../zipkin/ZipkinSimpleFallbackRouteTest.java   |  68 ++++++++++++
 .../scribe/ZipkinOneRouteFallbackScribe.java    |  74 +++++++++++++
 3 files changed, 238 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b48915a7/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
index f4bf0b0..5dd38e7 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
@@ -19,7 +19,9 @@ package org.apache.camel.zipkin;
 import java.io.Closeable;
 import java.util.EventObject;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
 import com.github.kristofa.brave.Brave;
 import com.github.kristofa.brave.ClientSpanThreadBinder;
@@ -59,7 +61,11 @@ import static org.apache.camel.builder.ExpressionBuilder.routeIdExpression;
  * For both kinds you can use wildcards and regular expressions to match, which is using the rules from
  * {@link EndpointHelper#matchPattern(String, String)} and {@link EndpointHelper#matchEndpoint(CamelContext, String, String)}
  * <p/>
- * At least one mapping must be configured, you can use <tt>*</tt> to match all incoming and outgoing messages.
+ * To match all Camel messages you can use <tt>*</tt> in the pattern and configure that to the same service name.
+ * <br/>
+ * If no mapping has been configured then Camel will fallback and use endpoint uri's as service names.
+ * However its recommended to configure service mappings so you can use human logic names instead of Camel
+ * endpoint uris in the names.
  */
 @ManagedResource(description = "Managing ZipkinEventNotifier")
 public class ZipkinEventNotifier extends EventNotifierSupport implements StatefulService {
@@ -67,8 +73,10 @@ public class ZipkinEventNotifier extends EventNotifierSupport implements Statefu
     private float rate = 1.0f;
     private SpanCollector spanCollector;
     private Map<String, String> serviceMappings = new HashMap<>();
+    private Set<String> excludePatterns = new HashSet<>();
     private Map<String, Brave> braves = new HashMap<>();
     private boolean includeMessageBody;
+    private boolean useFallbackServiceNames;
 
     public ZipkinEventNotifier() {
     }
@@ -128,6 +136,21 @@ public class ZipkinEventNotifier extends EventNotifierSupport implements Statefu
         serviceMappings.put(pattern, serviceName);
     }
 
+    public Set<String> getExcludePatterns() {
+        return excludePatterns;
+    }
+
+    public void setExcludePatterns(Set<String> excludePatterns) {
+        this.excludePatterns = excludePatterns;
+    }
+
+    /**
+     * Adds an exclude pattern that will disable tracing with zipkin for Camel messages that matches the pattern.
+     */
+    public void addExcludePattern(String pattern) {
+        excludePatterns.add(pattern);
+    }
+
     @ManagedAttribute(description = "Whether to include the Camel message body in the zipkin traces")
     public boolean isIncludeMessageBody() {
         return includeMessageBody;
@@ -149,7 +172,8 @@ public class ZipkinEventNotifier extends EventNotifierSupport implements Statefu
         super.doStart();
 
         if (serviceMappings.isEmpty()) {
-            throw new IllegalStateException("At least one service name must be configured");
+            log.warn("No service name(s) has been configured. Camel will fallback and use endpoint uris as service names.");
+            useFallbackServiceNames = true;
         }
 
         // create braves mapped per service name
@@ -196,9 +220,15 @@ public class ZipkinEventNotifier extends EventNotifierSupport implements Statefu
 
         String id = routeIdExpression().evaluate(exchange, String.class);
         if (id != null) {
+            // exclude patterns take precedence
+            for (String pattern : excludePatterns) {
+                if (EndpointHelper.matchPattern(id, pattern)) {
+                    return null;
+                }
+            }
             for (Map.Entry<String, String> entry : serviceMappings.entrySet()) {
                 String pattern = entry.getKey();
-                if (EndpointHelper.matchPattern(pattern, id)) {
+                if (EndpointHelper.matchPattern(id, pattern)) {
                     answer = entry.getValue();
                     break;
                 }
@@ -208,9 +238,15 @@ public class ZipkinEventNotifier extends EventNotifierSupport implements Statefu
         if (answer == null) {
             id = exchange.getFromRouteId();
             if (id != null) {
+                // exclude patterns take precedence
+                for (String pattern : excludePatterns) {
+                    if (EndpointHelper.matchPattern(id, pattern)) {
+                        return null;
+                    }
+                }
                 for (Map.Entry<String, String> entry : serviceMappings.entrySet()) {
                     String pattern = entry.getKey();
-                    if (EndpointHelper.matchPattern(pattern, id)) {
+                    if (EndpointHelper.matchPattern(id, pattern)) {
                         answer = entry.getValue();
                         break;
                     }
@@ -221,6 +257,12 @@ public class ZipkinEventNotifier extends EventNotifierSupport implements Statefu
         if (answer == null && endpoint != null) {
             String url = endpoint.getEndpointUri();
             if (url != null) {
+                // exclude patterns take precedence
+                for (String pattern : excludePatterns) {
+                    if (EndpointHelper.matchPattern(url, pattern)) {
+                        return null;
+                    }
+                }
                 for (Map.Entry<String, String> entry : serviceMappings.entrySet()) {
                     String pattern = entry.getKey();
                     if (EndpointHelper.matchEndpoint(exchange.getContext(), url, pattern)) {
@@ -234,6 +276,12 @@ public class ZipkinEventNotifier extends EventNotifierSupport implements Statefu
         if (answer == null && exchange.getFromEndpoint() != null) {
             String url = exchange.getFromEndpoint().getEndpointUri();
             if (url != null) {
+                // exclude patterns take precedence
+                for (String pattern : excludePatterns) {
+                    if (EndpointHelper.matchPattern(url, pattern)) {
+                        return null;
+                    }
+                }
                 for (Map.Entry<String, String> entry : serviceMappings.entrySet()) {
                     String pattern = entry.getKey();
                     if (EndpointHelper.matchEndpoint(exchange.getContext(), url, pattern)) {
@@ -244,15 +292,49 @@ public class ZipkinEventNotifier extends EventNotifierSupport implements Statefu
             }
         }
 
-        return answer;
+        if (answer == null && useFallbackServiceNames) {
+            String key = null;
+            if (endpoint != null) {
+                key = endpoint.getEndpointKey();
+            } else if (exchange.getFromEndpoint() != null) {
+                key = exchange.getFromEndpoint().getEndpointKey();
+            }
+            // exclude patterns take precedence
+            for (String pattern : excludePatterns) {
+                if (EndpointHelper.matchPattern(key, pattern)) {
+                    return null;
+                }
+            }
+            if (log.isTraceEnabled() && key != null) {
+                log.trace("Using serviceName: {} as fallback", key);
+            }
+            return key;
+        } else {
+            if (log.isTraceEnabled() && answer != null) {
+                log.trace("Using serviceName: {}", answer);
+            }
+            return answer;
+        }
     }
 
     private Brave getBrave(String serviceName) {
+        Brave brave = null;
         if (serviceName != null) {
-            return braves.get(serviceName);
-        } else {
-            return null;
+            brave = braves.get(serviceName);
+
+            if (brave == null && useFallbackServiceNames) {
+                log.debug("Creating Brave assigned to serviceName: {}", serviceName + " as fallback");
+                Brave.Builder builder = new Brave.Builder(serviceName);
+                builder = builder.traceSampler(Sampler.create(rate));
+                if (spanCollector != null) {
+                    builder = builder.spanCollector(spanCollector);
+                }
+                brave = builder.build();
+                braves.put(serviceName, brave);
+            }
         }
+
+        return brave;
     }
 
     @Override
@@ -304,7 +386,7 @@ public class ZipkinEventNotifier extends EventNotifierSupport implements Statefu
         event.getExchange().setProperty(key, span);
 
         if (log.isDebugEnabled()) {
-            log.debug("clientRequest[service={}, spanId={}]", serviceName, span != null ? span.getId() : "<null>");
+            log.debug("clientRequest\t[service={}, spanId={}]", serviceName, span != null ? span.getId() : "<null>");
         }
     }
 
@@ -317,7 +399,8 @@ public class ZipkinEventNotifier extends EventNotifierSupport implements Statefu
         binder.setCurrentSpan(null);
 
         if (log.isDebugEnabled()) {
-            log.debug("clientResponse[service={}, spanId={}]", serviceName, span != null ? span.getId() : "<null>");
+            // one space to align client vs server in the logs
+            log.debug("clientResponse\t[service={}, spanId={}]", serviceName, span != null ? span.getId() : "<null>");
         }
     }
 
@@ -329,7 +412,7 @@ public class ZipkinEventNotifier extends EventNotifierSupport implements Statefu
         event.getExchange().setProperty(key, span);
 
         if (log.isDebugEnabled()) {
-            log.debug("serverRequest[service={}, spanId={}]", serviceName, span != null ? span.getSpan().getId() : "<null>");
+            log.debug("serverRequest\t[service={}, spanId={}]", serviceName, span != null ? span.getSpan().getId() : "<null>");
         }
     }
 
@@ -342,7 +425,7 @@ public class ZipkinEventNotifier extends EventNotifierSupport implements Statefu
         binder.setCurrentSpan(null);
 
         if (log.isDebugEnabled()) {
-            log.debug("serverResponse[service={}, spanId={}, status=exchangeCompleted]", serviceName, span != null ? span.getSpan().getId() : "<null>");
+            log.debug("serverResponse\t[service={}, spanId={}]\t[status=exchangeCompleted]", serviceName, span != null ? span.getSpan().getId() : "<null>");
         }
     }
 
@@ -355,7 +438,7 @@ public class ZipkinEventNotifier extends EventNotifierSupport implements Statefu
         binder.setCurrentSpan(null);
 
         if (log.isDebugEnabled()) {
-            log.debug("serverResponse[service={}, spanId={}, status=exchangeFailed]", serviceName, span != null ? span.getSpan().getId() : "<null>");
+            log.debug("serverResponse[service={}, spanId={}]\t[status=exchangeFailed]", serviceName, span != null ? span.getSpan().getId() : "<null>");
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/b48915a7/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSimpleFallbackRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSimpleFallbackRouteTest.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSimpleFallbackRouteTest.java
new file mode 100644
index 0000000..5fa940a
--- /dev/null
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSimpleFallbackRouteTest.java
@@ -0,0 +1,68 @@
+/**
+ * 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.zipkin;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class ZipkinSimpleFallbackRouteTest extends CamelTestSupport {
+
+    private ZipkinEventNotifier zipkin;
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        zipkin = new ZipkinEventNotifier();
+        // no service so should use fallback naming style
+        // we do not want to trace any direct endpoints
+        zipkin.addExcludePattern("direct:*");
+        zipkin.setSpanCollector(new ZipkinLoggingSpanCollector());
+        context.getManagementStrategy().addEventNotifier(zipkin);
+
+        return context;
+    }
+
+    @Test
+    public void testZipkinRoute() throws Exception {
+        NotifyBuilder notify = new NotifyBuilder(context).whenDone(5).create();
+
+        for (int i = 0; i < 5; i++) {
+            template.sendBody("seda:dude", "Hello World");
+        }
+
+        assertTrue(notify.matches(30, TimeUnit.SECONDS));
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("seda:dude").routeId("dude")
+                        .log("routing at ${routeId}")
+                        .delay(simple("${random(1000,2000)}"));
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b48915a7/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinOneRouteFallbackScribe.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinOneRouteFallbackScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinOneRouteFallbackScribe.java
new file mode 100644
index 0000000..8f3ed4e
--- /dev/null
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinOneRouteFallbackScribe.java
@@ -0,0 +1,74 @@
+/**
+ * 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.zipkin.scribe;
+
+import com.github.kristofa.brave.scribe.ScribeSpanCollector;
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.zipkin.ZipkinEventNotifier;
+import org.junit.Test;
+
+/**
+ * Integration test requires running Zipkin/Scribe running
+ *
+ * The easiest way is to run using zipkin-docker: https://github.com/openzipkin/docker-zipkin
+ *
+ * Adjust the IP address to what IP docker-machines have assigned, you can use
+ * <tt>docker-machines ls</tt>
+ */
+public class ZipkinOneRouteFallbackScribe extends CamelTestSupport {
+
+    private String ip = "192.168.99.100";
+    private ZipkinEventNotifier zipkin;
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        zipkin = new ZipkinEventNotifier();
+        // no service so should use fallback naming style
+        // we do not want to trace any direct endpoints
+        zipkin.addExcludePattern("direct:*");
+        zipkin.setIncludeMessageBody(true);
+        zipkin.setSpanCollector(new ScribeSpanCollector(ip, 9410));
+        context.getManagementStrategy().addEventNotifier(zipkin);
+
+        return context;
+    }
+
+    @Test
+    public void testZipkinRoute() throws Exception {
+        template.requestBody("direct:start", "Hello Goofy");
+        template.requestBody("direct:start", "Hello again Goofy");
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").to("seda:goofy");
+
+                from("seda:goofy").routeId("goofy")
+                        .log("routing at ${routeId}")
+                        .delay(simple("${random(1000,2000)}"));
+            }
+        };
+    }
+}


[02/12] camel git commit: CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.

Posted by da...@apache.org.
CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7153f3c3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7153f3c3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7153f3c3

Branch: refs/heads/master
Commit: 7153f3c3fcee3a653ecc0572a3790e918415df98
Parents: 70ff21b
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 29 13:33:39 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 29 14:41:54 2016 +0200

----------------------------------------------------------------------
 .../zipkin/ZipkinClientRequestAdapter.java      | 30 ++++++++++---
 .../zipkin/ZipkinClientResponseAdaptor.java     | 42 ++++++++++++++---
 .../camel/zipkin/ZipkinEventNotifier.java       | 37 +++++++++++----
 .../zipkin/ZipkinServerRequestAdapter.java      | 30 ++++++++++---
 .../zipkin/ZipkinServerResponseAdapter.java     | 47 +++++++++++++++++---
 .../zipkin/scribe/ZipkinTwoRouteScribe.java     |  8 +++-
 .../src/test/resources/log4j.properties         |  2 +-
 7 files changed, 161 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7153f3c3/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
index b3c80b1..824d58d 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
@@ -16,8 +16,10 @@
  */
 package org.apache.camel.zipkin;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.List;
 import java.util.Locale;
 
 import com.github.kristofa.brave.ClientRequestAdapter;
@@ -27,17 +29,20 @@ import com.github.kristofa.brave.SpanId;
 import com.github.kristofa.brave.internal.Nullable;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
+import org.apache.camel.util.MessageHelper;
 import org.apache.camel.util.URISupport;
 
 public final class ZipkinClientRequestAdapter implements ClientRequestAdapter {
 
+    private final ZipkinEventNotifier eventNotifier;
     private final String serviceName;
     private final Exchange exchange;
     private final Endpoint endpoint;
     private final String spanName;
     private final String url;
 
-    public ZipkinClientRequestAdapter(String serviceName, Exchange exchange, Endpoint endpoint) {
+    public ZipkinClientRequestAdapter(ZipkinEventNotifier eventNotifier, String serviceName, Exchange exchange, Endpoint endpoint) {
+        this.eventNotifier = eventNotifier;
         this.serviceName = serviceName;
         this.exchange = exchange;
         this.endpoint = endpoint;
@@ -66,12 +71,23 @@ public final class ZipkinClientRequestAdapter implements ClientRequestAdapter {
 
     @Override
     public Collection<KeyValueAnnotation> requestAnnotations() {
-        String id = exchange.getExchangeId();
-        String mep = exchange.getPattern().name();
-
         KeyValueAnnotation key1 = KeyValueAnnotation.create("camel.client.endpoint.url", url);
-        KeyValueAnnotation key2 = KeyValueAnnotation.create("camel.client.exchange.id", id);
-        KeyValueAnnotation key3 = KeyValueAnnotation.create("camel.client.exchange.pattern", mep);
-        return Arrays.asList(key1, key2, key3);
+        KeyValueAnnotation key2 = KeyValueAnnotation.create("camel.client.exchange.id", exchange.getExchangeId());
+        KeyValueAnnotation key3 = KeyValueAnnotation.create("camel.client.exchange.pattern", exchange.getPattern().name());
+
+        KeyValueAnnotation key4 = null;
+        if (eventNotifier.isIncludeMessageBody()) {
+            String body = MessageHelper.extractBodyForLogging(exchange.hasOut() ? exchange.getOut() : exchange.getIn(), "");
+            key4 = KeyValueAnnotation.create("camel.client.exchange.message.request.body", body);
+        }
+
+        List<KeyValueAnnotation> list = new ArrayList<>();
+        list.add(key1);
+        list.add(key2);
+        list.add(key3);
+        if (key4 != null) {
+            list.add(key4);
+        }
+        return list;
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7153f3c3/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java
index 296c021..8885ecd 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java
@@ -16,30 +16,62 @@
  */
 package org.apache.camel.zipkin;
 
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.List;
 
 import com.github.kristofa.brave.ClientResponseAdapter;
 import com.github.kristofa.brave.KeyValueAnnotation;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
+import org.apache.camel.util.MessageHelper;
+import org.apache.camel.util.URISupport;
 
 public class ZipkinClientResponseAdaptor implements ClientResponseAdapter {
 
+    private final ZipkinEventNotifier eventNotifier;
     private final Exchange exchange;
     private final Endpoint endpoint;
+    private final String url;
 
-    public ZipkinClientResponseAdaptor(Exchange exchange, Endpoint endpoint) {
+    public ZipkinClientResponseAdaptor(ZipkinEventNotifier eventNotifier, Exchange exchange, Endpoint endpoint) {
+        this.eventNotifier = eventNotifier;
         this.exchange = exchange;
         this.endpoint = endpoint;
+        this.url = URISupport.sanitizeUri(endpoint.getEndpointUri());
     }
 
     @Override
     public Collection<KeyValueAnnotation> responseAnnotations() {
-        if (exchange.getException() != null) {
-            return Collections.singletonList(KeyValueAnnotation.create("camel.failure", exchange.getException().getMessage()));
-        } else {
-            return Collections.emptyList();
+        KeyValueAnnotation key1 = KeyValueAnnotation.create("camel.client.endpoint.url", url);
+        KeyValueAnnotation key2 = KeyValueAnnotation.create("camel.client.exchange.id", exchange.getExchangeId());
+        KeyValueAnnotation key3 = KeyValueAnnotation.create("camel.client.exchange.pattern", exchange.getPattern().name());
+
+        KeyValueAnnotation key4 = null;
+        if (eventNotifier.isIncludeMessageBody()) {
+            String body = MessageHelper.extractBodyForLogging(exchange.hasOut() ? exchange.getOut() : exchange.getIn(), "");
+            key4 = KeyValueAnnotation.create("camel.client.exchange.message.response.body", body);
+        }
+
+        KeyValueAnnotation key5 = null;
+        // lets capture http response code for http based components
+        String responseCode = exchange.hasOut() ? exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE, String.class) : exchange.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE, String.class);
+        if (responseCode != null) {
+            key5 = KeyValueAnnotation.create("camel.client.exchange.message.response.code", responseCode);
+        }
+
+        List<KeyValueAnnotation> list = new ArrayList<>();
+        list.add(key1);
+        list.add(key2);
+        list.add(key3);
+        if (key4 != null) {
+            list.add(key4);
+        }
+        if (key5 != null) {
+            list.add(key5);
         }
+        return list;
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7153f3c3/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
index b8301e9..d06985a 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
@@ -31,6 +31,9 @@ import com.twitter.zipkin.gen.Span;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
+import org.apache.camel.StatefulService;
+import org.apache.camel.api.management.ManagedAttribute;
+import org.apache.camel.api.management.ManagedResource;
 import org.apache.camel.management.event.ExchangeCompletedEvent;
 import org.apache.camel.management.event.ExchangeCreatedEvent;
 import org.apache.camel.management.event.ExchangeFailedEvent;
@@ -58,12 +61,14 @@ import static org.apache.camel.builder.ExpressionBuilder.routeIdExpression;
  * <p/>
  * At least one mapping must be configured, you can use <tt>*</tt> to match all incoming and outgoing messages.
  */
-public class ZipkinEventNotifier extends EventNotifierSupport {
+@ManagedResource(description = "Managing ZipkinEventNotifier")
+public class ZipkinEventNotifier extends EventNotifierSupport implements StatefulService {
 
     private float rate = 1.0f;
     private SpanCollector spanCollector;
     private Map<String, String> serviceMappings = new HashMap<>();
     private Map<String, Brave> braves = new HashMap<>();
+    private boolean includeMessageBody;
 
     public ZipkinEventNotifier() {
     }
@@ -123,6 +128,22 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
         serviceMappings.put(pattern, serviceName);
     }
 
+    @ManagedAttribute(description = "Whether to include the Camel message body in the zipkin traces")
+    public boolean isIncludeMessageBody() {
+        return includeMessageBody;
+    }
+
+    /**
+     * Whether to include the Camel message body in the zipkin traces.
+     * <p/>
+     * This is not recommended for production usage, or when having big payloads. You can limit the size by
+     * configuring the <a href="http://camel.apache.org/how-do-i-set-the-max-chars-when-debug-logging-messages-in-camel.html">max debug log size</a>.
+     */
+    @ManagedAttribute(description = "Whether to include the Camel message body in the zipkin traces")
+    public void setIncludeMessageBody(boolean includeMessageBody) {
+        this.includeMessageBody = includeMessageBody;
+    }
+
     @Override
     protected void doStart() throws Exception {
         super.doStart();
@@ -276,7 +297,7 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
 
     private void clientRequest(Brave brave, String serviceName, ExchangeSendingEvent event) {
         ClientSpanThreadBinder binder = brave.clientSpanThreadBinder();
-        brave.clientRequestInterceptor().handle(new ZipkinClientRequestAdapter(serviceName, event.getExchange(), event.getEndpoint()));
+        brave.clientRequestInterceptor().handle(new ZipkinClientRequestAdapter(this, serviceName, event.getExchange(), event.getEndpoint()));
         Span span = binder.getCurrentClientSpan();
 
         String key = "CamelZipkinClientSpan-" + serviceName;
@@ -292,7 +313,7 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
         String key = "CamelZipkinClientSpan-" + serviceName;
         Span span = event.getExchange().getProperty(key, Span.class);
         binder.setCurrentSpan(span);
-        brave.clientResponseInterceptor().handle(new ZipkinClientResponseAdaptor(event.getExchange(), event.getEndpoint()));
+        brave.clientResponseInterceptor().handle(new ZipkinClientResponseAdaptor(this, event.getExchange(), event.getEndpoint()));
         binder.setCurrentSpan(null);
 
         if (log.isDebugEnabled()) {
@@ -302,7 +323,7 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
 
     private void serverRequest(Brave brave, String serviceName, ExchangeCreatedEvent event) {
         ServerSpanThreadBinder binder = brave.serverSpanThreadBinder();
-        brave.serverRequestInterceptor().handle(new ZipkinServerRequestAdapter(event.getExchange()));
+        brave.serverRequestInterceptor().handle(new ZipkinServerRequestAdapter(this, event.getExchange()));
         ServerSpan span = binder.getCurrentServerSpan();
         String key = "CamelZipkinServerSpan-" + serviceName;
         event.getExchange().setProperty(key, span);
@@ -317,11 +338,11 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
         String key = "CamelZipkinServerSpan-" + serviceName;
         ServerSpan span = event.getExchange().getProperty(key, ServerSpan.class);
         binder.setCurrentSpan(span);
-        brave.serverResponseInterceptor().handle(new ZipkinServerResponseAdapter(event.getExchange()));
+        brave.serverResponseInterceptor().handle(new ZipkinServerResponseAdapter(this, event.getExchange()));
         binder.setCurrentSpan(null);
 
         if (log.isDebugEnabled()) {
-            log.debug("serverResponse: service={}, spanId={} ", serviceName, span != null ? span.getSpan().getId() : "<null>");
+            log.debug("serverResponse[service={}, spanId={}, status=exchangeCompleted]", serviceName, span != null ? span.getSpan().getId() : "<null>");
         }
     }
 
@@ -330,11 +351,11 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
         String key = "CamelZipkinServerSpan-" + serviceName;
         ServerSpan span = event.getExchange().getProperty(key, ServerSpan.class);
         binder.setCurrentSpan(span);
-        brave.serverResponseInterceptor().handle(new ZipkinServerResponseAdapter(event.getExchange()));
+        brave.serverResponseInterceptor().handle(new ZipkinServerResponseAdapter(this, event.getExchange()));
         binder.setCurrentSpan(null);
 
         if (log.isDebugEnabled()) {
-            log.debug("serverResponse[service={}, spanId={}]", serviceName, span != null ? span.getSpan().getId() : "<null>");
+            log.debug("serverResponse[service={}, spanId={}, status=exchangeFailed]", serviceName, span != null ? span.getSpan().getId() : "<null>");
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/7153f3c3/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
index 59c6b4f..6dc89a2 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
@@ -16,8 +16,10 @@
  */
 package org.apache.camel.zipkin;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.List;
 import java.util.Locale;
 
 import com.github.kristofa.brave.KeyValueAnnotation;
@@ -26,18 +28,21 @@ import com.github.kristofa.brave.SpanId;
 import com.github.kristofa.brave.TraceData;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
+import org.apache.camel.util.MessageHelper;
 import org.apache.camel.util.URISupport;
 
 import static org.apache.camel.zipkin.ZipkinHelper.getSpanId;
 
 public class ZipkinServerRequestAdapter implements ServerRequestAdapter {
 
+    private final ZipkinEventNotifier eventNotifier;
     private final Exchange exchange;
     private final Endpoint endpoint;
     private final String spanName;
     private final String url;
 
-    public ZipkinServerRequestAdapter(Exchange exchange) {
+    public ZipkinServerRequestAdapter(ZipkinEventNotifier eventNotifier, Exchange exchange) {
+        this.eventNotifier = eventNotifier;
         this.exchange = exchange;
         this.endpoint = exchange.getFromEndpoint();
         this.spanName = URISupport.sanitizeUri(endpoint.getEndpointKey()).toLowerCase(Locale.US);
@@ -64,13 +69,24 @@ public class ZipkinServerRequestAdapter implements ServerRequestAdapter {
 
     @Override
     public Collection<KeyValueAnnotation> requestAnnotations() {
-        String id = exchange.getExchangeId();
-        String mep = exchange.getPattern().name();
-
         KeyValueAnnotation key1 = KeyValueAnnotation.create("camel.server.endpoint.url", url);
-        KeyValueAnnotation key2 = KeyValueAnnotation.create("camel.server.exchange.id", id);
-        KeyValueAnnotation key3 = KeyValueAnnotation.create("camel.server.exchange.pattern", mep);
-        return Arrays.asList(key1, key2, key3);
+        KeyValueAnnotation key2 = KeyValueAnnotation.create("camel.server.exchange.id", exchange.getExchangeId());
+        KeyValueAnnotation key3 = KeyValueAnnotation.create("camel.server.exchange.pattern", exchange.getPattern().name());
+
+        KeyValueAnnotation key4 = null;
+        if (eventNotifier.isIncludeMessageBody()) {
+            String body = MessageHelper.extractBodyForLogging(exchange.hasOut() ? exchange.getOut() : exchange.getIn(), "");
+            key4 = KeyValueAnnotation.create("camel.server.exchange.message.request.body", body);
+        }
+
+        List<KeyValueAnnotation> list = new ArrayList<>();
+        list.add(key1);
+        list.add(key2);
+        list.add(key3);
+        if (key4 != null) {
+            list.add(key4);
+        }
+        return list;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7153f3c3/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java
index 0a7035c..3c33a12 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java
@@ -16,30 +16,67 @@
  */
 package org.apache.camel.zipkin;
 
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
+import java.util.List;
 
 import com.github.kristofa.brave.KeyValueAnnotation;
 import com.github.kristofa.brave.ServerResponseAdapter;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
+import org.apache.camel.util.MessageHelper;
+import org.apache.camel.util.URISupport;
 
 public class ZipkinServerResponseAdapter implements ServerResponseAdapter {
 
+    private final ZipkinEventNotifier eventNotifier;
     private final Exchange exchange;
     private final Endpoint endpoint;
+    private final String url;
 
-    public ZipkinServerResponseAdapter(Exchange exchange) {
+    public ZipkinServerResponseAdapter(ZipkinEventNotifier eventNotifier, Exchange exchange) {
+        this.eventNotifier = eventNotifier;
         this.exchange = exchange;
         this.endpoint = exchange.getFromEndpoint();
+        this.url = URISupport.sanitizeUri(endpoint.getEndpointUri());
     }
 
     @Override
     public Collection<KeyValueAnnotation> responseAnnotations() {
+        String id = exchange.getExchangeId();
+        String mep = exchange.getPattern().name();
+
+        KeyValueAnnotation key1 = KeyValueAnnotation.create("camel.server.endpoint.url", url);
+        KeyValueAnnotation key2 = KeyValueAnnotation.create("camel.server.exchange.id", id);
+        KeyValueAnnotation key3 = KeyValueAnnotation.create("camel.server.exchange.pattern", mep);
+
+        KeyValueAnnotation key4 = null;
         if (exchange.getException() != null) {
-            return Collections.singletonList(KeyValueAnnotation.create("camel.server.failure", exchange.getException().getMessage()));
-        } else {
-            return Collections.emptyList();
+            String message = exchange.getException().getMessage();
+            key4 = KeyValueAnnotation.create("camel.server.exchange.failure", message);
+        } else if (eventNotifier.isIncludeMessageBody()) {
+            String body = MessageHelper.extractBodyForLogging(exchange.hasOut() ? exchange.getOut() : exchange.getIn(), "");
+            key4 = KeyValueAnnotation.create("camel.server.exchange.message.response.body", body);
+        }
+
+        KeyValueAnnotation key5 = null;
+        // lets capture http response code for http based components
+        String responseCode = exchange.hasOut() ? exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE, String.class) : exchange.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE, String.class);
+        if (responseCode != null) {
+            key5 = KeyValueAnnotation.create("camel.server.exchange.message.response.code", responseCode);
         }
+
+        List<KeyValueAnnotation> list = new ArrayList<>();
+        list.add(key1);
+        list.add(key2);
+        list.add(key3);
+        if (key4 != null) {
+            list.add(key4);
+        }
+        if (key5 != null) {
+            list.add(key5);
+        }
+        return list;
     }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7153f3c3/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTwoRouteScribe.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTwoRouteScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTwoRouteScribe.java
index 7e72c17..2c59bbc 100644
--- a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTwoRouteScribe.java
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTwoRouteScribe.java
@@ -45,6 +45,8 @@ public class ZipkinTwoRouteScribe extends CamelTestSupport {
         // we have 2 routes as services
         zipkin.addServiceMapping("seda:cat", "cat");
         zipkin.addServiceMapping("seda:dog", "dog");
+        // capture message body as well
+        zipkin.setIncludeMessageBody(true);
         zipkin.setSpanCollector(new ScribeSpanCollector(ip, 9410));
         context.getManagementStrategy().addEventNotifier(zipkin);
 
@@ -53,7 +55,7 @@ public class ZipkinTwoRouteScribe extends CamelTestSupport {
 
     @Test
     public void testZipkinRoute() throws Exception {
-        template.requestBody("direct:start", "Hello Cat and Dog");
+        template.requestBody("direct:start", "Camel say hello Cat");
     }
 
     @Override
@@ -66,11 +68,13 @@ public class ZipkinTwoRouteScribe extends CamelTestSupport {
                 from("seda:cat").routeId("cat")
                         .log("routing at ${routeId}")
                         .delay(simple("${random(1000,2000)}"))
+                        .setBody().constant("Cat says hello Dog")
                         .to("seda:dog");
 
                 from("seda:dog").routeId("dog")
                         .log("routing at ${routeId}")
-                        .delay(simple("${random(0,500)}"));
+                        .delay(simple("${random(0,500)}"))
+                        .setBody().constant("Dog say hello Cat and Camel");
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/7153f3c3/components/camel-zipkin/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/resources/log4j.properties b/components/camel-zipkin/src/test/resources/log4j.properties
index 538c5bd..ab7b29f 100644
--- a/components/camel-zipkin/src/test/resources/log4j.properties
+++ b/components/camel-zipkin/src/test/resources/log4j.properties
@@ -18,7 +18,7 @@
 #
 # The logging properties used
 #
-log4j.rootLogger=INFO, out
+log4j.rootLogger=INFO, file
 
 #log4j.logger.org.apache.camel=DEBUG
 log4j.logger.org.apache.camel.zipkin=DEBUG


[08/12] camel git commit: CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.

Posted by da...@apache.org.
CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5a92de6e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5a92de6e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5a92de6e

Branch: refs/heads/master
Commit: 5a92de6edb880b610c9c85d72a29175cdbe97e5c
Parents: a336ee9
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 29 11:06:56 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 29 14:41:54 2016 +0200

----------------------------------------------------------------------
 .../zipkin/ZipkinClientRequestAdapter.java      |   4 +-
 .../camel/zipkin/ZipkinEventNotifier.java       | 191 ++++++++++++-------
 .../zipkin/ZipkinServerRequestAdapter.java      |   4 +-
 .../zipkin/scribe/ZipkinOneRouteScribe.java     |  80 ++++++++
 .../scribe/ZipkinRouteConcurrentScribe.java     |  10 +-
 .../zipkin/scribe/ZipkinSimpleRouteScribe.java  |   8 +-
 .../zipkin/scribe/ZipkinTimerRouteScribe.java   |  78 ++++++++
 .../src/test/resources/log4j.properties         |   4 +-
 8 files changed, 298 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5a92de6e/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
index 08e1679..e6e30477 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
@@ -64,7 +64,7 @@ public final class ZipkinClientRequestAdapter implements ClientRequestAdapter {
 
     @Override
     public Collection<KeyValueAnnotation> requestAnnotations() {
-        String msgId = exchange.getIn().getMessageId();
-        return Collections.singletonList(KeyValueAnnotation.create("camel.message.id", msgId));
+        String id = exchange.getExchangeId();
+        return Collections.singletonList(KeyValueAnnotation.create("camel.exchange.id", id));
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/5a92de6e/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
index 97c57c2..ad0742e 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.zipkin;
 
+import java.io.Closeable;
 import java.util.EventObject;
 import java.util.HashMap;
 import java.util.Map;
@@ -23,6 +24,8 @@ import java.util.Map;
 import com.github.kristofa.brave.Brave;
 import com.github.kristofa.brave.ClientSpanThreadBinder;
 import com.github.kristofa.brave.Sampler;
+import com.github.kristofa.brave.ServerSpan;
+import com.github.kristofa.brave.ServerSpanThreadBinder;
 import com.github.kristofa.brave.SpanCollector;
 import com.twitter.zipkin.gen.Span;
 import org.apache.camel.CamelContext;
@@ -35,6 +38,8 @@ import org.apache.camel.management.event.ExchangeSendingEvent;
 import org.apache.camel.management.event.ExchangeSentEvent;
 import org.apache.camel.support.EventNotifierSupport;
 import org.apache.camel.util.EndpointHelper;
+import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.ServiceHelper;
 
 import static org.apache.camel.builder.ExpressionBuilder.routeIdExpression;
 
@@ -45,8 +50,8 @@ import static org.apache.camel.builder.ExpressionBuilder.routeIdExpression;
  * This means you need to configure which which Camel endpoints that maps to zipkin service names.
  * The mapping can be configured using
  * <ul>
- *     <li>route id - A Camel route id</li>
- *     <li>endpoint url - A Camel endpoint url</li>
+ * <li>route id - A Camel route id</li>
+ * <li>endpoint url - A Camel endpoint url</li>
  * </ul>
  * For both kinds you can use wildcards and regular expressions to match, which is using the rules from
  * {@link EndpointHelper#matchPattern(String, String)} and {@link EndpointHelper#matchEndpoint(CamelContext, String, String)}
@@ -122,6 +127,19 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
                 braves.put(serviceName, brave);
             }
         }
+
+        ServiceHelper.startService(spanCollector);
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        super.doStop();
+
+        // stop and close collector
+        ServiceHelper.stopAndShutdownService(spanCollector);
+        if (spanCollector instanceof Closeable) {
+            IOHelper.close((Closeable) spanCollector);
+        }
     }
 
     @Override
@@ -134,16 +152,7 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
         String answer = null;
 
         String id = routeIdExpression().evaluate(exchange, String.class);
-        for (Map.Entry<String, String> entry : serviceMappings.entrySet()) {
-            String pattern = entry.getKey();
-            if (EndpointHelper.matchPattern(pattern, id)) {
-                answer = entry.getValue();
-                break;
-            }
-        }
-
-        if (answer == null) {
-            id = exchange.getFromRouteId();
+        if (id != null) {
             for (Map.Entry<String, String> entry : serviceMappings.entrySet()) {
                 String pattern = entry.getKey();
                 if (EndpointHelper.matchPattern(pattern, id)) {
@@ -153,24 +162,41 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
             }
         }
 
+        if (answer == null) {
+            id = exchange.getFromRouteId();
+            if (id != null) {
+                for (Map.Entry<String, String> entry : serviceMappings.entrySet()) {
+                    String pattern = entry.getKey();
+                    if (EndpointHelper.matchPattern(pattern, id)) {
+                        answer = entry.getValue();
+                        break;
+                    }
+                }
+            }
+        }
+
         if (answer == null && endpoint != null) {
             String url = endpoint.getEndpointUri();
-            for (Map.Entry<String, String> entry : serviceMappings.entrySet()) {
-                String pattern = entry.getKey();
-                if (EndpointHelper.matchEndpoint(exchange.getContext(), url, pattern)) {
-                    answer = entry.getValue();
-                    break;
+            if (url != null) {
+                for (Map.Entry<String, String> entry : serviceMappings.entrySet()) {
+                    String pattern = entry.getKey();
+                    if (EndpointHelper.matchEndpoint(exchange.getContext(), url, pattern)) {
+                        answer = entry.getValue();
+                        break;
+                    }
                 }
             }
         }
 
         if (answer == null && exchange.getFromEndpoint() != null) {
             String url = exchange.getFromEndpoint().getEndpointUri();
-            for (Map.Entry<String, String> entry : serviceMappings.entrySet()) {
-                String pattern = entry.getKey();
-                if (EndpointHelper.matchEndpoint(exchange.getContext(), url, pattern)) {
-                    answer = entry.getValue();
-                    break;
+            if (url != null) {
+                for (Map.Entry<String, String> entry : serviceMappings.entrySet()) {
+                    String pattern = entry.getKey();
+                    if (EndpointHelper.matchEndpoint(exchange.getContext(), url, pattern)) {
+                        answer = entry.getValue();
+                        break;
+                    }
                 }
             }
         }
@@ -189,73 +215,98 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
     @Override
     public void notify(EventObject event) throws Exception {
         if (event instanceof ExchangeSendingEvent) {
-            clientRequest((ExchangeSendingEvent) event);
+            ExchangeSendingEvent ese = (ExchangeSendingEvent) event;
+            String serviceName = getServiceName(ese.getExchange(), ese.getEndpoint());
+            Brave brave = getBrave(serviceName);
+            if (brave != null) {
+                clientRequest(brave, serviceName, ese);
+            }
         } else if (event instanceof ExchangeSentEvent) {
-            clientResponse((ExchangeSentEvent) event);
+            ExchangeSentEvent ese = (ExchangeSentEvent) event;
+            String serviceName = getServiceName(ese.getExchange(), ese.getEndpoint());
+            Brave brave = getBrave(serviceName);
+            if (brave != null) {
+                clientResponse(brave, serviceName, ese);
+            }
         } else if (event instanceof ExchangeCreatedEvent) {
-            serverRequest((ExchangeCreatedEvent) event);
+            ExchangeCreatedEvent ece = (ExchangeCreatedEvent) event;
+            String serviceName = getServiceName(ece.getExchange(), null);
+            Brave brave = getBrave(serviceName);
+            if (brave != null) {
+                serverRequest(brave, serviceName, ece);
+            }
         } else if (event instanceof ExchangeCompletedEvent) {
-            serverResponse((ExchangeCompletedEvent) event);
+            ExchangeCompletedEvent ece = (ExchangeCompletedEvent) event;
+            String serviceName = getServiceName(ece.getExchange(), null);
+            Brave brave = getBrave(serviceName);
+            if (brave != null) {
+                serverResponse(brave, serviceName, ece);
+            }
         } else if (event instanceof ExchangeFailedEvent) {
-            serverResponse((ExchangeFailedEvent) event);
+            ExchangeFailedEvent efe = (ExchangeFailedEvent) event;
+            String serviceName = getServiceName(efe.getExchange(), null);
+            Brave brave = getBrave(serviceName);
+            if (brave != null) {
+                serverResponse(brave, serviceName, efe);
+            }
         }
     }
 
-    private void clientRequest(ExchangeSendingEvent event) {
-        String serviceName = getServiceName(event.getExchange(), event.getEndpoint());
-        Brave brave = getBrave(serviceName);
-        if (brave != null) {
-            ClientSpanThreadBinder binder = brave.clientSpanThreadBinder();
-            brave.clientRequestInterceptor().handle(new ZipkinClientRequestAdapter(serviceName, event.getExchange(), event.getEndpoint()));
-            Span span = binder.getCurrentClientSpan();
-            event.getExchange().setProperty("CamelZipkinSpan", span);
+    private void clientRequest(Brave brave, String serviceName, ExchangeSendingEvent event) {
+        ClientSpanThreadBinder binder = brave.clientSpanThreadBinder();
+        brave.clientRequestInterceptor().handle(new ZipkinClientRequestAdapter(serviceName, event.getExchange(), event.getEndpoint()));
+        Span span = binder.getCurrentClientSpan();
+        event.getExchange().setProperty("CamelZipkinClientSpan", span);
+
+        if (log.isDebugEnabled()) {
+            log.debug("clientRequest: service={}, id={} ", serviceName, span != null ? span.getId() : "<null>");
         }
     }
 
-    private void clientResponse(ExchangeSentEvent event) {
-        String serviceName = getServiceName(event.getExchange(), event.getEndpoint());
-        Brave brave = getBrave(serviceName);
-        if (brave != null) {
-            ClientSpanThreadBinder binder = brave.clientSpanThreadBinder();
-            Span span = event.getExchange().getProperty("CamelZipkinSpan", Span.class);
-            binder.setCurrentSpan(span);
-            brave.clientResponseInterceptor().handle(new ZipkinClientResponseAdaptor(event.getExchange(), event.getEndpoint()));
-            binder.setCurrentSpan(null);
+    private void clientResponse(Brave brave, String serviceName, ExchangeSentEvent event) {
+        ClientSpanThreadBinder binder = brave.clientSpanThreadBinder();
+        Span span = event.getExchange().getProperty("CamelZipkinClientSpan", Span.class);
+        binder.setCurrentSpan(span);
+        brave.clientResponseInterceptor().handle(new ZipkinClientResponseAdaptor(event.getExchange(), event.getEndpoint()));
+        binder.setCurrentSpan(null);
+
+        if (log.isDebugEnabled()) {
+            log.debug("clientResponse: service={}, id={} ", serviceName, span != null ? span.getId() : "<null>");
         }
     }
 
-    private void serverRequest(ExchangeCreatedEvent event) {
-        String serviceName = getServiceName(event.getExchange(), null);
-        Brave brave = getBrave(serviceName);
-        if (brave != null) {
-            ClientSpanThreadBinder binder = brave.clientSpanThreadBinder();
-            brave.serverRequestInterceptor().handle(new ZipkinServerRequestAdapter(event.getExchange()));
-            Span span = binder.getCurrentClientSpan();
-            event.getExchange().setProperty("CamelZipkinSpan", span);
+    private void serverRequest(Brave brave, String serviceName, ExchangeCreatedEvent event) {
+        ServerSpanThreadBinder binder = brave.serverSpanThreadBinder();
+        brave.serverRequestInterceptor().handle(new ZipkinServerRequestAdapter(event.getExchange()));
+        ServerSpan span = binder.getCurrentServerSpan();
+        event.getExchange().setProperty("CamelZipkinServerSpan", span);
+
+        if (log.isDebugEnabled()) {
+            log.debug("serverRequest: service={}, id={} ", serviceName, span != null ? span.getSpan().getId() : "<null>");
         }
     }
 
-    private void serverResponse(ExchangeCompletedEvent event) {
-        String serviceName = getServiceName(event.getExchange(), null);
-        Brave brave = getBrave(serviceName);
-        if (brave != null) {
-            ClientSpanThreadBinder binder = brave.clientSpanThreadBinder();
-            Span span = event.getExchange().getProperty("CamelZipkinSpan", Span.class);
-            binder.setCurrentSpan(span);
-            brave.serverResponseInterceptor().handle(new ZipkinServerResponseAdapter(event.getExchange()));
-            binder.setCurrentSpan(null);
+    private void serverResponse(Brave brave, String serviceName, ExchangeCompletedEvent event) {
+        ServerSpanThreadBinder binder = brave.serverSpanThreadBinder();
+        ServerSpan span = event.getExchange().getProperty("CamelZipkinServerSpan", ServerSpan.class);
+        binder.setCurrentSpan(span);
+        brave.serverResponseInterceptor().handle(new ZipkinServerResponseAdapter(event.getExchange()));
+        binder.setCurrentSpan(null);
+
+        if (log.isDebugEnabled()) {
+            log.debug("serverResponse: service={}, id={} ", serviceName, span != null ? span.getSpan().getId() : "<null>");
         }
     }
 
-    private void serverResponse(ExchangeFailedEvent event) {
-        String serviceName = getServiceName(event.getExchange(), null);
-        Brave brave = getBrave(serviceName);
-        if (brave != null) {
-            ClientSpanThreadBinder binder = brave.clientSpanThreadBinder();
-            Span span = event.getExchange().getProperty("CamelZipkinSpan", Span.class);
-            binder.setCurrentSpan(span);
-            brave.serverResponseInterceptor().handle(new ZipkinServerResponseAdapter(event.getExchange()));
-            binder.setCurrentSpan(null);
+    private void serverResponse(Brave brave, String serviceName, ExchangeFailedEvent event) {
+        ServerSpanThreadBinder binder = brave.serverSpanThreadBinder();
+        ServerSpan span = event.getExchange().getProperty("CamelZipkinServerSpan", ServerSpan.class);
+        binder.setCurrentSpan(span);
+        brave.serverResponseInterceptor().handle(new ZipkinServerResponseAdapter(event.getExchange()));
+        binder.setCurrentSpan(null);
+
+        if (log.isDebugEnabled()) {
+            log.debug("serverResponse: service={}, id={} ", serviceName, span != null ? span.getSpan().getId() : "<null>");
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/5a92de6e/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
index fa67ddb..c5daef9 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
@@ -62,8 +62,8 @@ public class ZipkinServerRequestAdapter implements ServerRequestAdapter {
 
     @Override
     public Collection<KeyValueAnnotation> requestAnnotations() {
-        String msgId = exchange.getIn().getMessageId();
-        return Collections.singletonList(KeyValueAnnotation.create("camel.message.id", msgId));
+        String id = exchange.getExchangeId();
+        return Collections.singletonList(KeyValueAnnotation.create("camel.exchange.id", id));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/5a92de6e/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinOneRouteScribe.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinOneRouteScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinOneRouteScribe.java
new file mode 100644
index 0000000..c14a026
--- /dev/null
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinOneRouteScribe.java
@@ -0,0 +1,80 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.zipkin.scribe;
+
+import java.util.concurrent.TimeUnit;
+
+import com.github.kristofa.brave.scribe.ScribeSpanCollector;
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.zipkin.ZipkinEventNotifier;
+import org.junit.Test;
+
+/**
+ * Integration test requires running Zipkin/Scribe running
+ *
+ * The easiest way is to run using zipkin-docker: https://github.com/openzipkin/docker-zipkin
+ *
+ * Adjust the IP address to what IP docker-machines have assigned, you can use
+ * <tt>docker-machines ls</tt>
+ */
+public class ZipkinOneRouteScribe extends CamelTestSupport {
+
+    private String ip = "192.168.99.100";
+    private ZipkinEventNotifier zipkin;
+
+    // TODO: producer template also
+    // TODO: message id added x2
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        zipkin = new ZipkinEventNotifier();
+        zipkin.addServiceMapping("seda:cat", "cat");
+        zipkin.setSpanCollector(new ScribeSpanCollector(ip, 9410));
+        context.getManagementStrategy().addEventNotifier(zipkin);
+
+        return context;
+    }
+
+    @Test
+    public void testZipkinRoute() throws Exception {
+        NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
+
+        for (int i = 0; i < 1; i++) {
+            template.sendBody("seda:cat", "Hello Cat");
+        }
+
+        assertTrue(notify.matches(30, TimeUnit.SECONDS));
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("seda:cat").routeId("cat")
+                        .log("routing at ${routeId}")
+                        .delay(simple("${random(1000,2000)}"));
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/5a92de6e/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java
index d371547..65fdfdf 100644
--- a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java
@@ -31,9 +31,13 @@ import org.junit.Test;
  * Integration test requires running Zipkin/Scribe running
  *
  * The easiest way is to run using zipkin-docker: https://github.com/openzipkin/docker-zipkin
+ *
+ * Adjust the IP address to what IP docker-machines have assigned, you can use
+ * <tt>docker-machines ls</tt>
  */
 public class ZipkinRouteConcurrentScribe extends CamelTestSupport {
 
+    private String ip = "192.168.99.100";
     private ZipkinEventNotifier zipkin;
 
     @Override
@@ -43,7 +47,7 @@ public class ZipkinRouteConcurrentScribe extends CamelTestSupport {
         zipkin = new ZipkinEventNotifier();
         zipkin.addServiceMapping("seda:foo", "foo");
         zipkin.addServiceMapping("seda:bar", "bar");
-        zipkin.setSpanCollector(new ScribeSpanCollector("192.168.99.101", 9410));
+        zipkin.setSpanCollector(new ScribeSpanCollector(ip, 9410));
         context.getManagementStrategy().addEventNotifier(zipkin);
 
         return context;
@@ -65,12 +69,12 @@ public class ZipkinRouteConcurrentScribe extends CamelTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("seda:foo").routeId("foo")
+                from("seda:foo?concurrentConsumers=5").routeId("foo")
                         .log("routing at ${routeId}")
                         .delay(simple("${random(1000,2000)}"))
                         .to("seda:bar");
 
-                from("seda:bar").routeId("bar")
+                from("seda:bar?concurrentConsumers=5").routeId("bar")
                         .log("routing at ${routeId}")
                         .delay(simple("${random(0,500)}"));
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/5a92de6e/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java
index 3d91927..fc898c8 100644
--- a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java
@@ -31,9 +31,13 @@ import org.junit.Test;
  * Integration test requires running Zipkin/Scribe running
  *
  * The easiest way is to run using zipkin-docker: https://github.com/openzipkin/docker-zipkin
+ *
+ * Adjust the IP address to what IP docker-machines have assigned, you can use
+ * <tt>docker-machines ls</tt>
  */
 public class ZipkinSimpleRouteScribe extends CamelTestSupport {
 
+    private String ip = "192.168.99.100";
     private ZipkinEventNotifier zipkin;
 
     @Override
@@ -42,7 +46,7 @@ public class ZipkinSimpleRouteScribe extends CamelTestSupport {
 
         zipkin = new ZipkinEventNotifier();
         zipkin.addServiceMapping("seda:dude", "dude");
-        zipkin.setSpanCollector(new ScribeSpanCollector("192.168.99.101", 9410));
+        zipkin.setSpanCollector(new ScribeSpanCollector(ip, 9410));
         context.getManagementStrategy().addEventNotifier(zipkin);
 
         return context;
@@ -50,7 +54,7 @@ public class ZipkinSimpleRouteScribe extends CamelTestSupport {
 
     @Test
     public void testZipkinRoute() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context).whenDone(10).create();
+        NotifyBuilder notify = new NotifyBuilder(context).whenDone(5).create();
 
         for (int i = 0; i < 5; i++) {
             template.sendBody("seda:dude", "Hello World");

http://git-wip-us.apache.org/repos/asf/camel/blob/5a92de6e/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTimerRouteScribe.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTimerRouteScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTimerRouteScribe.java
new file mode 100644
index 0000000..a822b08
--- /dev/null
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTimerRouteScribe.java
@@ -0,0 +1,78 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.zipkin.scribe;
+
+import java.util.concurrent.TimeUnit;
+
+import com.github.kristofa.brave.scribe.ScribeSpanCollector;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.zipkin.ZipkinEventNotifier;
+import org.junit.Test;
+
+/**
+ * Integration test requires running Zipkin/Scribe running
+ *
+ * The easiest way is to run using zipkin-docker: https://github.com/openzipkin/docker-zipkin
+ *
+ * Adjust the IP address to what IP docker-machines have assigned, you can use
+ * <tt>docker-machines ls</tt>
+ */
+public class ZipkinTimerRouteScribe extends CamelTestSupport {
+
+    private String ip = "192.168.99.100";
+    private ZipkinEventNotifier zipkin;
+
+    // TODO: producer template also (add a skip flag)
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        zipkin = new ZipkinEventNotifier();
+        zipkin.addServiceMapping("seda:timer", "timer");
+        zipkin.setSpanCollector(new ScribeSpanCollector(ip, 9410));
+        context.getManagementStrategy().addEventNotifier(zipkin);
+
+        return context;
+    }
+
+    @Test
+    public void testZipkinRoute() throws Exception {
+        NotifyBuilder notify = new NotifyBuilder(context).from("seda:timer").whenDone(1).create();
+
+        assertTrue(notify.matches(30, TimeUnit.SECONDS));
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("timer:trigger?repeatCount=1").setBody().constant("Hello Cat").to(ExchangePattern.InOut, "seda:timer");
+
+                from("seda:timer").routeId("timer")
+                        .log("routing at ${routeId}")
+                        .delay(simple("${random(1000,2000)}"));
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/5a92de6e/components/camel-zipkin/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/resources/log4j.properties b/components/camel-zipkin/src/test/resources/log4j.properties
index 5d05c44..538c5bd 100644
--- a/components/camel-zipkin/src/test/resources/log4j.properties
+++ b/components/camel-zipkin/src/test/resources/log4j.properties
@@ -18,10 +18,10 @@
 #
 # The logging properties used
 #
-log4j.rootLogger=INFO, file
+log4j.rootLogger=INFO, out
 
 #log4j.logger.org.apache.camel=DEBUG
-#log4j.logger.org.apache.camel.zipkin=DEBUG
+log4j.logger.org.apache.camel.zipkin=DEBUG
 #log4j.logger.com.github.kristofa.brave=DEBUG
 
 # CONSOLE appender not used by default


[12/12] camel git commit: CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.

Posted by da...@apache.org.
CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f8ef4eb1
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f8ef4eb1
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f8ef4eb1

Branch: refs/heads/master
Commit: f8ef4eb1aa3fe937b08806aa2b63fb96716b6179
Parents: afc18f9
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 29 14:44:22 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 29 14:44:22 2016 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/itest/karaf/CamelZipkinTest.java  | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f8ef4eb1/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelZipkinTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelZipkinTest.java b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelZipkinTest.java
index 7a665d5..2916976 100644
--- a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelZipkinTest.java
+++ b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelZipkinTest.java
@@ -18,8 +18,6 @@ package org.apache.camel.itest.karaf;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.PaxExam;
 
 @RunWith(PaxExam.class)
@@ -29,12 +27,7 @@ public class CamelZipkinTest extends AbstractFeatureTest {
 
     @Test
     public void test() throws Exception {
-        // TODO: test zipkin
-    }
-
-    @Configuration
-    public static Option[] configure() {
-        return configure(COMPONENT);
+        installCamelFeature(COMPONENT);
     }
 
 }


[04/12] camel git commit: CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.

Posted by da...@apache.org.
CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3a4087cd
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3a4087cd
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3a4087cd

Branch: refs/heads/master
Commit: 3a4087cd80b85e8e3c610c1e9b1a88ab5600d518
Parents: d1c3bbf
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Mar 25 15:47:48 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 29 14:41:54 2016 +0200

----------------------------------------------------------------------
 components/camel-zipkin/pom.xml                 |  70 ++++++
 .../zipkin/ZipkinClientRequestAdapter.java      |  70 ++++++
 .../zipkin/ZipkinClientResponseAdaptor.java     |  45 ++++
 .../camel/zipkin/ZipkinEventNotifier.java       | 246 +++++++++++++++++++
 .../org/apache/camel/zipkin/ZipkinHelper.java   |  34 +++
 .../zipkin/ZipkinLoggingSpanCollector.java      |  67 +++++
 .../zipkin/ZipkinServerRequestAdapter.java      |  69 ++++++
 .../zipkin/ZipkinServerResponseAdapter.java     |  45 ++++
 .../src/main/resources/META-INF/LICENSE.txt     | 203 +++++++++++++++
 .../src/main/resources/META-INF/NOTICE.txt      |  11 +
 .../camel/zipkin/ZipkinRouteScribeTest.java     |  73 ++++++
 .../apache/camel/zipkin/ZipkinRouteTest.java    |  72 ++++++
 .../src/test/resources/log4j.properties         |  41 ++++
 components/pom.xml                              |   1 +
 14 files changed, 1047 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3a4087cd/components/camel-zipkin/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/pom.xml b/components/camel-zipkin/pom.xml
new file mode 100644
index 0000000..567626a
--- /dev/null
+++ b/components/camel-zipkin/pom.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<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">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <artifactId>components</artifactId>
+    <groupId>org.apache.camel</groupId>
+    <version>2.18-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>camel-zipkin</artifactId>
+  <packaging>bundle</packaging>
+  <name>Camel :: Zookeeper</name>
+  <description>Camel Zipkin Support</description>
+
+  <properties>
+    <camel.osgi.export.pkg>org.apache.camel.zipkin.*</camel.osgi.export.pkg>
+  </properties>
+
+  <dependencies>
+
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+    </dependency>
+
+    <!-- brave/zkpkin -->
+    <dependency>
+      <groupId>com.github.kristofa</groupId>
+      <artifactId>brave-core</artifactId>
+      <version>3.5.0</version>
+    </dependency>
+    <dependency>
+      <groupId>com.github.kristofa</groupId>
+      <artifactId>brave-spancollector-scribe</artifactId>
+      <version>3.5.0</version>
+    </dependency>
+
+    <!-- test dependencies -->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-test</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+  </dependencies>
+
+</project>

http://git-wip-us.apache.org/repos/asf/camel/blob/3a4087cd/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
new file mode 100644
index 0000000..5254578
--- /dev/null
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
@@ -0,0 +1,70 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.zipkin;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Locale;
+
+import com.github.kristofa.brave.ClientRequestAdapter;
+import com.github.kristofa.brave.IdConversion;
+import com.github.kristofa.brave.KeyValueAnnotation;
+import com.github.kristofa.brave.SpanId;
+import com.github.kristofa.brave.internal.Nullable;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.util.URISupport;
+
+public final class ZipkinClientRequestAdapter implements ClientRequestAdapter {
+
+    private final String serviceName;
+    private final Exchange exchange;
+    private final Endpoint endpoint;
+    private final String spanName;
+
+    public ZipkinClientRequestAdapter(String serviceName, Exchange exchange, Endpoint endpoint) {
+        this.serviceName = serviceName;
+        this.exchange = exchange;
+        this.endpoint = endpoint;
+        this.spanName = URISupport.sanitizeUri(endpoint.getEndpointKey()).toLowerCase(Locale.US);
+    }
+
+    @Override
+    public String getSpanName() {
+        return spanName;
+    }
+
+    @Override
+    public void addSpanIdToRequest(@Nullable SpanId spanId) {
+        exchange.getIn().setHeader("CamelZipkinTraceId", IdConversion.convertToString(spanId.getTraceId()));
+        exchange.getIn().setHeader("CamelZipkinSpanId", IdConversion.convertToString(spanId.getSpanId()));
+        if (spanId.getParentSpanId() != null) {
+            exchange.getIn().setHeader("CamelZipkinParentSpanId", IdConversion.convertToString(spanId.getParentSpanId()));
+        }
+    }
+
+    @Override
+    public String getClientServiceName() {
+        return serviceName;
+    }
+
+    @Override
+    public Collection<KeyValueAnnotation> requestAnnotations() {
+        String msgId = exchange.getIn().getMessageId();
+        return Collections.singletonList(KeyValueAnnotation.create("CamelMessageId", msgId));
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/3a4087cd/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java
new file mode 100644
index 0000000..daddeff
--- /dev/null
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java
@@ -0,0 +1,45 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.zipkin;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import com.github.kristofa.brave.ClientResponseAdapter;
+import com.github.kristofa.brave.KeyValueAnnotation;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+
+public class ZipkinClientResponseAdaptor implements ClientResponseAdapter {
+
+    private final Exchange exchange;
+    private final Endpoint endpoint;
+
+    public ZipkinClientResponseAdaptor(Exchange exchange, Endpoint endpoint) {
+        this.exchange = exchange;
+        this.endpoint = endpoint;
+    }
+
+    @Override
+    public Collection<KeyValueAnnotation> responseAnnotations() {
+        if (exchange.getException() != null) {
+            return Collections.singletonList(KeyValueAnnotation.create("CamelZipkinFailed", exchange.getException().getMessage()));
+        } else {
+            return Collections.emptyList();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/3a4087cd/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
new file mode 100644
index 0000000..30b8ca1
--- /dev/null
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
@@ -0,0 +1,246 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.zipkin;
+
+import java.util.EventObject;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.github.kristofa.brave.Brave;
+import com.github.kristofa.brave.ClientSpanThreadBinder;
+import com.github.kristofa.brave.Sampler;
+import com.github.kristofa.brave.SpanCollector;
+import com.twitter.zipkin.gen.Span;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.management.event.ExchangeCompletedEvent;
+import org.apache.camel.management.event.ExchangeCreatedEvent;
+import org.apache.camel.management.event.ExchangeFailedEvent;
+import org.apache.camel.management.event.ExchangeSendingEvent;
+import org.apache.camel.management.event.ExchangeSentEvent;
+import org.apache.camel.support.EventNotifierSupport;
+import org.apache.camel.util.EndpointHelper;
+
+import static org.apache.camel.builder.ExpressionBuilder.routeIdExpression;
+
+public class ZipkinEventNotifier extends EventNotifierSupport {
+
+    private float rate = 1.0f;
+    private SpanCollector spanCollector;
+    private Map<String, String> serviceMappings = new HashMap<>();
+    private Map<String, Brave> braves = new HashMap<>();
+
+    public ZipkinEventNotifier() {
+    }
+
+    public float getRate() {
+        return rate;
+    }
+
+    public void setRate(float rate) {
+        this.rate = rate;
+    }
+
+    public SpanCollector getSpanCollector() {
+        return spanCollector;
+    }
+
+    public void setSpanCollector(SpanCollector spanCollector) {
+        this.spanCollector = spanCollector;
+    }
+
+    public String getServiceName() {
+        return serviceMappings.get("*");
+    }
+
+    public void setServiceName(String serviceName) {
+        serviceMappings.put("*", serviceName);
+    }
+
+    public Map<String, String> getServiceMappings() {
+        return serviceMappings;
+    }
+
+    public void setServiceMappings(Map<String, String> serviceMappings) {
+        this.serviceMappings = serviceMappings;
+    }
+
+    public void addServiceMapping(String routeId, String serviceName) {
+        serviceMappings.put(routeId, serviceName);
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+
+        if (serviceMappings.isEmpty()) {
+            throw new IllegalStateException("At least one service name must be configured");
+        }
+
+        // create braves mapped per service name
+        for (Map.Entry<String, String> entry : serviceMappings.entrySet()) {
+            String pattern = entry.getKey();
+            String serviceName = entry.getValue();
+            Brave brave = braves.get(pattern);
+            if (brave == null) {
+                Brave.Builder builder = new Brave.Builder(serviceName);
+                builder = builder.traceSampler(Sampler.create(rate));
+                if (spanCollector != null) {
+                    builder = builder.spanCollector(spanCollector);
+                }
+                brave = builder.build();
+                braves.put(serviceName, brave);
+            }
+        }
+    }
+
+    @Override
+    public boolean isEnabled(EventObject event) {
+        return event instanceof ExchangeSendingEvent || event instanceof ExchangeSentEvent
+                || event instanceof ExchangeCreatedEvent || event instanceof ExchangeCompletedEvent || event instanceof ExchangeFailedEvent;
+    }
+
+    private String getServiceName(Exchange exchange, Endpoint endpoint) {
+        String answer = null;
+
+        String id = routeIdExpression().evaluate(exchange, String.class);
+        for (Map.Entry<String, String> entry : serviceMappings.entrySet()) {
+            String pattern = entry.getKey();
+            if (EndpointHelper.matchPattern(pattern, id)) {
+                answer = entry.getValue();
+                break;
+            }
+        }
+
+        if (answer == null) {
+            id = exchange.getFromRouteId();
+            for (Map.Entry<String, String> entry : serviceMappings.entrySet()) {
+                String pattern = entry.getKey();
+                if (EndpointHelper.matchPattern(pattern, id)) {
+                    answer = entry.getValue();
+                    break;
+                }
+            }
+        }
+
+        if (answer == null && endpoint != null) {
+            String url = endpoint.getEndpointUri();
+            for (Map.Entry<String, String> entry : serviceMappings.entrySet()) {
+                String pattern = entry.getKey();
+                if (EndpointHelper.matchEndpoint(exchange.getContext(), url, pattern)) {
+                    answer = entry.getValue();
+                    break;
+                }
+            }
+        }
+
+        if (answer == null && exchange.getFromEndpoint() != null) {
+            String url = exchange.getFromEndpoint().getEndpointUri();
+            for (Map.Entry<String, String> entry : serviceMappings.entrySet()) {
+                String pattern = entry.getKey();
+                if (EndpointHelper.matchEndpoint(exchange.getContext(), url, pattern)) {
+                    answer = entry.getValue();
+                    break;
+                }
+            }
+        }
+
+        return answer;
+    }
+
+    private Brave getBrave(String serviceName) {
+        if (serviceName != null) {
+            return braves.get(serviceName);
+        } else {
+            return null;
+        }
+    }
+
+    @Override
+    public void notify(EventObject event) throws Exception {
+        if (event instanceof ExchangeSendingEvent) {
+            clientRequest((ExchangeSendingEvent) event);
+        } else if (event instanceof ExchangeSentEvent) {
+            clientResponse((ExchangeSentEvent) event);
+        } else if (event instanceof ExchangeCreatedEvent) {
+            serverRequest((ExchangeCreatedEvent) event);
+        } else if (event instanceof ExchangeCompletedEvent) {
+            serverResponse((ExchangeCompletedEvent) event);
+        } else if (event instanceof ExchangeFailedEvent) {
+            serverResponse((ExchangeFailedEvent) event);
+        }
+    }
+
+    private void clientRequest(ExchangeSendingEvent event) {
+        String serviceName = getServiceName(event.getExchange(), event.getEndpoint());
+        Brave brave = getBrave(serviceName);
+        if (brave != null) {
+            ClientSpanThreadBinder binder = brave.clientSpanThreadBinder();
+            brave.clientRequestInterceptor().handle(new ZipkinClientRequestAdapter(serviceName, event.getExchange(), event.getEndpoint()));
+            Span span = binder.getCurrentClientSpan();
+            event.getExchange().setProperty("CamelZipkinSpan", span);
+        }
+    }
+
+    private void clientResponse(ExchangeSentEvent event) {
+        String serviceName = getServiceName(event.getExchange(), event.getEndpoint());
+        Brave brave = getBrave(serviceName);
+        if (brave != null) {
+            ClientSpanThreadBinder binder = brave.clientSpanThreadBinder();
+            Span span = event.getExchange().getProperty("CamelZipkinSpan", Span.class);
+            binder.setCurrentSpan(span);
+            brave.clientResponseInterceptor().handle(new ZipkinClientResponseAdaptor(event.getExchange(), event.getEndpoint()));
+            binder.setCurrentSpan(null);
+        }
+    }
+
+    private void serverRequest(ExchangeCreatedEvent event) {
+        String serviceName = getServiceName(event.getExchange(), null);
+        Brave brave = getBrave(serviceName);
+        if (brave != null) {
+            ClientSpanThreadBinder binder = brave.clientSpanThreadBinder();
+            brave.serverRequestInterceptor().handle(new ZipkinServerRequestAdapter(event.getExchange()));
+            Span span = binder.getCurrentClientSpan();
+            event.getExchange().setProperty("CamelZipkinSpan", span);
+        }
+    }
+
+    private void serverResponse(ExchangeCompletedEvent event) {
+        String serviceName = getServiceName(event.getExchange(), null);
+        Brave brave = getBrave(serviceName);
+        if (brave != null) {
+            ClientSpanThreadBinder binder = brave.clientSpanThreadBinder();
+            Span span = event.getExchange().getProperty("CamelZipkinSpan", Span.class);
+            binder.setCurrentSpan(span);
+            brave.serverResponseInterceptor().handle(new ZipkinServerResponseAdapter(event.getExchange()));
+            binder.setCurrentSpan(null);
+        }
+    }
+
+    private void serverResponse(ExchangeFailedEvent event) {
+        String serviceName = getServiceName(event.getExchange(), null);
+        Brave brave = getBrave(serviceName);
+        if (brave != null) {
+            ClientSpanThreadBinder binder = brave.clientSpanThreadBinder();
+            Span span = event.getExchange().getProperty("CamelZipkinSpan", Span.class);
+            binder.setCurrentSpan(span);
+            brave.serverResponseInterceptor().handle(new ZipkinServerResponseAdapter(event.getExchange()));
+            binder.setCurrentSpan(null);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/3a4087cd/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinHelper.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinHelper.java
new file mode 100644
index 0000000..d5c8c57
--- /dev/null
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinHelper.java
@@ -0,0 +1,34 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.zipkin;
+
+import com.github.kristofa.brave.IdConversion;
+import com.github.kristofa.brave.SpanId;
+
+public final class ZipkinHelper {
+
+    private ZipkinHelper() {
+    }
+
+    public static SpanId getSpanId(String traceId, String spanId, String parentSpanId) {
+        if (parentSpanId != null) {
+            return SpanId.create(IdConversion.convertToLong(traceId), IdConversion.convertToLong(spanId), IdConversion.convertToLong(parentSpanId));
+        }
+        return SpanId.create(IdConversion.convertToLong(traceId), IdConversion.convertToLong(spanId), null);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/3a4087cd/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java
new file mode 100644
index 0000000..71d551a
--- /dev/null
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java
@@ -0,0 +1,67 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.zipkin;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import com.github.kristofa.brave.IdConversion;
+import com.github.kristofa.brave.SpanCollector;
+import com.twitter.zipkin.gen.BinaryAnnotation;
+import com.twitter.zipkin.gen.Span;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ZipkinLoggingSpanCollector implements SpanCollector {
+
+    private final Set<BinaryAnnotation> defaultAnnotations = new LinkedHashSet<BinaryAnnotation>();
+    private final String name;
+    private final Logger logger;
+
+    public ZipkinLoggingSpanCollector() {
+        this(ZipkinLoggingSpanCollector.class.getName());
+    }
+
+    public ZipkinLoggingSpanCollector(String name) {
+        this.name = name;
+        this.logger = LoggerFactory.getLogger(name);
+    }
+
+    @Override
+    public void collect(Span span) {
+        if (!defaultAnnotations.isEmpty()) {
+            for (BinaryAnnotation ba : defaultAnnotations) {
+                span.addToBinary_annotations(ba);
+            }
+        }
+
+        if (logger.isInfoEnabled()) {
+            long ms = span.getDuration() != null ? span.getDuration() / 1000 : -1;
+            String id = IdConversion.convertToString(span.getId());
+            String line = String.format("%s(%s) - %s ms", span.getName(), id, ms);
+            logger.info(line);
+        }
+    }
+
+    @Override
+    public void addDefaultAnnotation(String key, String value) {
+        defaultAnnotations.add(BinaryAnnotation.create(key, value, null));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/3a4087cd/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
new file mode 100644
index 0000000..c6ec850
--- /dev/null
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
@@ -0,0 +1,69 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.zipkin;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Locale;
+
+import com.github.kristofa.brave.KeyValueAnnotation;
+import com.github.kristofa.brave.ServerRequestAdapter;
+import com.github.kristofa.brave.SpanId;
+import com.github.kristofa.brave.TraceData;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.util.URISupport;
+
+import static org.apache.camel.zipkin.ZipkinHelper.getSpanId;
+
+public class ZipkinServerRequestAdapter implements ServerRequestAdapter {
+
+    private final Exchange exchange;
+    private final Endpoint endpoint;
+    private final String spanName;
+
+    public ZipkinServerRequestAdapter(Exchange exchange) {
+        this.exchange = exchange;
+        this.endpoint = exchange.getFromEndpoint();
+        this.spanName = URISupport.sanitizeUri(endpoint.getEndpointKey()).toLowerCase(Locale.US);
+    }
+
+    @Override
+    public TraceData getTraceData() {
+        String traceId = exchange.getIn().getHeader("CamelZipkinTraceId", String.class);
+        String spanId = exchange.getIn().getHeader("CamelZipkinSpanId", String.class);
+        String parentSpanId = exchange.getIn().getHeader("CamelZipkinParentSpanId", String.class);
+        if (traceId != null && spanId != null) {
+            SpanId span = getSpanId(traceId, spanId, parentSpanId);
+            return TraceData.builder().sample(true).spanId(span).build();
+        } else {
+            return TraceData.builder().build();
+        }
+    }
+
+    @Override
+    public String getSpanName() {
+        return spanName;
+    }
+
+    @Override
+    public Collection<KeyValueAnnotation> requestAnnotations() {
+        String msgId = exchange.getIn().getMessageId();
+        return Collections.singletonList(KeyValueAnnotation.create("CamelMessageId", msgId));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/3a4087cd/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java
new file mode 100644
index 0000000..8cb5b67
--- /dev/null
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java
@@ -0,0 +1,45 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.zipkin;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import com.github.kristofa.brave.KeyValueAnnotation;
+import com.github.kristofa.brave.ServerResponseAdapter;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+
+public class ZipkinServerResponseAdapter implements ServerResponseAdapter {
+
+    private final Exchange exchange;
+    private final Endpoint endpoint;
+
+    public ZipkinServerResponseAdapter(Exchange exchange) {
+        this.exchange = exchange;
+        this.endpoint = exchange.getFromEndpoint();
+    }
+
+    @Override
+    public Collection<KeyValueAnnotation> responseAnnotations() {
+        if (exchange.getException() != null) {
+            return Collections.singletonList(KeyValueAnnotation.create("failure", exchange.getException().getMessage()));
+        } else {
+            return Collections.emptyList();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/3a4087cd/components/camel-zipkin/src/main/resources/META-INF/LICENSE.txt
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/resources/META-INF/LICENSE.txt b/components/camel-zipkin/src/main/resources/META-INF/LICENSE.txt
new file mode 100644
index 0000000..6b0b127
--- /dev/null
+++ b/components/camel-zipkin/src/main/resources/META-INF/LICENSE.txt
@@ -0,0 +1,203 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
+

http://git-wip-us.apache.org/repos/asf/camel/blob/3a4087cd/components/camel-zipkin/src/main/resources/META-INF/NOTICE.txt
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/resources/META-INF/NOTICE.txt b/components/camel-zipkin/src/main/resources/META-INF/NOTICE.txt
new file mode 100644
index 0000000..2e215bf
--- /dev/null
+++ b/components/camel-zipkin/src/main/resources/META-INF/NOTICE.txt
@@ -0,0 +1,11 @@
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the Apache Camel distribution.                    ==
+   =========================================================================
+
+   This product includes software developed by
+   The Apache Software Foundation (http://www.apache.org/).
+
+   Please read the different LICENSE files present in the licenses directory of
+   this distribution.

http://git-wip-us.apache.org/repos/asf/camel/blob/3a4087cd/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteScribeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteScribeTest.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteScribeTest.java
new file mode 100644
index 0000000..94d2ca4
--- /dev/null
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteScribeTest.java
@@ -0,0 +1,73 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.zipkin;
+
+import java.util.concurrent.TimeUnit;
+
+import com.github.kristofa.brave.scribe.ScribeSpanCollector;
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class ZipkinRouteScribeTest extends CamelTestSupport {
+
+    private ZipkinEventNotifier zipkin;
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        zipkin = new ZipkinEventNotifier();
+        zipkin.addServiceMapping("seda:foo", "foo");
+        zipkin.addServiceMapping("seda:bar", "bar");
+        zipkin.setSpanCollector(new ScribeSpanCollector("192.168.99.101", 9410));
+        context.getManagementStrategy().addEventNotifier(zipkin);
+
+        return context;
+    }
+
+    @Test
+    public void testZipkinRoute() throws Exception {
+        NotifyBuilder notify = new NotifyBuilder(context).whenDone(10).create();
+
+        for (int i = 0; i < 5; i++) {
+            template.sendBody("seda:foo", "Hello World");
+        }
+
+        assertTrue(notify.matches(60, TimeUnit.SECONDS));
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("seda:foo").routeId("foo")
+                        .log("routing at ${routeId}")
+                        .delay(simple("${random(1000,2000)}"))
+                        .to("seda:bar");
+
+                from("seda:bar").routeId("bar")
+                        .log("routing at ${routeId}")
+                        .delay(simple("${random(0,500)}"));
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/3a4087cd/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteTest.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteTest.java
new file mode 100644
index 0000000..15a4a41
--- /dev/null
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteTest.java
@@ -0,0 +1,72 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.zipkin;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class ZipkinRouteTest extends CamelTestSupport {
+
+    private ZipkinEventNotifier zipkin;
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        zipkin = new ZipkinEventNotifier();
+        zipkin.addServiceMapping("seda:foo", "foo");
+        zipkin.addServiceMapping("seda:bar", "bar");
+        zipkin.setSpanCollector(new ZipkinLoggingSpanCollector());
+        context.getManagementStrategy().addEventNotifier(zipkin);
+
+        return context;
+    }
+
+    @Test
+    public void testZipkinRoute() throws Exception {
+        NotifyBuilder notify = new NotifyBuilder(context).whenDone(10).create();
+
+        for (int i = 0; i < 5; i++) {
+            template.sendBody("seda:foo", "Hello World");
+        }
+
+        assertTrue(notify.matches(30, TimeUnit.SECONDS));
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("seda:foo?concurrentConsumers=5").routeId("foo")
+                        .log("routing at ${routeId}")
+                        .delay(simple("${random(1000,2000)}"))
+                        .to("seda:bar");
+
+                from("seda:bar?concurrentConsumers=5").routeId("bar")
+                        .log("routing at ${routeId}")
+                        .delay(simple("${random(0,500)}"));
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/3a4087cd/components/camel-zipkin/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/resources/log4j.properties b/components/camel-zipkin/src/test/resources/log4j.properties
new file mode 100644
index 0000000..69b028b
--- /dev/null
+++ b/components/camel-zipkin/src/test/resources/log4j.properties
@@ -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.
+#
+
+#
+# The logging properties used
+#
+log4j.rootLogger=INFO, out
+
+#log4j.logger.org.apache.camel=DEBUG
+#log4j.logger.org.apache.camel.zipkin=DEBUG
+log4j.logger.com.github.kristofa.brave=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+#log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+# MDC
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %-10.10X{camel.breadcrumbId} - %-10.10X{camel.exchangeId} - %-10.10X{camel.correlationId} - %-10.10X{camel.routeId} - %m%n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.file.file=target/camel-zipkin-test.log
+# MDC
+#log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %-10.10X{camel.breadcrumbId} - %-10.10X{camel.exchangeId} - %-10.10X{camel.correlationId} - %-10.10X{camel.routeId} - %m%n

http://git-wip-us.apache.org/repos/asf/camel/blob/3a4087cd/components/pom.xml
----------------------------------------------------------------------
diff --git a/components/pom.xml b/components/pom.xml
index 1e86994..2624e0c 100644
--- a/components/pom.xml
+++ b/components/pom.xml
@@ -263,6 +263,7 @@
     <module>camel-xstream</module>
     <module>camel-yammer</module>
     <module>camel-zipfile</module>
+    <module>camel-zipkin</module>
     <module>camel-zookeeper</module>
   </modules>
 


[06/12] camel git commit: CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.

Posted by da...@apache.org.
CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d4e9cc6b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d4e9cc6b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d4e9cc6b

Branch: refs/heads/master
Commit: d4e9cc6b0f56d831d7920a0053574f520195dd51
Parents: 5a92de6
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 29 11:19:19 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 29 14:41:54 2016 +0200

----------------------------------------------------------------------
 .../apache/camel/zipkin/ZipkinClientRequestAdapter.java  | 11 +++++++++--
 .../apache/camel/zipkin/ZipkinServerRequestAdapter.java  | 11 +++++++++--
 .../apache/camel/zipkin/ZipkinServerResponseAdapter.java |  2 +-
 .../camel/zipkin/scribe/ZipkinTimerRouteScribe.java      |  6 +++---
 .../camel-zipkin/src/test/resources/log4j.properties     |  2 +-
 5 files changed, 23 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d4e9cc6b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
index e6e30477..b3c80b1 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
@@ -16,8 +16,8 @@
  */
 package org.apache.camel.zipkin;
 
+import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Locale;
 
 import com.github.kristofa.brave.ClientRequestAdapter;
@@ -35,12 +35,14 @@ public final class ZipkinClientRequestAdapter implements ClientRequestAdapter {
     private final Exchange exchange;
     private final Endpoint endpoint;
     private final String spanName;
+    private final String url;
 
     public ZipkinClientRequestAdapter(String serviceName, Exchange exchange, Endpoint endpoint) {
         this.serviceName = serviceName;
         this.exchange = exchange;
         this.endpoint = endpoint;
         this.spanName = URISupport.sanitizeUri(endpoint.getEndpointKey()).toLowerCase(Locale.US);
+        this.url = URISupport.sanitizeUri(endpoint.getEndpointUri());
     }
 
     @Override
@@ -65,6 +67,11 @@ public final class ZipkinClientRequestAdapter implements ClientRequestAdapter {
     @Override
     public Collection<KeyValueAnnotation> requestAnnotations() {
         String id = exchange.getExchangeId();
-        return Collections.singletonList(KeyValueAnnotation.create("camel.exchange.id", id));
+        String mep = exchange.getPattern().name();
+
+        KeyValueAnnotation key1 = KeyValueAnnotation.create("camel.client.endpoint.url", url);
+        KeyValueAnnotation key2 = KeyValueAnnotation.create("camel.client.exchange.id", id);
+        KeyValueAnnotation key3 = KeyValueAnnotation.create("camel.client.exchange.pattern", mep);
+        return Arrays.asList(key1, key2, key3);
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/d4e9cc6b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
index c5daef9..59c6b4f 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
@@ -16,8 +16,8 @@
  */
 package org.apache.camel.zipkin;
 
+import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Locale;
 
 import com.github.kristofa.brave.KeyValueAnnotation;
@@ -35,11 +35,13 @@ public class ZipkinServerRequestAdapter implements ServerRequestAdapter {
     private final Exchange exchange;
     private final Endpoint endpoint;
     private final String spanName;
+    private final String url;
 
     public ZipkinServerRequestAdapter(Exchange exchange) {
         this.exchange = exchange;
         this.endpoint = exchange.getFromEndpoint();
         this.spanName = URISupport.sanitizeUri(endpoint.getEndpointKey()).toLowerCase(Locale.US);
+        this.url = URISupport.sanitizeUri(endpoint.getEndpointUri());
     }
 
     @Override
@@ -63,7 +65,12 @@ public class ZipkinServerRequestAdapter implements ServerRequestAdapter {
     @Override
     public Collection<KeyValueAnnotation> requestAnnotations() {
         String id = exchange.getExchangeId();
-        return Collections.singletonList(KeyValueAnnotation.create("camel.exchange.id", id));
+        String mep = exchange.getPattern().name();
+
+        KeyValueAnnotation key1 = KeyValueAnnotation.create("camel.server.endpoint.url", url);
+        KeyValueAnnotation key2 = KeyValueAnnotation.create("camel.server.exchange.id", id);
+        KeyValueAnnotation key3 = KeyValueAnnotation.create("camel.server.exchange.pattern", mep);
+        return Arrays.asList(key1, key2, key3);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/d4e9cc6b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java
index 2ba8594..0a7035c 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java
@@ -37,7 +37,7 @@ public class ZipkinServerResponseAdapter implements ServerResponseAdapter {
     @Override
     public Collection<KeyValueAnnotation> responseAnnotations() {
         if (exchange.getException() != null) {
-            return Collections.singletonList(KeyValueAnnotation.create("camel.failure", exchange.getException().getMessage()));
+            return Collections.singletonList(KeyValueAnnotation.create("camel.server.failure", exchange.getException().getMessage()));
         } else {
             return Collections.emptyList();
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/d4e9cc6b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTimerRouteScribe.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTimerRouteScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTimerRouteScribe.java
index a822b08..017102c 100644
--- a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTimerRouteScribe.java
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTimerRouteScribe.java
@@ -41,8 +41,6 @@ public class ZipkinTimerRouteScribe extends CamelTestSupport {
     private String ip = "192.168.99.100";
     private ZipkinEventNotifier zipkin;
 
-    // TODO: producer template also (add a skip flag)
-
     @Override
     protected CamelContext createCamelContext() throws Exception {
         CamelContext context = super.createCamelContext();
@@ -59,6 +57,8 @@ public class ZipkinTimerRouteScribe extends CamelTestSupport {
     public void testZipkinRoute() throws Exception {
         NotifyBuilder notify = new NotifyBuilder(context).from("seda:timer").whenDone(1).create();
 
+        template.sendBody("direct:start", "Hello Timer");
+
         assertTrue(notify.matches(30, TimeUnit.SECONDS));
     }
 
@@ -67,7 +67,7 @@ public class ZipkinTimerRouteScribe extends CamelTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("timer:trigger?repeatCount=1").setBody().constant("Hello Cat").to(ExchangePattern.InOut, "seda:timer");
+                from("direct:start").to(ExchangePattern.InOut, "seda:timer");
 
                 from("seda:timer").routeId("timer")
                         .log("routing at ${routeId}")

http://git-wip-us.apache.org/repos/asf/camel/blob/d4e9cc6b/components/camel-zipkin/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/resources/log4j.properties b/components/camel-zipkin/src/test/resources/log4j.properties
index 538c5bd..ab7b29f 100644
--- a/components/camel-zipkin/src/test/resources/log4j.properties
+++ b/components/camel-zipkin/src/test/resources/log4j.properties
@@ -18,7 +18,7 @@
 #
 # The logging properties used
 #
-log4j.rootLogger=INFO, out
+log4j.rootLogger=INFO, file
 
 #log4j.logger.org.apache.camel=DEBUG
 log4j.logger.org.apache.camel.zipkin=DEBUG


[05/12] camel git commit: CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.

Posted by da...@apache.org.
CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a336ee9c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a336ee9c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a336ee9c

Branch: refs/heads/master
Commit: a336ee9cc39f22fccfeca27f6219672ffe564a95
Parents: 3a4087c
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 29 09:18:55 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 29 14:41:54 2016 +0200

----------------------------------------------------------------------
 components/camel-zipkin/pom.xml                 | 23 ++++++
 .../zipkin/ZipkinClientRequestAdapter.java      |  2 +-
 .../zipkin/ZipkinClientResponseAdaptor.java     |  2 +-
 .../camel/zipkin/ZipkinEventNotifier.java       | 20 ++++-
 .../org/apache/camel/zipkin/ZipkinHelper.java   |  3 +
 .../zipkin/ZipkinLoggingSpanCollector.java      |  5 +-
 .../zipkin/ZipkinServerRequestAdapter.java      |  2 +-
 .../zipkin/ZipkinServerResponseAdapter.java     |  2 +-
 .../camel/zipkin/ZipkinRouteConcurrentTest.java | 72 ++++++++++++++++++
 .../camel/zipkin/ZipkinRouteScribeTest.java     | 73 ------------------
 .../apache/camel/zipkin/ZipkinRouteTest.java    | 72 ------------------
 .../camel/zipkin/ZipkinSimpleRouteTest.java     | 66 ++++++++++++++++
 .../scribe/ZipkinRouteConcurrentScribe.java     | 79 ++++++++++++++++++++
 .../zipkin/scribe/ZipkinSimpleRouteScribe.java  | 73 ++++++++++++++++++
 .../src/test/resources/log4j.properties         |  4 +-
 15 files changed, 343 insertions(+), 155 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/pom.xml b/components/camel-zipkin/pom.xml
index 567626a..bd82334 100644
--- a/components/camel-zipkin/pom.xml
+++ b/components/camel-zipkin/pom.xml
@@ -67,4 +67,27 @@
 
   </dependencies>
 
+  <profiles>
+    <profile>
+      <id>scribe-test</id>
+      <build>
+        <plugins>
+          <plugin>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+              <childDelegation>false</childDelegation>
+              <useFile>true</useFile>
+              <forkCount>1</forkCount>
+              <reuseForks>true</reuseForks>
+              <forkedProcessTimeoutInSeconds>300</forkedProcessTimeoutInSeconds>
+              <includes>
+                <include>**/*ScribeTest.java</include>
+              </includes>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+
 </project>

http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
index 5254578..08e1679 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
@@ -65,6 +65,6 @@ public final class ZipkinClientRequestAdapter implements ClientRequestAdapter {
     @Override
     public Collection<KeyValueAnnotation> requestAnnotations() {
         String msgId = exchange.getIn().getMessageId();
-        return Collections.singletonList(KeyValueAnnotation.create("CamelMessageId", msgId));
+        return Collections.singletonList(KeyValueAnnotation.create("camel.message.id", msgId));
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java
index daddeff..296c021 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java
@@ -37,7 +37,7 @@ public class ZipkinClientResponseAdaptor implements ClientResponseAdapter {
     @Override
     public Collection<KeyValueAnnotation> responseAnnotations() {
         if (exchange.getException() != null) {
-            return Collections.singletonList(KeyValueAnnotation.create("CamelZipkinFailed", exchange.getException().getMessage()));
+            return Collections.singletonList(KeyValueAnnotation.create("camel.failure", exchange.getException().getMessage()));
         } else {
             return Collections.emptyList();
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
index 30b8ca1..97c57c2 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
@@ -25,6 +25,7 @@ import com.github.kristofa.brave.ClientSpanThreadBinder;
 import com.github.kristofa.brave.Sampler;
 import com.github.kristofa.brave.SpanCollector;
 import com.twitter.zipkin.gen.Span;
+import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.management.event.ExchangeCompletedEvent;
@@ -37,6 +38,21 @@ import org.apache.camel.util.EndpointHelper;
 
 import static org.apache.camel.builder.ExpressionBuilder.routeIdExpression;
 
+/**
+ * To use zipkin with Camel then setup this {@link org.apache.camel.spi.EventNotifier} in your Camel application.
+ * <p/>
+ * Events (span) are captured for incoming and outgoing messages being sent to/from Camel.
+ * This means you need to configure which which Camel endpoints that maps to zipkin service names.
+ * The mapping can be configured using
+ * <ul>
+ *     <li>route id - A Camel route id</li>
+ *     <li>endpoint url - A Camel endpoint url</li>
+ * </ul>
+ * For both kinds you can use wildcards and regular expressions to match, which is using the rules from
+ * {@link EndpointHelper#matchPattern(String, String)} and {@link EndpointHelper#matchEndpoint(CamelContext, String, String)}
+ * <p/>
+ * At least one mapping must be configured, you can use <tt>*</tt> to match all incoming and outgoing messages.
+ */
 public class ZipkinEventNotifier extends EventNotifierSupport {
 
     private float rate = 1.0f;
@@ -79,8 +95,8 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
         this.serviceMappings = serviceMappings;
     }
 
-    public void addServiceMapping(String routeId, String serviceName) {
-        serviceMappings.put(routeId, serviceName);
+    public void addServiceMapping(String pattern, String serviceName) {
+        serviceMappings.put(pattern, serviceName);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinHelper.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinHelper.java
index d5c8c57..2fe33e4 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinHelper.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinHelper.java
@@ -19,6 +19,9 @@ package org.apache.camel.zipkin;
 import com.github.kristofa.brave.IdConversion;
 import com.github.kristofa.brave.SpanId;
 
+/**
+ * Helper class.
+ */
 public final class ZipkinHelper {
 
     private ZipkinHelper() {

http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java
index 71d551a..f77156c 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java
@@ -16,8 +16,6 @@
  */
 package org.apache.camel.zipkin;
 
-import java.text.SimpleDateFormat;
-import java.util.Date;
 import java.util.LinkedHashSet;
 import java.util.Set;
 
@@ -28,6 +26,9 @@ import com.twitter.zipkin.gen.Span;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * To collect zipkin span's using a logger.
+ */
 public class ZipkinLoggingSpanCollector implements SpanCollector {
 
     private final Set<BinaryAnnotation> defaultAnnotations = new LinkedHashSet<BinaryAnnotation>();

http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
index c6ec850..fa67ddb 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
@@ -63,7 +63,7 @@ public class ZipkinServerRequestAdapter implements ServerRequestAdapter {
     @Override
     public Collection<KeyValueAnnotation> requestAnnotations() {
         String msgId = exchange.getIn().getMessageId();
-        return Collections.singletonList(KeyValueAnnotation.create("CamelMessageId", msgId));
+        return Collections.singletonList(KeyValueAnnotation.create("camel.message.id", msgId));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java
index 8cb5b67..2ba8594 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java
@@ -37,7 +37,7 @@ public class ZipkinServerResponseAdapter implements ServerResponseAdapter {
     @Override
     public Collection<KeyValueAnnotation> responseAnnotations() {
         if (exchange.getException() != null) {
-            return Collections.singletonList(KeyValueAnnotation.create("failure", exchange.getException().getMessage()));
+            return Collections.singletonList(KeyValueAnnotation.create("camel.failure", exchange.getException().getMessage()));
         } else {
             return Collections.emptyList();
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteConcurrentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteConcurrentTest.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteConcurrentTest.java
new file mode 100644
index 0000000..6db0a0e
--- /dev/null
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteConcurrentTest.java
@@ -0,0 +1,72 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.zipkin;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class ZipkinRouteConcurrentTest extends CamelTestSupport {
+
+    private ZipkinEventNotifier zipkin;
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        zipkin = new ZipkinEventNotifier();
+        zipkin.addServiceMapping("seda:foo", "foo");
+        zipkin.addServiceMapping("seda:bar", "bar");
+        zipkin.setSpanCollector(new ZipkinLoggingSpanCollector());
+        context.getManagementStrategy().addEventNotifier(zipkin);
+
+        return context;
+    }
+
+    @Test
+    public void testZipkinRoute() throws Exception {
+        NotifyBuilder notify = new NotifyBuilder(context).whenDone(5).create();
+
+        for (int i = 0; i < 5; i++) {
+            template.sendBody("seda:foo", "Hello World");
+        }
+
+        assertTrue(notify.matches(30, TimeUnit.SECONDS));
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("seda:foo?concurrentConsumers=5").routeId("foo")
+                        .log("routing at ${routeId}")
+                        .delay(simple("${random(1000,2000)}"))
+                        .to("seda:bar");
+
+                from("seda:bar?concurrentConsumers=5").routeId("bar")
+                        .log("routing at ${routeId}")
+                        .delay(simple("${random(0,500)}"));
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteScribeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteScribeTest.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteScribeTest.java
deleted file mode 100644
index 94d2ca4..0000000
--- a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteScribeTest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.zipkin;
-
-import java.util.concurrent.TimeUnit;
-
-import com.github.kristofa.brave.scribe.ScribeSpanCollector;
-import org.apache.camel.CamelContext;
-import org.apache.camel.RoutesBuilder;
-import org.apache.camel.builder.NotifyBuilder;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
-
-public class ZipkinRouteScribeTest extends CamelTestSupport {
-
-    private ZipkinEventNotifier zipkin;
-
-    @Override
-    protected CamelContext createCamelContext() throws Exception {
-        CamelContext context = super.createCamelContext();
-
-        zipkin = new ZipkinEventNotifier();
-        zipkin.addServiceMapping("seda:foo", "foo");
-        zipkin.addServiceMapping("seda:bar", "bar");
-        zipkin.setSpanCollector(new ScribeSpanCollector("192.168.99.101", 9410));
-        context.getManagementStrategy().addEventNotifier(zipkin);
-
-        return context;
-    }
-
-    @Test
-    public void testZipkinRoute() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context).whenDone(10).create();
-
-        for (int i = 0; i < 5; i++) {
-            template.sendBody("seda:foo", "Hello World");
-        }
-
-        assertTrue(notify.matches(60, TimeUnit.SECONDS));
-    }
-
-    @Override
-    protected RoutesBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                from("seda:foo").routeId("foo")
-                        .log("routing at ${routeId}")
-                        .delay(simple("${random(1000,2000)}"))
-                        .to("seda:bar");
-
-                from("seda:bar").routeId("bar")
-                        .log("routing at ${routeId}")
-                        .delay(simple("${random(0,500)}"));
-            }
-        };
-    }
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteTest.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteTest.java
deleted file mode 100644
index 15a4a41..0000000
--- a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.zipkin;
-
-import java.util.concurrent.TimeUnit;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.RoutesBuilder;
-import org.apache.camel.builder.NotifyBuilder;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
-
-public class ZipkinRouteTest extends CamelTestSupport {
-
-    private ZipkinEventNotifier zipkin;
-
-    @Override
-    protected CamelContext createCamelContext() throws Exception {
-        CamelContext context = super.createCamelContext();
-
-        zipkin = new ZipkinEventNotifier();
-        zipkin.addServiceMapping("seda:foo", "foo");
-        zipkin.addServiceMapping("seda:bar", "bar");
-        zipkin.setSpanCollector(new ZipkinLoggingSpanCollector());
-        context.getManagementStrategy().addEventNotifier(zipkin);
-
-        return context;
-    }
-
-    @Test
-    public void testZipkinRoute() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context).whenDone(10).create();
-
-        for (int i = 0; i < 5; i++) {
-            template.sendBody("seda:foo", "Hello World");
-        }
-
-        assertTrue(notify.matches(30, TimeUnit.SECONDS));
-    }
-
-    @Override
-    protected RoutesBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                from("seda:foo?concurrentConsumers=5").routeId("foo")
-                        .log("routing at ${routeId}")
-                        .delay(simple("${random(1000,2000)}"))
-                        .to("seda:bar");
-
-                from("seda:bar?concurrentConsumers=5").routeId("bar")
-                        .log("routing at ${routeId}")
-                        .delay(simple("${random(0,500)}"));
-            }
-        };
-    }
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSimpleRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSimpleRouteTest.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSimpleRouteTest.java
new file mode 100644
index 0000000..0c719cc
--- /dev/null
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSimpleRouteTest.java
@@ -0,0 +1,66 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.zipkin;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class ZipkinSimpleRouteTest extends CamelTestSupport {
+
+    private ZipkinEventNotifier zipkin;
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        zipkin = new ZipkinEventNotifier();
+        zipkin.addServiceMapping("seda:dude", "dude");
+        zipkin.setSpanCollector(new ZipkinLoggingSpanCollector());
+        context.getManagementStrategy().addEventNotifier(zipkin);
+
+        return context;
+    }
+
+    @Test
+    public void testZipkinRoute() throws Exception {
+        NotifyBuilder notify = new NotifyBuilder(context).whenDone(5).create();
+
+        for (int i = 0; i < 5; i++) {
+            template.sendBody("seda:dude", "Hello World");
+        }
+
+        assertTrue(notify.matches(30, TimeUnit.SECONDS));
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("seda:dude").routeId("dude")
+                        .log("routing at ${routeId}")
+                        .delay(simple("${random(1000,2000)}"));
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java
new file mode 100644
index 0000000..d371547
--- /dev/null
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java
@@ -0,0 +1,79 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.zipkin.scribe;
+
+import java.util.concurrent.TimeUnit;
+
+import com.github.kristofa.brave.scribe.ScribeSpanCollector;
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.zipkin.ZipkinEventNotifier;
+import org.junit.Test;
+
+/**
+ * Integration test requires running Zipkin/Scribe running
+ *
+ * The easiest way is to run using zipkin-docker: https://github.com/openzipkin/docker-zipkin
+ */
+public class ZipkinRouteConcurrentScribe extends CamelTestSupport {
+
+    private ZipkinEventNotifier zipkin;
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        zipkin = new ZipkinEventNotifier();
+        zipkin.addServiceMapping("seda:foo", "foo");
+        zipkin.addServiceMapping("seda:bar", "bar");
+        zipkin.setSpanCollector(new ScribeSpanCollector("192.168.99.101", 9410));
+        context.getManagementStrategy().addEventNotifier(zipkin);
+
+        return context;
+    }
+
+    @Test
+    public void testZipkinRoute() throws Exception {
+        NotifyBuilder notify = new NotifyBuilder(context).whenDone(5).create();
+
+        for (int i = 0; i < 5; i++) {
+            template.sendBody("seda:foo", "Hello World");
+        }
+
+        assertTrue(notify.matches(60, TimeUnit.SECONDS));
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("seda:foo").routeId("foo")
+                        .log("routing at ${routeId}")
+                        .delay(simple("${random(1000,2000)}"))
+                        .to("seda:bar");
+
+                from("seda:bar").routeId("bar")
+                        .log("routing at ${routeId}")
+                        .delay(simple("${random(0,500)}"));
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java
new file mode 100644
index 0000000..3d91927
--- /dev/null
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java
@@ -0,0 +1,73 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.zipkin.scribe;
+
+import java.util.concurrent.TimeUnit;
+
+import com.github.kristofa.brave.scribe.ScribeSpanCollector;
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.zipkin.ZipkinEventNotifier;
+import org.junit.Test;
+
+/**
+ * Integration test requires running Zipkin/Scribe running
+ *
+ * The easiest way is to run using zipkin-docker: https://github.com/openzipkin/docker-zipkin
+ */
+public class ZipkinSimpleRouteScribe extends CamelTestSupport {
+
+    private ZipkinEventNotifier zipkin;
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        zipkin = new ZipkinEventNotifier();
+        zipkin.addServiceMapping("seda:dude", "dude");
+        zipkin.setSpanCollector(new ScribeSpanCollector("192.168.99.101", 9410));
+        context.getManagementStrategy().addEventNotifier(zipkin);
+
+        return context;
+    }
+
+    @Test
+    public void testZipkinRoute() throws Exception {
+        NotifyBuilder notify = new NotifyBuilder(context).whenDone(10).create();
+
+        for (int i = 0; i < 5; i++) {
+            template.sendBody("seda:dude", "Hello World");
+        }
+
+        assertTrue(notify.matches(30, TimeUnit.SECONDS));
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("seda:dude").routeId("dude")
+                        .log("routing at ${routeId}")
+                        .delay(simple("${random(1000,2000)}"));
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a336ee9c/components/camel-zipkin/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/resources/log4j.properties b/components/camel-zipkin/src/test/resources/log4j.properties
index 69b028b..5d05c44 100644
--- a/components/camel-zipkin/src/test/resources/log4j.properties
+++ b/components/camel-zipkin/src/test/resources/log4j.properties
@@ -18,11 +18,11 @@
 #
 # The logging properties used
 #
-log4j.rootLogger=INFO, out
+log4j.rootLogger=INFO, file
 
 #log4j.logger.org.apache.camel=DEBUG
 #log4j.logger.org.apache.camel.zipkin=DEBUG
-log4j.logger.com.github.kristofa.brave=DEBUG
+#log4j.logger.com.github.kristofa.brave=DEBUG
 
 # CONSOLE appender not used by default
 log4j.appender.out=org.apache.log4j.ConsoleAppender


[03/12] camel git commit: CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.

Posted by da...@apache.org.
CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/70ff21b2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/70ff21b2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/70ff21b2

Branch: refs/heads/master
Commit: 70ff21b230505662e57391d0ea06f9a5ff885649
Parents: c15d1cb
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 29 12:06:27 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 29 14:41:54 2016 +0200

----------------------------------------------------------------------
 .../camel/zipkin/ZipkinEventNotifier.java       | 36 ++++++++++++++++----
 1 file changed, 29 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/70ff21b2/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
index 9e9edbc..b8301e9 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
@@ -72,6 +72,12 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
         return rate;
     }
 
+    /**
+     * Configures a rate that decides how many events should be traced by zpkin.
+     * The rate is expressed as a percentage (1.0f = 100%, 0.5f is 50%, 0.1f is 10%).
+     *
+     * @param rate minimum sample rate is 0.0001, or 0.01% of traces
+     */
     public void setRate(float rate) {
         this.rate = rate;
     }
@@ -80,6 +86,9 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
         return spanCollector;
     }
 
+    /**
+     * The collector to use for sending zipkin span events to the zipkin server.
+     */
     public void setSpanCollector(SpanCollector spanCollector) {
         this.spanCollector = spanCollector;
     }
@@ -88,6 +97,9 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
         return serviceMappings.get("*");
     }
 
+    /**
+     * To use a global service name that matches all Camel events
+     */
     public void setServiceName(String serviceName) {
         serviceMappings.put("*", serviceName);
     }
@@ -100,6 +112,13 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
         this.serviceMappings = serviceMappings;
     }
 
+    /**
+     * Adds a service mapping that matches Camel events to the given zipkin serivce name.
+     * See more details at the class javadoc.
+     *
+     * @param pattern  the pattern such as route id, endpoint url
+     * @param serviceName the zpkin service name
+     */
     public void addServiceMapping(String pattern, String serviceName) {
         serviceMappings.put(pattern, serviceName);
     }
@@ -144,8 +163,11 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
 
     @Override
     public boolean isEnabled(EventObject event) {
-        return event instanceof ExchangeSendingEvent || event instanceof ExchangeSentEvent
-                || event instanceof ExchangeCreatedEvent || event instanceof ExchangeCompletedEvent || event instanceof ExchangeFailedEvent;
+        return event instanceof ExchangeSendingEvent
+                || event instanceof ExchangeSentEvent
+                || event instanceof ExchangeCreatedEvent
+                || event instanceof ExchangeCompletedEvent
+                || event instanceof ExchangeFailedEvent;
     }
 
     private String getServiceName(Exchange exchange, Endpoint endpoint) {
@@ -261,7 +283,7 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
         event.getExchange().setProperty(key, span);
 
         if (log.isDebugEnabled()) {
-            log.debug("clientRequest: service={}, id={} ", serviceName, span != null ? span.getId() : "<null>");
+            log.debug("clientRequest[service={}, spanId={}]", serviceName, span != null ? span.getId() : "<null>");
         }
     }
 
@@ -274,7 +296,7 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
         binder.setCurrentSpan(null);
 
         if (log.isDebugEnabled()) {
-            log.debug("clientResponse: service={}, id={} ", serviceName, span != null ? span.getId() : "<null>");
+            log.debug("clientResponse[service={}, spanId={}]", serviceName, span != null ? span.getId() : "<null>");
         }
     }
 
@@ -286,7 +308,7 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
         event.getExchange().setProperty(key, span);
 
         if (log.isDebugEnabled()) {
-            log.debug("serverRequest: service={}, id={} ", serviceName, span != null ? span.getSpan().getId() : "<null>");
+            log.debug("serverRequest[service={}, spanId={}]", serviceName, span != null ? span.getSpan().getId() : "<null>");
         }
     }
 
@@ -299,7 +321,7 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
         binder.setCurrentSpan(null);
 
         if (log.isDebugEnabled()) {
-            log.debug("serverResponse: service={}, id={} ", serviceName, span != null ? span.getSpan().getId() : "<null>");
+            log.debug("serverResponse: service={}, spanId={} ", serviceName, span != null ? span.getSpan().getId() : "<null>");
         }
     }
 
@@ -312,7 +334,7 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
         binder.setCurrentSpan(null);
 
         if (log.isDebugEnabled()) {
-            log.debug("serverResponse: service={}, id={} ", serviceName, span != null ? span.getSpan().getId() : "<null>");
+            log.debug("serverResponse[service={}, spanId={}]", serviceName, span != null ? span.getSpan().getId() : "<null>");
         }
     }
 


[07/12] camel git commit: CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.

Posted by da...@apache.org.
CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4b1737a9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4b1737a9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4b1737a9

Branch: refs/heads/master
Commit: 4b1737a9cee64f36bbaecf5af3d7b834eb33ce55
Parents: 7153f3c
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 29 13:37:16 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 29 14:41:54 2016 +0200

----------------------------------------------------------------------
 .../org/apache/camel/zipkin/ZipkinClientRequestAdapter.java  | 7 +++----
 .../org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java | 8 +++-----
 .../java/org/apache/camel/zipkin/ZipkinEventNotifier.java    | 6 +++---
 .../src/main/java/org/apache/camel/zipkin/ZipkinHelper.java  | 6 +++---
 .../org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java  | 6 +++---
 .../org/apache/camel/zipkin/ZipkinServerRequestAdapter.java  | 7 +++----
 .../org/apache/camel/zipkin/ZipkinServerResponseAdapter.java | 6 +++---
 .../org/apache/camel/zipkin/ZipkinRouteConcurrentTest.java   | 6 +++---
 .../java/org/apache/camel/zipkin/ZipkinSimpleRouteTest.java  | 6 +++---
 .../org/apache/camel/zipkin/scribe/ZipkinOneRouteScribe.java | 6 +++---
 .../camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java     | 6 +++---
 .../apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java  | 6 +++---
 .../apache/camel/zipkin/scribe/ZipkinTimerRouteScribe.java   | 6 +++---
 .../org/apache/camel/zipkin/scribe/ZipkinTwoRouteScribe.java | 6 +++---
 14 files changed, 42 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4b1737a9/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
index 824d58d..03028ba 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientRequestAdapter.java
@@ -5,9 +5,9 @@
  * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ *      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.
@@ -17,7 +17,6 @@
 package org.apache.camel.zipkin;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import java.util.Locale;

http://git-wip-us.apache.org/repos/asf/camel/blob/4b1737a9/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java
index 8885ecd..2e4fded 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinClientResponseAdaptor.java
@@ -5,9 +5,9 @@
  * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ *      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.
@@ -17,9 +17,7 @@
 package org.apache.camel.zipkin;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.List;
 
 import com.github.kristofa.brave.ClientResponseAdapter;

http://git-wip-us.apache.org/repos/asf/camel/blob/4b1737a9/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
index d06985a..f4bf0b0 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
@@ -5,9 +5,9 @@
  * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ *      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.

http://git-wip-us.apache.org/repos/asf/camel/blob/4b1737a9/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinHelper.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinHelper.java
index 2fe33e4..630f828 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinHelper.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinHelper.java
@@ -5,9 +5,9 @@
  * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ *      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.

http://git-wip-us.apache.org/repos/asf/camel/blob/4b1737a9/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java
index f77156c..84daddb 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java
@@ -5,9 +5,9 @@
  * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ *      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.

http://git-wip-us.apache.org/repos/asf/camel/blob/4b1737a9/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
index 6dc89a2..17281de 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerRequestAdapter.java
@@ -5,9 +5,9 @@
  * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ *      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.
@@ -17,7 +17,6 @@
 package org.apache.camel.zipkin;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import java.util.Locale;

http://git-wip-us.apache.org/repos/asf/camel/blob/4b1737a9/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java
index 3c33a12..7fa33d9 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinServerResponseAdapter.java
@@ -5,9 +5,9 @@
  * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ *      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.

http://git-wip-us.apache.org/repos/asf/camel/blob/4b1737a9/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteConcurrentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteConcurrentTest.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteConcurrentTest.java
index 6db0a0e..ac607de 100644
--- a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteConcurrentTest.java
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinRouteConcurrentTest.java
@@ -5,9 +5,9 @@
  * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ *      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.

http://git-wip-us.apache.org/repos/asf/camel/blob/4b1737a9/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSimpleRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSimpleRouteTest.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSimpleRouteTest.java
index 0c719cc..2114ea0 100644
--- a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSimpleRouteTest.java
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSimpleRouteTest.java
@@ -5,9 +5,9 @@
  * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ *      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.

http://git-wip-us.apache.org/repos/asf/camel/blob/4b1737a9/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinOneRouteScribe.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinOneRouteScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinOneRouteScribe.java
index de48945..93da37b 100644
--- a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinOneRouteScribe.java
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinOneRouteScribe.java
@@ -5,9 +5,9 @@
  * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ *      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.

http://git-wip-us.apache.org/repos/asf/camel/blob/4b1737a9/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java
index 3b91b00..527d7a2 100644
--- a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java
@@ -5,9 +5,9 @@
  * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ *      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.

http://git-wip-us.apache.org/repos/asf/camel/blob/4b1737a9/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java
index 5032366..7848967 100644
--- a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java
@@ -5,9 +5,9 @@
  * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ *      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.

http://git-wip-us.apache.org/repos/asf/camel/blob/4b1737a9/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTimerRouteScribe.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTimerRouteScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTimerRouteScribe.java
index 9e03d66..237df63 100644
--- a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTimerRouteScribe.java
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTimerRouteScribe.java
@@ -5,9 +5,9 @@
  * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ *      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.

http://git-wip-us.apache.org/repos/asf/camel/blob/4b1737a9/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTwoRouteScribe.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTwoRouteScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTwoRouteScribe.java
index 2c59bbc..fc55e40 100644
--- a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTwoRouteScribe.java
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTwoRouteScribe.java
@@ -5,9 +5,9 @@
  * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ *      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.


[10/12] camel git commit: CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.

Posted by da...@apache.org.
CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c6a25854
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c6a25854
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c6a25854

Branch: refs/heads/master
Commit: c6a25854b972e1a10e3e181d8cdb59087910d377
Parents: b48915a
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 29 14:18:40 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 29 14:42:24 2016 +0200

----------------------------------------------------------------------
 components/camel-zipkin/pom.xml | 7 +++++--
 parent/pom.xml                  | 1 +
 2 files changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c6a25854/components/camel-zipkin/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/pom.xml b/components/camel-zipkin/pom.xml
index bd82334..e5e5b31 100644
--- a/components/camel-zipkin/pom.xml
+++ b/components/camel-zipkin/pom.xml
@@ -45,12 +45,15 @@
     <dependency>
       <groupId>com.github.kristofa</groupId>
       <artifactId>brave-core</artifactId>
-      <version>3.5.0</version>
+      <version>${brave-zipkin-version}</version>
     </dependency>
+
+    <!-- for testing using a real zipkin server -->
     <dependency>
       <groupId>com.github.kristofa</groupId>
       <artifactId>brave-spancollector-scribe</artifactId>
-      <version>3.5.0</version>
+      <version>${brave-zipkin-version}</version>
+      <scope>test</scope>
     </dependency>
 
     <!-- test dependencies -->

http://git-wip-us.apache.org/repos/asf/camel/blob/c6a25854/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 1005a6d..0ff8534 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -77,6 +77,7 @@
     <bouncycastle-version>1.54</bouncycastle-version>
     <boxjavalibv2.version>3.2.1</boxjavalibv2.version>
     <braintree-gateway-version>2.58.0</braintree-gateway-version>
+    <brave-zipkin-version>3.5.0</brave-zipkin-version>
     <build-helper-maven-plugin-version>1.10</build-helper-maven-plugin-version>
     <c3p0-version>0.9.5.2</c3p0-version>
     <californium-version>1.0.0-M3</californium-version>


[09/12] camel git commit: CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.

Posted by da...@apache.org.
CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c15d1cb2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c15d1cb2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c15d1cb2

Branch: refs/heads/master
Commit: c15d1cb228ca0a50266af705dccaf5f4e8a50725
Parents: d4e9cc6
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 29 11:41:03 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 29 14:41:54 2016 +0200

----------------------------------------------------------------------
 .../camel/zipkin/ZipkinEventNotifier.java       | 16 ++--
 .../zipkin/scribe/ZipkinOneRouteScribe.java     | 17 +----
 .../scribe/ZipkinRouteConcurrentScribe.java     | 11 ++-
 .../zipkin/scribe/ZipkinSimpleRouteScribe.java  | 12 +--
 .../zipkin/scribe/ZipkinTimerRouteScribe.java   |  1 +
 .../zipkin/scribe/ZipkinTwoRouteScribe.java     | 77 ++++++++++++++++++++
 .../src/test/resources/log4j.properties         |  2 +-
 7 files changed, 105 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c15d1cb2/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
index ad0742e..9e9edbc 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinEventNotifier.java
@@ -256,7 +256,9 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
         ClientSpanThreadBinder binder = brave.clientSpanThreadBinder();
         brave.clientRequestInterceptor().handle(new ZipkinClientRequestAdapter(serviceName, event.getExchange(), event.getEndpoint()));
         Span span = binder.getCurrentClientSpan();
-        event.getExchange().setProperty("CamelZipkinClientSpan", span);
+
+        String key = "CamelZipkinClientSpan-" + serviceName;
+        event.getExchange().setProperty(key, span);
 
         if (log.isDebugEnabled()) {
             log.debug("clientRequest: service={}, id={} ", serviceName, span != null ? span.getId() : "<null>");
@@ -265,7 +267,8 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
 
     private void clientResponse(Brave brave, String serviceName, ExchangeSentEvent event) {
         ClientSpanThreadBinder binder = brave.clientSpanThreadBinder();
-        Span span = event.getExchange().getProperty("CamelZipkinClientSpan", Span.class);
+        String key = "CamelZipkinClientSpan-" + serviceName;
+        Span span = event.getExchange().getProperty(key, Span.class);
         binder.setCurrentSpan(span);
         brave.clientResponseInterceptor().handle(new ZipkinClientResponseAdaptor(event.getExchange(), event.getEndpoint()));
         binder.setCurrentSpan(null);
@@ -279,7 +282,8 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
         ServerSpanThreadBinder binder = brave.serverSpanThreadBinder();
         brave.serverRequestInterceptor().handle(new ZipkinServerRequestAdapter(event.getExchange()));
         ServerSpan span = binder.getCurrentServerSpan();
-        event.getExchange().setProperty("CamelZipkinServerSpan", span);
+        String key = "CamelZipkinServerSpan-" + serviceName;
+        event.getExchange().setProperty(key, span);
 
         if (log.isDebugEnabled()) {
             log.debug("serverRequest: service={}, id={} ", serviceName, span != null ? span.getSpan().getId() : "<null>");
@@ -288,7 +292,8 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
 
     private void serverResponse(Brave brave, String serviceName, ExchangeCompletedEvent event) {
         ServerSpanThreadBinder binder = brave.serverSpanThreadBinder();
-        ServerSpan span = event.getExchange().getProperty("CamelZipkinServerSpan", ServerSpan.class);
+        String key = "CamelZipkinServerSpan-" + serviceName;
+        ServerSpan span = event.getExchange().getProperty(key, ServerSpan.class);
         binder.setCurrentSpan(span);
         brave.serverResponseInterceptor().handle(new ZipkinServerResponseAdapter(event.getExchange()));
         binder.setCurrentSpan(null);
@@ -300,7 +305,8 @@ public class ZipkinEventNotifier extends EventNotifierSupport {
 
     private void serverResponse(Brave brave, String serviceName, ExchangeFailedEvent event) {
         ServerSpanThreadBinder binder = brave.serverSpanThreadBinder();
-        ServerSpan span = event.getExchange().getProperty("CamelZipkinServerSpan", ServerSpan.class);
+        String key = "CamelZipkinServerSpan-" + serviceName;
+        ServerSpan span = event.getExchange().getProperty(key, ServerSpan.class);
         binder.setCurrentSpan(span);
         brave.serverResponseInterceptor().handle(new ZipkinServerResponseAdapter(event.getExchange()));
         binder.setCurrentSpan(null);

http://git-wip-us.apache.org/repos/asf/camel/blob/c15d1cb2/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinOneRouteScribe.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinOneRouteScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinOneRouteScribe.java
index c14a026..de48945 100644
--- a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinOneRouteScribe.java
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinOneRouteScribe.java
@@ -16,12 +16,9 @@
  */
 package org.apache.camel.zipkin.scribe;
 
-import java.util.concurrent.TimeUnit;
-
 import com.github.kristofa.brave.scribe.ScribeSpanCollector;
 import org.apache.camel.CamelContext;
 import org.apache.camel.RoutesBuilder;
-import org.apache.camel.builder.NotifyBuilder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.camel.zipkin.ZipkinEventNotifier;
@@ -40,14 +37,12 @@ public class ZipkinOneRouteScribe extends CamelTestSupport {
     private String ip = "192.168.99.100";
     private ZipkinEventNotifier zipkin;
 
-    // TODO: producer template also
-    // TODO: message id added x2
-
     @Override
     protected CamelContext createCamelContext() throws Exception {
         CamelContext context = super.createCamelContext();
 
         zipkin = new ZipkinEventNotifier();
+        // we have one route as service
         zipkin.addServiceMapping("seda:cat", "cat");
         zipkin.setSpanCollector(new ScribeSpanCollector(ip, 9410));
         context.getManagementStrategy().addEventNotifier(zipkin);
@@ -57,13 +52,7 @@ public class ZipkinOneRouteScribe extends CamelTestSupport {
 
     @Test
     public void testZipkinRoute() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
-
-        for (int i = 0; i < 1; i++) {
-            template.sendBody("seda:cat", "Hello Cat");
-        }
-
-        assertTrue(notify.matches(30, TimeUnit.SECONDS));
+        template.requestBody("direct:start", "Hello Cat");
     }
 
     @Override
@@ -71,6 +60,8 @@ public class ZipkinOneRouteScribe extends CamelTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
+                from("direct:start").to("seda:cat");
+
                 from("seda:cat").routeId("cat")
                         .log("routing at ${routeId}")
                         .delay(simple("${random(1000,2000)}"));

http://git-wip-us.apache.org/repos/asf/camel/blob/c15d1cb2/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java
index 65fdfdf..3b91b00 100644
--- a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinRouteConcurrentScribe.java
@@ -45,6 +45,7 @@ public class ZipkinRouteConcurrentScribe extends CamelTestSupport {
         CamelContext context = super.createCamelContext();
 
         zipkin = new ZipkinEventNotifier();
+        // we have 2 routes as services
         zipkin.addServiceMapping("seda:foo", "foo");
         zipkin.addServiceMapping("seda:bar", "bar");
         zipkin.setSpanCollector(new ScribeSpanCollector(ip, 9410));
@@ -55,10 +56,10 @@ public class ZipkinRouteConcurrentScribe extends CamelTestSupport {
 
     @Test
     public void testZipkinRoute() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context).whenDone(5).create();
+        NotifyBuilder notify = new NotifyBuilder(context).from("seda:foo").whenDone(5).create();
 
         for (int i = 0; i < 5; i++) {
-            template.sendBody("seda:foo", "Hello World");
+            template.requestBody("direct:foo", "Hello World");
         }
 
         assertTrue(notify.matches(60, TimeUnit.SECONDS));
@@ -69,12 +70,14 @@ public class ZipkinRouteConcurrentScribe extends CamelTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("seda:foo?concurrentConsumers=5").routeId("foo")
+                from("direct:start").to("sed:foo");
+
+                from("seda:foo?concurrentConsumers=2").routeId("foo")
                         .log("routing at ${routeId}")
                         .delay(simple("${random(1000,2000)}"))
                         .to("seda:bar");
 
-                from("seda:bar?concurrentConsumers=5").routeId("bar")
+                from("seda:bar?concurrentConsumers=2").routeId("bar")
                         .log("routing at ${routeId}")
                         .delay(simple("${random(0,500)}"));
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/c15d1cb2/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java
index fc898c8..5032366 100644
--- a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinSimpleRouteScribe.java
@@ -16,12 +16,9 @@
  */
 package org.apache.camel.zipkin.scribe;
 
-import java.util.concurrent.TimeUnit;
-
 import com.github.kristofa.brave.scribe.ScribeSpanCollector;
 import org.apache.camel.CamelContext;
 import org.apache.camel.RoutesBuilder;
-import org.apache.camel.builder.NotifyBuilder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.camel.zipkin.ZipkinEventNotifier;
@@ -45,6 +42,7 @@ public class ZipkinSimpleRouteScribe extends CamelTestSupport {
         CamelContext context = super.createCamelContext();
 
         zipkin = new ZipkinEventNotifier();
+        // we have one route as service
         zipkin.addServiceMapping("seda:dude", "dude");
         zipkin.setSpanCollector(new ScribeSpanCollector(ip, 9410));
         context.getManagementStrategy().addEventNotifier(zipkin);
@@ -54,13 +52,9 @@ public class ZipkinSimpleRouteScribe extends CamelTestSupport {
 
     @Test
     public void testZipkinRoute() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context).whenDone(5).create();
-
         for (int i = 0; i < 5; i++) {
-            template.sendBody("seda:dude", "Hello World");
+            template.requestBody("direct:start", "Hello World");
         }
-
-        assertTrue(notify.matches(30, TimeUnit.SECONDS));
     }
 
     @Override
@@ -68,6 +62,8 @@ public class ZipkinSimpleRouteScribe extends CamelTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
+                from("direct:start").to("seda:dude");
+
                 from("seda:dude").routeId("dude")
                         .log("routing at ${routeId}")
                         .delay(simple("${random(1000,2000)}"));

http://git-wip-us.apache.org/repos/asf/camel/blob/c15d1cb2/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTimerRouteScribe.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTimerRouteScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTimerRouteScribe.java
index 017102c..9e03d66 100644
--- a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTimerRouteScribe.java
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTimerRouteScribe.java
@@ -46,6 +46,7 @@ public class ZipkinTimerRouteScribe extends CamelTestSupport {
         CamelContext context = super.createCamelContext();
 
         zipkin = new ZipkinEventNotifier();
+        // we have one route as service
         zipkin.addServiceMapping("seda:timer", "timer");
         zipkin.setSpanCollector(new ScribeSpanCollector(ip, 9410));
         context.getManagementStrategy().addEventNotifier(zipkin);

http://git-wip-us.apache.org/repos/asf/camel/blob/c15d1cb2/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTwoRouteScribe.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTwoRouteScribe.java b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTwoRouteScribe.java
new file mode 100644
index 0000000..7e72c17
--- /dev/null
+++ b/components/camel-zipkin/src/test/java/org/apache/camel/zipkin/scribe/ZipkinTwoRouteScribe.java
@@ -0,0 +1,77 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.zipkin.scribe;
+
+import com.github.kristofa.brave.scribe.ScribeSpanCollector;
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.zipkin.ZipkinEventNotifier;
+import org.junit.Test;
+
+/**
+ * Integration test requires running Zipkin/Scribe running
+ *
+ * The easiest way is to run using zipkin-docker: https://github.com/openzipkin/docker-zipkin
+ *
+ * Adjust the IP address to what IP docker-machines have assigned, you can use
+ * <tt>docker-machines ls</tt>
+ */
+public class ZipkinTwoRouteScribe extends CamelTestSupport {
+
+    private String ip = "192.168.99.100";
+    private ZipkinEventNotifier zipkin;
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        zipkin = new ZipkinEventNotifier();
+        // we have 2 routes as services
+        zipkin.addServiceMapping("seda:cat", "cat");
+        zipkin.addServiceMapping("seda:dog", "dog");
+        zipkin.setSpanCollector(new ScribeSpanCollector(ip, 9410));
+        context.getManagementStrategy().addEventNotifier(zipkin);
+
+        return context;
+    }
+
+    @Test
+    public void testZipkinRoute() throws Exception {
+        template.requestBody("direct:start", "Hello Cat and Dog");
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").to("seda:cat");
+
+                from("seda:cat").routeId("cat")
+                        .log("routing at ${routeId}")
+                        .delay(simple("${random(1000,2000)}"))
+                        .to("seda:dog");
+
+                from("seda:dog").routeId("dog")
+                        .log("routing at ${routeId}")
+                        .delay(simple("${random(0,500)}"));
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/c15d1cb2/components/camel-zipkin/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/test/resources/log4j.properties b/components/camel-zipkin/src/test/resources/log4j.properties
index ab7b29f..538c5bd 100644
--- a/components/camel-zipkin/src/test/resources/log4j.properties
+++ b/components/camel-zipkin/src/test/resources/log4j.properties
@@ -18,7 +18,7 @@
 #
 # The logging properties used
 #
-log4j.rootLogger=INFO, file
+log4j.rootLogger=INFO, out
 
 #log4j.logger.org.apache.camel=DEBUG
 log4j.logger.org.apache.camel.zipkin=DEBUG


[11/12] camel git commit: CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.

Posted by da...@apache.org.
CAMEL-9759: camel-zipkin - Instrument Camel. Work in progress.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/afc18f97
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/afc18f97
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/afc18f97

Branch: refs/heads/master
Commit: afc18f97781b475bdd4e15072ad8c51729aa9c6a
Parents: c6a2585
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 29 14:40:48 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 29 14:42:24 2016 +0200

----------------------------------------------------------------------
 apache-camel/pom.xml                            |  4 ++
 .../src/main/descriptors/common-bin.xml         |  1 +
 components/camel-zipkin/pom.xml                 |  4 +-
 .../zipkin/ZipkinLoggingSpanCollector.java      | 13 +------
 parent/pom.xml                                  |  6 +++
 .../features/src/main/resources/features.xml    |  9 ++++-
 .../camel/itest/karaf/CamelZipkinTest.java      | 40 ++++++++++++++++++++
 7 files changed, 61 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/afc18f97/apache-camel/pom.xml
----------------------------------------------------------------------
diff --git a/apache-camel/pom.xml b/apache-camel/pom.xml
index faf142e..264f2fe 100644
--- a/apache-camel/pom.xml
+++ b/apache-camel/pom.xml
@@ -948,6 +948,10 @@
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
+      <artifactId>camel-zipkin</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
       <artifactId>camel-zookeeper</artifactId>
     </dependency>
 

http://git-wip-us.apache.org/repos/asf/camel/blob/afc18f97/apache-camel/src/main/descriptors/common-bin.xml
----------------------------------------------------------------------
diff --git a/apache-camel/src/main/descriptors/common-bin.xml b/apache-camel/src/main/descriptors/common-bin.xml
index ae2c879..fcbc250 100644
--- a/apache-camel/src/main/descriptors/common-bin.xml
+++ b/apache-camel/src/main/descriptors/common-bin.xml
@@ -247,6 +247,7 @@
         <include>org.apache.camel:camel-xstream</include>
         <include>org.apache.camel:camel-yammer</include>
         <include>org.apache.camel:camel-zipfile</include>
+        <include>org.apache.camel:camel-zipkin</include>
         <include>org.apache.camel:camel-zookeeper</include>
         <include>org.apache.camel:camel-catalog</include>
         <include>org.apache.camel:camel-catalog-lucene</include>

http://git-wip-us.apache.org/repos/asf/camel/blob/afc18f97/components/camel-zipkin/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/pom.xml b/components/camel-zipkin/pom.xml
index e5e5b31..0027d3a 100644
--- a/components/camel-zipkin/pom.xml
+++ b/components/camel-zipkin/pom.xml
@@ -47,13 +47,11 @@
       <artifactId>brave-core</artifactId>
       <version>${brave-zipkin-version}</version>
     </dependency>
-
-    <!-- for testing using a real zipkin server -->
+    <!-- to send to zipkin server -->
     <dependency>
       <groupId>com.github.kristofa</groupId>
       <artifactId>brave-spancollector-scribe</artifactId>
       <version>${brave-zipkin-version}</version>
-      <scope>test</scope>
     </dependency>
 
     <!-- test dependencies -->

http://git-wip-us.apache.org/repos/asf/camel/blob/afc18f97/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java
----------------------------------------------------------------------
diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java
index 84daddb..608ef3a 100644
--- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java
+++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinLoggingSpanCollector.java
@@ -16,12 +16,8 @@
  */
 package org.apache.camel.zipkin;
 
-import java.util.LinkedHashSet;
-import java.util.Set;
-
 import com.github.kristofa.brave.IdConversion;
 import com.github.kristofa.brave.SpanCollector;
-import com.twitter.zipkin.gen.BinaryAnnotation;
 import com.twitter.zipkin.gen.Span;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -31,7 +27,6 @@ import org.slf4j.LoggerFactory;
  */
 public class ZipkinLoggingSpanCollector implements SpanCollector {
 
-    private final Set<BinaryAnnotation> defaultAnnotations = new LinkedHashSet<BinaryAnnotation>();
     private final String name;
     private final Logger logger;
 
@@ -46,12 +41,6 @@ public class ZipkinLoggingSpanCollector implements SpanCollector {
 
     @Override
     public void collect(Span span) {
-        if (!defaultAnnotations.isEmpty()) {
-            for (BinaryAnnotation ba : defaultAnnotations) {
-                span.addToBinary_annotations(ba);
-            }
-        }
-
         if (logger.isInfoEnabled()) {
             long ms = span.getDuration() != null ? span.getDuration() / 1000 : -1;
             String id = IdConversion.convertToString(span.getId());
@@ -62,7 +51,7 @@ public class ZipkinLoggingSpanCollector implements SpanCollector {
 
     @Override
     public void addDefaultAnnotation(String key, String value) {
-        defaultAnnotations.add(BinaryAnnotation.create(key, value, null));
+        // noop
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/afc18f97/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 0ff8534..fb672f9 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -311,6 +311,7 @@
     <jettison-version>1.3.7</jettison-version>
     <jgit-version>4.2.0.201601211800-r</jgit-version>
     <jgroups-version>3.6.8.Final</jgroups-version>
+    <libthrift-version>0.9.0</libthrift-version>
     <jibx-version>1.2.6</jibx-version>
     <jing-bundle-version>20030619_5</jing-bundle-version>
     <jing-version>20030619</jing-version>
@@ -1804,6 +1805,11 @@
       </dependency>
       <dependency>
         <groupId>org.apache.camel</groupId>
+        <artifactId>camel-zipkin</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.camel</groupId>
         <artifactId>camel-zookeeper</artifactId>
         <version>${project.version}</version>
       </dependency>

http://git-wip-us.apache.org/repos/asf/camel/blob/afc18f97/platforms/karaf/features/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml
index 67986fe..1ef3c26 100644
--- a/platforms/karaf/features/src/main/resources/features.xml
+++ b/platforms/karaf/features/src/main/resources/features.xml
@@ -1489,7 +1489,6 @@
     <bundle>mvn:org.apache.camel/camel-solr/${project.version}</bundle>
   </feature>
   <feature name='camel-spark-rest' version='${project.version}' resolver='(obr)' start-level='50'>
-    <details>camel-spark-rest requires Java 8 and Jetty9</details>
     <feature version='${project.version}'>camel-core</feature>
     <feature version='${project.version}'>camel-jetty9</feature>
     <bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.sparkjava-core/${spark-rest-bundle-version}</bundle>
@@ -1815,6 +1814,14 @@
     <feature version='${project.version}'>camel-core</feature>
     <bundle>mvn:org.apache.camel/camel-zipfile/${project.version}</bundle>
   </feature>
+  <feature name='camel-zipkin' version='${project.version}' resolver='(obr)' start-level='50'>
+    <details>camel-zpikin using spancollector-scribe does not yet work in OSGi</details>
+    <feature version='${project.version}'>camel-core</feature>
+    <bundle dependency='true'>wrap:mvn:com.github.kristofa/brave-core/${brave-zipkin-version}</bundle>
+    <!--<bundle dependency='true'>wrap:mvn:com.github.kristofa/brave-spancollector-scribe/${brave-zipkin-version}</bundle>-->
+    <bundle dependency='true'>mvn:org.apache.thrift/libthrift/${libthrift-version}</bundle>
+    <bundle>mvn:org.apache.camel/camel-zipkin/${project.version}</bundle>
+  </feature>
   <feature name='camel-zookeeper' version='${project.version}' resolver='(obr)' start-level='50'>
     <feature version='${project.version}'>camel-core</feature>
     <bundle dependency='true'>mvn:org.apache.zookeeper/zookeeper/${zookeeper-version}</bundle>

http://git-wip-us.apache.org/repos/asf/camel/blob/afc18f97/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelZipkinTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelZipkinTest.java b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelZipkinTest.java
new file mode 100644
index 0000000..7a665d5
--- /dev/null
+++ b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelZipkinTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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.itest.karaf;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+@RunWith(PaxExam.class)
+public class CamelZipkinTest extends AbstractFeatureTest {
+
+    public static final String COMPONENT = extractName(CamelZipkinTest.class);
+
+    @Test
+    public void test() throws Exception {
+        // TODO: test zipkin
+    }
+
+    @Configuration
+    public static Option[] configure() {
+        return configure(COMPONENT);
+    }
+
+}