Browse Source

Merge branch 'develop' of gitadmin/tuoheng_gateway into release

pull/145/head
wanjing 1 year ago
parent
commit
39c0354987
2 changed files with 26 additions and 0 deletions
  1. +6
    -0
      pom.xml
  2. +20
    -0
      src/main/java/com/tuoheng/gateway/filter/SkywalkingFilter.java

+ 6
- 0
pom.xml View File

@@ -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 View File

@@ -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);
}
}

Loading…
Cancel
Save