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 2020/08/11 18:43:18 UTC

[camel-spring-boot] branch master updated: opentelemetry spring boot support (#132)

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-spring-boot.git


The following commit(s) were added to refs/heads/master by this push:
     new 5272ec7  opentelemetry spring boot support (#132)
5272ec7 is described below

commit 5272ec7a372dc6c2b9b05b2770050ea33baab0b2
Author: Ruben Vargas Palma <ru...@gmail.com>
AuthorDate: Tue Aug 11 13:43:08 2020 -0500

    opentelemetry spring boot support (#132)
    
    Signed-off-by: Ruben <ru...@gmail.com>
---
 .../src/main/docs/opentelemetry-starter.adoc       | 32 +++++++++++++
 .../opentelemetry/starter/CamelOpenTelemetry.java  | 34 +++++++++++++
 .../starter/OpenTelemetryAutoConfiguration.java    | 56 ++++++++++++++++++++++
 .../OpenTelemetryConditionalAutoConfiguration.java | 31 ++++++++++++
 .../OpenTelemetryConfigurationProperties.java      | 52 ++++++++++++++++++++
 .../src/main/resources/META-INF/spring.factories   | 18 +++++++
 6 files changed, 223 insertions(+)

diff --git a/components-starter/camel-opentelemetry-starter/src/main/docs/opentelemetry-starter.adoc b/components-starter/camel-opentelemetry-starter/src/main/docs/opentelemetry-starter.adoc
new file mode 100644
index 0000000..b62aecb
--- /dev/null
+++ b/components-starter/camel-opentelemetry-starter/src/main/docs/opentelemetry-starter.adoc
@@ -0,0 +1,32 @@
+// spring-boot-auto-configure options: START
+:page-partial:
+:doctitle: Camel Spring Boot Starter for opentelemetry
+
+== Spring Boot Auto-Configuration
+
+When using opentelemetry with Spring Boot make sure to use the following Maven dependency to have support for auto configuration:
+
+[source,xml]
+----
+<dependency>
+  <groupId>org.apache.camel.springboot</groupId>
+  <artifactId>camel-opentelemetry-starter</artifactId>
+  <version>x.x.x</version>
+  <!-- use the same version as your Camel core version -->
+</dependency>
+----
+
+
+The component supports 2 options, which are listed below.
+
+
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|===
+| Name | Description | Default | Type
+| *camel.opentelemetry.encoding* | Activate or deactivate dash encoding in headers (required by JMS) for messaging |  | Boolean
+| *camel.opentelemetry.exclude-patterns* | Sets exclude pattern(s) that will disable tracing for Camel messages that matches the pattern. |  | Set
+|===
+
+
+// spring-boot-auto-configure options: END
diff --git a/components-starter/camel-opentelemetry-starter/src/main/java/org/apache/camel/opentelemetry/starter/CamelOpenTelemetry.java b/components-starter/camel-opentelemetry-starter/src/main/java/org/apache/camel/opentelemetry/starter/CamelOpenTelemetry.java
new file mode 100644
index 0000000..c828805
--- /dev/null
+++ b/components-starter/camel-opentelemetry-starter/src/main/java/org/apache/camel/opentelemetry/starter/CamelOpenTelemetry.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
+ *
+ *      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.opentelemetry.starter;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.springframework.context.annotation.Import;
+
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Inherited
+@Import(OpenTelemetryAutoConfiguration.class)
+public @interface CamelOpenTelemetry{
+}
diff --git a/components-starter/camel-opentelemetry-starter/src/main/java/org/apache/camel/opentelemetry/starter/OpenTelemetryAutoConfiguration.java b/components-starter/camel-opentelemetry-starter/src/main/java/org/apache/camel/opentelemetry/starter/OpenTelemetryAutoConfiguration.java
new file mode 100644
index 0000000..abbcf15
--- /dev/null
+++ b/components-starter/camel-opentelemetry-starter/src/main/java/org/apache/camel/opentelemetry/starter/OpenTelemetryAutoConfiguration.java
@@ -0,0 +1,56 @@
+/*
+ * 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.opentelemetry.starter;
+
+import io.opentelemetry.trace.Tracer;
+import org.apache.camel.CamelContext;
+import org.apache.camel.opentelemetry.OpenTelemetryTracer;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration(proxyBeanMethods = false)
+@EnableConfigurationProperties(OpenTelemetryConfigurationProperties.class)
+@ConditionalOnProperty(value = "camel.opentelemetry.enabled", matchIfMissing = true)
+public class OpenTelemetryAutoConfiguration {
+
+    @Autowired(required = false)
+    private Tracer tracer;
+
+    @Bean(initMethod = "", destroyMethod = "")
+    // Camel handles the lifecycle of this bean
+    @ConditionalOnMissingBean(OpenTelemetryTracer.class)
+    OpenTelemetryTracer openTelemetryEventNotifier(CamelContext camelContext,
+                                                 OpenTelemetryConfigurationProperties config) {
+        OpenTelemetryTracer ottracer = new OpenTelemetryTracer();
+        if (tracer != null) {
+            ottracer.setTracer(tracer);
+        }
+        if (config.getExcludePatterns() != null) {
+            ottracer.setExcludePatterns(config.getExcludePatterns());
+        }
+        if (config.getEncoding() != null) {
+            ottracer.setEncoding(config.getEncoding().booleanValue());
+        }
+        ottracer.init(camelContext);
+
+        return ottracer;
+    }
+}
diff --git a/components-starter/camel-opentelemetry-starter/src/main/java/org/apache/camel/opentelemetry/starter/OpenTelemetryConditionalAutoConfiguration.java b/components-starter/camel-opentelemetry-starter/src/main/java/org/apache/camel/opentelemetry/starter/OpenTelemetryConditionalAutoConfiguration.java
new file mode 100644
index 0000000..db0255c
--- /dev/null
+++ b/components-starter/camel-opentelemetry-starter/src/main/java/org/apache/camel/opentelemetry/starter/OpenTelemetryConditionalAutoConfiguration.java
@@ -0,0 +1,31 @@
+/*
+ * 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.opentelemetry.starter;
+
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+
+/**
+ * A configuration controller to enable OpenTracing via the configuration property.
+ * Useful to bootstrap OpenTracing when not using the {@link CamelOpenTelemetry} annotation.
+ */
+@Configuration(proxyBeanMethods = false)
+@ConditionalOnProperty(value = "camel.opentelemetry.enabled")
+@Import(OpenTelemetryAutoConfiguration.class)
+public class OpenTelemetryConditionalAutoConfiguration {
+}
diff --git a/components-starter/camel-opentelemetry-starter/src/main/java/org/apache/camel/opentelemetry/starter/OpenTelemetryConfigurationProperties.java b/components-starter/camel-opentelemetry-starter/src/main/java/org/apache/camel/opentelemetry/starter/OpenTelemetryConfigurationProperties.java
new file mode 100644
index 0000000..a27cd19
--- /dev/null
+++ b/components-starter/camel-opentelemetry-starter/src/main/java/org/apache/camel/opentelemetry/starter/OpenTelemetryConfigurationProperties.java
@@ -0,0 +1,52 @@
+/*
+ * 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.opentelemetry.starter;
+
+import java.util.Set;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties(prefix = "camel.opentelemetry")
+public class OpenTelemetryConfigurationProperties {
+
+    /**
+     * Sets exclude pattern(s) that will disable tracing for Camel messages that
+     * matches the pattern.
+     */
+    private Set<String> excludePatterns;
+    /**
+     * Activate or deactivate dash encoding in headers (required by JMS) for
+     * messaging
+     */
+    private Boolean encoding;
+
+    public Set<String> getExcludePatterns() {
+        return excludePatterns;
+    }
+
+    public void setExcludePatterns(Set<String> excludePatterns) {
+        this.excludePatterns = excludePatterns;
+    }
+
+    public Boolean getEncoding() {
+        return encoding;
+    }
+
+    public void setEncoding(Boolean encoding) {
+        this.encoding = encoding;
+    }
+}
diff --git a/components-starter/camel-opentelemetry-starter/src/main/resources/META-INF/spring.factories b/components-starter/camel-opentelemetry-starter/src/main/resources/META-INF/spring.factories
new file mode 100644
index 0000000..33d68f9
--- /dev/null
+++ b/components-starter/camel-opentelemetry-starter/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,18 @@
+## ---------------------------------------------------------------------------
+## 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.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+org.apache.camel.opentelemetry.starter.OpenTelemetryConditionalAutoConfiguration
\ No newline at end of file