Skip to content

Commit

Permalink
add config for web mvc sample case.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenmudu committed Jul 11, 2024
1 parent 6ee9b91 commit 5c4584f
Show file tree
Hide file tree
Showing 17 changed files with 929 additions and 210 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ velocity.log
logs
.m2
.mvn/
*.jar

# gradle related ignore in sub directories
.gradle
Expand Down
295 changes: 295 additions & 0 deletions otel-simple-kafka/Formatter.xml

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions otel-simple-kafka/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
</dependency>

<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-instrumentation-annotations</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
*/
public class CommonConstans {

public static final String TOPIC_NAME = "otel-test-topic";
public static final String TOPIC_NAME = "test-topic";
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.chenmudu.otel.kafka.consumer;

import io.opentelemetry.instrumentation.annotations.SpanAttribute;
import io.opentelemetry.instrumentation.annotations.WithSpan;
import lombok.extern.slf4j.Slf4j;
import org.chenmudu.otel.kafka.common.CommonConstans;
import org.springframework.kafka.annotation.KafkaListener;
Expand All @@ -33,8 +35,53 @@ public class KafkaMqConsume {
* @param content str msg.
*/
@KafkaListener(topics = CommonConstans.TOPIC_NAME)
public void processMessage(String content) {
@WithSpan
// 随便
public void processMessage(@SpanAttribute("bizReciveParam") String content) {
//consume message.
log.info("KafkaMqConsume processMessage content msg : {}", content);
// biz core1
test21();
//biz core2
test22();
}

@WithSpan
private void test21() {
test211();
test212();
test213();
}

@WithSpan
private void test211() {

}

@WithSpan
private void test212() {

}

@WithSpan
private void test213() {

}

@WithSpan
private void test22() {
test221();
test222();
}

@WithSpan
private void test221() {

}

@WithSpan
private void test222() {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.chenmudu.otel.kafka.producer;

import io.opentelemetry.instrumentation.annotations.SpanAttribute;
import io.opentelemetry.instrumentation.annotations.WithSpan;
import org.chenmudu.otel.kafka.common.CommonConstans;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
Expand All @@ -34,6 +36,14 @@ public class KafkaMqProducer {
* io.opentelemetry.auto.kafka-clients-0.11
*/
public void sendMessage() {
template.send(CommonConstans.TOPIC_NAME, "hi, sofa tracer!");
final String msg = "hi, tracer";
template.send(CommonConstans.TOPIC_NAME, msg);

sayHi(msg);
}

@WithSpan
private void sayHi(@SpanAttribute("bizArg0001") final String bizArg1) {

}
}
4 changes: 2 additions & 2 deletions otel-simple-kafka/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
server.port=10008

spring.kafka.producer.bootstrap-servers=192.168.2.6:9092,192.168.2.6:9093
spring.kafka.producer.bootstrap-servers=192.168.129.166:9092,192.168.129.167:9092,192.168.129.201:9092
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.bootstrap-servers=192.168.129.166:9092,192.168.129.167:9092,192.168.129.201:9092
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer
2 changes: 1 addition & 1 deletion otel-simple-kafka/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<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" />
value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%-5level] - trace_id=%mdc{trace_id} span_id=%mdc{span_id} trace_flags=%mdc{trace_flags} %5p - %logger{30}.%method:%line %msg%n" />

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
Expand Down
6 changes: 6 additions & 0 deletions otel-simple-webmvc/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM openjdk:11
VOLUME /tmp
RUN echo "Asia/Shanghai" > /etc/timezone
COPY target/otel-simple-webmvc-0.0.1-SNAPSHOT.jar /usr/local/agent/app.jar
COPY opentelemetry-javaagent.jar /usr/local/agent/opentelemetry-javaagent.jar
ENTRYPOINT [ "sh", "-c", "java -javaagent:/usr/local/agent/opentelemetry-javaagent.jar -Dotel.resource.attributes=service.name=otel-simple-webmvc -Dotel.logs.exporter=otlp -Dotel.exporter.otlp.endpoint=http://localhost:4317 -jar /usr/local/agent/app.jar" ]
Loading

0 comments on commit 5c4584f

Please sign in to comment.