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/09/18 15:54:01 UTC

[camel-spring-boot-examples] 38/40: Added new OpenTrace example with ElastiCo APM Tracer

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-examples.git

commit 1a0d1348c84f86eaca79f8c8796954a4403ac72a
Author: Andrii Mealshchenko <ja...@gmail.com>
AuthorDate: Thu Sep 17 20:56:34 2020 +0300

    Added new OpenTrace example with ElastiCo APM Tracer
---
 .../README.adoc                                    |  48 ++++++++
 camel-example-spring-boot-apm-opentracing/pom.xml  | 126 +++++++++++++++++++++
 .../src/main/java/sample/camel/CamelConfig.java    |  18 +++
 .../src/main/java/sample/camel/CounterBean.java    |  26 +++++
 .../java/sample/camel/Service1Application.java     |  42 +++++++
 .../src/main/java/sample/camel/Service1Route.java  |  41 +++++++
 .../src/main/resources/application.properties      |  26 +++++
 7 files changed, 327 insertions(+)

diff --git a/camel-example-spring-boot-apm-opentracing/README.adoc b/camel-example-spring-boot-apm-opentracing/README.adoc
new file mode 100644
index 0000000..2638010
--- /dev/null
+++ b/camel-example-spring-boot-apm-opentracing/README.adoc
@@ -0,0 +1,48 @@
+== OpenTracing Example
+
+=== Introduction
+
+This example shows how to use Camel with OpenTracing to trace all
+incoming and outgoing Camel messages.
+
+The example uses a ElastiCo APM Client.
+
+Route client -> service1 using HTTP.
+
+=== Before you start
+
+You need to configure EAK stack - Elasticsearch, APM Server and Kibana
+Please follow https://www.elastic.co/guide/en/apm/get-started/current/install-and-run.html to get up and running
+
+=== Build
+
+You will need to compile this example first:
+
+[source,sh]
+----
+$ mvn compile
+----
+
+=== Run the example
+
+[source,sh]
+----
+$ mvn compile spring-boot:run
+
+The client application explicitly instantiates and initializes the
+implementation
+
+=== View results
+After seeing in console messages from timer, visit Kibana to view traces -
+http://localhost:5601/app/apm#/services/Service1Application/transactions/
+select any transaction and click "View full trace"
+
+=== Help and contributions
+
+If you hit any problem using Camel or have some feedback, then please
+https://camel.apache.org/support.html[let us know].
+
+We also love contributors, so
+https://camel.apache.org/contributing.html[get involved] :-)
+
+The Camel riders!
diff --git a/camel-example-spring-boot-apm-opentracing/pom.xml b/camel-example-spring-boot-apm-opentracing/pom.xml
new file mode 100644
index 0000000..b6dfd34
--- /dev/null
+++ b/camel-example-spring-boot-apm-opentracing/pom.xml
@@ -0,0 +1,126 @@
+<?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>
+        <groupId>org.apache.camel.springboot.example</groupId>
+        <artifactId>examples</artifactId>
+        <version>3.5.0</version>
+    </parent>
+
+    <artifactId>camel-example-spring-boot-apm-opentracing</artifactId>
+    <packaging>pom</packaging>
+    <name>Camel SB Examples :: OpenTracing APM</name>
+    <description>An example showing how to trace incoming and outgoing messages from Camel with OpenTracing with ElastiCo APM
+    </description>
+
+    <properties>
+        <category>Management and Monitoring</category>
+        <title>OpenTracing APM</title>
+        <spring.boot-version>${spring-boot-version}</spring.boot-version>
+    </properties>
+
+
+    <!-- import Spring-Boot and Camel BOM -->
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-dependencies</artifactId>
+                <version>${spring.boot-version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.camel.springboot</groupId>
+                <artifactId>camel-spring-boot-dependencies</artifactId>
+                <version>${project.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+
+        <!-- spring-boot -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter</artifactId>
+            <version>${spring.boot-version}</version>
+        </dependency>
+
+        <!-- camel -->
+        <dependency>
+            <groupId>org.apache.camel.springboot</groupId>
+            <artifactId>camel-spring-boot-starter</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.springboot</groupId>
+            <artifactId>camel-opentracing-starter</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.springboot</groupId>
+            <artifactId>camel-jetty-starter</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.springboot</groupId>
+            <artifactId>camel-http-starter</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+
+        <!-- CDI API -->
+        <dependency>
+            <groupId>javax.enterprise</groupId>
+            <artifactId>cdi-api</artifactId>
+            <version>${cdi-api-2.0-version}</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <!-- elastico -->
+        <dependency>
+            <groupId>co.elastic.apm</groupId>
+            <artifactId>apm-agent-attach</artifactId>
+            <version>1.18.0</version>
+        </dependency>
+        <dependency>
+            <groupId>co.elastic.apm</groupId>
+            <artifactId>apm-opentracing</artifactId>
+            <version>1.18.0</version>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>${spring-boot-version}</version>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/camel-example-spring-boot-apm-opentracing/src/main/java/sample/camel/CamelConfig.java b/camel-example-spring-boot-apm-opentracing/src/main/java/sample/camel/CamelConfig.java
new file mode 100644
index 0000000..6c5f875
--- /dev/null
+++ b/camel-example-spring-boot-apm-opentracing/src/main/java/sample/camel/CamelConfig.java
@@ -0,0 +1,18 @@
+package sample.camel;
+
+import co.elastic.apm.opentracing.ElasticApmTracer;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class CamelConfig {
+    @Bean
+    public ElasticApmTracer tracer() {
+        return new ElasticApmTracer();
+    }
+
+    @Bean
+    public CounterBean counterBean() {
+        return new CounterBean();
+    }
+}
diff --git a/camel-example-spring-boot-apm-opentracing/src/main/java/sample/camel/CounterBean.java b/camel-example-spring-boot-apm-opentracing/src/main/java/sample/camel/CounterBean.java
new file mode 100644
index 0000000..9c7dff4
--- /dev/null
+++ b/camel-example-spring-boot-apm-opentracing/src/main/java/sample/camel/CounterBean.java
@@ -0,0 +1,26 @@
+/*
+ * 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 sample.camel;
+
+public class CounterBean {
+
+    private int counter;
+
+    public String someMethod(String body) {
+        return "" + ++counter;
+    }
+}
diff --git a/camel-example-spring-boot-apm-opentracing/src/main/java/sample/camel/Service1Application.java b/camel-example-spring-boot-apm-opentracing/src/main/java/sample/camel/Service1Application.java
new file mode 100644
index 0000000..52c4f9c
--- /dev/null
+++ b/camel-example-spring-boot-apm-opentracing/src/main/java/sample/camel/Service1Application.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 sample.camel;
+
+import co.elastic.apm.attach.ElasticApmAttacher;
+import org.apache.camel.opentracing.starter.CamelOpenTracing;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * A Spring Boot application that starts the Camel OpenTracing application.
+ * <p/>
+ * Notice we use the `@CamelOpenTracing` annotation to enable Camel with OpenTracing.
+ */
+@SpringBootApplication
+@CamelOpenTracing
+public class Service1Application {
+    /**
+     * A main method to start this application.
+     */
+
+    public static void main(String[] args) {
+        ElasticApmAttacher.attach();
+        SpringApplication.run(Service1Application.class, args);
+    }
+
+
+}
diff --git a/camel-example-spring-boot-apm-opentracing/src/main/java/sample/camel/Service1Route.java b/camel-example-spring-boot-apm-opentracing/src/main/java/sample/camel/Service1Route.java
new file mode 100644
index 0000000..fbcb570
--- /dev/null
+++ b/camel-example-spring-boot-apm-opentracing/src/main/java/sample/camel/Service1Route.java
@@ -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.
+ */
+package sample.camel;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.springframework.stereotype.Component;
+
+@Component
+public class Service1Route extends RouteBuilder {
+
+    @Override
+    public void configure() throws Exception {
+         from("timer:trigger?exchangePattern=InOut&period=30000").streamCaching()
+            .bean("counterBean")
+            .log(" Client request: ${body}")
+            .to("http://localhost:9090/service1")
+            .log("Client response: ${body}");
+
+        from("jetty:http://0.0.0.0:9090/service1").routeId("service1").streamCaching()
+            .removeHeaders("CamelHttp*")
+            .log("Service1 request: ${body}")
+            .delay(simple("${random(1000,2000)}"))
+            .transform(simple("Service1-${body}"))
+            .log("Service1 response: ${body}");
+    }
+
+}
diff --git a/camel-example-spring-boot-apm-opentracing/src/main/resources/application.properties b/camel-example-spring-boot-apm-opentracing/src/main/resources/application.properties
new file mode 100644
index 0000000..e320a74
--- /dev/null
+++ b/camel-example-spring-boot-apm-opentracing/src/main/resources/application.properties
@@ -0,0 +1,26 @@
+## ---------------------------------------------------------------------------
+## 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 name of Camel
+camel.springboot.name=Service1
+camel.springboot.main-run-controller=true
+
+# the port number the service will use for accepting incoming HTTP requests
+service1.port=9090
+
+logging.level.org.apache.camel=DEBUG
+logging.level.opentracing.level = DEBUG