11

我正在使用 Zipkin 遵循指南。我涉及 3 个微服务A -> B -> C,我正在将标头从 A 传播到 B,从 B 传播到 C。但是在 Zipkin 仪表板中,我只看到 and 的条目,A -> BB -> C不是A -> B -> C

这些是标题:

[
    "x-request-id",
    "x-b3-traceid",
    "x-b3-spanid",
    "x-b3-parentspanid",
    "x-b3-sampled",
    "x-b3-flags",
    "x-ot-span-context"
]

我可以看到在 Bx-b3-parentspanid中是空的,我想这是错误的,但我认为另一个正在工作......这怎么可能?

编辑:添加代码片段以显示标头传播

A -> B传播:

app.post("/job", (req, res) => postJob(req.body, req.headers).then((response) => res.send(response)))

...

const postJob = (job, headers) => rp({
    method: "POST",
    uri: `${API_ENDPOINT}/api/job`,
    json: true,
    body: job,
    headers: Object.keys(headers).filter((key) => TRACING_HEADERS.includes(key)).map((key) => headers[key])
})

B -> C传播:

@PostMapping("/api/job")
@ResponseBody
fun publish(
    @RequestBody job: Job,
    @RequestHeader("x-request-id") xreq: String?,
    @RequestHeader("x-b3-traceid") xtraceid: String?,
    @RequestHeader("x-b3-spanid") xspanid: String?,
    @RequestHeader("x-b3-parentspanid") xparentspanid: String?,
    @RequestHeader("x-b3-sampled") xsampled: String?,
    @RequestHeader("x-b3-flags") xflags: String?,
    @RequestHeader("x-ot-span-context") xotspan: String?
): JobResponse = jobsService.publishJob(
    job, mapOf(
        "x-request-id" to xreq,
        "x-b3-traceid" to xtraceid,
        "x-b3-spanid" to xspanid,
        "x-b3-parentspanid" to xparentspanid,
        "x-b3-sampled" to xsampled,
        "x-b3-flags" to xflags,
        "x-ot-span-context" to xotspan
    )
)

...

fun publishJob(job: Job, headers: Map<String, String?>): JobResponse {
        val enabled = restTemplate.exchange(
            "${gatekeeperConfiguration.endpoint}/",
            HttpMethod.GET,
            HttpEntity(headers),
            EnabledResponse::class.java
        ).body
        if (!enabled!!.isEnabled) // TODO we intentionally want this to crash if body is null
            return JobResponse(JobRequestStatus.REJECTED)

        return if (this.queue.publish(job)) JobResponse(JobRequestStatus.OK)
        else throw RuntimeException("I don't know what to do, yet")
    }
4

2 回答 2

0

x-b3-parentspanid ( https://github.com/openzipkin/b3-propagation ) 的 b3-propagation 可以通过添加在 application.yml 中进行配置:

opentracing:
  jaeger:
    enable-b3-propagation: true
于 2020-12-04T17:17:32.667 回答
0

Object.keys(headers).filter((key) => TRACING_HEADERS.includes(key)).map((key) => headers[key])返回一个数组

你想要的是:

Object.keys(headers)                                                                                                                                                                              
  .filter(key => TRACING_HEADERS.includes(key))                                                                                                                                                                    
  .reduce((obj, key) => {                                                                                                                                                                                          
    obj[key] = headers[key];                                                                                                                                                                                       
    return obj;                                                                                                                                                                                                    
  }, {})

我很确定这不是 istio / 分布式跟踪问题 ;-)

于 2019-12-10T04:31:59.737 回答