Istio分布式跟踪仅显示1个跨度

时间:2018-02-18 22:13:48

标签: kubernetes zipkin istio

我正在使用Zipkin关注this指南。 我有3个微服务,A -> B -> C,我正在将标头从A传播到B,从B传播到C. 但在Zipkin仪表板中,我只看到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"
]

我可以看到B x-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")
    }

2 个答案:

答案 0 :(得分: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 /分布式跟踪问题;-)

答案 1 :(得分:0)

可以在application.yml中配置

x-b3-parentspanid(https://github.com/openzipkin/b3-propagation)的b3传播,方法是添加:

opentracing:
  jaeger:
    enable-b3-propagation: true