• skywalking springgateway 全链路


    环境

    spring-cloud-gateway 3.1.0

    springGateway整合skywalking

    skywalking 默认是不整合springGateway的,需要手动拷贝skywalking optional-plugins下的
    apm-spring-cloud-gateway-N.x-plugin-8.13.0.jar

    apm-spring-webflux-5.x-plugin-8.13.0.jar
    架包拷贝到plugins目录下
    gateway架包的选择根据springgateway的版本进行选择
    在这里插入图片描述

    配置请求标识

    经过上一步配置的请求会存在调用链路,但是链路仅到网关,不会到后续服务

    处理方法

    1. 服务中引入架包
      pom
            
                org.apache.skywalking
                apm-toolkit-trace
                8.14.0
            
    
            
                org.apache.skywalking
                apm-toolkit-webflux
                8.14.0
            
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    1. 配置链路id
    package com.kittlen.gateway.filter;
    
    import org.apache.skywalking.apm.toolkit.trace.TraceContext;
    import org.apache.skywalking.apm.toolkit.webflux.WebFluxSkyWalkingOperators;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
    import org.springframework.cloud.gateway.filter.GatewayFilterChain;
    import org.springframework.cloud.gateway.filter.GlobalFilter;
    import org.springframework.stereotype.Component;
    import org.springframework.web.server.ServerWebExchange;
    import reactor.core.publisher.Mono;
    
    /**
     * @author kittlen
     * @version 1.0
     * @date 2023/9/5 13:41
     * skywalking 全链路配置
     */
    @Component
    public class PutTraceIdIntoResponseHeaderFilter implements GlobalFilter {
    
        String xTraceIdKey = "x-trace-id";
    
        @Override
        public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
            String traceId = WebFluxSkyWalkingOperators.continueTracing(exchange, TraceContext::traceId);
            exchange.getResponse().getHeaders().set(xTraceIdKey, traceId);
            return chain.filter(exchange);
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
  • 相关阅读:
    打怪兽问题
    用大模型实现PPT可视化几种思路
    服务器操作系统到底用win还是linux好?
    u盘被格式化了文件还可以恢复吗?
    1.3.2有理数减法(第一课时)作业设计
    程序员 男方净身出户离婚协议书
    java面试题
    记录-2023/11/15
    聚苯乙烯/Fe3O4纳米复合材料PS@Fe3O4|硫化锌-四氧化三铁(ZnS/Fe3O40纳米复合物(齐岳)
    Linux:GNU/Linux、BSD、自由软件、GPL、glibc词义说明
  • 原文地址:https://blog.csdn.net/weixin_44728369/article/details/132691850