我正在使用 Zipkin 遵循本指南。我涉及 3 个微服务A -> B -> C,我正在将标头从 A 传播到 B,从 B 传播到 C。但是在 Zipkin 仪表板中,我只看到 and 的条目,A -> B而B -> 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")
}