Explorar el Código

添加traceId代码

pull/144/head
wanjing hace 1 año
padre
commit
7b9c32a688
Se han modificado 2 ficheros con 26 adiciones y 0 borrados
  1. +6
    -0
      pom.xml
  2. +20
    -0
      src/main/java/com/tuoheng/gateway/filter/SkywalkingFilter.java

+ 6
- 0
pom.xml Ver fichero

@@ -99,6 +99,12 @@
<version>9.0.0</version>
</dependency>

<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-toolkit-webflux</artifactId>
<version>9.0.0</version>
</dependency>

</dependencies>

<!-- 构建环境变量 -->

+ 20
- 0
src/main/java/com/tuoheng/gateway/filter/SkywalkingFilter.java Ver fichero

@@ -0,0 +1,20 @@
package com.tuoheng.gateway.filter;

import org.apache.skywalking.apm.toolkit.trace.TraceContext;
import org.apache.skywalking.apm.toolkit.webflux.WebFluxSkyWalkingOperators;
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;

@Component
public class SkywalkingFilter implements GlobalFilter {

@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
String traceId = WebFluxSkyWalkingOperators.continueTracing(exchange, TraceContext::traceId);
exchange.getResponse().getHeaders().set("x-trace-id", traceId);
return chain.filter(exchange);
}
}

Cargando…
Cancelar
Guardar