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 2019/12/04 11:29:07 UTC

[camel] branch master updated: Allow to add custom decorator to open tracing via java api

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 6b089f8  Allow to add custom decorator to open tracing via java api
6b089f8 is described below

commit 6b089f89c84acc81b0e918cd838f1b2619d75fa4
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Dec 4 12:28:30 2019 +0100

    Allow to add custom decorator to open tracing via java api
---
 .../apache/camel/opentracing/OpenTracingTracer.java | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

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 4a58f11..64a74df 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
@@ -70,7 +70,7 @@ import org.apache.camel.util.StringHelper;
 @ManagedResource(description = "OpenTracingTracer")
 public class OpenTracingTracer extends ServiceSupport implements RoutePolicyFactory, StaticService, CamelContextAware {
 
-    private static Map<String, SpanDecorator> decorators = new HashMap<>();
+    private static final Map<String, SpanDecorator> DECORATORS = new HashMap<>();
 
     private final OpenTracingEventNotifier eventNotifier = new OpenTracingEventNotifier();
     private final OpenTracingLogListener logListener = new OpenTracingLogListener();
@@ -81,13 +81,13 @@ public class OpenTracingTracer extends ServiceSupport implements RoutePolicyFact
 
     static {
         ServiceLoader.load(SpanDecorator.class).forEach(d -> {
-            SpanDecorator existing = decorators.get(d.getComponent());
+            SpanDecorator existing = DECORATORS.get(d.getComponent());
             // Add span decorator if no existing decorator for the component,
             // or if derived from the existing decorator's class, allowing
             // custom decorators to be added if they extend the standard
             // decorators
             if (existing == null || existing.getClass().isInstance(d)) {
-                decorators.put(d.getComponent(), d);
+                DECORATORS.put(d.getComponent(), d);
             }
         });
     }
@@ -95,6 +95,13 @@ public class OpenTracingTracer extends ServiceSupport implements RoutePolicyFact
     public OpenTracingTracer() {
     }
 
+    /**
+     * To add a custom decorator that does not come out of the box with camel-opentracing.
+     */
+    public void addDecorator(SpanDecorator decorator) {
+        DECORATORS.put(decorator.getComponent(), decorator);
+    }
+
     @Override
     public RoutePolicy createRoutePolicy(CamelContext camelContext, String routeId, NamedNode route) {
         // ensure this opentracing tracer gets initialized when Camel starts
@@ -109,10 +116,8 @@ public class OpenTracingTracer extends ServiceSupport implements RoutePolicyFact
     public void init(CamelContext camelContext) {
         if (!camelContext.hasService(this)) {
             try {
-                // start this service eager so we init before Camel is starting
-                // up
+                // start this service eager so we init before Camel is starting up
                 camelContext.addService(this, true, true);
-
             } catch (Exception e) {
                 throw RuntimeCamelException.wrapRuntimeCamelException(e);
             }
@@ -209,7 +214,7 @@ public class OpenTracingTracer extends ServiceSupport implements RoutePolicyFact
         String splitURI[] = StringHelper.splitOnCharacter(uri, ":", 2);
         if (splitURI[1] != null) {
             String scheme = splitURI[0];
-            sd = decorators.get(scheme);
+            sd = DECORATORS.get(scheme);
         }
         if (sd == null) {
             // okay there was no decorator found via component name (scheme), then try FQN
@@ -217,7 +222,7 @@ public class OpenTracingTracer extends ServiceSupport implements RoutePolicyFact
                 Component comp = ((DefaultEndpoint) endpoint).getComponent();
                 String fqn = comp.getClass().getName();
                 // lookup via FQN
-                sd = decorators.values().stream().filter(d -> fqn.equals(d.getComponentClassName())).findFirst().orElse(null);
+                sd = DECORATORS.values().stream().filter(d -> fqn.equals(d.getComponentClassName())).findFirst().orElse(null);
             }
         }
         if (sd == null) {