代码之家  ›  专栏  ›  技术社区  ›  Zoltan Altfatter

correlationId已传播到spring sleuth 1.x

  •  0
  • Zoltan Altfatter  · 技术社区  · 6 年前

    我有以下设置:

    代理(P)--HTTP-->Spring Boot 2应用程序(X)--HTTP-->Spring Boot 1应用程序(Y)

    requestId 作为我需要包含在X和Y的日志中的HTTP报头。

    spring: sleuth: propagation-keys: requestId

    CurrentTraceContext 实施灵感来自 Slf4jCurrentTraceContext 我加上

    MDC.put("requestId", ExtraFieldPropagation.get(currentSpan, "requestId"));

    %d{yy-MM-dd E HH:mm:ss.SSS} %5p [component=${springAppName},requestId=%X{requestId:-}] %m%n"

    但现在我需要传播 请求ID 同样适用于Y应用程序。

    不幸的是,我不能利用SpringCloudSleuth2.0中引入的好东西(比如BraveLibrary中的TraceContext),因为这是一个SpringBoot1.x应用程序。

    想知道有什么选择吗?

    我在考虑延长期限 Slf4jSpanLogger DefaultTracer 但不知道如何得到 请求ID SpanLogger中没有TraceContext。

    1 回复  |  直到 6 年前
        1
  •  0
  •   marc_s    4 年前

    requestId 必须在标题里。您必须修改为boot1.x解析HTTP头的当前逻辑,并从头中检索该值并将其放入范围中。

    不过,最简单的方法是在baggage cause baggage为boot1.x开箱即用时传播该值。如果我们看到 baggage- 带前缀的头文件,sleuth1.3.x将自动传播它。记得在boot2.0中把行李列为白名单。