Skip to content

Commit

Permalink
tag 2021.01.03 add rabbit & kafka simple case to current otel guides.…
Browse files Browse the repository at this point in the history
… committer:陈晨。

add kafka & rabbit simple case and update read me file contents.
  • Loading branch information
chenmudu committed Jan 3, 2021
1 parent 5c7cc08 commit a020be4
Show file tree
Hide file tree
Showing 21 changed files with 589 additions and 21 deletions.
48 changes: 29 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ java -javaagent:path/to/opentelemetry-javaagent-all.jar
```
2. 设置VmOptions,关于Exporter,otel默认为自己的OTLP Exporter,这里我们选择~~使用zipkin作为默认Exporter,其兼容jaeger的RestApi。使用Http方式上报至Jaeger的Collector中(~~也可以使用Otel-Collector~~)~~
```sh
// 省略此步骤,当你使用Otel-Collector的时候。
-Dotel.exporter=zipkin
```
3. 向Environment variable添加参数对:
```sh
OTEL_EXPORTER_ZIPKIN_SERVICE_NAME = jvm instance name
OTEL_RESOURCE_ATTRIBUTES=service.name=otel-simple-moudlename
```

4. 关于[Otel官方参数设置。](https://github.com/open-telemetry/opentelemetry-java-instrumentation#getting-started)
Expand Down Expand Up @@ -91,6 +92,8 @@ OTEL_RESOURCE_ATTRIBUTES=service.name=your service name
* [Open-Telemetry-Java 示例工程(基于 Spring Rdb 示例Rdb)](otel-simple-rdb)
* [Open-Telemetry-Java 示例工程(基于 Spring Async 示例Async)](otel-simple-async)
* [Open-Telemetry-Java 示例工程(基于 Spring Data 示例Data系列)](otel-simple-spring-data)
* [Open-Telemetry-Java 示例工程(基于 Spring Amqp 示例RabbitMq)](otel-simple-rabbit)
* [Open-Telemetry-Java 示例工程(基于 Spring Kafka 示例KafkaMq)](otel-simple-kafka)
* [Open-Telemetry-Java 示例工程(关于 Otel Collector 个人配置参考)](https://github.com/chenmudu/open-telemetry-java-guides/tree/master/config/otel-col-config.yaml)

#### 测试环境
Expand All @@ -117,24 +120,31 @@ OTEL_RESOURCE_ATTRIBUTES=service.name=your service name

#### 测试库及框架列表

| Library/Framework | Versions |Test Result |
|---------------------------|--------------------------------|--------------------------|
| Servlet | 4.0 |Y |
| WebMvc | 5.1.15 |Y |
| WebFlux | 5.1.15 |Y |
| RestTemplate(sync & async)| 5.1.15 |N/Y(错当rest temeplate为http client. 且不支持 async resttemplate.)|
| ApacheHttpClient(sync & async) | 4.5.12/4.1.4 |Y |
| HttpUrlConnection | java8 |Y |
| OkHttp(sync & async) | 3.6.0 |Y |
| JdbcMysqlConnector | 8.0.22 |Y |
| Spring-Data-Jdbc | 2.1.14(1.0.17.RELEASE) |Y |
| Spring-Data-Jpa | 2.1.14(2.1.17.RELEASE) |Y |
| Spring-Data-Rest | 2.1.14(3.1.17.RELEASE) |Y |
| Spring-Data-Mongo | 2.1.14(2.1.17.RELEASE) |Y |
| Spring-data-Redis | 2.1.14(2.1.17.RELEASE) |Y |
| Spring-data-Es | 2.1.14(3.1.17.RELEASE) |Y |
| Spring-data-Neo4j | 2.1.14(5.1.17.RELEASE) |N 还未测试 |
| ....... | ..... |Y |
| Library/Framework | Versions |Test Result |官方最低版本支持 |
|---------------------------|--------------------------------|--------------------------|-----------------|
| Servlet | 4.0 |Y | 2.2+ |
| WebMvc | 5.1.15 |Y | 3.1+ |
| WebFlux | 5.1.15 |Y | 5.0+ |
| RestTemplate(sync & async)| 5.1.15 |N/Y(错当rest temeplate为http client. 且不支持 async resttemplate.)故此推荐,如果生产使用RestTemplate,将其底层替换为HttpClient,包括连接池、其他参数等| 官方无支持|
| ApacheHttpClient(sync & async) | 4.5.12/4.1.4 |Y | 2.0+/1.9+ (not including 2.x yet)|
| HttpUrlConnection | java8 |Y | Java 7+ |
| OkHttp(sync & async) | 3.6.0 |Y | 3.0+ |
| JdbcMysqlConnector | 8.0.22 |Y ||
| Spring-Data-Jdbc | 2.1.14(1.0.17.RELEASE) |Y | 1.8+ |
| Spring-Data-Jpa | 2.1.14(2.1.17.RELEASE) |Y | 1.8+ |
| Spring-Data-Rest | 2.1.14(3.1.17.RELEASE) |Y | 1.8+ |
| Spring-Data-Mongo | 2.1.14(2.1.17.RELEASE) |Y | 1.8+ |
| Spring-data-Redis | 2.1.14(2.1.17.RELEASE) |Y | 1.8+ |
| lettuce-core | 5.1.8.RELEASE |Y | 4.0+ (not including 6.x yet) |
| Jedis-Client | 2.9.0 |Y | 1.4+ |
| Redisson-Client | 0.0.0 |N 还未测试 | 3.0+ |
| Spring-data-Es | 2.1.14(3.1.17.RELEASE) |Y | 1.8+ |
| Spring-data-Neo4j | 2.1.14(5.1.17.RELEASE) |N 还未测试 | 1.8+ |
| Spring-Rabbit | 2.1.14(2.1.14.RELEASE) |Y ||
| Rabbit-Client | 5.4.3 |Y | 2.7+ |
| Spring-Kafka | 2.1.13 |Y ||
| Kafka-Client | 2.0.1 |Y | 0.11+ |
| ....... | ..... |Y | |

#### 关于其他

Expand Down
13 changes: 13 additions & 0 deletions otel-simple-kafka/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### Open-Telemetry-Simple-Kafka 案例工程

> Open-Telemetry-Simple-Kafka 实际测试了 Spring Kafka 以及 Kafka Client。
##### 测试模块快速开始

1. 确保[Guides 案例工程下的步骤](../README.md)执行完毕。

2. 启动此模块[otel-simple-kafka](https://github.com/chenmudu/open-telemetry-java-guides/tree/master/otel-simple-kafka/src/main/java/org/chenmudu/otel/kafka)下的 KafkaMqMvcRunMain .

3. 访问http://localhost:10008/kafkamq。

4. Copy Console 中的 TraceId访问 http://localhost:16686/ 即可观测结果。
31 changes: 31 additions & 0 deletions otel-simple-kafka/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>open-telemetry-java-guides</artifactId>
<groupId>org.chenmudu.otel</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>otel-simple-kafka</artifactId>

<dependencies>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* MIT License
* <p>
* Copyright (c) 2020 chenmudu (陈晨)
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/
package org.chenmudu.otel.kafka;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
*
* @author [email protected] 2020/01/03 23:06
*/
@SpringBootApplication
public class KafkaMqRunMain {

public static void main(String[] args) {
SpringApplication.run(KafkaMqRunMain.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* MIT License
* <p>
* Copyright (c) 2020 chenmudu (陈晨)
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/
package org.chenmudu.otel.kafka.common;

/**
*
* @author [email protected] 2021/1/3 16:01
*/
public class CommonConstans {

public static final String TOPIC_NAME = "otel-test-topic";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* MIT License
* <p>
* Copyright (c) 2020 chenmudu (陈晨)
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/
package org.chenmudu.otel.kafka.consumer;

import lombok.extern.slf4j.Slf4j;
import org.chenmudu.otel.kafka.common.CommonConstans;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
*
* @author [email protected] 2021/1/3 16:05
*/
@Slf4j
@Component
public class KafkaMqConsume {

/**
* io.opentelemetry.auto.kafka-clients
* @param content str msg.
*/
@KafkaListener(topics = CommonConstans.TOPIC_NAME)
public void processMessage(String content) {
//consume message.
log.info("KafkaMqConsume processMessage content msg : {}", content);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* MIT License
* <p>
* Copyright (c) 2020 chenmudu (陈晨)
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/
package org.chenmudu.otel.kafka.controller;

import lombok.extern.slf4j.Slf4j;
import org.chenmudu.otel.kafka.producer.KafkaMqProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
*
* @author [email protected] 2021/1/3 14:57
*/
@Slf4j
@RestController
public class OtelTestKafkaController {

@Autowired
private KafkaMqProducer kafkaMqProducer;

@GetMapping("kafkamq")
public String testKafkaMq() {
log.info("OtelTestKafkaController testKafkaMq started!");
kafkaMqProducer.sendMessage();
return "hi,otel!";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* MIT License
* <p>
* Copyright (c) 2020 chenmudu (陈晨)
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/
package org.chenmudu.otel.kafka.producer;

import org.chenmudu.otel.kafka.common.CommonConstans;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

/**
*
* @author [email protected] 2021/1/3 16:04
*/
@Component
public class KafkaMqProducer {

@Autowired
private KafkaTemplate template;

/**
* io.opentelemetry.auto.kafka-clients-0.11
*/
public void sendMessage() {
template.send(CommonConstans.TOPIC_NAME, "hi, sofa tracer!");
}
}
7 changes: 7 additions & 0 deletions otel-simple-kafka/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
server.port=10008

spring.kafka.producer.bootstrap-servers=192.168.2.6:9092,192.168.2.6:9093
spring.kafka.consumer.group-id=data-otel-test
spring.kafka.consumer.bootstrap-servers=192.168.2.6:9092,192.168.2.6:9093
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer
15 changes: 15 additions & 0 deletions otel-simple-kafka/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<configuration>
<jmxConfigurator/>
<property name="charset" value="UTF-8" />
<property name="pattern"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%-5level] - [%X{traceId},%X{spanId}]- %logger{30}.%method:%line %msg%n" />

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${pattern}</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
13 changes: 13 additions & 0 deletions otel-simple-rabbit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### Open-Telemetry-Simple-Rabbit 案例工程

> Open-Telemetry-Simple-Rabbit 实际测试了 Spring Amqp 以及 Rabbit Client。
##### 测试模块快速开始

1. 确保[Guides 案例工程下的步骤](../README.md)执行完毕。

2. 启动此模块[otel-simple-rabbit](https://github.com/chenmudu/open-telemetry-java-guides/tree/master/otel-simple-rabbit/src/main/java/org/chenmudu/otel/rabbit)下的 RabbitMqMvcRunMain .

3. 访问http://localhost:10007/rabbitmq。

4. Copy Console 中的 TraceId访问 http://localhost:16686/ 即可观测结果。
32 changes: 32 additions & 0 deletions otel-simple-rabbit/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>open-telemetry-java-guides</artifactId>
<groupId>org.chenmudu.otel</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>otel-simple-rabbitmq</artifactId>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>

</project>
Loading

0 comments on commit a020be4

Please sign in to comment.