You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2017/03/15 13:40:36 UTC
[2/2] camel git commit: CAMEL-10920: lookup tracer from the registry
before using the global tracer
CAMEL-10920: lookup tracer from the registry before using the global tracer
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e6131db3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e6131db3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e6131db3
Branch: refs/heads/master
Commit: e6131db33a67fcfbfafe7d08265d7fde0ab8405e
Parents: 2b267a6
Author: Nicola Ferraro <ni...@gmail.com>
Authored: Wed Mar 15 14:40:21 2017 +0100
Committer: Nicola Ferraro <ni...@gmail.com>
Committed: Wed Mar 15 14:40:21 2017 +0100
----------------------------------------------------------------------
.../src/main/docs/opentracing.adoc | 5 +-
.../camel/opentracing/OpenTracingTracer.java | 11 +++-
.../OpentracingSpanCollectorInRegistryTest.java | 54 ++++++++++++++++++++
3 files changed, 67 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/e6131db3/components/camel-opentracing/src/main/docs/opentracing.adoc
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/main/docs/opentracing.adoc b/components/camel-opentracing/src/main/docs/opentracing.adoc
index 7778660..3db0b46 100644
--- a/components/camel-opentracing/src/main/docs/opentracing.adoc
+++ b/components/camel-opentracing/src/main/docs/opentracing.adoc
@@ -24,9 +24,10 @@ To enable camel-opentracing you need to configure first
[source,java]
--------------------------------------------------------------------------------------------------
OpenTracingTracer ottracer = new OpenTracingTracer();
-// by default uses the Global Tracer, but can override with specific OpenTracing implementation
+// By default it uses the Global Tracer, but you can override it with a specific OpenTracing implementation.
+// As an alternative, you can also set a tracer in the registry and it it will be looked up.
ottracer.setTracer(...);
-// and then set the CamelContext
+// And then set the CamelContext
ottracer.setCamelContext(camelContext);
--------------------------------------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/e6131db3/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/OpenTracingTracer.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/OpenTracingTracer.java b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/OpenTracingTracer.java
index 6f709f2..9f45aa2 100644
--- a/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/OpenTracingTracer.java
+++ b/components/camel-opentracing/src/main/java/org/apache/camel/opentracing/OpenTracingTracer.java
@@ -21,6 +21,7 @@ import java.util.EventObject;
import java.util.HashMap;
import java.util.Map;
import java.util.ServiceLoader;
+import java.util.Set;
import io.opentracing.Span;
import io.opentracing.Tracer;
@@ -66,7 +67,7 @@ public class OpenTracingTracer extends ServiceSupport implements RoutePolicyFact
private final OpenTracingEventNotifier eventNotifier = new OpenTracingEventNotifier();
private final SpanManager spanManager = DefaultSpanManager.getInstance();
- private Tracer tracer = GlobalTracer.get();
+ private Tracer tracer;
private CamelContext camelContext;
static {
@@ -134,6 +135,14 @@ public class OpenTracingTracer extends ServiceSupport implements RoutePolicyFact
}
if (tracer == null) {
+ Set<Tracer> tracers = camelContext.getRegistry().findByType(Tracer.class);
+ if (tracers.size() == 1) {
+ tracer = tracers.iterator().next();
+ }
+ }
+
+ if (tracer == null) {
+ // fallback to the global tracer if no tracers are configured
tracer = GlobalTracer.get();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/e6131db3/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/OpentracingSpanCollectorInRegistryTest.java
----------------------------------------------------------------------
diff --git a/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/OpentracingSpanCollectorInRegistryTest.java b/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/OpentracingSpanCollectorInRegistryTest.java
new file mode 100644
index 0000000..e2c8f18
--- /dev/null
+++ b/components/camel-opentracing/src/test/java/org/apache/camel/opentracing/OpentracingSpanCollectorInRegistryTest.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.opentracing;
+
+import io.opentracing.NoopTracer;
+import io.opentracing.NoopTracerFactory;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class OpentracingSpanCollectorInRegistryTest extends CamelTestSupport {
+
+ private OpenTracingTracer openTracing;
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+
+ openTracing = new OpenTracingTracer();
+ openTracing.init(context);
+
+ return context;
+ }
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry registry = super.createRegistry();
+ registry.bind("tracer", NoopTracerFactory.create());
+ return registry;
+ }
+
+ @Test
+ public void testZipkinConfiguration() throws Exception {
+ assertNotNull(openTracing.getTracer());
+ assertTrue(openTracing.getTracer() instanceof NoopTracer);
+ }
+
+}