and*_*rew 11 zipkin kubernetes istio
我正在按照这个指南,使用Zipkin.我有3个微服务A -> B -> C,我将标头从A传播到B,从B传播到C.但在Zipkin仪表板中,我只看到条目,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"
]
Run Code Online (Sandbox Code Playgroud)
我可以看到在B中x-b3-parentspanid是空的,我猜这是错的,但另一个正在工作我想......怎么可能?
编辑:添加代码片段以显示标头传播
A -> B 传播:
app.post("/job", (req, res) => postJob(req.body, req.headers).then((response) => res.send(response)))
Run Code Online (Sandbox Code Playgroud)
...
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])
})
Run Code Online (Sandbox Code Playgroud)
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
)
)
Run Code Online (Sandbox Code Playgroud)
...
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")
}
Run Code Online (Sandbox Code Playgroud)
小智 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;
}, {})
Run Code Online (Sandbox Code Playgroud)
我很确定这不是 istio / 分布式跟踪问题 ;-)
| 归档时间: |
|
| 查看次数: |
441 次 |
| 最近记录: |