mirror of
https://gitee.com/yudaocode/SpringBoot-Labs.git
synced 2026-09-06 07:17:26 +08:00
增加 skywalking 示例 - trace annotations
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
<artifactId>lab-39-logback</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- SkyWalking 对 Logback 的集成 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.skywalking</groupId>
|
||||
<artifactId>apm-toolkit-logback-1.x</artifactId>
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
|
||||
|
||||
<!-- 控制台 Appender -->
|
||||
<property name="CONSOLE_LOG_X_PATTERN" value="%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %tid %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>
|
||||
<property name="CONSOLE_LOG_PATTERN" value="%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %tid %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<!-- 日志的格式化 -->
|
||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
||||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
|
||||
<Pattern>${CONSOLE_LOG_X_PATTERN}</Pattern>
|
||||
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
|
||||
</layout>
|
||||
</encoder>
|
||||
</appender>
|
||||
@@ -31,9 +31,10 @@
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
</rollingPolicy>
|
||||
<!-- 日志的格式化 -->
|
||||
<encoder>
|
||||
<pattern>${FILE_LOG_PATTERN}</pattern>
|
||||
<charset>utf8</charset>
|
||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
||||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
|
||||
<Pattern>${FILE_LOG_PATTERN}</Pattern>
|
||||
</layout>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
|
||||
31
lab-39/lab-39-trace-annotations/pom.xml
Normal file
31
lab-39/lab-39-trace-annotations/pom.xml
Normal file
@@ -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>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.2.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<artifactId>lab-39-trace-annotations</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- SkyWalking 工具类 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.skywalking</groupId>
|
||||
<artifactId>apm-toolkit-trace</artifactId>
|
||||
<version>6.6.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对 SpringMVC 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package cn.iocoder.springboot.lab39.skywalkingdemo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class TraceAnnotationsApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(TraceAnnotationsApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.iocoder.springboot.lab39.skywalkingdemo.controller;
|
||||
|
||||
import org.apache.skywalking.apm.toolkit.trace.ActiveSpan;
|
||||
import org.apache.skywalking.apm.toolkit.trace.Trace;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/demo")
|
||||
public class DemoController {
|
||||
|
||||
@GetMapping("/trace_annotations")
|
||||
@Trace(operationName = "trace_annotations")
|
||||
public String echo() {
|
||||
// 自定义 SkyWalking Span
|
||||
ActiveSpan.tag("mp", "芋道源码");
|
||||
|
||||
// 返回
|
||||
return "trace_annotations";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
server:
|
||||
port: 8079
|
||||
@@ -24,6 +24,7 @@
|
||||
<module>lab-39-rabbitmq-demo</module>
|
||||
<module>lab-39-activemq</module>
|
||||
<module>lab-39-logback</module>
|
||||
<module>lab-39-trace-annotations</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
||||
Reference in New Issue
Block a user