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
pom 复制代码
        <dependency>
            <groupId>org.apache.skywalking</groupId>
            <artifactId>apm-toolkit-trace</artifactId>
            <version>8.14.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.skywalking</groupId>
            <artifactId>apm-toolkit-webflux</artifactId>
            <version>8.14.0</version>
        </dependency>
  1. 配置链路id
java 复制代码
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);
    }
}
相关推荐
RDCJM26 分钟前
Spring Boot spring.factories文件详细说明
spring boot·后端·spring
随风,奔跑1 小时前
Spring Cloud Alibaba(四)---Spring Cloud Gateway
后端·spring·gateway
uElY ITER4 小时前
基于Spring Boot 3 + Spring Security6 + JWT + Redis实现登录、token身份认证
spring boot·redis·spring
jiayong235 小时前
Hermes Agent 的 Skills、Plugins、Gateway 深度解析
ai·gateway·agent·hermes agent·hermes
smileNicky5 小时前
Spring AI系列之集成 Milvus 构建 RAG 智能问答系统
人工智能·spring·milvus
LSL666_6 小时前
快速Spring Cloud+ELK+AOP搭建一个简单的项目
spring·elk·spring cloud
smileNicky6 小时前
Spring AI系列之基于MCP协议实现天气预报工具插件
人工智能·spring boot·spring
杰克尼6 小时前
天机学堂项目总结(day11~day12)
spring·spring cloud
云烟成雨TD6 小时前
Spring AI Alibaba 1.x 系列【36】FlowAgent 和 BaseAgent 抽象类
java·人工智能·spring
鬼蛟6 小时前
Gateway
gateway