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

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


The following commit(s) were added to refs/heads/main by this push:
     new fcab67a1f5e fix(components): compute properly endpoints with no name
fcab67a1f5e is described below

commit fcab67a1f5e88697d3021c268c8b4cf7eda30381
Author: Pasquale Congiusti <pasquale.congiu...@gmail.com>
AuthorDate: Mon Mar 31 11:27:55 2025 +0200

    fix(components): compute properly endpoints with no name
    
    Closes CAMEL-21897
---
 .../camel/telemetry/SpanDecoratorManagerImpl.java  | 21 +++++---
 .../decorators/AbstractSpanDecorator.java          | 12 +++--
 .../org.apache.camel.telemetry.SpanDecorator       | 60 ++++++++++++++++++++++
 .../apache/camel/telemetry/URIDecoratorTest.java   | 42 +++++++++++++++
 .../main/java/org/apache/camel/tracing/Tracer.java | 21 +++++---
 .../tracing/decorators/AbstractSpanDecorator.java  | 12 +++--
 .../org/apache/camel/tracing/URIDecoratorTest.java | 32 ++++++++++++
 7 files changed, 176 insertions(+), 24 deletions(-)

diff --git 
a/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/SpanDecoratorManagerImpl.java
 
b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/SpanDecoratorManagerImpl.java
index 329f22a2fe2..d792e8dfcc5 100644
--- 
a/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/SpanDecoratorManagerImpl.java
+++ 
b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/SpanDecoratorManagerImpl.java
@@ -62,14 +62,7 @@ public class SpanDecoratorManagerImpl implements 
SpanDecoratorManager {
 
     @Override
     public SpanDecorator get(Endpoint endpoint) {
-        SpanDecorator sd = null;
-
-        String uri = endpoint.getEndpointUri();
-        String[] splitURI = StringHelper.splitOnCharacter(uri, ":", 2);
-        if (splitURI[1] != null) {
-            String scheme = splitURI[0];
-            sd = DECORATORS.get(scheme);
-        }
+        SpanDecorator sd = this.getFromUri(endpoint.getEndpointUri());
         if (sd == null && endpoint instanceof DefaultEndpoint de) {
             Component comp = de.getComponent();
             String fqn = comp.getClass().getName();
@@ -84,6 +77,18 @@ public class SpanDecoratorManagerImpl implements 
SpanDecoratorManager {
         return sd;
     }
 
+    SpanDecorator getFromUri(String uri) {
+        SpanDecorator sd = null;
+
+        String[] splitURI = StringHelper.splitOnCharacter(uri, ":", 2);
+        if (splitURI[1] != null) {
+            String scheme = splitURI[0];
+            sd = DECORATORS.get(scheme);
+        }
+
+        return sd;
+    }
+
     @Override
     public SpanDecorator get(String processorName) {
         return new ProcessorSpanDecorator(processorName);
diff --git 
a/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AbstractSpanDecorator.java
 
b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AbstractSpanDecorator.java
index f3292f4cc6e..8f549b1d575 100644
--- 
a/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AbstractSpanDecorator.java
+++ 
b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AbstractSpanDecorator.java
@@ -47,14 +47,18 @@ public abstract class AbstractSpanDecorator implements 
SpanDecorator {
      * @return          The stripped value from the URI
      */
     public static String stripSchemeAndOptions(Endpoint endpoint) {
-        int start = endpoint.getEndpointUri().indexOf(':');
+        return stripSchemeAndOptions(endpoint.getEndpointUri());
+    }
+
+    public static String stripSchemeAndOptions(String endpointUri) {
+        int start = endpointUri.indexOf(':');
         start++;
         // Remove any leading '/'
-        while (endpoint.getEndpointUri().charAt(start) == '/') {
+        while (endpointUri.length() > start && endpointUri.charAt(start) == 
'/') {
             start++;
         }
-        int end = endpoint.getEndpointUri().indexOf('?');
-        return end == -1 ? endpoint.getEndpointUri().substring(start) : 
endpoint.getEndpointUri().substring(start, end);
+        int end = endpointUri.indexOf('?');
+        return end == -1 ? endpointUri.substring(start) : 
endpointUri.substring(start, end);
     }
 
     public static Map<String, String> toQueryParameters(String uri) {
diff --git 
a/components/camel-telemetry/src/main/resources/META-INF/services/org.apache.camel.telemetry.SpanDecorator
 
b/components/camel-telemetry/src/main/resources/META-INF/services/org.apache.camel.telemetry.SpanDecorator
new file mode 100644
index 00000000000..03454bde355
--- /dev/null
+++ 
b/components/camel-telemetry/src/main/resources/META-INF/services/org.apache.camel.telemetry.SpanDecorator
@@ -0,0 +1,60 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.camel.telemetry.decorators.ActiveMQ6SpanDecorator
+org.apache.camel.telemetry.decorators.ActiveMQSpanDecorator
+org.apache.camel.telemetry.decorators.AhcSpanDecorator
+org.apache.camel.telemetry.decorators.AmqpSpanDecorator
+org.apache.camel.telemetry.decorators.AzureServiceBusSpanDecorator
+org.apache.camel.telemetry.decorators.CometdSpanDecorator
+org.apache.camel.telemetry.decorators.CometdsSpanDecorator
+org.apache.camel.telemetry.decorators.CqlSpanDecorator
+org.apache.camel.telemetry.decorators.DirectSpanDecorator
+org.apache.camel.telemetry.decorators.DisruptorSpanDecorator
+org.apache.camel.telemetry.decorators.DisruptorvmSpanDecorator
+org.apache.camel.telemetry.decorators.ElasticsearchSpanDecorator
+org.apache.camel.telemetry.decorators.FileSpanDecorator
+org.apache.camel.telemetry.decorators.FtpSpanDecorator
+org.apache.camel.telemetry.decorators.FtpsSpanDecorator
+org.apache.camel.telemetry.decorators.HttpSpanDecorator
+org.apache.camel.telemetry.decorators.HttpsSpanDecorator
+org.apache.camel.telemetry.decorators.IronmqSpanDecorator
+org.apache.camel.telemetry.decorators.JdbcSpanDecorator
+org.apache.camel.telemetry.decorators.JettySpanDecorator
+org.apache.camel.telemetry.decorators.JmsSpanDecorator
+org.apache.camel.telemetry.decorators.KafkaSpanDecorator
+org.apache.camel.telemetry.decorators.LogSpanDecorator
+org.apache.camel.telemetry.decorators.MongoDBSpanDecorator
+org.apache.camel.telemetry.decorators.NatsSpanDecorator
+org.apache.camel.telemetry.decorators.NettyHttpSpanDecorator
+org.apache.camel.telemetry.decorators.Paho5SpanDecorator
+org.apache.camel.telemetry.decorators.PahoSpanDecorator
+org.apache.camel.telemetry.decorators.PlatformHttpSpanDecorator
+org.apache.camel.telemetry.decorators.RestOpenapiSpanDecorator
+org.apache.camel.telemetry.decorators.RestSpanDecorator
+org.apache.camel.telemetry.decorators.SchedulerSpanDecorator
+org.apache.camel.telemetry.decorators.SedaSpanDecorator
+org.apache.camel.telemetry.decorators.ServletSpanDecorator
+org.apache.camel.telemetry.decorators.SftpSpanDecorator
+org.apache.camel.telemetry.decorators.Sjms2SpanDecorator
+org.apache.camel.telemetry.decorators.SjmsSpanDecorator
+org.apache.camel.telemetry.decorators.SpringRabbitmqSpanDecorator
+org.apache.camel.telemetry.decorators.SqlSpanDecorator
+org.apache.camel.telemetry.decorators.StompSpanDecorator
+org.apache.camel.telemetry.decorators.TimerSpanDecorator
+org.apache.camel.telemetry.decorators.UndertowSpanDecorator
+org.apache.camel.telemetry.decorators.VertxHttpSpanDecorator
\ No newline at end of file
diff --git 
a/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/URIDecoratorTest.java
 
b/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/URIDecoratorTest.java
new file mode 100644
index 00000000000..cf82d9fb88e
--- /dev/null
+++ 
b/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/URIDecoratorTest.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.telemetry;
+
+import org.apache.camel.telemetry.decorators.AbstractSpanDecorator;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class URIDecoratorTest {
+
+    SpanDecoratorManagerImpl sdm = new SpanDecoratorManagerImpl();
+
+    @Test
+    public void testSpanDecoratorFromURI() {
+        SpanDecorator sd = sdm.getFromUri("platform-http:/");
+        SpanDecorator sd2 = sdm.getFromUri("http://my-svc/path?q=123";);
+        assertEquals("platform-http", sd.getComponent());
+        assertEquals("http", sd2.getComponent());
+    }
+
+    @Test
+    public void testStripSchemeAndOptions() {
+        assertEquals("", 
AbstractSpanDecorator.stripSchemeAndOptions("platform-http:/"));
+        assertEquals("my-svc/path", 
AbstractSpanDecorator.stripSchemeAndOptions("http://my-svc/path?q=123";));
+    }
+
+}
diff --git 
a/components/camel-tracing/src/main/java/org/apache/camel/tracing/Tracer.java 
b/components/camel-tracing/src/main/java/org/apache/camel/tracing/Tracer.java
index 65f178e3d79..855e3e8ac9a 100644
--- 
a/components/camel-tracing/src/main/java/org/apache/camel/tracing/Tracer.java
+++ 
b/components/camel-tracing/src/main/java/org/apache/camel/tracing/Tracer.java
@@ -210,14 +210,7 @@ public abstract class Tracer extends ServiceSupport 
implements CamelTracingServi
     }
 
     protected SpanDecorator getSpanDecorator(Endpoint endpoint) {
-        SpanDecorator sd = null;
-
-        String uri = endpoint.getEndpointUri();
-        String[] splitURI = StringHelper.splitOnCharacter(uri, ":", 2);
-        if (splitURI[1] != null) {
-            String scheme = splitURI[0];
-            sd = DECORATORS.get(scheme);
-        }
+        SpanDecorator sd = Tracer.getFromUri(endpoint.getEndpointUri());
         if (sd == null && endpoint instanceof DefaultEndpoint de) {
             Component comp = de.getComponent();
             String fqn = comp.getClass().getName();
@@ -232,6 +225,18 @@ public abstract class Tracer extends ServiceSupport 
implements CamelTracingServi
         return sd;
     }
 
+    static SpanDecorator getFromUri(String uri) {
+        SpanDecorator sd = null;
+
+        String[] splitURI = StringHelper.splitOnCharacter(uri, ":", 2);
+        if (splitURI[1] != null) {
+            String scheme = splitURI[0];
+            sd = DECORATORS.get(scheme);
+        }
+
+        return sd;
+    }
+
     private boolean isExcluded(Exchange exchange, Endpoint endpoint) {
         String url = endpoint.getEndpointUri();
         if (url != null && excludePatterns != null) {
diff --git 
a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractSpanDecorator.java
 
b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractSpanDecorator.java
index f54d88a0697..d3b3bc73d72 100644
--- 
a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractSpanDecorator.java
+++ 
b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractSpanDecorator.java
@@ -45,14 +45,18 @@ public abstract class AbstractSpanDecorator implements 
SpanDecorator {
      * @return          The stripped value from the URI
      */
     public static String stripSchemeAndOptions(Endpoint endpoint) {
-        int start = endpoint.getEndpointUri().indexOf(':');
+        return stripSchemeAndOptions(endpoint.getEndpointUri());
+    }
+
+    public static String stripSchemeAndOptions(String endpointUri) {
+        int start = endpointUri.indexOf(':');
         start++;
         // Remove any leading '/'
-        while (endpoint.getEndpointUri().charAt(start) == '/') {
+        while (endpointUri.length() > start && endpointUri.charAt(start) == 
'/') {
             start++;
         }
-        int end = endpoint.getEndpointUri().indexOf('?');
-        return end == -1 ? endpoint.getEndpointUri().substring(start) : 
endpoint.getEndpointUri().substring(start, end);
+        int end = endpointUri.indexOf('?');
+        return end == -1 ? endpointUri.substring(start) : 
endpointUri.substring(start, end);
     }
 
     public static Map<String, String> toQueryParameters(String uri) {
diff --git 
a/components/camel-tracing/src/test/java/org/apache/camel/tracing/URIDecoratorTest.java
 
b/components/camel-tracing/src/test/java/org/apache/camel/tracing/URIDecoratorTest.java
new file mode 100644
index 00000000000..a32a76c803f
--- /dev/null
+++ 
b/components/camel-tracing/src/test/java/org/apache/camel/tracing/URIDecoratorTest.java
@@ -0,0 +1,32 @@
+/*
+ * 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.tracing;
+
+import org.apache.camel.tracing.decorators.AbstractSpanDecorator;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class URIDecoratorTest {
+
+    @Test
+    public void testStripSchemeAndOptions() {
+        assertEquals("", 
AbstractSpanDecorator.stripSchemeAndOptions("platform-http:/"));
+        assertEquals("my-svc/path", 
AbstractSpanDecorator.stripSchemeAndOptions("http://my-svc/path?q=123";));
+    }
+
+}

Reply via email to