fix: 修复Gateway网关使用Webflux,导致skywalking日志打印traceId失效. #262
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
解决方案:
使用Webflux的插件以及包工具,手动获取TraceId后设置到MDC.(WebFluxSkyWalkingTraceContext.traceId(exchange))
解决步骤:
1、首先下载Skywalking Agent后,查看Plugin文件夹下是否存在Weblux以及Gateway相关的jar包,如果不存在需要从option-plugin文件夹进行拷贝。
2、引入依赖 apm-toolkit-webflux,与Skywalking版本一致
3、编写工具类或者直接通过方法获取
4、编写过滤器:gateway.filter 下的GlobalFilter,设置优先顺序执行 (不能是WebFliter)。
5、Gateway异常处理需要重新获取
注意:本次修复测试skywalking的版本依赖于9.4.0,而项目中版本为9.5.0。每个版本的Agent可能存在不同,请使用时注意版本问题。