springboot skywalking tranceId

原创
2020/09/19 17:53
阅读数 3.7K
<!-- https://mvnrepository.com/artifact/org.apache.skywalking/apm-toolkit-trace -->
<!-- 该引用用于代码获取tranceId -->
<dependency>
    <groupId>org.apache.skywalking</groupId>
    <artifactId>apm-toolkit-trace</artifactId>
    <version>8.1.0</version>
    <scope>provided</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.skywalking/apm-toolkit-logback-1.x -->
<!-- 该引用用于logback获取tranceId,也就是tid -->
<dependency>
    <groupId>org.apache.skywalking</groupId>
    <artifactId>apm-toolkit-logback-1.x</artifactId>
    <version>8.1.0</version>
</dependency>

 

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <jmxConfigurator/>
    <property name="log_pattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS Z} [%tid] [%thread] %-5level %logger{50}:%line %msg%n"></property>
    <appender name="consoleLog" 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>${log_pattern}</pattern>
            </layout>
        </encoder>
    </appender>
    <appender name="fileLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <!--编码-->
        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <!--展示格式-->
            <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
                <pattern>${log_pattern}</pattern>
            </layout>
        </encoder>
        <!--滚动策略 -->
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <!--路径 -->
            <fileNamePattern>log/%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <!--超过100M分文件-->
            <maxFileSize>100MB</maxFileSize>
        </rollingPolicy>
    </appender>
    <!--指定最基础的日志输出级别-->
    <root level="info">
        <appender-ref ref="consoleLog"/>
        <appender-ref ref="fileLog"/>
    </root>
</configuration>

代码获取TranceId:

String traceId = TraceContext.traceId();

 

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部